From 2322641be19e928c1dae0e2536f43f154d5c73a6 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Thu, 2 Sep 2021 13:31:46 +0100 Subject: [PATCH 0001/1120] 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 0000000000..1f41835c04 --- /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 0000000000..eb4d4de89a --- /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 0000000000..fde7c94d9b --- /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 0000000000..e7998a203a --- /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 0000000000..690ae3a754 --- /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 0000000000..e69de29bb2 diff --git a/testlib/src/main/resources/gherkin/emptyBefore.feature b/testlib/src/main/resources/gherkin/emptyBefore.feature new file mode 100644 index 0000000000..8b13789179 --- /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 0000000000..e69de29bb2 diff --git a/testlib/src/main/resources/gherkin/invalidGherkinBefore.feature b/testlib/src/main/resources/gherkin/invalidGherkinBefore.feature new file mode 100644 index 0000000000..665bf227ca --- /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 0000000000..44467df367 --- /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 0000000000..aa94821bbc --- /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 0000000000..cbad451b45 --- /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 0000000000..a474cf1418 --- /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 0000000000..e69de29bb2 diff --git a/testlib/src/main/resources/gherkin/notGherkinBefore.feature b/testlib/src/main/resources/gherkin/notGherkinBefore.feature new file mode 100644 index 0000000000..517db4bd1e --- /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 0000000000..bba6b044ac --- /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 0000000000..bba6b044ac --- /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 0000000000..1210bf21dd --- /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 0002/1120] 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 28f8f85b54..92d8b1553f 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 0000000000..59ff16805f --- /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 7959bdc71d..ba42d75958 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 0000000000..4b1fdc7efe --- /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 0003/1120] 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 ea30ad2eaf..ae96f58b94 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 162d8fbe6a..677e9d9d33 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 0be284494f88b514699a45a948612a19be33461f Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Mon, 15 Nov 2021 08:31:38 +0100 Subject: [PATCH 0004/1120] Upgrade Message: Print current version --- lib/src/main/java/com/diffplug/spotless/Jvm.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Jvm.java b/lib/src/main/java/com/diffplug/spotless/Jvm.java index e22e0c6339..858d9d8d6c 100644 --- a/lib/src/main/java/com/diffplug/spotless/Jvm.java +++ b/lib/src/main/java/com/diffplug/spotless/Jvm.java @@ -198,8 +198,9 @@ private String buildUpgradeFormatterMessage(V fmtVersion) { StringBuilder builder = new StringBuilder(); V recommendedFmtVersionOrNull = getRecommendedFormatterVersion(); if (null != recommendedFmtVersionOrNull && (fmtVersionComparator.compare(fmtVersion, recommendedFmtVersionOrNull) < 0)) { - builder.append(String.format("You are not using latest version on JVM %d+.%n", getRequiredJvmVersion(recommendedFmtVersionOrNull))); - builder.append(String.format("Try to upgrade to %s %s, which may have fixed this problem.", fmtName, getRecommendedFormatterVersion())); + builder.append(String.format("%s %s is currently being used, but outdated.%n", fmtName, fmtVersion)); + builder.append(String.format("%s %s is the recommended version, which may have fixed this problem.%n", fmtName, recommendedFmtVersionOrNull)); + builder.append(String.format("%s %s requires JVM %d+.", fmtName, recommendedFmtVersionOrNull, getRequiredJvmVersion(recommendedFmtVersionOrNull))); } else { V higherFormatterVersionOrNull = fmt2jvmVersion.higherKey(fmtVersion); if (null != higherFormatterVersionOrNull) { From 7da4090540a0b7d1639e7eda47c9b003367dfe34 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 19:38:48 -0400 Subject: [PATCH 0005/1120] implement buf format gradle step --- README.md | 1 + .../diffplug/spotless/protobuf/BufStep.java | 99 +++++++++++++++++++ .../spotless/protobuf/ProtobufConstants.java | 20 ++++ plugin-gradle/README.md | 18 ++++ .../gradle/spotless/ProtobufExtension.java | 76 ++++++++++++++ .../gradle/spotless/SpotlessExtension.java | 6 ++ .../gradle/spotless/BufIntegrationTest.java | 55 +++++++++++ .../src/main/resources/protobuf/buf/buf.proto | 5 + .../resources/protobuf/buf/buf.proto.clean | 5 + .../main/resources/protobuf/buf/license.proto | 7 ++ .../protobuf/buf/license.proto.clean | 8 ++ .../spotless/protobuf/BufStepTest.java | 31 ++++++ 12 files changed, 331 insertions(+) create mode 100644 lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java create mode 100644 lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java create mode 100644 testlib/src/main/resources/protobuf/buf/buf.proto create mode 100644 testlib/src/main/resources/protobuf/buf/buf.proto.clean create mode 100644 testlib/src/main/resources/protobuf/buf/license.proto create mode 100644 testlib/src/main/resources/protobuf/buf/license.proto.clean create mode 100644 testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java diff --git a/README.md b/README.md index f95ea7a7ca..fbdf738104 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`pom.SortPomStepStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStepStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`protobuf.BufStep`](lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java new file mode 100644 index 0000000000..601a47f193 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java @@ -0,0 +1,99 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.protobuf; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import javax.annotation.Nullable; + +import com.diffplug.spotless.ForeignExe; +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ProcessRunner; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +public class BufStep { + public static String name() { + return "buf"; + } + + public static String defaultVersion() { + return "1.4.0"; + } + + private final String version; + private final @Nullable String pathToExe; + + private BufStep(String version, @Nullable String pathToExe) { + this.version = version; + this.pathToExe = pathToExe; + } + + public static BufStep withVersion(String version) { + return new BufStep(version, null); + } + + public BufStep withPathToExe(String pathToExe) { + return new BufStep(version, pathToExe); + } + + public FormatterStep create() { + return FormatterStep.createLazy(name(), this::createState, State::toFunc); + } + + private State createState() throws IOException, InterruptedException { + String instructions = "https://docs.buf.build/installation"; + String exeAbsPath = ForeignExe.nameAndVersion("buf", version) + .pathToExe(pathToExe) + .versionRegex(Pattern.compile("(\\S*)")) + .fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}") + .confirmVersionAndGetAbsolutePath(); + return new State(this, exeAbsPath); + } + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + static class State implements Serializable { + private static final long serialVersionUID = -1825662356883926318L; + // used for up-to-date checks and caching + final String version; + // used for executing + final transient List args; + + State(BufStep step, String exeAbsPath) { + this.version = step.version; + this.args = Arrays.asList(exeAbsPath, "format"); + } + + String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException { + String[] processArgs = args.toArray(new String[args.size() + 1]); + // add an argument to the end + processArgs[args.size()] = file.getAbsolutePath(); + return runner.exec(input.getBytes(StandardCharsets.UTF_8), processArgs).assertExitZero(StandardCharsets.UTF_8); + } + + FormatterFunc.Closeable toFunc() { + ProcessRunner runner = new ProcessRunner(); + return FormatterFunc.Closeable.of(runner, this::format); + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java b/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java new file mode 100644 index 0000000000..b24df7cc38 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java @@ -0,0 +1,20 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.protobuf; + +public class ProtobufConstants { + public static final String LICENSE_HEADER_DELIMITER = "syntax"; +} diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 48572377b8..7bf684923c 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -65,6 +65,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier)) - [Scala](#scala) ([scalafmt](#scalafmt)) - [C/C++](#cc) ([clang-format](#clang-format), [eclipse cdt](#eclipse-cdt)) + - [Protobuf](#protobuf) ([buf](#buf), [clang-format](#clang-format)) - [Python](#python) ([black](#black)) - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) @@ -457,6 +458,23 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') +## Protobuf + +### buf + +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) + +```gradle +spotless { + protobuf { + // by default the target is every '.proto' file in the project + buf() + + licenseHeader '/* (C) $YEAR */' // or licenseHeaderFile + } +} +``` + ## FreshMark `com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java new file mode 100644 index 0000000000..44565e8073 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -0,0 +1,76 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import static com.diffplug.spotless.protobuf.ProtobufConstants.LICENSE_HEADER_DELIMITER; + +import java.util.Objects; + +import javax.inject.Inject; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.protobuf.BufStep; + +public class ProtobufExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { + static final String NAME = "protobuf"; + + @Inject + public ProtobufExtension(SpotlessExtension spotless) { + super(spotless); + } + + @Override + public LicenseHeaderConfig licenseHeader(String licenseHeader) { + return licenseHeader(licenseHeader, LICENSE_HEADER_DELIMITER); + } + + @Override + public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { + return licenseHeaderFile(licenseHeaderFile, LICENSE_HEADER_DELIMITER); + } + + /** Adds the specified version of ktlint. */ + public BufFormatExtension buf(String version) { + Objects.requireNonNull(version); + return new BufFormatExtension(version); + } + + public BufFormatExtension buf() { + return buf(BufStep.defaultVersion()); + } + + public class BufFormatExtension { + private final String version; + + BufFormatExtension(String version) { + this.version = version; + addStep(createStep()); + } + + private FormatterStep createStep() { + return BufStep.withVersion(version).create(); + } + } + + /** If the user hasn't specified files, assume all protobuf files should be checked. */ + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + target = parseTarget("**/*.proto"); + } + super.setupTask(task); + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java index 57aa3b2d83..8aa9d2e619 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java @@ -188,6 +188,12 @@ public void json(Action closure) { format(JsonExtension.NAME, JsonExtension.class, closure); } + /** Configures the special protobuf-specific extension. */ + public void protobuf(Action closure) { + requireNonNull(closure); + format(ProtobufExtension.NAME, ProtobufExtension.class, closure); + } + /** Configures a custom extension. */ public void format(String name, Action closure) { requireNonNull(name, "name"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java new file mode 100644 index 0000000000..03f45a46c8 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +class BufIntegrationTest extends GradleIntegrationHarness { + @Test + void buf() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " protobuf {", + " buf()", + " }", + "}"); + setFile("buf.proto").toResource("protobuf/buf/buf.proto"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("buf.proto").sameAsResource("protobuf/buf/buf.proto.clean"); + } + + @Test + void bufWithLicense() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " protobuf {", + " buf()", + " licenseHeader '/* (C) 2022 */'", + " }", + "}"); + setFile("license.proto").toResource("protobuf/buf/license.proto"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("license.proto").sameAsResource("protobuf/buf/license.proto.clean"); + } +} diff --git a/testlib/src/main/resources/protobuf/buf/buf.proto b/testlib/src/main/resources/protobuf/buf/buf.proto new file mode 100644 index 0000000000..a90d58bbd0 --- /dev/null +++ b/testlib/src/main/resources/protobuf/buf/buf.proto @@ -0,0 +1,5 @@ +message Testing { + required string field1 = 1; + required int32 field2 = 2; + optional string field3 = 3; +} \ No newline at end of file diff --git a/testlib/src/main/resources/protobuf/buf/buf.proto.clean b/testlib/src/main/resources/protobuf/buf/buf.proto.clean new file mode 100644 index 0000000000..faa8d91f24 --- /dev/null +++ b/testlib/src/main/resources/protobuf/buf/buf.proto.clean @@ -0,0 +1,5 @@ +message Testing { + required string field1 = 1; + required int32 field2 = 2; + optional string field3 = 3; +} diff --git a/testlib/src/main/resources/protobuf/buf/license.proto b/testlib/src/main/resources/protobuf/buf/license.proto new file mode 100644 index 0000000000..aabedc5093 --- /dev/null +++ b/testlib/src/main/resources/protobuf/buf/license.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +message Testing { + required string field1 = 1; + required int32 field2 = 2; + optional string field3 = 3; +} diff --git a/testlib/src/main/resources/protobuf/buf/license.proto.clean b/testlib/src/main/resources/protobuf/buf/license.proto.clean new file mode 100644 index 0000000000..11761efc28 --- /dev/null +++ b/testlib/src/main/resources/protobuf/buf/license.proto.clean @@ -0,0 +1,8 @@ +/* (C) 2022 */ +syntax = "proto3"; + +message Testing { + required string field1 = 1; + required int32 field2 = 2; + optional string field3 = 3; +} diff --git a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java new file mode 100644 index 0000000000..c2079f462f --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.protobuf; + +import java.io.File; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.StepHarnessWithFile; + +class BufStepTest { + @Test + void test() throws Exception { + try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(BufStep.withVersion(BufStep.defaultVersion()).create())) { + harness.testResource(new File("src/main/resources/protobuf/buf/buf.proto"), "protobuf/buf/buf.proto", "protobuf/buf/buf.proto.clean"); + } + } +} From ef357fccb31837434a00680de5b56fc43bb91025 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 19:58:04 -0400 Subject: [PATCH 0006/1120] update changelogs --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8d2011de17..bd3b15a4cf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added support for Protobuf formatting based on [Buf](https://buf.build/) (#1208). ## [2.25.3] - 2022-05-10 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index fe7b0f879f..9d172a4cfd 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Added support for Protobuf formatting based on [Buf](https://buf.build/) (#1208). ## [6.6.0] - 2022-05-10 ### Added From 4e56621aa8858ea528ea5eb0689f55dbd502503a Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 20:02:52 -0400 Subject: [PATCH 0007/1120] fix bad comment --- .../java/com/diffplug/gradle/spotless/ProtobufExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index 44565e8073..660f0b3efb 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -42,7 +42,7 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { return licenseHeaderFile(licenseHeaderFile, LICENSE_HEADER_DELIMITER); } - /** Adds the specified version of ktlint. */ + /** Adds the specified version of buf. */ public BufFormatExtension buf(String version) { Objects.requireNonNull(version); return new BufFormatExtension(version); From 5b16ed1324116bd46f3364d8c5ccca4fce5b6703 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 20:45:28 -0400 Subject: [PATCH 0008/1120] allow specification of path to exe --- .../gradle/spotless/ProtobufExtension.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index 660f0b3efb..59a63b97fd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -42,6 +42,15 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { return licenseHeaderFile(licenseHeaderFile, LICENSE_HEADER_DELIMITER); } + /** If the user hasn't specified files, assume all protobuf files should be checked. */ + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + target = parseTarget("**/*.proto"); + } + super.setupTask(task); + } + /** Adds the specified version of buf. */ public BufFormatExtension buf(String version) { Objects.requireNonNull(version); @@ -53,24 +62,21 @@ public BufFormatExtension buf() { } public class BufFormatExtension { - private final String version; + BufStep step; BufFormatExtension(String version) { - this.version = version; + this.step = BufStep.withVersion(version); addStep(createStep()); } - private FormatterStep createStep() { - return BufStep.withVersion(version).create(); + public BufFormatExtension pathToExe(String pathToExe) { + step = step.withPathToExe(pathToExe); + replaceStep(createStep()); + return this; } - } - /** If the user hasn't specified files, assume all protobuf files should be checked. */ - @Override - protected void setupTask(SpotlessTask task) { - if (target == null) { - target = parseTarget("**/*.proto"); + private FormatterStep createStep() { + return step.create(); } - super.setupTask(task); } } From 85759c82067a2f1104b9b0ddfdaef51c50acf500 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 23:03:04 -0400 Subject: [PATCH 0009/1120] fix table --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fbdf738104..b55c4c4518 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('protobuf.BufSetp') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', From 2ec3dcef2c4c24b52e9e315317cd522b2273c8d4 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 23:03:16 -0400 Subject: [PATCH 0010/1120] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b55c4c4518..e6455348a0 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', -lib('protobuf.BufSetp') +'{{yes}} | {{no}} | {{no}} | {{no}} |', +lib('protobuf.BufStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', From 8d25fd8a65b5c80232b58f94373b29efa6f97cb7 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 23:21:19 -0400 Subject: [PATCH 0011/1120] add tag to disable buf tests in CI --- gradle/special-tests.gradle | 3 +- .../gradle/spotless/BufIntegrationTest.java | 3 ++ .../com/diffplug/spotless/tag/BufTest.java | 30 +++++++++++++++++++ .../spotless/protobuf/BufStepTest.java | 3 ++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java diff --git a/gradle/special-tests.gradle b/gradle/special-tests.gradle index c435bc7e81..c3fa9cec0b 100644 --- a/gradle/special-tests.gradle +++ b/gradle/special-tests.gradle @@ -3,7 +3,8 @@ apply plugin: 'com.adarshr.test-logger' def special = [ 'Npm', 'Black', - 'Clang' + 'Clang', + 'Buf' ] boolean isCiServer = System.getenv().containsKey("CI") diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java index 03f45a46c8..5625f927ce 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java @@ -17,8 +17,11 @@ import java.io.IOException; +import com.diffplug.spotless.tag.BufTest; + import org.junit.jupiter.api.Test; +@BufTest class BufIntegrationTest extends GradleIntegrationHarness { @Test void buf() throws IOException { diff --git a/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java new file mode 100644 index 0000000000..cf358c3816 --- /dev/null +++ b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.tag; + +import org.junit.jupiter.api.Tag; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({TYPE, METHOD}) +@Retention(RUNTIME) +@Tag("Buf") +public @interface BufTest {} diff --git a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java index c2079f462f..f54cd2cae3 100644 --- a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java @@ -17,10 +17,13 @@ import java.io.File; +import com.diffplug.spotless.tag.BufTest; + import org.junit.jupiter.api.Test; import com.diffplug.spotless.StepHarnessWithFile; +@BufTest class BufStepTest { @Test void test() throws Exception { From 78712ba6c3e67acc310287da30bd3f284f7edff5 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 23:36:27 -0400 Subject: [PATCH 0012/1120] lint --- .../com/diffplug/gradle/spotless/BufIntegrationTest.java | 4 ++-- .../src/main/java/com/diffplug/spotless/tag/BufTest.java | 8 ++++---- .../java/com/diffplug/spotless/protobuf/BufStepTest.java | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java index 5625f927ce..ba08c51838 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java @@ -17,10 +17,10 @@ import java.io.IOException; -import com.diffplug.spotless.tag.BufTest; - import org.junit.jupiter.api.Test; +import com.diffplug.spotless.tag.BufTest; + @BufTest class BufIntegrationTest extends GradleIntegrationHarness { @Test diff --git a/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java index cf358c3816..490218ef7b 100644 --- a/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java +++ b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java @@ -15,14 +15,14 @@ */ package com.diffplug.spotless.tag; -import org.junit.jupiter.api.Tag; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import org.junit.jupiter.api.Tag; @Target({TYPE, METHOD}) @Retention(RUNTIME) diff --git a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java index f54cd2cae3..0cd72129c6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java @@ -17,11 +17,10 @@ import java.io.File; -import com.diffplug.spotless.tag.BufTest; - import org.junit.jupiter.api.Test; import com.diffplug.spotless.StepHarnessWithFile; +import com.diffplug.spotless.tag.BufTest; @BufTest class BufStepTest { From 5c44a8e906dbf3d404d7d38758d4980f66cb1996 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 13 May 2022 00:50:09 -0400 Subject: [PATCH 0013/1120] add doc to pathToExe noting executable path trick --- .../gradle/spotless/ProtobufExtension.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index 59a63b97fd..ac9f37ec8c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -69,6 +69,30 @@ public class BufFormatExtension { addStep(createStep()); } + /** + * When used in conjunction with the {@code buf-gradle-plugin}, + * the {@code buf} executable can be resolved from its {@code bufTool} configuration: + * + *
+		 * {@code
+		 * spotless {
+         *     protobuf {
+         *         buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).singleFile.absolutePath)
+         *     }
+		 * }
+		 * }
+		 * 
+ * + * Be sure to disable the {@code buf-gradle-plugin}'s native support of {@code buf format}: + * + *
+		 * {@code
+		 * buf {
+         *     enforceFormat = false
+		 * }
+		 * }
+		 * 
+ */ public BufFormatExtension pathToExe(String pathToExe) { step = step.withPathToExe(pathToExe); replaceStep(createStep()); From 580037dc7b6bf58aa7b7072327b0c12649c29968 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 13 May 2022 00:55:45 -0400 Subject: [PATCH 0014/1120] add to readme as well --- plugin-gradle/README.md | 15 +++++++++++++++ .../gradle/spotless/ProtobufExtension.java | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 7bf684923c..273afb54d1 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -475,6 +475,21 @@ spotless { } ``` +When used in conjunction with the [buf-gradle-plugin](https://github.com/andrewparmet/buf-gradle-plugin), the `buf` executable can be resolved from its `bufTool` configuration: + +```gradle +spotless { + protobuf { + buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).getSingleFile().getAbsolutePath()) + } +} + +// Be sure to disable the buf-gradle-plugin's native support of `buf format`: +buf { + enforceFormat = false +} +``` + ## FreshMark `com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index ac9f37ec8c..8754880f69 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -76,9 +76,9 @@ public class BufFormatExtension { *
 		 * {@code
 		 * spotless {
-         *     protobuf {
-         *         buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).singleFile.absolutePath)
-         *     }
+         *   protobuf {
+         *     buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).getSingleFile().getAbsolutePath())
+         *   }
 		 * }
 		 * }
 		 * 
@@ -88,7 +88,7 @@ public class BufFormatExtension { *
 		 * {@code
 		 * buf {
-         *     enforceFormat = false
+         *   enforceFormat = false
 		 * }
 		 * }
 		 * 
From 3f7b1e87995210c852f87035e2eb396d993d66fd Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 13 May 2022 00:58:23 -0400 Subject: [PATCH 0015/1120] tidy up diction --- plugin-gradle/README.md | 2 +- .../java/com/diffplug/gradle/spotless/ProtobufExtension.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 273afb54d1..ec97352749 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -484,7 +484,7 @@ spotless { } } -// Be sure to disable the buf-gradle-plugin's native support of `buf format`: +// Be sure to disable the buf-gradle-plugin's execution of `buf format`: buf { enforceFormat = false } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index 8754880f69..5f24b97a02 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -83,7 +83,7 @@ public class BufFormatExtension { * } * * - * Be sure to disable the {@code buf-gradle-plugin}'s native support of {@code buf format}: + * Be sure to disable the {@code buf-gradle-plugin}'s execution of {@code buf format}: * *
 		 * {@code

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

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

diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
index 5f24b97a02..283fe21c58 100644
--- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
+++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
@@ -76,9 +76,9 @@ public class BufFormatExtension {
 		 * 
 		 * {@code
 		 * spotless {
-         *   protobuf {
-         *     buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).getSingleFile().getAbsolutePath())
-         *   }
+		 *   protobuf {
+		 *     buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).getSingleFile().getAbsolutePath())
+		 *   }
 		 * }
 		 * }
 		 * 
@@ -88,7 +88,7 @@ public class BufFormatExtension { *
 		 * {@code
 		 * buf {
-         *   enforceFormat = false
+		 *   enforceFormat = false
 		 * }
 		 * }
 		 * 
From 225d992fcf8fee26b7a3ca820f3fc82bc2bf064d Mon Sep 17 00:00:00 2001 From: "benjamin.gentner" Date: Fri, 2 Sep 2022 16:34:35 +0200 Subject: [PATCH 0017/1120] Fix Freshmark compatibility with JDK 15+ (fixes #803) --- .../spotless/markdown/FreshMarkStep.java | 16 +++++++++++++++- .../spotless/markdown/FreshMarkStepTest.java | 6 +----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java index 2591cac7a5..fd03e95046 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java @@ -19,6 +19,8 @@ import java.io.Serializable; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.NavigableMap; import java.util.Objects; @@ -31,6 +33,7 @@ import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Jvm; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.ThrowingEx.Supplier; @@ -42,6 +45,10 @@ private FreshMarkStep() {} private static final String DEFAULT_VERSION = "1.3.1"; private static final String NAME = "freshmark"; private static final String MAVEN_COORDINATE = "com.diffplug.freshmark:freshmark:"; + + private static final String NASHORN_MAVEN_COORDINATE = "org.openjdk.nashorn:nashorn-core:"; + + private static final String NASHORN_VERSION = "15.4"; private static final String FORMATTER_CLASS = "com.diffplug.freshmark.FreshMark"; private static final String FORMATTER_METHOD = "compile"; @@ -55,8 +62,15 @@ public static FormatterStep create(String version, Supplier> prop Objects.requireNonNull(version, "version"); Objects.requireNonNull(properties, "properties"); Objects.requireNonNull(provisioner, "provisioner"); + + List mavenCoordinates = new ArrayList<>(); + mavenCoordinates.add(MAVEN_COORDINATE + version); + if (Jvm.version() >= 15) { + mavenCoordinates.add(NASHORN_MAVEN_COORDINATE + NASHORN_VERSION); + } + return FormatterStep.createLazy(NAME, - () -> new State(JarState.from(MAVEN_COORDINATE + version, provisioner), properties.get()), + () -> new State(JarState.from(mavenCoordinates, provisioner), properties.get()), State::createFormat); } diff --git a/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java b/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java index 477642e247..a5fede28bc 100644 --- a/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,20 +15,16 @@ */ package com.diffplug.spotless.markdown; -import static org.junit.jupiter.api.condition.JRE.JAVA_14; - import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.SerializableEqualityTester; import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.TestProvisioner; -@EnabledForJreRange(max = JAVA_14) class FreshMarkStepTest { @Test void behavior() throws Exception { From f634a23b88a0271da4fab9de840c86c86592eea9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 05:46:52 +0000 Subject: [PATCH 0018/1120] Update dependency com.github.spotbugs:spotbugs-annotations to v4.7.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 09d152d886..9b90d05ee8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ artifactIdGradle=spotless-plugin-gradle # Build requirements VER_JAVA=1.8 -VER_SPOTBUGS=4.5.0 +VER_SPOTBUGS=4.7.2 VER_JSR_305=3.0.2 # Dependencies provided by Spotless plugin From 58a50f648168979fb2478db9b2781ac1764550b3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 05:47:06 +0000 Subject: [PATCH 0019/1120] Update plugin com.diffplug.spotless-changelog to v2.4.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 1706b5fa7f..8e9c3a2d35 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,7 +8,7 @@ pluginManagement { // https://github.com/spotbugs/spotbugs-gradle-plugin/releases id 'com.github.spotbugs' version '5.0.12' // https://github.com/diffplug/spotless-changelog - id 'com.diffplug.spotless-changelog' version '2.3.2' + id 'com.diffplug.spotless-changelog' version '2.4.0' // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases From 36e5cc6d61a8b728cf21e5b42b03fccdc66a872e Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 14 Sep 2022 05:56:03 +0000 Subject: [PATCH 0020/1120] Published gradle/6.11.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 78a9b46693..f7c15244d5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.11.0] - 2022-09-14 ### Added * `formatAnnotations()` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat()`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ### Changes diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index a6d05daa9d..29e748295e 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.10.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.11.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -143,7 +143,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -267,8 +267,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -319,8 +319,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -383,7 +383,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -415,7 +415,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -447,7 +447,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -481,7 +481,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -502,7 +502,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -527,7 +527,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -567,7 +567,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -610,7 +610,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -835,7 +835,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -902,9 +902,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -937,11 +937,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.10.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 0b186ab5217a53bf33f047dc00952cb0889e9121 Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 14 Sep 2022 05:57:45 +0000 Subject: [PATCH 0021/1120] Published maven/2.26.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 5d47dc4f4f..1ce37116a1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.26.0] - 2022-09-14 ### Added * `formatAnnotations` step to correct formatting of Java type annotations. It puts type annotations on the same line as the type that they qualify. Run it after a Java formatting step, such as `googleJavaFormat`. ([#1275](https://github.com/diffplug/spotless/pull/1275)) ### Changes diff --git a/plugin-maven/README.md b/plugin-maven/README.md index d80773f3f1..19796770ef 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.25.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.25.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.26.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.26.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From cdf7c015ad6f5ebb5b7efbc2b9d75f1e3dfbced4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 11:09:59 +0000 Subject: [PATCH 0022/1120] Update plugin com.diffplug.spotless to v6.11.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 91de4f9e48..fb37734f5f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.5.0' + id 'com.diffplug.spotless' version '6.11.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.0.0' // https://github.com/gradle-nexus/publish-plugin/releases From 556bb22349d3328c1824431d27798b815a92dfa4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 15 Sep 2022 21:10:36 +0000 Subject: [PATCH 0023/1120] Update dependency org.eclipse.aether:aether-api to v1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9b90d05ee8..d37961f958 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,6 +32,6 @@ VER_MOCKITO=3.12.4 # Used for Maven Plugin VER_MAVEN_API=3.0 -VER_ECLIPSE_AETHER=0.9.1.v20140329 +VER_ECLIPSE_AETHER=1.1.0 VER_MUSTACHE=0.9.10 VER_PLEXUS_RESOURCES=1.2.0 From 80111ddeb4e5f877dccf6ba9fcd2ca67d89ea600 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 16 Sep 2022 00:10:49 +0000 Subject: [PATCH 0024/1120] Update dependency org.mockito:mockito-core to v4 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9b90d05ee8..4ac4b94fa5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.0 VER_ASSERTJ=3.23.1 -VER_MOCKITO=3.12.4 +VER_MOCKITO=4.8.0 # Used for Maven Plugin VER_MAVEN_API=3.0 From f87bd70b6cd34392898da055f3d7507491b36368 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 16 Sep 2022 00:10:56 +0000 Subject: [PATCH 0025/1120] Update win orb to v5 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a5ca735442..83e434bcec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2.1 orbs: - win: circleci/windows@2.4.1 + win: circleci/windows@5.0.0 anchors: env_gradle: &env_gradle From 57788b87e745f9b1f01682aaa36565faada5e6c1 Mon Sep 17 00:00:00 2001 From: Tormod Alf Try Tufteland Date: Fri, 16 Sep 2022 15:33:48 +0200 Subject: [PATCH 0026/1120] feat: ktlint editorConfigOverrides for plugin-maven --- plugin-maven/README.md | 4 ++++ .../com/diffplug/spotless/maven/kotlin/Ktlint.java | 14 +++++++++++++- .../diffplug/spotless/maven/kotlin/KtlintTest.java | 10 ++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 19796770ef..a6a8491784 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -359,6 +359,10 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ```xml 0.43.2 + + true + true + ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 796523d315..5792ee0611 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -22,14 +22,26 @@ import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + public class Ktlint implements FormatterStepFactory { @Parameter private String version; + @Parameter + private Map editorConfigOverride; + @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { String ktlintVersion = version != null ? version : KtLintStep.defaultVersion(); - return KtLintStep.create(ktlintVersion, config.getProvisioner()); + + if (editorConfigOverride == null) { + editorConfigOverride = new HashMap<>(); + } + + return KtLintStep.create(ktlintVersion, config.getProvisioner(), false, Collections.emptyMap(), editorConfigOverride); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index 887f7a3f50..ba6f1d8e2c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -29,4 +29,14 @@ void testKtlint() throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("kotlin/ktlint/basic.clean"); } + + @Test + void testKtlintEditorConfigOverride() throws Exception { + writePomWithKotlinSteps("truetrue"); + + String path = "src/main/kotlin/Main.kt"; + setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + } } From e4f1fc92a1c280c6b370530e6f64a69b8daa8296 Mon Sep 17 00:00:00 2001 From: Tormod Alf Try Tufteland Date: Fri, 16 Sep 2022 16:43:53 +0200 Subject: [PATCH 0027/1120] doc: add changes --- CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 23c20dc957..b0117a4bd5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Support for `editorConfigOverride` in `ktlint`, `plugin-maven`. ([#1335](https://github.com/diffplug/spotless/pull/1335) fixes [#1334](https://github.com/diffplug/spotless/issues/1334)) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1ce37116a1..6046e7aed1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Support for `editorConfigOverride` in `ktlint`, `plugin-maven`. ([#1335](https://github.com/diffplug/spotless/pull/1335) fixes [#1334](https://github.com/diffplug/spotless/issues/1334)) ## [2.26.0] - 2022-09-14 ### Added From 96803ae88ff4d0d4de554dc4a5f00fb1d4b47cdf Mon Sep 17 00:00:00 2001 From: Tormod Alf Try Tufteland Date: Sat, 17 Sep 2022 10:57:17 +0200 Subject: [PATCH 0028/1120] fix: linting --- .../com/diffplug/spotless/maven/kotlin/Ktlint.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 5792ee0611..45bda05065 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,10 @@ */ package com.diffplug.spotless.maven.kotlin; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; @@ -22,10 +26,6 @@ import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - public class Ktlint implements FormatterStepFactory { @Parameter From 59c166a369e77867d28b453b94787111f36a96a7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 19 Sep 2022 13:02:20 -0700 Subject: [PATCH 0029/1120] Only changes are in plugin-maven, so that's the only changelog that should change. --- CHANGES.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b0117a4bd5..23c20dc957 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,8 +10,6 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -### Added -* Support for `editorConfigOverride` in `ktlint`, `plugin-maven`. ([#1335](https://github.com/diffplug/spotless/pull/1335) fixes [#1334](https://github.com/diffplug/spotless/issues/1334)) ## [2.30.0] - 2022-09-14 ### Added From de9bb1f757bf2502551cd98dd8f371abf2d1a3fb Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 19 Sep 2022 20:09:52 +0000 Subject: [PATCH 0030/1120] Published maven/2.27.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6046e7aed1..6c3ff896a9 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.27.0] - 2022-09-19 ### Added * Support for `editorConfigOverride` in `ktlint`, `plugin-maven`. ([#1335](https://github.com/diffplug/spotless/pull/1335) fixes [#1334](https://github.com/diffplug/spotless/issues/1334)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index a6a8491784..a7ab01cfa0 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.26.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.26.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.27.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 92e21d9a64f6aa753695b83114e5ed6db022f6d9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 20 Sep 2022 22:09:47 +0000 Subject: [PATCH 0031/1120] Update dependency org.junit.jupiter:junit-jupiter to v5.9.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 155ac981bc..b7bbe3ea6a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r -VER_JUNIT=5.9.0 +VER_JUNIT=5.9.1 VER_ASSERTJ=3.23.1 VER_MOCKITO=4.8.0 From d99ee528b065046b153d208a718ee57734d84469 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 23 Sep 2022 22:03:23 +0000 Subject: [PATCH 0032/1120] Update dependency com.facebook:ktfmt to v0.41 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index dfb2a38d73..dfd67e59ed 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -54,7 +54,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' - String VER_KTFMT = '0.40' + String VER_KTFMT = '0.41' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") { From b0bb294147cd30966b88335391b6becb880526de Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 13:37:54 +0000 Subject: [PATCH 0033/1120] Update dependency com.palantir.javaformat:palantir-java-format to v2 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index dfb2a38d73..ef10376f18 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -52,7 +52,7 @@ dependencies { sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' - palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' + palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:2.27.0' String VER_KTFMT = '0.40' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" From dc9f4291f80bcb15dd63721abbba70f4ab0c371a Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 28 Sep 2022 21:18:52 +0800 Subject: [PATCH 0034/1120] fix: maven plugin should identify skip config key Signed-off-by: tison --- .../com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 c68733f387..f163fa2802 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 @@ -91,6 +91,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true) private String goal; + @Parameter(defaultValue = "false") + private boolean skip; + @Parameter(property = "spotless.apply.skip", defaultValue = "false") private boolean applySkip; @@ -200,6 +203,10 @@ public final void execute() throws MojoExecutionException { } private boolean shouldSkip() { + if (skip) { + return true; + } + switch (goal) { case GOAL_CHECK: return checkSkip; @@ -208,6 +215,7 @@ private boolean shouldSkip() { default: break; } + return false; } From 622f3a0c0bdb679a9f3a9123ba598dd2e6201be7 Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 28 Sep 2022 22:48:37 +0800 Subject: [PATCH 0035/1120] update CHANGES Signed-off-by: tison --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6c3ff896a9..d46447ea38 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `skip` config key should work again now. ([#1353](https://github.com/diffplug/spotless/pull/1353) fixes [#1227](https://github.com/diffplug/spotless/issues/1227) and [#491](https://github.com/diffplug/spotless/issues/491)) ## [2.27.0] - 2022-09-19 ### Added From 7667a849d377b546d45350b77b65e0793e3d17dc Mon Sep 17 00:00:00 2001 From: circleci Date: Wed, 28 Sep 2022 17:29:42 +0000 Subject: [PATCH 0036/1120] Published maven/2.27.1 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d46447ea38..33b8f2b03a 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.27.1] - 2022-09-28 ### Fixed * `skip` config key should work again now. ([#1353](https://github.com/diffplug/spotless/pull/1353) fixes [#1227](https://github.com/diffplug/spotless/issues/1227) and [#491](https://github.com/diffplug/spotless/issues/491)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index a7ab01cfa0..b60cfa1a38 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.27.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.1/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.27.1-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From aa48b8d9f1b4b0785d33dbecd4acb96e5c39b1e1 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Tue, 4 Oct 2022 00:58:47 +0800 Subject: [PATCH 0037/1120] Allow replacement to be null for ReplaceRegex of plugin maven --- .../com/diffplug/spotless/maven/generic/Replace.java | 12 +++++++----- .../spotless/maven/generic/ReplaceRegex.java | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Replace.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Replace.java index 947ceee8e2..53967fd7d7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Replace.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Replace.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,10 +35,12 @@ public class Replace implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { - if (name == null || search == null || replacement == null) { - throw new IllegalArgumentException("Must specify 'name', 'search' and 'replacement'."); + if (name == null || search == null) { + throw new IllegalArgumentException("Must specify 'name' and 'search'."); } - - return ReplaceStep.create(name, search, replacement); + // Use empty string if replacement is not provided. In pom.xml there is no way to specify + // an empty string as a property value as maven will always trim the value and if it is + // empty, maven will consider the property as not provided. + return ReplaceStep.create(name, search, replacement != null ? replacement : ""); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/ReplaceRegex.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/ReplaceRegex.java index 243f14220e..9983aa8475 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/ReplaceRegex.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/ReplaceRegex.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,10 +35,12 @@ public class ReplaceRegex implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { - if (name == null || searchRegex == null || replacement == null) { - throw new IllegalArgumentException("Must specify 'name', 'searchRegex' and 'replacement'."); + if (name == null || searchRegex == null) { + throw new IllegalArgumentException("Must specify 'name' and 'searchRegex'."); } - - return ReplaceRegexStep.create(name, searchRegex, replacement); + // Use empty string if replacement is not provided. In pom.xml there is no way to specify + // an empty string as a property value as maven will always trim the value and if it is + // empty, maven will consider the property as not provided. + return ReplaceRegexStep.create(name, searchRegex, replacement != null ? replacement : ""); } } From 49892456496c283d23b47b6d4f0bc5f6a44c885e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 10 Oct 2022 16:26:53 +0200 Subject: [PATCH 0038/1120] Update changelog. --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 33b8f2b03a..e42fd89add 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `replace` and `replaceRegex` steps now allow you to replace something with an empty string, previously this would generate a null pointer exception. (fixes [#1359](https://github.com/diffplug/spotless/issues/1359)) ## [2.27.1] - 2022-09-28 ### Fixed From 23784ba9e1774c91218a77e2b60ba12343b33c8c Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 10 Oct 2022 14:50:07 +0000 Subject: [PATCH 0039/1120] Published maven/2.27.2 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e42fd89add..7da89e6712 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.27.2] - 2022-10-10 ### Fixed * `replace` and `replaceRegex` steps now allow you to replace something with an empty string, previously this would generate a null pointer exception. (fixes [#1359](https://github.com/diffplug/spotless/issues/1359)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index b60cfa1a38..2a249357a6 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.1/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.27.1-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.2/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.27.2-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 3d6da4b821e70c3b451e7234c5b6d053ab89cef4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 10 Oct 2022 17:58:50 +0200 Subject: [PATCH 0040/1120] Move the repositories block higher. --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 16136e07ec..5766e6b85e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,6 @@ +repositories { + mavenCentral() +} apply from: rootProject.file('gradle/java-publish.gradle') apply from: rootProject.file('gradle/changelog.gradle') allprojects { @@ -5,9 +8,6 @@ allprojects { } apply from: rootProject.file('gradle/spotless-freshmark.gradle') -repositories { - mavenCentral() -} spotless { groovyGradle { target '*.gradle', 'gradle/*.gradle' From 744a2d9fdcaac0d8d3b45a03e30b32322c2e0ae2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 10 Oct 2022 18:14:13 +0200 Subject: [PATCH 0041/1120] Fixes. --- plugin-gradle/build.gradle | 2 +- plugin-maven/build.gradle | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 8fec4beb92..f1b3320b50 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -1,10 +1,10 @@ apply from: rootProject.file('gradle/changelog.gradle') ext.artifactId = project.artifactIdGradle version = spotlessChangelog.versionNext +apply plugin: 'java-library' apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/spotless-freshmark.gradle') -apply plugin: 'java-library' apply plugin: 'com.gradle.plugin-publish' apply plugin: 'java-gradle-plugin' diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 174f10ef6a..b7ac8a36c8 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -5,6 +5,7 @@ buildscript { plugins { id 'cz.malohlava.visteg' version '1.0.5' // https://github.com/mmalohlava/gradle-visteg } +repositories { mavenCentral() } apply from: rootProject.file('gradle/changelog.gradle') apply from: rootProject.file('gradle/spotless-freshmark.gradle') From bd12e20cbb58ad4b51d63bb47b24911f364357ae Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 11 Oct 2022 10:36:42 -0700 Subject: [PATCH 0042/1120] Don't treat `@Value` as a type annotation --- .../java/com/diffplug/spotless/java/FormatAnnotationsStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java index 2d01e305a0..d05a53ee1b 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java @@ -371,7 +371,7 @@ public final class FormatAnnotationsStep { "UpperBoundBottom", "UpperBoundLiteral", "UpperBoundUnknown", - "Value", + "ValueTypeAnno", "VariableNameDefaultBottom", "VariableNameDefaultMiddle", "VariableNameDefaultTop", From 26f8f59966c02ee2a1d238a5ffa34b6016018285 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 11 Oct 2022 10:42:38 -0700 Subject: [PATCH 0043/1120] Add test cases for type annotations on classes --- ...FormatAnnotationsAccessModifiersInput.test | 57 +++++++++++++++++++ ...ormatAnnotationsAccessModifiersOutput.test | 57 +++++++++++++++++++ .../FormatAnnotationsTestInput.test | 9 +++ .../FormatAnnotationsTestOutput.test | 7 +++ 4 files changed, 130 insertions(+) create mode 100644 testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test create mode 100644 testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test new file mode 100644 index 0000000000..6ac5519cc9 --- /dev/null +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test @@ -0,0 +1,57 @@ +// Annotations in the wrong order. The preferred order is: +// * declaration annotations +// * access modifiers such as `public` +// * type annotations +// * type + +class FormatAnnotationsAccessModifiers { + + @Nullable public Object myMethod1() { + return null; + } + + @Nullable + public Object myMethod2() { + return null; + } + + @Nullable + public + Object myMethod3() { + return null; + } + + @Nullable + @Deprecated + public Object myMethod4() { + return null; + } + + @Override + @Nullable + @Deprecated + public Object myMethod5() { + return null; + } + + @Nullable @Deprecated public Object myMethod6() { + return null; + } +} + +@Deprecated +@Interned +@MustCall("close") +@SuppressWarnings +public class MyClass3 { + // No body +} + +public +@Deprecated +@SuppressWarnings +@Interned +@MustCall("close") +class MyClass4 { + // No body +} diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test new file mode 100644 index 0000000000..6ac5519cc9 --- /dev/null +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test @@ -0,0 +1,57 @@ +// Annotations in the wrong order. The preferred order is: +// * declaration annotations +// * access modifiers such as `public` +// * type annotations +// * type + +class FormatAnnotationsAccessModifiers { + + @Nullable public Object myMethod1() { + return null; + } + + @Nullable + public Object myMethod2() { + return null; + } + + @Nullable + public + Object myMethod3() { + return null; + } + + @Nullable + @Deprecated + public Object myMethod4() { + return null; + } + + @Override + @Nullable + @Deprecated + public Object myMethod5() { + return null; + } + + @Nullable @Deprecated public Object myMethod6() { + return null; + } +} + +@Deprecated +@Interned +@MustCall("close") +@SuppressWarnings +public class MyClass3 { + // No body +} + +public +@Deprecated +@SuppressWarnings +@Interned +@MustCall("close") +class MyClass4 { + // No body +} diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test index fb711451d1..b93631db5a 100644 --- a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestInput.test @@ -75,3 +75,12 @@ class FormatAnnotationsTest { @Localized String localized; } + +@Deprecated +@SuppressWarnings +public +@Interned +@MustCall("close") +class MyClass1 { + // No body +} diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test index ca37e66d86..6daabf198c 100644 --- a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsTestOutput.test @@ -49,3 +49,10 @@ class FormatAnnotationsTest { @Localized String localized; } + +@Deprecated +@SuppressWarnings +public +@Interned @MustCall("close") class MyClass1 { + // No body +} From 4b13e329e25a872c125d8f4c8eb8b05a0ca60d90 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 13 Oct 2022 10:25:39 -0700 Subject: [PATCH 0044/1120] Add changelog --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 23c20dc957..dc0bd38c60 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f7c15244d5..a8adac938d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1ce37116a1..268cf97322 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) ## [2.26.0] - 2022-09-14 ### Added From e79625731bdef4bdb0a58557975231c52f1339ff Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 13 Oct 2022 10:47:02 -0700 Subject: [PATCH 0045/1120] Add invocation of test --- .../spotless/maven/java/FormatAnnotationsStepTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java index 8560b73fd4..972a4b4f7f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/FormatAnnotationsStepTest.java @@ -30,4 +30,14 @@ void testFormatAnnotations() throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsTestOutput.test"); } + + @Test + void testFormatAnnotationsAccessModifiers() throws Exception { + writePomWithJavaSteps(""); + + String path = "src/main/java/test.java"; + setFile(path).toResource("java/formatannotations/FormatAnnotationsAccessModifiersInput.test"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("java/formatannotations/FormatAnnotationsAccessModifiersOutput.test"); + } } From 276810c5109831dcd04bfc9932a1e84b2afb67d1 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Thu, 13 Oct 2022 14:37:50 -0700 Subject: [PATCH 0046/1120] Add tests, fix expected output --- ...FormatAnnotationsAccessModifiersInput.test | 6 +++++ ...ormatAnnotationsAccessModifiersOutput.test | 25 ++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test index 6ac5519cc9..13546f9a84 100644 --- a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersInput.test @@ -27,6 +27,12 @@ class FormatAnnotationsAccessModifiers { return null; } + @Deprecated + @Nullable + public Object myMethod4a() { + return null; + } + @Override @Nullable @Deprecated diff --git a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test index 6ac5519cc9..ffc6169c4c 100644 --- a/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test +++ b/testlib/src/main/resources/java/formatannotations/FormatAnnotationsAccessModifiersOutput.test @@ -10,26 +10,27 @@ class FormatAnnotationsAccessModifiers { return null; } - @Nullable - public Object myMethod2() { + @Nullable public Object myMethod2() { return null; } - @Nullable - public + @Nullable public Object myMethod3() { return null; } - @Nullable - @Deprecated + @Nullable @Deprecated public Object myMethod4() { return null; } - @Override - @Nullable @Deprecated + @Nullable public Object myMethod4a() { + return null; + } + + @Override + @Nullable @Deprecated public Object myMethod5() { return null; } @@ -40,9 +41,7 @@ class FormatAnnotationsAccessModifiers { } @Deprecated -@Interned -@MustCall("close") -@SuppressWarnings +@Interned @MustCall("close") @SuppressWarnings public class MyClass3 { // No body } @@ -50,8 +49,6 @@ public class MyClass3 { public @Deprecated @SuppressWarnings -@Interned -@MustCall("close") -class MyClass4 { +@Interned @MustCall("close") class MyClass4 { // No body } From 650374d4be3aa9489f4f2580d3bc96957c40257f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 17 Oct 2022 07:07:09 +0000 Subject: [PATCH 0047/1120] fix(deps): update dependency com.github.spotbugs:spotbugs-annotations to v4.7.3 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index b7bbe3ea6a..31a94db7df 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ artifactIdGradle=spotless-plugin-gradle # Build requirements VER_JAVA=1.8 -VER_SPOTBUGS=4.7.2 +VER_SPOTBUGS=4.7.3 VER_JSR_305=3.0.2 # Dependencies provided by Spotless plugin From 28ca68cc4552dc530132161934fa54260494fbc4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 19 Oct 2022 00:55:20 +0000 Subject: [PATCH 0048/1120] chore(deps): update plugin com.github.spotbugs to v5.0.13 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 47699727c4..0ce22a9a8c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,7 @@ pluginManagement { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.12' + id 'com.github.spotbugs' version '5.0.13' // https://github.com/diffplug/spotless-changelog id 'com.diffplug.spotless-changelog' version '2.4.0' // https://github.com/diffplug/goomph/blob/main/CHANGES.md From 707e50edb0a5d54d9634d28acfa403b209d57740 Mon Sep 17 00:00:00 2001 From: Bruno Medeiros Date: Wed, 19 Oct 2022 23:12:34 +0800 Subject: [PATCH 0049/1120] fix(ktlint): support ktlint_disabled_rules in 0.47+ --- .../glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 842294a5cc..66274fd0ef 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -100,9 +100,13 @@ private static EditorConfigOverride createEditorConfigOverride(final List .filter(rule -> rule instanceof UsesEditorConfigProperties) .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); + // get complete list of supported properties in DefaultEditorConfigProperties.INSTANCE + List> editorConfigProperties = DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties(); + editorConfigProperties.add(DefaultEditorConfigProperties.INSTANCE.getKtlintDisabledRulesProperty()); + // Create a mapping of properties to their names based on rule properties and default properties Map> supportedProperties = Stream - .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) + .concat(ruleProperties, editorConfigProperties.stream()) .distinct() .collect(Collectors.toMap(property -> property.getType().getName(), property -> property)); From 6824821bcd072a0a35370a2dc4604d8635fe35c9 Mon Sep 17 00:00:00 2001 From: Bruno Medeiros Date: Fri, 21 Oct 2022 10:14:38 +0800 Subject: [PATCH 0050/1120] user mutable list implementation before adding element --- .../glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 66274fd0ef..757ffc922b 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -17,6 +17,7 @@ import static java.util.Collections.emptySet; +import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -101,7 +102,7 @@ private static EditorConfigOverride createEditorConfigOverride(final List .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); // get complete list of supported properties in DefaultEditorConfigProperties.INSTANCE - List> editorConfigProperties = DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties(); + List> editorConfigProperties = new ArrayList<>(DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties()); editorConfigProperties.add(DefaultEditorConfigProperties.INSTANCE.getKtlintDisabledRulesProperty()); // Create a mapping of properties to their names based on rule properties and default properties From fb3f658631df27bd98cf5bb0a54dae13be4b9818 Mon Sep 17 00:00:00 2001 From: Bruno Medeiros Date: Fri, 21 Oct 2022 10:15:04 +0800 Subject: [PATCH 0051/1120] add change log entries --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index dc0bd38c60..f6671d2191 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] ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) +* Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a8adac938d..5acd85ddc8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) +* Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 75659026d4..b08a2366fd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) +* Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ## [2.27.2] - 2022-10-10 ### Fixed From ec2e1b2aa274476a1c7a52741b98c7905fd7ebbc Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 21 Oct 2022 19:58:11 +0000 Subject: [PATCH 0052/1120] fix(deps): update dependency org.mockito:mockito-core to v4.8.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 31a94db7df..5df7719934 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.1 VER_ASSERTJ=3.23.1 -VER_MOCKITO=4.8.0 +VER_MOCKITO=4.8.1 # Used for Maven Plugin VER_MAVEN_API=3.0 From bff7c23af18d9a65f0f1baedcd190edd2e832807 Mon Sep 17 00:00:00 2001 From: Jasper Vandemalle Date: Wed, 26 Oct 2022 11:55:07 +0200 Subject: [PATCH 0053/1120] Fix SortPomStepStep typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fb1a3670e6..605305bd29 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', -lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', @@ -115,7 +115,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | | [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | -| [`pom.SortPomStepStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStepStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | | [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | From be4892f9d300d507225e65169c6f2a0e84afcb53 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 1 Nov 2022 01:32:49 +0000 Subject: [PATCH 0054/1120] fix(deps): update dependency org.scalameta:scalafmt-core_2.13 to v3.6.1 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index dfb2a38d73..34f04371d6 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -91,7 +91,7 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' - String VER_SCALAFMT="3.5.9" + String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" String VER_DIKTAT = "1.2.3" From 3785b1be4ab93a906fa933a317a6877968239201 Mon Sep 17 00:00:00 2001 From: jochenberger Date: Thu, 3 Nov 2022 14:56:07 +0100 Subject: [PATCH 0055/1120] Fix link --- plugin-gradle/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 29e748295e..7f5590da21 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -303,7 +303,7 @@ spotless { ### eclipse groovy -[homepage](https://github.com/groovy/groovy-eclipse/wiki). [changelog](https://github.com/groovy/groovy-eclipse/releases). [compatible versions](https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/groovy_eclipse_formatter). The Groovy formatter uses some of the [eclipse jdt](#eclipse-jdt) configuration parameters in addition to groovy-specific ones. All parameters can be configured within a single file, like the Java properties file [greclipse.properties](../testlib/src/main/resources/groovy/greclipse/format/greclipse.properties) in the previous example. The formatter step can also load the [exported Eclipse properties](../ECLIPSE_SCREENSHOTS.md) and augment it with the `.metadata/.plugins/org.eclipse.core.runtime/.settings/org.codehaus.groovy.eclipse.ui.prefs` from your Eclipse workspace as shown below. +[homepage](https://github.com/groovy/groovy-eclipse/wiki). [changelog](https://github.com/groovy/groovy-eclipse/releases). [compatible versions](https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter). The Groovy formatter uses some of the [eclipse jdt](#eclipse-jdt) configuration parameters in addition to groovy-specific ones. All parameters can be configured within a single file, like the Java properties file [greclipse.properties](../testlib/src/main/resources/groovy/greclipse/format/greclipse.properties) in the previous example. The formatter step can also load the [exported Eclipse properties](../ECLIPSE_SCREENSHOTS.md) and augment it with the `.metadata/.plugins/org.eclipse.core.runtime/.settings/org.codehaus.groovy.eclipse.ui.prefs` from your Eclipse workspace as shown below. ```gradle spotless { From 8d4d944eaff35a7e372e79517b0b67f91dde9400 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 11 Nov 2022 12:04:59 +0000 Subject: [PATCH 0056/1120] chore(deps): update plugin com.gradle.plugin-publish to v1.1.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 0ce22a9a8c..6184ab802f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,7 +2,7 @@ pluginManagement { plugins { id 'com.diffplug.spotless' version '6.11.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish - id 'com.gradle.plugin-publish' version '1.0.0' + id 'com.gradle.plugin-publish' version '1.1.0' // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' // https://github.com/spotbugs/spotbugs-gradle-plugin/releases From e8133131e12e3ba1a95257770376f59b64903ebf Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 14 Nov 2022 20:13:44 +0000 Subject: [PATCH 0057/1120] fix(deps): update dependency org.mockito:mockito-core to v4.9.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 5df7719934..fc2b2b43da 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.1 VER_ASSERTJ=3.23.1 -VER_MOCKITO=4.8.1 +VER_MOCKITO=4.9.0 # Used for Maven Plugin VER_MAVEN_API=3.0 From 9773159231029cb23212d7a2b4656d508dc8525c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 15 Nov 2022 17:15:34 +0000 Subject: [PATCH 0058/1120] fix(deps): update dependency org.cqfn.diktat:diktat-rules to v1.2.4.2 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index dfb2a38d73..cf3216ade6 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -94,7 +94,7 @@ dependencies { String VER_SCALAFMT="3.5.9" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" - String VER_DIKTAT = "1.2.3" + String VER_DIKTAT = "1.2.4.2" diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" // used for markdown formatting From 35a56eaed731ea5d43786fd7c5a2ab4fc8d3dff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mino?= Date: Sun, 20 Nov 2022 00:37:49 +0100 Subject: [PATCH 0059/1120] Support for group of imports without blank lines between groups To keep compatibility with existing configuration, a special delimiter `|` is introduced to separate subgroup of imports inside a group. For example "java|javax" will not generate a blank line between the java group and the javax group. The notion of ImportsGroup has been introduced for clarification, allowing code has been simplification. Fixes #1375 --- CHANGES.md | 1 + .../spotless/java/ImportSorterImpl.java | 174 ++++++++---------- plugin-gradle/README.md | 4 +- plugin-maven/README.md | 8 +- .../JavaCodeSortedImportsSubgroups.test | 16 ++ .../JavaCodeUnsortedImportsSubgroups.test | 15 ++ .../spotless/java/ImportOrderStepTest.java | 6 + 7 files changed, 119 insertions(+), 105 deletions(-) create mode 100644 testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroups.test create mode 100644 testlib/src/main/resources/java/importsorter/JavaCodeUnsortedImportsSubgroups.test diff --git a/CHANGES.md b/CHANGES.md index f6671d2191..4bd52e1aa0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +* ImportOrder: support groups of imports without blank lines [#1401](https://github.com/diffplug/spotless/pull/1401) ## [2.30.0] - 2022-09-14 ### Added diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index ec075ffedd..6dd8d58ba4 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -17,6 +17,8 @@ import java.io.Serializable; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.annotation.Nullable; @@ -25,12 +27,41 @@ // which itself is licensed under the Apache 2.0 license. final class ImportSorterImpl { - private final List template = new ArrayList<>(); + private static final String CATCH_ALL_SUBGROUP = ""; + private static final String STATIC_KEYWORD = "static "; + private static final String STATIC_SYMBOL = "\\#"; + private static final String SUBGROUP_SEPARATOR = "|"; + + private final List importsGroups; private final Map> matchingImports = new HashMap<>(); private final List notMatching = new ArrayList<>(); private final Set allImportOrderItems = new HashSet<>(); private final Comparator ordering; + // An ImportsGroup is a group of imports ; each group is separated by blank lines. + // A group is composed of subgroups : imports are sorted by subgroup. + private static class ImportsGroup { + + private final List subGroups; + + public ImportsGroup(String importOrder) { + this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR)) + .map(this::normalizeStatic) + .collect(Collectors.toList()); + } + + private String normalizeStatic(String subgroup) { + if (subgroup.startsWith(STATIC_SYMBOL)) { + return subgroup.replace(STATIC_SYMBOL, STATIC_KEYWORD); + } + return subgroup; + } + + public List getSubGroups() { + return subGroups; + } + } + static List sort(List imports, List importsOrder, boolean wildcardsLast, String lineFormat) { ImportSorterImpl importsSorter = new ImportSorterImpl(importsOrder, wildcardsLast); return importsSorter.sort(imports, lineFormat); @@ -40,43 +71,42 @@ private List sort(List imports, String lineFormat) { filterMatchingImports(imports); mergeNotMatchingItems(false); mergeNotMatchingItems(true); - mergeMatchingItems(); + List sortedImported = mergeMatchingItems(); - return getResult(lineFormat); + return getResult(sortedImported, lineFormat); } private ImportSorterImpl(List importOrder, boolean wildcardsLast) { - List importOrderCopy = new ArrayList<>(importOrder); - normalizeStaticOrderItems(importOrderCopy); - putStaticItemIfNotExists(importOrderCopy); - template.addAll(importOrderCopy); + importsGroups = importOrder.stream().filter(Objects::nonNull).map(ImportsGroup::new).collect(Collectors.toList()); + putStaticItemIfNotExists(importsGroups); + putCatchAllGroupIfNotExists(importsGroups); + ordering = new OrderingComparator(wildcardsLast); - this.allImportOrderItems.addAll(importOrderCopy); + + List subgroups = importsGroups.stream().map(ImportsGroup::getSubGroups).flatMap(Collection::stream).collect(Collectors.toList()); + this.allImportOrderItems.addAll(subgroups); } - private static void putStaticItemIfNotExists(List allImportOrderItems) { - boolean contains = false; + private void putStaticItemIfNotExists(List importsGroups) { + boolean catchAllSubGroupExist = importsGroups.stream().anyMatch(group -> group.getSubGroups().contains(STATIC_KEYWORD)); + if (catchAllSubGroupExist) { + return; + } + int indexOfFirstStatic = 0; - for (int i = 0; i < allImportOrderItems.size(); i++) { - String allImportOrderItem = allImportOrderItems.get(i); - if (allImportOrderItem.equals("static ")) { - contains = true; - } - if (allImportOrderItem.startsWith("static ")) { + for (int i = 0; i < importsGroups.size(); i++) { + boolean subgroupMatch = importsGroups.get(i).getSubGroups().stream().anyMatch(subgroup -> subgroup.startsWith(STATIC_KEYWORD)); + if (subgroupMatch) { indexOfFirstStatic = i; } } - if (!contains) { - allImportOrderItems.add(indexOfFirstStatic, "static "); - } + importsGroups.add(indexOfFirstStatic, new ImportsGroup(STATIC_KEYWORD)); } - private static void normalizeStaticOrderItems(List allImportOrderItems) { - for (int i = 0; i < allImportOrderItems.size(); i++) { - String s = allImportOrderItems.get(i); - if (s.startsWith("\\#")) { - allImportOrderItems.set(i, s.replace("\\#", "static ")); - } + private void putCatchAllGroupIfNotExists(List importsGroups) { + boolean catchAllSubGroupExist = importsGroups.stream().anyMatch(group -> group.getSubGroups().contains(CATCH_ALL_SUBGROUP)); + if (!catchAllSubGroupExist) { + importsGroups.add(new ImportsGroup(CATCH_ALL_SUBGROUP)); } } @@ -87,9 +117,7 @@ private void filterMatchingImports(List imports) { for (String anImport : imports) { String orderItem = getBestMatchingImportOrderItem(anImport); if (orderItem != null) { - if (!matchingImports.containsKey(orderItem)) { - matchingImports.put(orderItem, new ArrayList<>()); - } + matchingImports.computeIfAbsent(orderItem, key -> new ArrayList<>()); matchingImports.get(orderItem).add(anImport); } else { notMatching.add(anImport); @@ -116,34 +144,14 @@ private void filterMatchingImports(List imports) { * not matching means it does not match any order item, so it will be appended before or after order items */ private void mergeNotMatchingItems(boolean staticItems) { - sort(notMatching); - - int firstIndexOfOrderItem = getFirstIndexOfOrderItem(notMatching, staticItems); - int indexOfOrderItem = 0; for (String notMatchingItem : notMatching) { if (!matchesStatic(staticItems, notMatchingItem)) { continue; } boolean isOrderItem = isOrderItem(notMatchingItem, staticItems); - if (isOrderItem) { - indexOfOrderItem = template.indexOf(notMatchingItem); - } else { - if (indexOfOrderItem == 0 && firstIndexOfOrderItem != 0) { - // insert before alphabetically first order item - template.add(firstIndexOfOrderItem, notMatchingItem); - firstIndexOfOrderItem++; - } else if (firstIndexOfOrderItem == 0) { - // no order is specified - if (template.size() > 0 && (template.get(template.size() - 1).startsWith("static"))) { - // insert N after last static import - template.add(ImportSorter.N); - } - template.add(notMatchingItem); - } else { - // insert after the previous order item - template.add(indexOfOrderItem + 1, notMatchingItem); - indexOfOrderItem++; - } + if (!isOrderItem) { + matchingImports.computeIfAbsent(CATCH_ALL_SUBGROUP, key -> new ArrayList<>()); + matchingImports.get(CATCH_ALL_SUBGROUP).add(notMatchingItem); } } } @@ -153,76 +161,44 @@ private boolean isOrderItem(String notMatchingItem, boolean staticItems) { return contains && matchesStatic(staticItems, notMatchingItem); } - /** - * gets first order item from sorted input list, and finds out it's index in template. - */ - private int getFirstIndexOfOrderItem(List notMatching, boolean staticItems) { - int firstIndexOfOrderItem = 0; - for (String notMatchingItem : notMatching) { - if (!matchesStatic(staticItems, notMatchingItem)) { - continue; - } - boolean isOrderItem = isOrderItem(notMatchingItem, staticItems); - if (isOrderItem) { - firstIndexOfOrderItem = template.indexOf(notMatchingItem); - break; - } - } - return firstIndexOfOrderItem; - } - private static boolean matchesStatic(boolean staticItems, String notMatchingItem) { - boolean isStatic = notMatchingItem.startsWith("static "); + boolean isStatic = notMatchingItem.startsWith(STATIC_KEYWORD); return (isStatic && staticItems) || (!isStatic && !staticItems); } - private void mergeMatchingItems() { - for (int i = 0; i < template.size(); i++) { - String item = template.get(i); - if (allImportOrderItems.contains(item)) { - // find matching items for order item - List strings = matchingImports.get(item); + private List mergeMatchingItems() { + List template = new ArrayList<>(); + for (ImportsGroup group : importsGroups) { + boolean groupIsNotEmpty = false; + for (String subgroup : group.getSubGroups()) { + List strings = matchingImports.get(subgroup); if (strings == null || strings.isEmpty()) { - // if there is none, just remove order item - template.remove(i); - i--; continue; } + groupIsNotEmpty = true; List matchingItems = new ArrayList<>(strings); sort(matchingItems); - - // replace order item by matching import statements - // this is a mess and it is only a luck that it works :-] - template.remove(i); - if (i != 0 && !template.get(i - 1).equals(ImportSorter.N)) { - template.add(i, ImportSorter.N); - i++; - } - if (i + 1 < template.size() && !template.get(i + 1).equals(ImportSorter.N) - && !template.get(i).equals(ImportSorter.N)) { - template.add(i, ImportSorter.N); - } - template.addAll(i, matchingItems); - if (i != 0 && !template.get(i - 1).equals(ImportSorter.N)) { - template.add(i, ImportSorter.N); - } - + template.addAll(matchingItems); + } + if (groupIsNotEmpty) { + template.add(ImportSorter.N); } } // if there is \n on the end, remove it - if (template.size() > 0 && template.get(template.size() - 1).equals(ImportSorter.N)) { + if (!template.isEmpty() && template.get(template.size() - 1).equals(ImportSorter.N)) { template.remove(template.size() - 1); } + return template; } private void sort(List items) { items.sort(ordering); } - private List getResult(String lineFormat) { + private List getResult(List sortedImported, String lineFormat) { List strings = new ArrayList<>(); - for (String s : template) { + for (String s : sortedImported) { if (s.equals(ImportSorter.N)) { strings.add(s); } else { diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 7f5590da21..03d933aea2 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -151,8 +151,8 @@ spotless { // Use the default importOrder configuration importOrder() // optional: you can specify import groups directly - // note: you can use an empty string for all the imports you didn't specify explicitly, and '\\#` prefix for static imports - importOrder('java', 'javax', 'com.acme', '', '\\#com.acme', '\\#') + // note: you can use an empty string for all the imports you didn't specify explicitly, '|' to join group without blank line, and '\\#` prefix for static imports + importOrder('java|javax', 'com.acme', '', '\\#com.acme', '\\#') // optional: instead of specifying import groups directly you can specify a config file // export config file: https://github.com/diffplug/spotless/blob/main/ECLIPSE_SCREENSHOTS.md#creating-spotlessimportorder importOrderFile('eclipse-import-order.txt') // import order file as exported from eclipse diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2a249357a6..d596af229b 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -181,8 +181,8 @@ any other maven phase (i.e. compile) then it can be configured as below; false - java,javax,org,com,com.diffplug,,\\#com.diffplug,\\# - + java|javax,org,com,com.diffplug,,\\#com.diffplug,\\# + @@ -286,8 +286,8 @@ These mechanisms already exist for the Gradle plugin. - java,javax,org,com,com.diffplug,,\\#com.diffplug,\\# - + java|javax,org,com,com.diffplug,,\\#com.diffplug,\\# + diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroups.test b/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroups.test new file mode 100644 index 0000000000..b2346bb19c --- /dev/null +++ b/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroups.test @@ -0,0 +1,16 @@ +import java.awt.*; +import java.lang.Runnable; +import java.lang.Thread; +import java.util.*; +import java.util.List; +import javax.annotation.Nullable; +import javax.inject.Inject; + +import org.dooda.Didoo; +import static com.foo.Bar; +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; + +import static java.lang.Exception.*; +import static java.lang.Runnable.*; +import static org.hamcrest.Matchers.*; diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedImportsSubgroups.test b/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedImportsSubgroups.test new file mode 100644 index 0000000000..35d8c465e4 --- /dev/null +++ b/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedImportsSubgroups.test @@ -0,0 +1,15 @@ +import static java.lang.Exception.*; +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import org.dooda.Didoo; +import java.util.List; +import javax.inject.Inject; +import java.lang.Thread; +import java.util.*; +import java.lang.Runnable; +import static org.hamcrest.Matchers.*; +import javax.annotation.Nullable; + +import static java.lang.Runnable.*; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.foo.Bar +import java.awt.*; diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index 332b5bc979..2db3651e02 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java @@ -34,6 +34,12 @@ void sortImportsFromArray() throws Throwable { assertOnResources(step, "java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImports.test"); } + @Test + void sortImportsFromArrayWithSubgroups() throws Throwable { + FormatterStep step = ImportOrderStep.forJava().createFrom("java|javax", "org|\\#com", "\\#"); + assertOnResources(step, "java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroups.test"); + } + @Test void sortImportsFromFile() throws Throwable { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); From a1314e93e2274da1a29bfdec6c8056fcfd0d5293 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 16:52:08 -0800 Subject: [PATCH 0060/1120] Update changelogs. --- CHANGES.md | 3 ++- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4bd52e1aa0..634542e6af 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,10 +10,11 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) -* ImportOrder: support groups of imports without blank lines [#1401](https://github.com/diffplug/spotless/pull/1401) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 5acd85ddc8..b002c5bd74 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index b08a2366fd..cd42f0e8d8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) From 997a4b5f9699cfbd5309bd81d6ef8a5d77f5403b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 22:14:59 -0800 Subject: [PATCH 0061/1120] spotlessApply --- .../java/com/diffplug/spotless/java/ImportSorterImpl.java | 6 +++--- .../com/diffplug/spotless/java/ImportOrderStepTest.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index 6dd8d58ba4..0390d99c1b 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,8 +46,8 @@ private static class ImportsGroup { public ImportsGroup(String importOrder) { this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR)) - .map(this::normalizeStatic) - .collect(Collectors.toList()); + .map(this::normalizeStatic) + .collect(Collectors.toList()); } private String normalizeStatic(String subgroup) { diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index 2db3651e02..32cf0a97c0 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From c280c4081a96d0ed3fea74ba4c0780d1431b389e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 23:12:29 -0800 Subject: [PATCH 0062/1120] Bump ktfmt to latest. --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java index 9e52bd0435..4f84d991bc 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -39,7 +39,7 @@ public class KtfmtStep { // prevent direct instantiation private KtfmtStep() {} - private static final String DEFAULT_VERSION = "0.40"; + private static final String DEFAULT_VERSION = "0.41"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; From 2ac1c46a6e161a44c0960fd1bb3ef042810799f2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 23:13:58 -0800 Subject: [PATCH 0063/1120] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 634542e6af..2b8dbcbb97 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +### Changes +* Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b002c5bd74..faf63fc28f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,6 +8,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +### Changes +* Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index cd42f0e8d8..a12b42b761 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,6 +8,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +### Changes +* Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) ## [2.27.2] - 2022-10-10 ### Fixed From 91534af62b65b0c66ef14d87000e67a9f7e044b9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 23:17:19 -0800 Subject: [PATCH 0064/1120] Bump the default ScalaFmtStep version. --- lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java index 6ef9fcd5a7..bff0d9b215 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java @@ -34,7 +34,7 @@ public class ScalaFmtStep { // prevent direct instantiation private ScalaFmtStep() {} - private static final String DEFAULT_VERSION = "3.5.9"; + private static final String DEFAULT_VERSION = "3.6.1"; private static final String DEFAULT_SCALA_MAJOR_VERSION = "2.13"; static final String NAME = "scalafmt"; From 4f20754c0930d26646110e86c71f03d5d0a0bbe0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 23:19:05 -0800 Subject: [PATCH 0065/1120] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2b8dbcbb97..04dedc886f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) +* Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index faf63fc28f..fdc40ef58b 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) +* Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a12b42b761..9d728c41e8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) +* Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) ## [2.27.2] - 2022-10-10 ### Fixed From aa8cd409b298ba801815ac759aa22deb1712c532 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 23 Nov 2022 23:22:31 -0800 Subject: [PATCH 0066/1120] Bump diktat 1.2.3 -> 1.2.4.2 --- CHANGES.md | 1 + lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java | 2 +- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 04dedc886f..0522c24fcd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) +* Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [2.30.0] - 2022-09-14 ### Added diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index f1cd3103d9..9fb5bd634f 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -32,7 +32,7 @@ private DiktatStep() {} private static final String MIN_SUPPORTED_VERSION = "1.2.1"; - private static final String DEFAULT_VERSION = "1.2.3"; + private static final String DEFAULT_VERSION = "1.2.4.2"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index fdc40ef58b..7a297ba536 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) +* Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9d728c41e8..3348adbb77 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) +* Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [2.27.2] - 2022-10-10 ### Fixed From 284dfaf0fc1b92a583f74bc3298f15295aa6a7f8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 00:05:06 -0800 Subject: [PATCH 0067/1120] Fix the scalafmt tests. --- testlib/src/main/resources/scala/scalafmt/scalafmt.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf index bcfec161f4..e15d7318fa 100644 --- a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf +++ b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.5.9 +version = 3.6.1 runner.dialect = scala213 style = defaultWithAlign # For pretty alignment. maxColumn = 20 # For my teensy narrow display From 933ad2a8b56f78cb47fcb43738b8bb2ed668c2f7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 00:20:17 -0800 Subject: [PATCH 0068/1120] Bump default `palantir-java-format` version to latest `2.10` -> `2.28` --- .../java/com/diffplug/spotless/java/PalantirJavaFormatStep.java | 2 +- .../com/diffplug/spotless/java/PalantirJavaFormatStepTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java index 89673787d6..67c55c2e86 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java @@ -29,7 +29,7 @@ private PalantirJavaFormatStep() {} private static final String NAME = "palantir-java-format"; private static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.1.0").add(11, "2.10.0"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.1.0").add(11, "2.28.0"); /** Creates a step which formats everything - code, import order, and unused imports. */ public static FormatterStep create(Provisioner provisioner) { diff --git a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java index a589992567..ad358cafc6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java @@ -40,7 +40,7 @@ void jvm13Features() throws Exception { @Test @EnabledForJreRange(min = JAVA_11) void behavior2() throws Exception { - FormatterStep step = PalantirJavaFormatStep.create("2.10.0", TestProvisioner.mavenCentral()); + FormatterStep step = PalantirJavaFormatStep.create("2.28.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/palantirjavaformat/JavaCodeUnformatted.test", "java/palantirjavaformat/JavaCodeFormatted.test") .testResource("java/palantirjavaformat/JavaCodeWithLicenseUnformatted.test", "java/palantirjavaformat/JavaCodeWithLicenseFormatted.test") From d30fc64f1cf1a51289c9d34c61c6ec134aa6274f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 00:20:23 -0800 Subject: [PATCH 0069/1120] Bump changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 0522c24fcd..fdd4925141 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) * Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) +* Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [2.30.0] - 2022-09-14 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7a297ba536..cdc2be9766 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) * Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) +* Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 3348adbb77..dccbe089d5 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) * Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) +* Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#1393](https://github.com/diffplug/spotless/pull/1393)) ## [2.27.2] - 2022-10-10 ### Fixed From 075d6375bb35ad8bb66e21beefdd2ce90a6339f3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 00:21:33 -0800 Subject: [PATCH 0070/1120] Bump lib to latest. --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 472da94a61..9fd9981370 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -52,7 +52,7 @@ dependencies { sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' - palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:2.27.0' + palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:2.28.0' String VER_KTFMT = '0.41' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" From 050009fb378caadca16c062b741f81366ea5e4ac Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 00:29:24 -0800 Subject: [PATCH 0071/1120] Stop testing node on windows because it's too slow and we test it anyway with test_npm_8. --- .circleci/config.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 83e434bcec..dd9adf4c00 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -140,13 +140,6 @@ jobs: path: lib-extra/build/test-results/test - store_test_results: path: plugin-gradle/build/test-results/test - - run: - name: gradlew testNpm - command: gradlew testNpm --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true - - store_test_results: - path: testlib/build/test-results/testNpm - - store_test_results: - path: plugin-gradle/build/test-results/testNpm changelog_print: << : *env_gradle steps: From fd70d743f4832303e468f549b4f8b8d17398b73d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 01:05:29 -0800 Subject: [PATCH 0072/1120] Fix CI --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 9fd9981370..e398e80d23 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -52,7 +52,7 @@ dependencies { sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' - palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:2.28.0' + palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm String VER_KTFMT = '0.41' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" From d7d7ecce6d10b45739e49abed74162538cec62f6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 24 Nov 2022 13:33:20 -0800 Subject: [PATCH 0073/1120] Fix publishing by bumping spotless-changelog to latest. --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 6184ab802f..591901cab5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,7 +8,7 @@ pluginManagement { // https://github.com/spotbugs/spotbugs-gradle-plugin/releases id 'com.github.spotbugs' version '5.0.13' // https://github.com/diffplug/spotless-changelog - id 'com.diffplug.spotless-changelog' version '2.4.0' + id 'com.diffplug.spotless-changelog' version '2.4.1' // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases From f2f8b08dd855d79973fa29048d654b1e12cb35cb Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 24 Nov 2022 22:19:00 +0000 Subject: [PATCH 0074/1120] Published lib/2.31.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index fdd4925141..b4bdc4479e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.31.0] - 2022-11-24 ### Added * `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed From a31bba3e5a623f2dbb4eb98d1946961b8dbd23e3 Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 24 Nov 2022 22:20:03 +0000 Subject: [PATCH 0075/1120] Published gradle/6.12.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cdc2be9766..2060e5e90c 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.12.0] - 2022-11-24 ### Added * `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 03d933aea2..fcc0336cbb 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.11.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.12.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -143,7 +143,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -267,8 +267,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -319,8 +319,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -383,7 +383,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -415,7 +415,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -447,7 +447,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -481,7 +481,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -502,7 +502,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -527,7 +527,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -567,7 +567,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -610,7 +610,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -835,7 +835,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -902,9 +902,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -937,11 +937,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.11.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 4d34ad4dda4161df018863b22c9eb1162651da1d Mon Sep 17 00:00:00 2001 From: circleci Date: Thu, 24 Nov 2022 22:21:45 +0000 Subject: [PATCH 0076/1120] Published maven/2.28.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index dccbe089d5..9baefc2ec8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.28.0] - 2022-11-24 ### Added * `importOrder` now support groups of imports without blank lines ([#1401](https://github.com/diffplug/spotless/pull/1401)) ### Fixed diff --git a/plugin-maven/README.md b/plugin-maven/README.md index d596af229b..e6a2c47aae 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.27.2/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.27.2-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.28.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.28.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From aac6de4e80171e5a8dc6aaf5682bbc1069d956ad Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 24 Nov 2022 23:26:23 +0000 Subject: [PATCH 0077/1120] chore(deps): update plugin com.diffplug.spotless to v6.12.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 591901cab5..e0f3291da5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.11.0' + id 'com.diffplug.spotless' version '6.12.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.1.0' // https://github.com/gradle-nexus/publish-plugin/releases From ad9159e266647a422ec3d6b3f89e794f36515733 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 25 Nov 2022 15:18:54 +0000 Subject: [PATCH 0078/1120] chore(deps): update dependency gradle to v7.6 --- gradle/wrapper/gradle-wrapper.jar | Bin 60756 -> 61574 bytes gradle/wrapper/gradle-wrapper.properties | 3 ++- gradlew | 12 ++++++++---- gradlew.bat | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e5832f090a2944b7473328c07c9755baa3196..943f0cbfa754578e88a3dae77fce6e3dea56edbf 100755 GIT binary patch delta 36524 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%0DGK?7GHTj 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 VwlMN}`%er%aGR6olj~j${vQ;P=LY}) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661ee7..f398c33c4b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index a69d9cb6c2..65dcd68d65 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,10 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' @@ -143,12 +143,16 @@ fi if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac diff --git a/gradlew.bat b/gradlew.bat index f127cfd49d..93e3f59f13 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% From 4816da628f08453210e0cbf503988f321cae6686 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 30 Nov 2022 16:14:47 +0000 Subject: [PATCH 0079/1120] chore(deps): update plugin org.gradle.test-retry to v1.5.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index e0f3291da5..eb818a2c0e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ pluginManagement { // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases - id 'org.gradle.test-retry' version '1.4.1' + id 'org.gradle.test-retry' version '1.5.0' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags From 1f0397c6976d02ffa034441900145ac526e651d8 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Thu, 1 Dec 2022 12:30:05 +0100 Subject: [PATCH 0080/1120] Add m2e support This closes #1413 --- plugin-maven/build.gradle | 1 + .../spotless/maven/AbstractSpotlessMojo.java | 10 ++++-- .../spotless/maven/SpotlessApplyMojo.java | 1 + .../maven/incremental/UpToDateChecker.java | 22 +++++++++++++ .../m2e/lifecycle-mapping-metadata.xml | 32 +++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 plugin-maven/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index b7ac8a36c8..3ea73e6101 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -76,6 +76,7 @@ dependencies { implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}" implementation("org.codehaus.plexus:plexus-resources:${VER_PLEXUS_RESOURCES}") implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" + implementation 'org.sonatype.plexus:plexus-build-api:0.0.7' testImplementation project(":testlib") testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" 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 f163fa2802..a0180e6d75 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 @@ -88,6 +88,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Component private ResourceManager resourceManager; + @Component + protected BuildContext buildContext; + @Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true) private String goal; @@ -344,10 +347,13 @@ private UpToDateChecker createUpToDateChecker(Iterable formatters) { Path targetDir = project.getBasedir().toPath().resolve(project.getBuild().getDirectory()); indexFile = targetDir.resolve(DEFAULT_INDEX_FILE_NAME); } + final UpToDateChecker checker; if (upToDateChecking != null && upToDateChecking.isEnabled()) { getLog().info("Up-to-date checking enabled"); - return UpToDateChecker.forProject(project, indexFile, formatters, getLog()); + checker = UpToDateChecker.forProject(project, indexFile, formatters, getLog()); + } else { + checker = UpToDateChecker.noop(project, indexFile, getLog()); } - return UpToDateChecker.noop(project, indexFile, getLog()); + return UpToDateChecker.wrapWithBuildContext(checker, buildContext); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 6ea67240ee..4f3fb64f5a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -45,6 +45,7 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file); if (!dirtyState.isClean() && !dirtyState.didNotConverge()) { dirtyState.writeCanonicalTo(file); + buildContext.refresh(file); } } catch (IOException e) { throw new MojoExecutionException("Unable to format file " + file, e); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index 2fd2f3a1ea..6dd21728e3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -19,6 +19,7 @@ import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; +import org.sonatype.plexus.build.incremental.BuildContext; import com.diffplug.spotless.Formatter; @@ -37,4 +38,25 @@ static UpToDateChecker noop(MavenProject project, Path indexFile, Log log) { static UpToDateChecker forProject(MavenProject project, Path indexFile, Iterable formatters, Log log) { return IndexBasedChecker.create(project, indexFile, formatters, log); } + + static UpToDateChecker wrapWithBuildContext(UpToDateChecker delegate, BuildContext buildContext) { + return new UpToDateChecker() { + + @Override + public void setUpToDate(Path file) { + delegate.setUpToDate(file); + } + + @Override + public boolean isUpToDate(Path file) { + return !buildContext.hasDelta(file.toFile()) || delegate.isUpToDate(file); + } + + @Override + public void close() { + delegate.close(); + } + }; + } + } diff --git a/plugin-maven/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/plugin-maven/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml new file mode 100644 index 0000000000..9000b83704 --- /dev/null +++ b/plugin-maven/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml @@ -0,0 +1,32 @@ + + + + + + + + apply + check + + + + + true + false + + + + + \ No newline at end of file From a7c0f67a76da52d80f575fdf43ac481906210999 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Thu, 1 Dec 2022 12:41:37 +0100 Subject: [PATCH 0081/1120] fix formatting --- .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 2 +- .../spotless/maven/incremental/UpToDateChecker.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 4f3fb64f5a..7a15d01b17 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index 6dd21728e3..f63b8b4dfc 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -38,10 +38,10 @@ static UpToDateChecker noop(MavenProject project, Path indexFile, Log log) { static UpToDateChecker forProject(MavenProject project, Path indexFile, Iterable formatters, Log log) { return IndexBasedChecker.create(project, indexFile, formatters, log); } - + static UpToDateChecker wrapWithBuildContext(UpToDateChecker delegate, BuildContext buildContext) { return new UpToDateChecker() { - + @Override public void setUpToDate(Path file) { delegate.setUpToDate(file); @@ -58,5 +58,5 @@ public void close() { } }; } - + } From fa232426a5ea26cee7a8e483b3a81c3677a1c1d1 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Thu, 1 Dec 2022 12:45:57 +0100 Subject: [PATCH 0082/1120] add missing import --- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 1 + 1 file changed, 1 insertion(+) 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 a0180e6d75..e4fdc7dcd0 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 @@ -50,6 +50,7 @@ import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; +import org.sonatype.plexus.build.incremental.BuildContext; import com.diffplug.spotless.Formatter; import com.diffplug.spotless.LineEnding; From b7b17a9831095685622934f34133585c55517c4e Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Sat, 3 Dec 2022 09:37:48 +0100 Subject: [PATCH 0083/1120] replace OR by AND --- .../diffplug/spotless/maven/incremental/UpToDateChecker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index f63b8b4dfc..be971cb374 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -49,7 +49,7 @@ public void setUpToDate(Path file) { @Override public boolean isUpToDate(Path file) { - return !buildContext.hasDelta(file.toFile()) || delegate.isUpToDate(file); + return !buildContext.hasDelta(file.toFile()) && delegate.isUpToDate(file); } @Override From b22f54fe8367051e3a3bd969e1c7155713beb1e3 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Sat, 3 Dec 2022 09:48:00 +0100 Subject: [PATCH 0084/1120] fix condition to only evaluate IndexBasedChecker when necessary --- .../diffplug/spotless/maven/incremental/UpToDateChecker.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index be971cb374..bda325d992 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -49,7 +49,10 @@ public void setUpToDate(Path file) { @Override public boolean isUpToDate(Path file) { - return !buildContext.hasDelta(file.toFile()) && delegate.isUpToDate(file); + if (buildContext.hasDelta(file)) { + return delegate.isUpToDate(file); + } + return true; } @Override From fc02156bdc8c265a20eb475e48438e93af783412 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Mon, 5 Dec 2022 09:53:10 +0100 Subject: [PATCH 0085/1120] fix compilation error and make field private --- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 2 +- .../diffplug/spotless/maven/incremental/UpToDateChecker.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 e4fdc7dcd0..2f3f0e4ab2 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 @@ -90,7 +90,7 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { private ResourceManager resourceManager; @Component - protected BuildContext buildContext; + private BuildContext buildContext; @Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true) private String goal; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index bda325d992..40dc84c8c6 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -49,7 +49,7 @@ public void setUpToDate(Path file) { @Override public boolean isUpToDate(Path file) { - if (buildContext.hasDelta(file)) { + if (buildContext.hasDelta(file.toFile())) { return delegate.isUpToDate(file); } return true; From 52ea9fb8e1694245ce74f1c03b3e3ffbdcddbdb1 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Mon, 5 Dec 2022 09:56:08 +0100 Subject: [PATCH 0086/1120] revert making field private, as accessed in subclasses --- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2f3f0e4ab2..e4fdc7dcd0 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 @@ -90,7 +90,7 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { private ResourceManager resourceManager; @Component - private BuildContext buildContext; + protected BuildContext buildContext; @Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true) private String goal; From 99272b229158ef0116c53ed9e8a7f69008638f93 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 9 Dec 2022 13:59:44 +0000 Subject: [PATCH 0087/1120] fix(deps): update dependency com.facebook:ktfmt to v0.42 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index e398e80d23..18935800fa 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -54,7 +54,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm - String VER_KTFMT = '0.41' + String VER_KTFMT = '0.42' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") { From 2e4197ec7a99482a090d3f5a7da70f040e497e98 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Thu, 15 Dec 2022 14:55:19 -0800 Subject: [PATCH 0088/1120] Fix typo in gradle properties Fix typo in constant used by gradle scripts: ECLISPE -> ECLIPSE --- _ext/eclipse-cdt/build.gradle | 4 ++-- _ext/eclipse-cdt/gradle.properties | 4 ++-- _ext/eclipse-groovy/build.gradle | 2 +- _ext/eclipse-groovy/gradle.properties | 2 +- _ext/eclipse-wtp/build.gradle | 10 +++++----- _ext/eclipse-wtp/gradle.properties | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/_ext/eclipse-cdt/build.gradle b/_ext/eclipse-cdt/build.gradle index 17819f4a2e..93ccac3b24 100644 --- a/_ext/eclipse-cdt/build.gradle +++ b/_ext/eclipse-cdt/build.gradle @@ -19,13 +19,13 @@ apply from: rootProject.file('gradle/java-publish.gradle') dependencies { implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" // Provides text partitioners for formatters - implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLISPE_JFACE}") { + implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } // Required to by CCorePlugin calling CDTLogWriter implementation "com.ibm.icu:icu4j:${VER_IBM_ICU}" // Required to by CCorePlugin calling PositionTrackerManager - implementation "org.eclipse.platform:org.eclipse.core.filebuffers:${VER_ECLISPE_EFS}" + implementation "org.eclipse.platform:org.eclipse.core.filebuffers:${VER_ECLIPSE_EFS}" testImplementation("org.slf4j:slf4j-simple:${VER_SLF4J}") } diff --git a/_ext/eclipse-cdt/gradle.properties b/_ext/eclipse-cdt/gradle.properties index 9c1c8a7ee6..10166b51d0 100644 --- a/_ext/eclipse-cdt/gradle.properties +++ b/_ext/eclipse-cdt/gradle.properties @@ -7,6 +7,6 @@ VER_JAVA=11 # Compile dependencies VER_ECLIPSE_CDT=10.5 VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[ -VER_ECLISPE_JFACE=[3.18.0,4.0.0[ -VER_ECLISPE_EFS=[3.7.0,4.0.0[ +VER_ECLIPSE_JFACE=[3.18.0,4.0.0[ +VER_ECLIPSE_EFS=[3.7.0,4.0.0[ VER_IBM_ICU=[67.1,68[ diff --git a/_ext/eclipse-groovy/build.gradle b/_ext/eclipse-groovy/build.gradle index e1382acd76..00a7fed489 100644 --- a/_ext/eclipse-groovy/build.gradle +++ b/_ext/eclipse-groovy/build.gradle @@ -41,7 +41,7 @@ apply from: rootProject.file('gradle/java-publish.gradle') dependencies { implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" // Provides text partitioners for formatters - implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLISPE_JFACE}") { + implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } testImplementation("org.slf4j:slf4j-simple:${VER_SLF4J}") diff --git a/_ext/eclipse-groovy/gradle.properties b/_ext/eclipse-groovy/gradle.properties index b8a21001fd..9569e765bc 100644 --- a/_ext/eclipse-groovy/gradle.properties +++ b/_ext/eclipse-groovy/gradle.properties @@ -7,7 +7,7 @@ VER_JAVA=11 # Compile VER_ECLIPSE=4.21 VER_SPOTLESS_ECLISPE_BASE=[3.4.2,4.0.0[ -VER_ECLISPE_JFACE=[3.15.300,4.0.0[ +VER_ECLIPSE_JFACE=[3.15.300,4.0.0[ VER_GRECLIPSE=4.3.0 VER_GROOVY=4.0.0 # Use org.eclipse.jdt.core patched for Groovy-Eclipse diff --git a/_ext/eclipse-wtp/build.gradle b/_ext/eclipse-wtp/build.gradle index 4001e100c2..ba32385a1b 100644 --- a/_ext/eclipse-wtp/build.gradle +++ b/_ext/eclipse-wtp/build.gradle @@ -64,20 +64,20 @@ dependencies { // Required by most WPT formatters implementation "com.ibm.icu:icu4j:${VER_IBM_ICU}" // The XSD/DTD and other models are defined with EMF. - implementation "org.eclipse.emf:org.eclipse.emf.common:${VER_ECLISPE_EMF}" - implementation "org.eclipse.emf:org.eclipse.emf.ecore:${VER_ECLISPE_EMF}" + implementation "org.eclipse.emf:org.eclipse.emf.common:${VER_ECLIPSE_EMF}" + implementation "org.eclipse.emf:org.eclipse.emf.ecore:${VER_ECLIPSE_EMF}" // Some WPT plugins requires OSGI bundle interfaces (but not effectively used) implementation "org.eclipse.platform:org.eclipse.osgi.services:${VER_ECLIPSE_OSGI_SERVICES}" // Provides document data structure and file buffers for formatters implementation "org.eclipse.platform:org.eclipse.core.filebuffers:${VER_ECLIPSE_FILE_BUFFERS}" // Provides text partitioners for formatters - implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLISPE_JFACE}") { + implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' } // Some WPT plugins use the EFS for storing temporary worspace data - implementation "org.eclipse.platform:org.eclipse.core.filesystem:${VER_ECLISPE_EFS}" + implementation "org.eclipse.platform:org.eclipse.core.filesystem:${VER_ECLIPSE_EFS}" // Required by org.eclipse.wst.xsd.core - implementation "org.eclipse.emf:org.eclipse.xsd:${VER_ECLISPE_XSD}" + implementation "org.eclipse.emf:org.eclipse.xsd:${VER_ECLIPSE_XSD}" testImplementation("org.slf4j:slf4j-simple:${VER_SLF4J}") } diff --git a/_ext/eclipse-wtp/gradle.properties b/_ext/eclipse-wtp/gradle.properties index 743748d1ba..f6cedd63e3 100644 --- a/_ext/eclipse-wtp/gradle.properties +++ b/_ext/eclipse-wtp/gradle.properties @@ -8,9 +8,9 @@ VER_JAVA=11 VER_ECLIPSE_WTP=2021-09 VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[ VER_IBM_ICU=[67.1,68[ -VER_ECLISPE_EMF=[2.22.0,3.0.0[ +VER_ECLIPSE_EMF=[2.22.0,3.0.0[ VER_ECLIPSE_OSGI_SERVICES=[3.10.0,4.0.0[ VER_ECLIPSE_FILE_BUFFERS=[3.7.0,4.0.0[ -VER_ECLISPE_JFACE=[3.18.0,4.0.0[ -VER_ECLISPE_EFS=[1.9.0,2.0.0[ -VER_ECLISPE_XSD=[2.18.0,3.0.0[ +VER_ECLIPSE_JFACE=[3.18.0,4.0.0[ +VER_ECLIPSE_EFS=[1.9.0,2.0.0[ +VER_ECLIPSE_XSD=[2.18.0,3.0.0[ From 697236562f7ce20025c619d30fe5756b1404bd0c Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Thu, 15 Dec 2022 14:56:28 -0800 Subject: [PATCH 0089/1120] Reduce ratchet memory usage for multi-module projects Ratchet creates a cache of Git repository per project but each Git repository is a new FileRepository instance even if two projects share the same repository on disk. Since FileRepository is thread-safe, change GitRatchet to cache FileRepository instances per git repository --- .../com/diffplug/spotless/extra/GitRatchet.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java index 6b8d5a9f41..3b0e3c06ed 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java @@ -138,6 +138,7 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) { private final static int WORKDIR = 2; Map gitRoots = new HashMap<>(); + Map gitRepositories = new HashMap<>(); Table rootTreeShaCache = HashBasedTable.create(); Map subtreeShaCache = new HashMap<>(); @@ -174,7 +175,7 @@ protected Repository repositoryFor(Project project) throws IOException { protected abstract @Nullable Project getParent(Project project); - private static @Nullable Repository traverseParentsUntil(File startWith, @Nullable File file) throws IOException { + private @Nullable Repository traverseParentsUntil(File startWith, @Nullable File file) throws IOException { while (startWith != null && !Objects.equals(startWith, file)) { if (isGitRoot(startWith)) { return createRepo(startWith); @@ -190,8 +191,14 @@ private static boolean isGitRoot(File dir) { return dotGit != null && RepositoryCache.FileKey.isGitRepository(dotGit, FS.DETECTED); } - static Repository createRepo(File dir) throws IOException { - return FileRepositoryBuilder.create(GitWorkarounds.getDotGitDir(dir)); + Repository createRepo(File dir) throws IOException { + File dotGitDir = GitWorkarounds.getDotGitDir(dir); + Repository repo = gitRepositories.get(dotGitDir); + if (repo == null) { + repo = FileRepositoryBuilder.create(dotGitDir); + gitRepositories.put(dotGitDir, repo); + } + return repo; } /** From f6f37f4d9e4cad9e1732afbfee4615a7fbbd1345 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Thu, 15 Dec 2022 15:07:57 -0800 Subject: [PATCH 0090/1120] Update CHANGES.md --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b4bdc4479e..b781dacb6d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +* Share git repositories across projects when using ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 2060e5e90c..a4aa656c3f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +* Share git repositories across projects when using ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9baefc2ec8..6b7d3e40d2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +* Share git repositories across projects when using ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) From fd6cd9a36ef70f68a128169e93d3430604101b94 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Thu, 15 Dec 2022 15:14:31 -0800 Subject: [PATCH 0091/1120] Add missing typo --- _ext/eclipse-cdt/build.gradle | 2 +- _ext/eclipse-cdt/gradle.properties | 2 +- _ext/eclipse-groovy/build.gradle | 2 +- _ext/eclipse-groovy/gradle.properties | 2 +- _ext/eclipse-jdt/build.gradle | 2 +- _ext/eclipse-jdt/gradle.properties | 2 +- _ext/eclipse-wtp/build.gradle | 2 +- _ext/eclipse-wtp/gradle.properties | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/_ext/eclipse-cdt/build.gradle b/_ext/eclipse-cdt/build.gradle index 93ccac3b24..0982b7d555 100644 --- a/_ext/eclipse-cdt/build.gradle +++ b/_ext/eclipse-cdt/build.gradle @@ -17,7 +17,7 @@ apply from: rootProject.file('gradle/java-publish.gradle') dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" + implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" // Provides text partitioners for formatters implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' diff --git a/_ext/eclipse-cdt/gradle.properties b/_ext/eclipse-cdt/gradle.properties index 10166b51d0..821ceea4d1 100644 --- a/_ext/eclipse-cdt/gradle.properties +++ b/_ext/eclipse-cdt/gradle.properties @@ -6,7 +6,7 @@ VER_JAVA=11 # Compile dependencies VER_ECLIPSE_CDT=10.5 -VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[ +VER_SPOTLESS_ECLIPSE_BASE=[3.5.0,4.0.0[ VER_ECLIPSE_JFACE=[3.18.0,4.0.0[ VER_ECLIPSE_EFS=[3.7.0,4.0.0[ VER_IBM_ICU=[67.1,68[ diff --git a/_ext/eclipse-groovy/build.gradle b/_ext/eclipse-groovy/build.gradle index 00a7fed489..a45590fada 100644 --- a/_ext/eclipse-groovy/build.gradle +++ b/_ext/eclipse-groovy/build.gradle @@ -39,7 +39,7 @@ apply from: rootProject.file('_ext/gradle/p2-fat-jar-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" + implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" // Provides text partitioners for formatters implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' diff --git a/_ext/eclipse-groovy/gradle.properties b/_ext/eclipse-groovy/gradle.properties index 9569e765bc..c1c6101caa 100644 --- a/_ext/eclipse-groovy/gradle.properties +++ b/_ext/eclipse-groovy/gradle.properties @@ -6,7 +6,7 @@ VER_JAVA=11 # Compile VER_ECLIPSE=4.21 -VER_SPOTLESS_ECLISPE_BASE=[3.4.2,4.0.0[ +VER_SPOTLESS_ECLIPSE_BASE=[3.4.2,4.0.0[ VER_ECLIPSE_JFACE=[3.15.300,4.0.0[ VER_GRECLIPSE=4.3.0 VER_GROOVY=4.0.0 diff --git a/_ext/eclipse-jdt/build.gradle b/_ext/eclipse-jdt/build.gradle index b0967822a9..283e52f86d 100644 --- a/_ext/eclipse-jdt/build.gradle +++ b/_ext/eclipse-jdt/build.gradle @@ -10,7 +10,7 @@ ext { } dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" + implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" implementation("org.eclipse.jdt:org.eclipse.jdt.core:${VER_ECLIPSE_JDT_CORE}") { exclude group: 'org.eclipse.platform', module: 'org.eclipse.ant.core' exclude group: 'org.eclipse.platform', module: 'org.eclipse.core.expressions' diff --git a/_ext/eclipse-jdt/gradle.properties b/_ext/eclipse-jdt/gradle.properties index 82a4423140..51d5f41014 100644 --- a/_ext/eclipse-jdt/gradle.properties +++ b/_ext/eclipse-jdt/gradle.properties @@ -6,4 +6,4 @@ VER_JAVA=11 # Compile VER_ECLIPSE_JDT_CORE=[3.13.0,4.0.0[ -VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[ +VER_SPOTLESS_ECLIPSE_BASE=[3.5.0,4.0.0[ diff --git a/_ext/eclipse-wtp/build.gradle b/_ext/eclipse-wtp/build.gradle index ba32385a1b..92a78578f6 100644 --- a/_ext/eclipse-wtp/build.gradle +++ b/_ext/eclipse-wtp/build.gradle @@ -60,7 +60,7 @@ apply from: rootProject.file('_ext/gradle/p2-fat-jar-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLISPE_BASE}" + implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" // Required by most WPT formatters implementation "com.ibm.icu:icu4j:${VER_IBM_ICU}" // The XSD/DTD and other models are defined with EMF. diff --git a/_ext/eclipse-wtp/gradle.properties b/_ext/eclipse-wtp/gradle.properties index f6cedd63e3..a341c0fb49 100644 --- a/_ext/eclipse-wtp/gradle.properties +++ b/_ext/eclipse-wtp/gradle.properties @@ -6,7 +6,7 @@ VER_JAVA=11 # Compile VER_ECLIPSE_WTP=2021-09 -VER_SPOTLESS_ECLISPE_BASE=[3.5.0,4.0.0[ +VER_SPOTLESS_ECLIPSE_BASE=[3.5.0,4.0.0[ VER_IBM_ICU=[67.1,68[ VER_ECLIPSE_EMF=[2.22.0,3.0.0[ VER_ECLIPSE_OSGI_SERVICES=[3.10.0,4.0.0[ From 7949f87aced31c56b6fbc86d9370dd7163816c90 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Thu, 15 Dec 2022 15:11:01 -0800 Subject: [PATCH 0092/1120] Update CHANGES.md --- _ext/eclipse-cdt/CHANGES.md | 2 ++ _ext/eclipse-groovy/CHANGES.md | 2 ++ _ext/eclipse-wtp/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/_ext/eclipse-cdt/CHANGES.md b/_ext/eclipse-cdt/CHANGES.md index bdc7d99ea9..cda212bd3d 100644 --- a/_ext/eclipse-cdt/CHANGES.md +++ b/_ext/eclipse-cdt/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `9.9.0`). ## [Unreleased] +### Fixed +* Fix typo in gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) ## [10.5.0] - 2021-12-13 ### Added diff --git a/_ext/eclipse-groovy/CHANGES.md b/_ext/eclipse-groovy/CHANGES.md index c80ce061d5..b0f909ccb2 100644 --- a/_ext/eclipse-groovy/CHANGES.md +++ b/_ext/eclipse-groovy/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.5.0`). ## [Unreleased] +### Fixed +* Fix typo in gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) ## [4.3.0] - 2021-10-13 ### Added diff --git a/_ext/eclipse-wtp/CHANGES.md b/_ext/eclipse-wtp/CHANGES.md index 6fc919aa0e..0001618b1f 100644 --- a/_ext/eclipse-wtp/CHANGES.md +++ b/_ext/eclipse-wtp/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.15.1`). ## [Unreleased] +### Fixed +* Fix typo in gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) ## [3.23.0] - 2021-09-22 ### Added From 38ca03bd1613bbfb368f45dabbe21b109aba0162 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 18 Dec 2022 10:20:11 -0800 Subject: [PATCH 0093/1120] spotlessApply --- build.gradle | 2 +- .../diffplug/spotless/extra/GitRatchet.java | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 5766e6b85e..f9e3d0de21 100644 --- a/build.gradle +++ b/build.gradle @@ -18,4 +18,4 @@ spotless { trimTrailingWhitespace() endWithNewline() } -} +} \ No newline at end of file diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java index 3b0e3c06ed..4ba59e6aa5 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -138,7 +138,7 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) { private final static int WORKDIR = 2; Map gitRoots = new HashMap<>(); - Map gitRepositories = new HashMap<>(); + Map gitRepositories = new HashMap<>(); Table rootTreeShaCache = HashBasedTable.create(); Map subtreeShaCache = new HashMap<>(); @@ -192,13 +192,13 @@ private static boolean isGitRoot(File dir) { } Repository createRepo(File dir) throws IOException { - File dotGitDir = GitWorkarounds.getDotGitDir(dir); - Repository repo = gitRepositories.get(dotGitDir); - if (repo == null) { - repo = FileRepositoryBuilder.create(dotGitDir); - gitRepositories.put(dotGitDir, repo); - } - return repo; + File dotGitDir = GitWorkarounds.getDotGitDir(dir); + Repository repo = gitRepositories.get(dotGitDir); + if (repo == null) { + repo = FileRepositoryBuilder.create(dotGitDir); + gitRepositories.put(dotGitDir, repo); + } + return repo; } /** From a4d552625952b62dd28e2e59fa6f76d179426091 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Mon, 19 Dec 2022 10:47:37 -0800 Subject: [PATCH 0094/1120] Simplify GitRatchet cache logic Change GitRatchet cache logic to use git root instead of projects as a caching key for FileRepository. --- .../diffplug/spotless/extra/GitRatchet.java | 55 +++---------------- 1 file changed, 8 insertions(+), 47 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java index 4ba59e6aa5..31f2f597f9 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import java.util.Optional; import javax.annotation.Nullable; @@ -137,8 +136,7 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) { private final static int INDEX = 1; private final static int WORKDIR = 2; - Map gitRoots = new HashMap<>(); - Map gitRepositories = new HashMap<>(); + Map gitRoots = new HashMap<>(); Table rootTreeShaCache = HashBasedTable.create(); Map subtreeShaCache = new HashMap<>(); @@ -148,25 +146,14 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) { * We cache the Repository for every Project in {@code gitRoots}, and use dynamic programming to populate it. */ protected Repository repositoryFor(Project project) throws IOException { - Repository repo = gitRoots.get(project); + File projectGitDir = GitWorkarounds.getDotGitDir(getDir(project)); + if (projectGitDir == null || !RepositoryCache.FileKey.isGitRepository(projectGitDir, FS.DETECTED)) { + throw new IllegalArgumentException("Cannot find git repository in any parent directory"); + } + Repository repo = gitRoots.get(projectGitDir); if (repo == null) { - if (isGitRoot(getDir(project))) { - repo = createRepo(getDir(project)); - } else { - Project parentProj = getParent(project); - if (parentProj == null) { - repo = traverseParentsUntil(getDir(project).getParentFile(), null); - if (repo == null) { - throw new IllegalArgumentException("Cannot find git repository in any parent directory"); - } - } else { - repo = traverseParentsUntil(getDir(project).getParentFile(), getDir(parentProj)); - if (repo == null) { - repo = repositoryFor(parentProj); - } - } - } - gitRoots.put(project, repo); + repo = FileRepositoryBuilder.create(projectGitDir); + gitRoots.put(projectGitDir, repo); } return repo; } @@ -175,32 +162,6 @@ protected Repository repositoryFor(Project project) throws IOException { protected abstract @Nullable Project getParent(Project project); - private @Nullable Repository traverseParentsUntil(File startWith, @Nullable File file) throws IOException { - while (startWith != null && !Objects.equals(startWith, file)) { - if (isGitRoot(startWith)) { - return createRepo(startWith); - } else { - startWith = startWith.getParentFile(); - } - } - return null; - } - - private static boolean isGitRoot(File dir) { - File dotGit = GitWorkarounds.getDotGitDir(dir); - return dotGit != null && RepositoryCache.FileKey.isGitRepository(dotGit, FS.DETECTED); - } - - Repository createRepo(File dir) throws IOException { - File dotGitDir = GitWorkarounds.getDotGitDir(dir); - Repository repo = gitRepositories.get(dotGitDir); - if (repo == null) { - repo = FileRepositoryBuilder.create(dotGitDir); - gitRepositories.put(dotGitDir, repo); - } - return repo; - } - /** * Fast way to return treeSha of the given ref against the git repository which stores the given project. * Because of parallel project evaluation, there may be races here, so we synchronize on ourselves. However, this method From 079257aa340e5ace264eb63cddda6260ddc7ee79 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 28 Dec 2022 16:25:37 +0000 Subject: [PATCH 0095/1120] fix(deps): update dependency org.mockito:mockito-core to v4.11.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index fc2b2b43da..577ed87535 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.1 VER_ASSERTJ=3.23.1 -VER_MOCKITO=4.9.0 +VER_MOCKITO=4.11.0 # Used for Maven Plugin VER_MAVEN_API=3.0 From e19bc6739c12c440e1b850bfba8e8b0876f6148d Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Fri, 30 Dec 2022 11:44:58 +0100 Subject: [PATCH 0096/1120] add support for skipping first few lines matching a pattern --- .../spotless/generic/LicenseHeaderStep.java | 69 ++++++++++++++----- .../gradle/spotless/FormatExtension.java | 6 ++ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 6a34c08828..5345adc150 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -51,7 +51,7 @@ public static LicenseHeaderStep headerDelimiter(String header, String delimiter) } public static LicenseHeaderStep headerDelimiter(ThrowingEx.Supplier headerLazy, String delimiter) { - return new LicenseHeaderStep(null, null, headerLazy, delimiter, DEFAULT_YEAR_DELIMITER, () -> YearMode.PRESERVE); + return new LicenseHeaderStep(null, null, headerLazy, delimiter, DEFAULT_YEAR_DELIMITER, () -> YearMode.PRESERVE, null); } final String name; @@ -60,14 +60,16 @@ public static LicenseHeaderStep headerDelimiter(ThrowingEx.Supplier head final String delimiter; final String yearSeparator; final Supplier yearMode; + final @Nullable String skipLinesPattern; - private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode) { + private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode, @Nullable String skipLinesPattern) { this.name = sanitizeName(name); - this.contentPattern = sanitizeContentPattern(contentPattern); + this.contentPattern = sanitizePattern(contentPattern); this.headerLazy = Objects.requireNonNull(headerLazy); this.delimiter = Objects.requireNonNull(delimiter); this.yearSeparator = Objects.requireNonNull(yearSeparator); this.yearMode = Objects.requireNonNull(yearMode); + this.skipLinesPattern = sanitizePattern(skipLinesPattern); } public String getName() { @@ -75,11 +77,11 @@ public String getName() { } public LicenseHeaderStep withName(String name) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withContentPattern(String contentPattern) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withHeaderString(String header) { @@ -87,15 +89,15 @@ public LicenseHeaderStep withHeaderString(String header) { } public LicenseHeaderStep withHeaderLazy(ThrowingEx.Supplier headerLazy) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withDelimiter(String delimiter) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withYearSeparator(String yearSeparator) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public LicenseHeaderStep withYearMode(YearMode yearMode) { @@ -103,7 +105,11 @@ public LicenseHeaderStep withYearMode(YearMode yearMode) { } public LicenseHeaderStep withYearModeLazy(Supplier yearMode) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + } + + public LicenseHeaderStep withSkipLinesPattern(String skipLinesPattern) { + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); } public FormatterStep build() { @@ -112,7 +118,7 @@ public FormatterStep build() { if (yearMode.get() == YearMode.SET_FROM_GIT) { formatterStep = FormatterStep.createNeverUpToDateLazy(name, () -> { boolean updateYear = false; // doesn't matter - Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear); + Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); return FormatterFunc.needsFile(runtime::setLicenseHeaderYearsFromGitHistory); }); } else { @@ -130,7 +136,7 @@ public FormatterStep build() { default: throw new IllegalStateException(yearMode.toString()); } - return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear); + return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); }, step -> step::format); } @@ -156,18 +162,18 @@ private String sanitizeName(@Nullable String name) { } @Nullable - private String sanitizeContentPattern(@Nullable String contentPattern) { - if (contentPattern == null) { - return contentPattern; + private String sanitizePattern(@Nullable String pattern) { + if (pattern == null) { + return pattern; } - contentPattern = contentPattern.trim(); + pattern = pattern.trim(); - if (contentPattern.isEmpty()) { + if (pattern.isEmpty()) { return null; } - return contentPattern; + return pattern; } private static final String DEFAULT_NAME_PREFIX = LicenseHeaderStep.class.getName(); @@ -195,6 +201,7 @@ private static class Runtime implements Serializable { private static final long serialVersionUID = 1475199492829130965L; private final Pattern delimiterPattern; + private final @Nullable Pattern skipLinesPattern; private final String yearSepOrFull; private final @Nullable String yearToday; private final @Nullable String beforeYear; @@ -203,7 +210,7 @@ private static class Runtime implements Serializable { private final boolean licenseHeaderWithRange; /** The license that we'd like enforced. */ - private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest) { + private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest, @Nullable String skipLinesPattern) { if (delimiter.contains("\n")) { throw new IllegalArgumentException("The delimiter must not contain any newlines."); } @@ -213,6 +220,7 @@ private Runtime(String licenseHeader, String delimiter, String yearSeparator, bo licenseHeader = licenseHeader + "\n"; } this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE); + this.skipLinesPattern = skipLinesPattern == null ? null : Pattern.compile(skipLinesPattern); Optional yearToken = getYearToken(licenseHeader); if (yearToken.isPresent()) { @@ -254,6 +262,31 @@ private static Optional getYearToken(String licenseHeader) { /** Formats the given string. */ private String format(String raw) { + if (skipLinesPattern == null) { + return addOrUpdateLicenseHeader(raw); + } else { + String[] lines = raw.split("\n"); + StringBuilder skippedLinesBuilder = new StringBuilder(); + StringBuilder remainingLinesBuilder = new StringBuilder(); + boolean lastMatched = true; + for (String line : lines) { + if (lastMatched) { + Matcher matcher = skipLinesPattern.matcher(line); + if (matcher.find()) { + skippedLinesBuilder.append(line).append('\n'); + } else { + remainingLinesBuilder.append(line).append('\n'); + lastMatched = false; + } + } else { + remainingLinesBuilder.append(line).append('\n'); + } + } + return skippedLinesBuilder + addOrUpdateLicenseHeader(remainingLinesBuilder.toString()); + } + } + + private String addOrUpdateLicenseHeader(String raw) { Matcher contentMatcher = delimiterPattern.matcher(raw); if (!contentMatcher.find()) { throw new IllegalArgumentException("Unable to find delimiter regex " + delimiterPattern); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index de0313eab4..84690bf063 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -462,6 +462,12 @@ public LicenseHeaderConfig yearSeparator(String yearSeparator) { return this; } + public LicenseHeaderConfig skipLinesPattern(String skipLinesPattern) { + builder = builder.withSkipLinesPattern(skipLinesPattern); + replaceStep(createStep()); + return this; + } + /** * @param updateYearWithLatest * Will turn {@code 2004} into {@code 2004-2020}, and {@code 2004-2019} into {@code 2004-2020} From e46b9a1a3b4581085d50d6002a2a78e3790b96e2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 31 Dec 2022 01:09:30 -0800 Subject: [PATCH 0097/1120] Fix changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b781dacb6d..a59f0c8570 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ## [2.31.0] - 2022-11-24 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a4aa656c3f..ebe7d0ceea 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ## [6.12.0] - 2022-11-24 ### Added @@ -10,7 +12,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) -* Share git repositories across projects when using ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6b7d3e40d2..07903bfae1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) ## [2.28.0] - 2022-11-24 ### Added From 9580038f011220a9a1047ac77f33649709d04c12 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 31 Dec 2022 09:27:29 +0000 Subject: [PATCH 0098/1120] chore(deps): update plugin io.github.davidburstrom.version-compatibility to v0.3.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index eb818a2c0e..828a3629c7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,7 +16,7 @@ pluginManagement { // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags - id 'io.github.davidburstrom.version-compatibility' version '0.1.0' + id 'io.github.davidburstrom.version-compatibility' version '0.3.0' } } plugins { From 46e8db412f261542f696db895430ef7edcd16039 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 31 Dec 2022 01:52:24 -0800 Subject: [PATCH 0099/1120] Add missing changelog entry for #1414 and #1413 --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 07903bfae1..e1c6b8ce48 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added support for M2E's incremental compilation ([#1414](https://github.com/diffplug/spotless/pull/1414) fixes [#1413](https://github.com/diffplug/spotless/issues/1413)) ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) From 18fd936aac915cbcb6bb7aa1e110ce6504d9a306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Burstr=C3=B6m?= Date: Sun, 1 Jan 2023 13:01:31 +0100 Subject: [PATCH 0100/1120] Fix the documentation so that it looks sane in Vim too --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bf1996778d..782e377d58 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,7 +36,7 @@ For the folders below in monospace text, they are published on maven central at | `lib-extra` | Contains the optional parts of Spotless which require external dependencies. `LineEnding.GIT_ATTRIBUTES` won't work unless `lib-extra` is available. | | `plugin-gradle` | Integrates spotless and all of its formatters into Gradle. | | `plugin-maven` | Integrates spotless and all of its formatters into Maven. | -| _ext | Folder for generating glue jars (specifically packaging Eclipse jars from p2 for consumption using maven). +| `_ext` | Folder for generating glue jars (specifically packaging Eclipse jars from p2 for consumption using maven). ## How to add a new FormatterStep @@ -119,7 +119,7 @@ There are many great formatters (prettier, clang-format, black, etc.) which live Because of Spotless' up-to-date checking and [git ratcheting](https://github.com/diffplug/spotless/tree/main/plugin-gradle#ratchet), Spotless actually doesn't have to call formatters very often, so even an expensive shell call for every single invocation isn't that bad. Anything that works is better than nothing, and we can always speed things up later if it feels too slow (but it probably won't). -## How to enable the _ext projects +## How to enable the `_ext` projects The `_ext` projects are disabled per default, since: From 918547f92cc6f1140f5f1bd889b6062440861199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Burstr=C3=B6m?= Date: Tue, 20 Dec 2022 22:27:14 +0100 Subject: [PATCH 0101/1120] Add support for KtLint 0.48.0 (fixes #1430) --- CHANGES.md | 3 + lib/build.gradle | 4 + .../compat/KtLintCompat0Dot48Dot0Adapter.java | 121 ++++++++++++++++++ .../glue/ktlint/KtlintFormatterFunc.java | 6 +- .../diffplug/spotless/kotlin/KtLintStep.java | 2 +- plugin-gradle/CHANGES.md | 2 + plugin-maven/CHANGES.md | 3 + .../spotless/kotlin/KtLintStepTest.java | 13 ++ 8 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java diff --git a/CHANGES.md b/CHANGES.md index a59f0c8570..171924a35f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) +* Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) ## [2.31.0] - 2022-11-24 ### Added diff --git a/lib/build.gradle b/lib/build.gradle index e398e80d23..8a816c61aa 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -34,6 +34,7 @@ versionCompatibility { '0.45.2', '0.46.0', '0.47.0', + '0.48.0', ] targetSourceSetName = 'ktlint' } @@ -90,6 +91,9 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java new file mode 100644 index 0000000000..8235c535a5 --- /dev/null +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -0,0 +1,121 @@ +/* + * 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.ktlint.compat; + +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.LintError; +import com.pinterest.ktlint.core.Rule; +import com.pinterest.ktlint.core.RuleProvider; +import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; +import com.pinterest.ktlint.core.api.EditorConfigDefaults; +import com.pinterest.ktlint.core.api.EditorConfigOverride; +import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; +import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty; +import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; +import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; + +import kotlin.Pair; +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter { + + static class FormatterCallback implements Function2 { + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); + } + return null; + } + } + + @Override + public String format(final String text, final String name, final boolean isScript, + final boolean useExperimental, + final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + Set allRuleProviders = new LinkedHashSet<>( + new StandardRuleSetProvider().getRuleProviders()); + if (useExperimental) { + allRuleProviders.addAll(new ExperimentalRuleSetProvider().getRuleProviders()); + } + + EditorConfigOverride editorConfigOverride; + if (editorConfigOverrideMap.isEmpty()) { + editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + } else { + editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( + RuleProvider::createNewRuleInstance).collect( + Collectors.toList()), + editorConfigOverrideMap); + } + + return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( + name, + text, + allRuleProviders, + userData, + formatterCallback, + isScript, + false, + EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(), + editorConfigOverride, + false)); + } + + /** + * Create EditorConfigOverride from user provided parameters. + */ + private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { + // Get properties from rules in the rule sets + Stream> ruleProperties = rules.stream() + .filter(rule -> rule instanceof UsesEditorConfigProperties) + .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); + + // Create a mapping of properties to their names based on rule properties and default properties + Map> supportedProperties = Stream + .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) + .distinct() + .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); + + // Create config properties based on provided property names and values + @SuppressWarnings("unchecked") + Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() + .map(entry -> { + EditorConfigProperty property = supportedProperties.get(entry.getKey()); + if (property != null) { + return new Pair<>(property, entry.getValue()); + } else { + return null; + } + }) + .filter(Objects::nonNull) + .toArray(Pair[]::new); + + return EditorConfigOverride.Companion.from(properties); + } +} diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index cc64eb9d66..45c5c5e4cf 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -27,6 +27,7 @@ import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -41,7 +42,10 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, Map userData, Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); - if (minorVersion >= 47) { + if (minorVersion >= 48) { + // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class + this.adapter = new KtLintCompat0Dot48Dot0Adapter(); + } else if (minorVersion == 47) { // rename RuleSet to RuleProvider this.adapter = new KtLintCompat0Dot47Dot0Adapter(); } else if (minorVersion >= 46) { diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 5627913e4a..f62c62b05b 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -33,7 +33,7 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.47.1"; + private static final String DEFAULT_VERSION = "0.48.0"; static final String NAME = "ktlint"; static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ebe7d0ceea..ec06599d20 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -12,11 +12,13 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) +* Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) * Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) * Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#1393](https://github.com/diffplug/spotless/pull/1393)) +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) ## [6.11.0] - 2022-09-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e1c6b8ce48..f401908166 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added support for M2E's incremental compilation ([#1414](https://github.com/diffplug/spotless/pull/1414) fixes [#1413](https://github.com/diffplug/spotless/issues/1413)) ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) +* Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) ## [2.28.0] - 2022-11-24 ### Added diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 71a0979422..3a55a19e92 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -144,6 +144,19 @@ void works0_47_1() throws Exception { }); } + @Test + void works0_48_0() throws Exception { + FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { + assertion.isInstanceOf(AssertionError.class); + assertion.hasMessage("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); + }); + } + @Test void equality() throws Exception { new SerializableEqualityTester() { From b3d8e89002c21324f03e896c0d786df3be09839d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:13:05 -0800 Subject: [PATCH 0102/1120] spotlessApply for 2023 --- .../com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java | 2 +- lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 45c5c5e4cf..fc64cdb23e 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index f62c62b05b..b444f0f1a7 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 3a55a19e92..42e377fde5 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. From b44d70d00add006427f3cb8ef2387da543addfa3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:14:22 -0800 Subject: [PATCH 0103/1120] Move changelog entries to the correct release. --- plugin-gradle/CHANGES.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ec06599d20..3e78920abe 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) +* Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) ## [6.12.0] - 2022-11-24 ### Added @@ -12,13 +15,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Don't treat `@Value` as a type annotation [#1367](https://github.com/diffplug/spotless/pull/1367) * Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#1378](https://github.com/diffplug/spotless/pull/1378) -* Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) ### Changes * Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#1340](https://github.com/diffplug/spotless/pull/1340)) * Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#1373](https://github.com/diffplug/spotless/pull/1373)) * Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#1393](https://github.com/diffplug/spotless/pull/1393)) * Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#1393](https://github.com/diffplug/spotless/pull/1393)) -* Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) ## [6.11.0] - 2022-09-14 ### Added From 9a8ccae9ec04ff5e6f37da07cc445242ef69c516 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:19:21 -0800 Subject: [PATCH 0104/1120] Bump default ktfmt 0.41 -> 0.42 --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java index 4f84d991bc..242c9c9173 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -39,7 +39,7 @@ public class KtfmtStep { // prevent direct instantiation private KtfmtStep() {} - private static final String DEFAULT_VERSION = "0.41"; + private static final String DEFAULT_VERSION = "0.42"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; From 8f7e00594de49856e2c14edf09d89352e0eddd60 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:21:01 -0800 Subject: [PATCH 0105/1120] spotlessApply --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java index 242c9c9173..b6f7a533eb 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. From 062e83584650be1dd47f5c8485426e8438b05600 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:21:13 -0800 Subject: [PATCH 0106/1120] Bump changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 171924a35f..fe37d3e845 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) +* Bump default `ktfmt` version to latest `0.41` -> `0.42` ([#1421](https://github.com/diffplug/spotless/pull/1421)) ## [2.31.0] - 2022-11-24 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 3e78920abe..6b98d25dc2 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,6 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) +* Bump default `ktfmt` version to latest `0.41` -> `0.42` ([#1421](https://github.com/diffplug/spotless/pull/1421)) ## [6.12.0] - 2022-11-24 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f401908166..e8fc8d3d49 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.0` ([#1432](https://github.com/diffplug/spotless/pull/1432)) +* Bump default `ktfmt` version to latest `0.41` -> `0.42` ([#1421](https://github.com/diffplug/spotless/pull/1421)) ## [2.28.0] - 2022-11-24 ### Added From 45a3c8a2b13cd223f4ca9cfd0831b7639f12fffd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 20:37:08 -0800 Subject: [PATCH 0107/1120] Reorder plugin application to keep Gradle 7.6 happy. --- plugin-gradle/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index f1b3320b50..ba60eb450f 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -2,11 +2,11 @@ apply from: rootProject.file('gradle/changelog.gradle') ext.artifactId = project.artifactIdGradle version = spotlessChangelog.versionNext apply plugin: 'java-library' +apply plugin: 'com.gradle.plugin-publish' +apply plugin: 'java-gradle-plugin' apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/spotless-freshmark.gradle') -apply plugin: 'com.gradle.plugin-publish' -apply plugin: 'java-gradle-plugin' dependencies { if (version.endsWith('-SNAPSHOT') || (rootProject.spotlessChangelog.versionNext == rootProject.spotlessChangelog.versionLast)) { From c13acee2130be0b730a14fbadade6e7f597001b7 Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 2 Jan 2023 04:44:42 +0000 Subject: [PATCH 0108/1120] Published lib/2.31.1 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index fe37d3e845..e3493f7c09 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.31.1] - 2023-01-02 ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) From 718a504c123de899e75300e7f2f6c55d7a40da42 Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 2 Jan 2023 04:45:56 +0000 Subject: [PATCH 0109/1120] Published gradle/6.12.1 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 46 ++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 6b98d25dc2..cac4f56567 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.12.1] - 2023-01-02 ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index fcc0336cbb..755d21d056 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.12.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.12.1-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -143,7 +143,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -267,8 +267,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -319,8 +319,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -383,7 +383,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -415,7 +415,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -447,7 +447,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -481,7 +481,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -502,7 +502,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -527,7 +527,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -567,7 +567,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -610,7 +610,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -835,7 +835,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -902,9 +902,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -937,11 +937,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 8146bf72d33c7ce443c21a748595eeea1087a5e1 Mon Sep 17 00:00:00 2001 From: circleci Date: Mon, 2 Jan 2023 04:47:36 +0000 Subject: [PATCH 0110/1120] Published maven/2.29.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e8fc8d3d49..84e06aa847 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.29.0] - 2023-01-02 ### Added * Added support for M2E's incremental compilation ([#1414](https://github.com/diffplug/spotless/pull/1414) fixes [#1413](https://github.com/diffplug/spotless/issues/1413)) ### Fixed diff --git a/plugin-maven/README.md b/plugin-maven/README.md index e6a2c47aae..80be3dbc37 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.28.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.28.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.29.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.29.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 2c03111edf22f9506520a31aff476017258d24b9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 21:04:36 -0800 Subject: [PATCH 0111/1120] Update GradleIntegrationHarness' JVM compatibility matrix. --- .../diffplug/gradle/spotless/GradleIntegrationHarness.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java index 6cc35290db..9e2f490429 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -53,9 +53,12 @@ public enum GradleVersionSupport { GradleVersionSupport(String version) { String minVersionForRunningJRE; switch (Jvm.version()) { + case 21: case 20: - case 19: // TODO: https://docs.gradle.org/current/userguide/compatibility.html + case 19: + minVersionForRunningJRE = "7.6"; + break; case 18: minVersionForRunningJRE = "7.5"; break; From 923d87561af4f914d0221d9145d50adcd003a36e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 21:05:02 -0800 Subject: [PATCH 0112/1120] Update groovy-xml to a version that Gradle 7.6 can tolerate. --- lib-extra/build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 38e7c37403..6dd195cde9 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -15,7 +15,9 @@ dependencies { implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" implementation "com.googlecode.concurrent-trees:concurrent-trees:2.6.1" // used for xml parsing in EclipseFormatter - implementation "org.codehaus.groovy:groovy-xml:3.0.10" + // TODO: Gradle barfs if this doesn't match its built-in version, + // would be great to drop this for something less sensitive if possible + implementation "org.codehaus.groovy:groovy-xml:3.0.13" // testing testImplementation project(':testlib') From 1f7bab70bff03a047e081c2d019be508810d3371 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 21:12:33 -0800 Subject: [PATCH 0113/1120] Turns out we don't need groovy-xml at all anymore. Lol. --- lib-extra/build.gradle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 6dd195cde9..d94992f8d3 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -14,10 +14,6 @@ dependencies { // needed by GitAttributesLineEndings implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" implementation "com.googlecode.concurrent-trees:concurrent-trees:2.6.1" - // used for xml parsing in EclipseFormatter - // TODO: Gradle barfs if this doesn't match its built-in version, - // would be great to drop this for something less sensitive if possible - implementation "org.codehaus.groovy:groovy-xml:3.0.13" // testing testImplementation project(':testlib') From d7ac1fe76f1fffe611af89b3535d1e44352e0433 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 21:14:48 -0800 Subject: [PATCH 0114/1120] Update changelog. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index e3493f7c09..40a2ae3e07 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) ## [2.31.1] - 2023-01-02 ### Fixed From 6e19b7edc7e5e6b4bf62214c18ff1b2b84e72c8c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 1 Jan 2023 21:23:38 -0800 Subject: [PATCH 0115/1120] Another needed update for the changelog. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 40a2ae3e07..cf43b4eb22 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] ### Changes * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) + * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` ## [2.31.1] - 2023-01-02 ### Fixed From ade6c0d48138af938aaa7039a22ef784e92036b0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 2 Jan 2023 06:21:18 +0000 Subject: [PATCH 0116/1120] chore(deps): update plugin com.diffplug.spotless to v6.12.1 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 828a3629c7..786baa1eba 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.12.0' + id 'com.diffplug.spotless' version '6.12.1' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.1.0' // https://github.com/gradle-nexus/publish-plugin/releases From 50e7cb01e05019c671e1411fb7c56f8bd7314f52 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Mon, 2 Jan 2023 19:34:54 +0100 Subject: [PATCH 0117/1120] apply license header updates --- .../java/com/diffplug/spotless/generic/LicenseHeaderStep.java | 2 +- .../main/java/com/diffplug/gradle/spotless/FormatExtension.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 5345adc150..d1fdf86e3e 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.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. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 84690bf063..9c1e239d39 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. From 9df255ed3c1a56aeec24e6e92190e6382cf45dcd Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 00:06:41 +0100 Subject: [PATCH 0118/1120] Add editor config file option to maven and gradle --- .../compat/KtLintCompat0Dot31Dot0Adapter.java | 4 ++-- .../compat/KtLintCompat0Dot32Dot0Adapter.java | 4 ++-- .../compat/KtLintCompat0Dot34Dot2Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot45Dot2Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot46Dot0Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot47Dot0Adapter.java | 17 ++++++++++++----- .../compat/KtLintCompat0Dot48Dot0Adapter.java | 15 +++++++++++---- .../glue/ktlint/compat/KtLintCompatAdapter.java | 4 ++-- .../glue/ktlint/KtlintFormatterFunc.java | 6 ++++-- .../diffplug/spotless/kotlin/KtLintStep.java | 15 +++++++++++---- .../gradle/spotless/KotlinExtension.java | 10 ++++++---- .../gradle/spotless/KotlinGradleExtension.java | 14 +++++++++++--- .../diffplug/spotless/maven/kotlin/Ktlint.java | 7 ++++--- 13 files changed, 74 insertions(+), 40 deletions(-) diff --git a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java index 56b8da2d20..a10bf9be0e 100644 --- a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java index 6f69fcc7ce..3f98abe3b3 100644 --- a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java index a3c8c8df3b..0352a8e1f0 100644 --- a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -61,7 +61,7 @@ public String format(final String text, final String name, final boolean isScrip userData, formatterCallback, isScript, - null, + editorConfigPath, false)); } } diff --git a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java index f7eadada3d..15c2238d5d 100644 --- a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -76,7 +76,7 @@ public String format(final String text, final String name, final boolean isScrip userData, formatterCallback, isScript, - null, + editorConfigPath, false, editorConfigOverride, false)); diff --git a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java index 873b91af80..28eba672a0 100644 --- a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -76,7 +76,7 @@ public String format(final String text, final String name, final boolean isScrip userData, formatterCallback, isScript, - null, + editorConfigPath, false, editorConfigOverride, false)); diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 757ffc922b..3445a688b1 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ import static java.util.Collections.emptySet; +import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; @@ -56,7 +58,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -68,14 +70,19 @@ public String format(final String text, final String name, final boolean isScrip EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + editorConfigOverride = new EditorConfigOverride(); } else { editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( RuleProvider::createNewRuleInstance).collect( Collectors.toList()), editorConfigOverrideMap); } - + Path editorConfigFilePath; + if (editorConfigPath == null) { + editorConfigFilePath = null; + } else { + editorConfigFilePath = new File(editorConfigPath).toPath(); + } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( name, text, @@ -86,7 +93,7 @@ public String format(final String text, final String name, final boolean isScrip isScript, null, false, - EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(), + EditorConfigDefaults.Companion.load(editorConfigFilePath), editorConfigOverride, false)); } diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 8235c535a5..3efc8c085d 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.io.File; +import java.nio.file.Path; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -54,7 +56,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, final String name, final boolean isScript, final boolean useExperimental, - final Map userData, + String editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -66,14 +68,19 @@ public String format(final String text, final String name, final boolean isScrip EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + editorConfigOverride = new EditorConfigOverride(); } else { editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( RuleProvider::createNewRuleInstance).collect( Collectors.toList()), editorConfigOverrideMap); } - + Path editorConfigFilePath; + if (editorConfigPath == null) { + editorConfigFilePath = null; + } else { + editorConfigFilePath = new File(editorConfigPath).toPath(); + } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( name, text, @@ -82,7 +89,7 @@ public String format(final String text, final String name, final boolean isScrip formatterCallback, isScript, false, - EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(), + EditorConfigDefaults.Companion.load(editorConfigFilePath), editorConfigOverride, false)); } diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 5097cac135..b3e5d1817a 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,6 @@ public interface KtLintCompatAdapter { - String format(String text, String name, boolean isScript, boolean useExperimental, Map userData, + String format(String text, String name, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, Map editorConfigOverrideMap); } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index fc64cdb23e..5b43bf5e14 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -37,9 +37,10 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @NotNull private final KtLintCompatAdapter adapter; private final boolean useExperimental; + private final String editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, Map userData, + public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { @@ -64,6 +65,7 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime // the OG this.adapter = new KtLintCompat0Dot31Dot0Adapter(); } + this.editorConfigPath = editorConfigPath; this.useExperimental = useExperimental; this.editorConfigOverrideMap = editorConfigOverrideMap; this.userData = userData; @@ -72,6 +74,6 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime @Override public String applyWithFile(String unix, File file) throws Exception { - return adapter.format(unix, file.getName(), isScript, useExperimental, userData, editorConfigOverrideMap); + return adapter.format(unix, file.getName(), isScript, useExperimental, editorConfigPath, userData, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index b444f0f1a7..9291e69fde 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -64,10 +64,15 @@ public static FormatterStep createForScript(String version, Provisioner provisio private static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, Map userData, Map editorConfigOverride) { + return create(version, provisioner, useExperimental, userData, editorConfigOverride); + } + + public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, + String editorConfig, Map userData, Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, isScript, useExperimental, userData, editorConfigOverride), + () -> new State(version, provisioner, isScript, useExperimental, editorConfig, userData, editorConfigOverride), State::createFormat); } @@ -86,9 +91,10 @@ static final class State implements Serializable { private final TreeMap userData; private final TreeMap editorConfigOverride; private final String version; + private final String editorConfigPath; State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - Map userData, Map editorConfigOverride) throws IOException { + String editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { this.version = version; String coordinate; @@ -104,6 +110,7 @@ static final class State implements Serializable { this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); this.jarState = JarState.from(coordinate + version, provisioner); + this.editorConfigPath = editorConfigPath; this.isScript = isScript; } @@ -111,8 +118,8 @@ FormatterFunc createFormat() throws Exception { final ClassLoader classLoader = jarState.getClassLoader(); Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); Constructor constructor = formatterFunc.getConstructor( - String.class, boolean.class, boolean.class, Map.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, useExperimental, userData, editorConfigOverride); + String.class, boolean.class, boolean.class, String.class, Map.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, useExperimental, editorConfigPath, userData, editorConfigOverride); } } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 546efab46d..eddeef36d6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -60,7 +60,7 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) { Objects.requireNonNull(version); - return new KotlinFormatExtension(version, false, Collections.emptyMap(), Collections.emptyMap()); + return new KotlinFormatExtension(version, false, null, Collections.emptyMap(), Collections.emptyMap()); } public KotlinFormatExtension ktlint() { @@ -71,13 +71,15 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; + private String editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, Map config, + KotlinFormatExtension(String version, boolean useExperimental, String editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; + this.editorConfigPath = editorConfigPath; this.userData = config; this.editorConfigOverride = editorConfigOverride; addStep(createStep()); @@ -106,7 +108,7 @@ public KotlinFormatExtension editorConfigOverride(Map editorConf } private FormatterStep createStep() { - return KtLintStep.create(version, provisioner(), useExperimental, userData, editorConfigOverride); + return KtLintStep.create(version, provisioner(), useExperimental, false, editorConfigPath, userData, editorConfigOverride); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index c1abe62bd1..5120d88754 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -45,7 +45,7 @@ public KotlinGradleExtension(SpotlessExtension spotless) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) { Objects.requireNonNull(version, "version"); - return new KotlinFormatExtension(version, false, Collections.emptyMap(), Collections.emptyMap()); + return new KotlinFormatExtension(version, false, null, Collections.emptyMap(), Collections.emptyMap()); } public KotlinFormatExtension ktlint() { @@ -56,18 +56,26 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; + private String editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, Map config, + KotlinFormatExtension(String version, boolean useExperimental, String editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; + this.editorConfigPath = editorConfigPath; this.userData = config; this.editorConfigOverride = editorConfigOverride; addStep(createStep()); } + public KotlinFormatExtension setEditorConfigPath(String editorConfigPath) { + this.editorConfigPath = editorConfigPath; + replaceStep(createStep()); + return this; + } + public KotlinFormatExtension setUseExperimental(boolean useExperimental) { this.useExperimental = useExperimental; replaceStep(createStep()); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 45bda05065..ad57c47976 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -30,7 +30,8 @@ public class Ktlint implements FormatterStepFactory { @Parameter private String version; - + @Parameter + private String editorConfigPath; @Parameter private Map editorConfigOverride; @@ -42,6 +43,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { editorConfigOverride = new HashMap<>(); } - return KtLintStep.create(ktlintVersion, config.getProvisioner(), false, Collections.emptyMap(), editorConfigOverride); + return KtLintStep.create(ktlintVersion, config.getProvisioner(), false, false, editorConfigPath, Collections.emptyMap(), editorConfigOverride); } } From 132ecc94a2380da4afcea336bdad5fcbf652fe93 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 2 Jan 2023 14:39:02 -0800 Subject: [PATCH 0119/1120] Breaking changes to Spotless' internal testing infrastructure `testlib` * `StepHarness` now operates on `Formatter` rather than a `FormatterStep`. * `StepHarnessWithFile` now takes a `ResourceHarness` in its constructor. * Standardized that we test exception *messages*, not types, which will ease the transition to linting later on. --- .../spotless/extra/GitAttributesTest.java | 25 ++-- .../diffplug/spotless/ResourceHarness.java | 55 ++++----- .../com/diffplug/spotless/StepHarness.java | 69 ++++++----- .../spotless/StepHarnessWithFile.java | 105 ++++++++++------- .../antlr4/Antlr4FormatterStepTest.java | 10 +- .../spotless/cpp/ClangFormatStepTest.java | 14 +-- .../spotless/generic/IndentStepTest.java | 28 ++--- .../spotless/generic/PipeStepPairTest.java | 16 ++- .../java/FormatAnnotationsStepTest.java | 18 +-- .../spotless/java/ImportOrderStepTest.java | 47 ++++---- .../json/JsonFormatterStepCommonTests.java | 5 +- .../spotless/json/JsonSimpleStepTest.java | 111 ++++++++++++++---- .../spotless/json/gson/GsonStepTest.java | 33 ++---- .../spotless/kotlin/DiktatStepTest.java | 42 ++----- .../spotless/kotlin/KtLintStepTest.java | 106 +++++++---------- .../npm/PrettierFormatterStepTest.java | 17 ++- .../spotless/scala/ScalaFmtStepTest.java | 33 +++--- 17 files changed, 373 insertions(+), 361 deletions(-) diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java index ed657c365a..a7cde9e58f 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/GitAttributesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -26,24 +26,19 @@ import org.eclipse.jgit.api.errors.GitAPIException; import org.junit.jupiter.api.Test; -import com.diffplug.common.base.Errors; import com.diffplug.common.base.StringPrinter; import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.ResourceHarness; class GitAttributesTest extends ResourceHarness { private List testFiles(String prefix) { - try { - List result = new ArrayList<>(); - for (String path : TEST_PATHS) { - String prefixedPath = prefix + path; - setFile(prefixedPath).toContent(""); - result.add(newFile(prefixedPath)); - } - return result; - } catch (IOException e) { - throw Errors.asRuntime(e); + List result = new ArrayList<>(); + for (String path : TEST_PATHS) { + String prefixedPath = prefix + path; + setFile(prefixedPath).toContent(""); + result.add(newFile(prefixedPath)); } + return result; } private List testFiles() { @@ -53,7 +48,7 @@ private List testFiles() { private static final List TEST_PATHS = Arrays.asList("someFile", "subfolder/someFile", "MANIFEST.MF", "subfolder/MANIFEST.MF"); @Test - void cacheTest() throws IOException { + void cacheTest() { setFile(".gitattributes").toContent(StringPrinter.buildStringFromLines( "* eol=lf", "*.MF eol=crlf")); @@ -84,7 +79,7 @@ void cacheTest() throws IOException { } @Test - void policyTest() throws IOException { + void policyTest() { setFile(".gitattributes").toContent(StringPrinter.buildStringFromLines( "* eol=lf", "*.MF eol=crlf")); @@ -96,7 +91,7 @@ void policyTest() throws IOException { } @Test - void policyDefaultLineEndingTest() throws GitAPIException, IOException { + void policyDefaultLineEndingTest() throws GitAPIException { Git git = Git.init().setDirectory(rootFolder()).call(); git.close(); setFile(".git/config").toContent(StringPrinter.buildStringFromLines( diff --git a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java index b4a8bbae24..d4a79fe417 100644 --- a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.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. @@ -54,7 +54,7 @@ protected File rootFolder() { } /** Returns a new child of the root folder. */ - protected File newFile(String subpath) throws IOException { + protected File newFile(String subpath) { return new File(rootFolder(), subpath); } @@ -85,16 +85,16 @@ protected void replace(String path, String toReplace, String replaceWith) throws } /** Returns the contents of the given file from the src/test/resources directory. */ - protected static String getTestResource(String filename) throws IOException { + protected static String getTestResource(String filename) { URL url = ResourceHarness.class.getResource("/" + filename); if (url == null) { throw new IllegalArgumentException("No such resource " + filename); } - return Resources.toString(url, StandardCharsets.UTF_8); + return ThrowingEx.get(() -> LineEnding.toUnix(Resources.toString(url, StandardCharsets.UTF_8))); } /** Returns Files (in a temporary folder) which has the contents of the given file from the src/test/resources directory. */ - protected List createTestFiles(String... filenames) throws IOException { + protected List createTestFiles(String... filenames) { List files = new ArrayList<>(filenames.length); for (String filename : filenames) { files.add(createTestFile(filename)); @@ -103,7 +103,7 @@ protected List createTestFiles(String... filenames) throws IOException { } /** Returns a File (in a temporary folder) which has the contents of the given file from the src/test/resources directory. */ - protected File createTestFile(String filename) throws IOException { + protected File createTestFile(String filename) { return createTestFile(filename, UnaryOperator.identity()); } @@ -111,39 +111,22 @@ protected File createTestFile(String filename) throws IOException { * Returns a File (in a temporary folder) which has the contents, possibly processed, of the given file from the * src/test/resources directory. */ - protected File createTestFile(String filename, UnaryOperator fileContentsProcessor) throws IOException { + protected File createTestFile(String filename, UnaryOperator fileContentsProcessor) { int lastSlash = filename.lastIndexOf('/'); String name = lastSlash >= 0 ? filename.substring(lastSlash) : filename; File file = newFile(name); file.getParentFile().mkdirs(); - Files.write(file.toPath(), fileContentsProcessor.apply(getTestResource(filename)).getBytes(StandardCharsets.UTF_8)); + ThrowingEx.run(() -> Files.write(file.toPath(), fileContentsProcessor.apply(getTestResource(filename)).getBytes(StandardCharsets.UTF_8))); return file; } - /** Reads the given resource from "before", applies the step, and makes sure the result is "after". */ - protected void assertOnResources(FormatterStep step, String unformattedPath, String expectedPath) throws Throwable { - assertOnResources(rawUnix -> step.format(rawUnix, new File("")), unformattedPath, expectedPath); - } - - /** Reads the given resource from "before", applies the step, and makes sure the result is "after". */ - protected void assertOnResources(FormatterFunc step, String unformattedPath, String expectedPath) throws Throwable { - String unformatted = LineEnding.toUnix(getTestResource(unformattedPath)); // unix-ified input - String formatted = step.apply(unformatted); - // no windows newlines - assertThat(formatted).doesNotContain("\r"); - - // unix-ify the test resource output in case git screwed it up - String expected = LineEnding.toUnix(getTestResource(expectedPath)); // unix-ified output - assertThat(formatted).isEqualTo(expected); - } - @CheckReturnValue - protected ReadAsserter assertFile(String path) throws IOException { + protected ReadAsserter assertFile(String path) { return new ReadAsserter(newFile(path)); } @CheckReturnValue - protected ReadAsserter assertFile(File file) throws IOException { + protected ReadAsserter assertFile(File file) { return new ReadAsserter(file); } @@ -176,7 +159,7 @@ public void matches(Consumer> conditions) } } - protected WriteAsserter setFile(String path) throws IOException { + protected WriteAsserter setFile(String path) { return new WriteAsserter(newFile(path)); } @@ -188,21 +171,25 @@ private WriteAsserter(File file) { this.file = file; } - public File toLines(String... lines) throws IOException { + public File toLines(String... lines) { return toContent(String.join("\n", Arrays.asList(lines))); } - public File toContent(String content) throws IOException { + public File toContent(String content) { return toContent(content, StandardCharsets.UTF_8); } - public File toContent(String content, Charset charset) throws IOException { - Files.write(file.toPath(), content.getBytes(charset)); + public File toContent(String content, Charset charset) { + ThrowingEx.run(() -> { + Files.write(file.toPath(), content.getBytes(charset)); + }); return file; } - public File toResource(String path) throws IOException { - Files.write(file.toPath(), getTestResource(path).getBytes(StandardCharsets.UTF_8)); + public File toResource(String path) { + ThrowingEx.run(() -> { + Files.write(file.toPath(), getTestResource(path).getBytes(StandardCharsets.UTF_8)); + }); return file; } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java index 8755f852d6..976a80df29 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarness.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. @@ -22,31 +22,21 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.Objects; -import java.util.function.Consumer; -import org.assertj.core.api.AbstractThrowableAssert; +import org.assertj.core.api.AbstractStringAssert; import org.assertj.core.api.Assertions; /** An api for testing a {@code FormatterStep} that doesn't depend on the File path. DO NOT ADD FILE SUPPORT TO THIS, use {@link StepHarnessWithFile} if you need that. */ public class StepHarness implements AutoCloseable { - private final FormatterFunc formatter; + private final Formatter formatter; - private StepHarness(FormatterFunc formatter) { + private StepHarness(Formatter formatter) { this.formatter = Objects.requireNonNull(formatter); } /** Creates a harness for testing steps which don't depend on the file. */ public static StepHarness forStep(FormatterStep step) { - // We don't care if an individual FormatterStep is misbehaving on line-endings, because - // Formatter fixes that. No reason to care in tests either. It's likely to pop up when - // running tests on Windows from time-to-time - return new StepHarness(FormatterFunc.Closeable.ofDangerous( - () -> { - if (step instanceof FormatterStepImpl.Standard) { - ((FormatterStepImpl.Standard) step).cleanupFormatterFunc(); - } - }, - input -> LineEnding.toUnix(step.format(input, new File(""))))); + return forSteps(step); } /** Creates a harness for testing steps which don't depend on the file. */ @@ -61,55 +51,62 @@ public static StepHarness forSteps(FormatterStep... steps) { /** Creates a harness for testing a formatter whose steps don't depend on the file. */ public static StepHarness forFormatter(Formatter formatter) { - return new StepHarness(FormatterFunc.Closeable.ofDangerous( - formatter::close, - input -> formatter.compute(input, new File("")))); + return new StepHarness(formatter); } /** Asserts that the given element is transformed as expected, and that the result is idempotent. */ - public StepHarness test(String before, String after) throws Exception { - String actual = formatter.apply(before); + public StepHarness test(String before, String after) { + String actual = formatter.compute(LineEnding.toUnix(before), new File("")); assertEquals(after, actual, "Step application failed"); return testUnaffected(after); } /** Asserts that the given element is idempotent w.r.t the step under test. */ - public StepHarness testUnaffected(String idempotentElement) throws Exception { - String actual = formatter.apply(idempotentElement); + public StepHarness testUnaffected(String idempotentElement) { + String actual = formatter.compute(LineEnding.toUnix(idempotentElement), new File("")); assertEquals(idempotentElement, actual, "Step is not idempotent"); return this; } /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarness testResource(String resourceBefore, String resourceAfter) throws Exception { + public StepHarness testResource(String resourceBefore, String resourceAfter) { String before = ResourceHarness.getTestResource(resourceBefore); String after = ResourceHarness.getTestResource(resourceAfter); return test(before, after); } /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarness testResourceUnaffected(String resourceIdempotent) throws Exception { + public StepHarness testResourceUnaffected(String resourceIdempotent) { String idempotentElement = ResourceHarness.getTestResource(resourceIdempotent); return testUnaffected(idempotentElement); } - /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarness testResourceException(String resourceBefore, Consumer> exceptionAssertion) throws Exception { - return testException(ResourceHarness.getTestResource(resourceBefore), exceptionAssertion); + public AbstractStringAssert testResourceExceptionMsg(String resourceBefore) { + return testExceptionMsg(ResourceHarness.getTestResource(resourceBefore)); } - /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarness testException(String before, Consumer> exceptionAssertion) throws Exception { - Throwable t = assertThrows(Throwable.class, () -> formatter.apply(before)); - AbstractThrowableAssert abstractAssert = Assertions.assertThat(t); - exceptionAssertion.accept(abstractAssert); - return this; + public AbstractStringAssert testExceptionMsg(String before) { + try { + formatter.compute(LineEnding.toUnix(before), FormatterStepImpl.SENTINEL); + throw new SecurityException("Expected exception"); + } catch (Throwable e) { + if (e instanceof SecurityException) { + throw new AssertionError(e.getMessage()); + } else { + Throwable rootCause = e; + while (rootCause.getCause() != null) { + if (rootCause instanceof IllegalStateException) { + break; + } + rootCause = rootCause.getCause(); + } + return Assertions.assertThat(rootCause.getMessage()); + } + } } @Override public void close() { - if (formatter instanceof FormatterFunc.Closeable) { - ((FormatterFunc.Closeable) formatter).close(); - } + formatter.close(); } } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java index 89be961d04..3d01a6bd44 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.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,78 +18,99 @@ import static org.junit.jupiter.api.Assertions.*; import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.Collections; import java.util.Objects; +import org.assertj.core.api.AbstractStringAssert; +import org.assertj.core.api.Assertions; + /** An api for testing a {@code FormatterStep} that depends on the File path. */ public class StepHarnessWithFile implements AutoCloseable { - private final FormatterFunc formatter; + private final Formatter formatter; + private final ResourceHarness harness; - private StepHarnessWithFile(FormatterFunc formatter) { + private StepHarnessWithFile(ResourceHarness harness, Formatter formatter) { + this.harness = Objects.requireNonNull(harness); this.formatter = Objects.requireNonNull(formatter); } /** Creates a harness for testing steps which do depend on the file. */ - public static StepHarnessWithFile forStep(FormatterStep step) { - // We don't care if an individual FormatterStep is misbehaving on line-endings, because - // Formatter fixes that. No reason to care in tests either. It's likely to pop up when - // running tests on Windows from time-to-time - return new StepHarnessWithFile(FormatterFunc.Closeable.ofDangerous( - () -> { - if (step instanceof FormatterStepImpl.Standard) { - ((FormatterStepImpl.Standard) step).cleanupFormatterFunc(); - } - }, - new FormatterFunc() { - @Override - public String apply(String unix) throws Exception { - return apply(unix, new File("")); - } - - @Override - public String apply(String unix, File file) throws Exception { - return LineEnding.toUnix(step.format(unix, file)); - } - })); + public static StepHarnessWithFile forStep(ResourceHarness harness, FormatterStep step) { + return new StepHarnessWithFile(harness, Formatter.builder() + .encoding(StandardCharsets.UTF_8) + .lineEndingsPolicy(LineEnding.UNIX.createPolicy()) + .steps(Collections.singletonList(step)) + .rootDir(harness.rootFolder().toPath()) + .build()); } /** Creates a harness for testing a formatter whose steps do depend on the file. */ - public static StepHarnessWithFile forFormatter(Formatter formatter) { - return new StepHarnessWithFile(FormatterFunc.Closeable.ofDangerous( - formatter::close, - input -> formatter.compute(input, new File("")))); + public static StepHarnessWithFile forFormatter(ResourceHarness harness, Formatter formatter) { + return new StepHarnessWithFile(harness, formatter); } /** Asserts that the given element is transformed as expected, and that the result is idempotent. */ - public StepHarnessWithFile test(File file, String before, String after) throws Exception { - String actual = formatter.apply(before, file); + public StepHarnessWithFile test(File file, String before, String after) { + String actual = formatter.compute(LineEnding.toUnix(before), file); assertEquals(after, actual, "Step application failed"); return testUnaffected(file, after); } /** Asserts that the given element is idempotent w.r.t the step under test. */ - public StepHarnessWithFile testUnaffected(File file, String idempotentElement) throws Exception { - String actual = formatter.apply(idempotentElement, file); + public StepHarnessWithFile testUnaffected(File file, String idempotentElement) { + String actual = formatter.compute(LineEnding.toUnix(idempotentElement), file); assertEquals(idempotentElement, actual, "Step is not idempotent"); return this; } /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarnessWithFile testResource(File file, String resourceBefore, String resourceAfter) throws Exception { - String before = ResourceHarness.getTestResource(resourceBefore); - String after = ResourceHarness.getTestResource(resourceAfter); - return test(file, before, after); + public StepHarnessWithFile testResource(String resourceBefore, String resourceAfter) { + return testResource(resourceBefore, resourceBefore, resourceAfter); + } + + public StepHarnessWithFile testResource(String filename, String resourceBefore, String resourceAfter) { + String contentBefore = ResourceHarness.getTestResource(resourceBefore); + File file = harness.setFile(filename).toContent(contentBefore); + return test(file, contentBefore, ResourceHarness.getTestResource(resourceAfter)); } /** Asserts that the given elements in the resources directory are transformed as expected. */ - public StepHarnessWithFile testResourceUnaffected(File file, String resourceIdempotent) throws Exception { - String idempotentElement = ResourceHarness.getTestResource(resourceIdempotent); - return testUnaffected(file, idempotentElement); + public StepHarnessWithFile testResourceUnaffected(String resourceIdempotent) { + String contentBefore = ResourceHarness.getTestResource(resourceIdempotent); + File file = harness.setFile(resourceIdempotent).toContent(contentBefore); + return testUnaffected(file, contentBefore); + } + + public AbstractStringAssert testResourceExceptionMsg(String resourceBefore) { + return testResourceExceptionMsg(resourceBefore, resourceBefore); + } + + public AbstractStringAssert testResourceExceptionMsg(String filename, String resourceBefore) { + String contentBefore = ResourceHarness.getTestResource(resourceBefore); + File file = harness.setFile(filename).toContent(contentBefore); + return testExceptionMsg(file, contentBefore); + } + + public AbstractStringAssert testExceptionMsg(File file, String before) { + try { + formatter.compute(LineEnding.toUnix(before), file); + throw new SecurityException("Expected exception"); + } catch (Throwable e) { + if (e instanceof SecurityException) { + throw new AssertionError(e.getMessage()); + } else { + Throwable rootCause = e; + while (rootCause.getCause() != null) { + rootCause = rootCause.getCause(); + } + return Assertions.assertThat(rootCause.getMessage()); + } + } } @Override public void close() { - if (formatter instanceof FormatterFunc.Closeable) { - ((FormatterFunc.Closeable) formatter).close(); - } + formatter.close(); } } diff --git a/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java index a26cbd4425..0f5b1b0bb7 100644 --- a/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/antlr4/Antlr4FormatterStepTest.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,15 +18,13 @@ import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.TestProvisioner; -class Antlr4FormatterStepTest extends ResourceHarness { - +class Antlr4FormatterStepTest { @Test void formatGrammar() throws Throwable { FormatterStep step = Antlr4FormatterStep.create(TestProvisioner.mavenCentral()); - assertOnResources(step, "antlr4/Hello.unformatted.g4", "antlr4/Hello.formatted.g4"); + StepHarness.forStep(step).testResource("antlr4/Hello.unformatted.g4", "antlr4/Hello.formatted.g4"); } - } diff --git a/testlib/src/test/java/com/diffplug/spotless/cpp/ClangFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/cpp/ClangFormatStepTest.java index cf0f551485..7e76b4eea1 100644 --- a/testlib/src/test/java/com/diffplug/spotless/cpp/ClangFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/cpp/ClangFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,26 +15,26 @@ */ package com.diffplug.spotless.cpp; -import java.io.File; import java.util.Arrays; import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.tag.ClangTest; @ClangTest -class ClangFormatStepTest { +class ClangFormatStepTest extends ResourceHarness { @Test - void test() throws Exception { - try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(ClangFormatStep.withVersion(ClangFormatStep.defaultVersion()).create())) { + void test() { + try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(this, ClangFormatStep.withVersion(ClangFormatStep.defaultVersion()).create())) { // can't be named java or it gets compiled into .class file - harness.testResource(new File("example.java"), "clang/example.java.dirty", "clang/example.java.clean"); + harness.testResource("example.java", "clang/example.java.dirty", "clang/example.java.clean"); // test every other language clang supports for (String ext : Arrays.asList("c", "cs", "js", "m", "proto")) { String filename = "example." + ext; String root = "clang/" + filename; - harness.testResource(new File(filename), root, root + ".clean"); + harness.testResource(filename, root, root + ".clean"); } } } diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/IndentStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/IndentStepTest.java index c7df4639e3..38503d7182 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/IndentStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/IndentStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -15,46 +15,42 @@ */ package com.diffplug.spotless.generic; -import java.io.File; - -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; import com.diffplug.spotless.StepHarness; -class IndentStepTest extends ResourceHarness { +class IndentStepTest { @Test - void tabToTab() throws Throwable { + void tabToTab() { FormatterStep indent = IndentStep.Type.TAB.create(4); - assertOnResources(indent, "indent/IndentedWithTab.test", "indent/IndentedWithTab.test"); + StepHarness.forStep(indent).testResource("indent/IndentedWithTab.test", "indent/IndentedWithTab.test"); } @Test - void spaceToSpace() throws Throwable { + void spaceToSpace() { FormatterStep indent = IndentStep.Type.SPACE.create(4); - assertOnResources(indent, "indent/IndentedWithSpace.test", "indent/IndentedWithSpace.test"); + StepHarness.forStep(indent).testResource("indent/IndentedWithSpace.test", "indent/IndentedWithSpace.test"); } @Test - void spaceToTab() throws Throwable { + void spaceToTab() { FormatterStep indent = IndentStep.Type.TAB.create(4); - assertOnResources(indent, "indent/IndentedWithSpace.test", "indent/IndentedWithTab.test"); + StepHarness.forStep(indent).testResource("indent/IndentedWithSpace.test", "indent/IndentedWithTab.test"); } @Test - void tabToSpace() throws Throwable { + void tabToSpace() { FormatterStep indent = IndentStep.Type.SPACE.create(4); - assertOnResources(indent, "indent/IndentedWithTab.test", "indent/IndentedWithSpace.test"); + StepHarness.forStep(indent).testResource("indent/IndentedWithTab.test", "indent/IndentedWithSpace.test"); } @Test - void doesntClipNewlines() throws Throwable { + void doesntClipNewlines() { FormatterStep indent = IndentStep.Type.SPACE.create(4); String blankNewlines = "\n\n\n\n"; - Assertions.assertEquals(blankNewlines, indent.format(blankNewlines, new File(""))); + StepHarness.forStep(indent).testUnaffected(blankNewlines); } @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/PipeStepPairTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/PipeStepPairTest.java index 6bb144e6b4..b648432b92 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/PipeStepPairTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/PipeStepPairTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ class PipeStepPairTest { @Test - void single() throws Exception { + void single() { PipeStepPair pair = PipeStepPair.named("underTest").openClose("spotless:off", "spotless:on").buildPair(); FormatterStep lowercase = FormatterStep.createNeverUpToDate("lowercase", str -> str.toLowerCase(Locale.ROOT)); StepHarness harness = StepHarness.forSteps(pair.in(), lowercase, pair.out()); @@ -47,7 +47,7 @@ void single() throws Exception { } @Test - void multiple() throws Exception { + void multiple() { PipeStepPair pair = PipeStepPair.named("underTest").openClose("spotless:off", "spotless:on").buildPair(); FormatterStep lowercase = FormatterStep.createNeverUpToDate("lowercase", str -> str.toLowerCase(Locale.ROOT)); StepHarness harness = StepHarness.forSteps(pair.in(), lowercase, pair.out()); @@ -81,23 +81,21 @@ void multiple() throws Exception { } @Test - void broken() throws Exception { + void broken() { PipeStepPair pair = PipeStepPair.named("underTest").openClose("spotless:off", "spotless:on").buildPair(); FormatterStep uppercase = FormatterStep.createNeverUpToDate("uppercase", str -> str.toUpperCase(Locale.ROOT)); StepHarness harness = StepHarness.forSteps(pair.in(), uppercase, pair.out()); // this fails because uppercase turns spotless:off into SPOTLESS:OFF, etc - harness.testException(StringPrinter.buildStringFromLines( + harness.testExceptionMsg(StringPrinter.buildStringFromLines( "A B C", "spotless:off", "D E F", "spotless:on", - "G H I"), exception -> { - exception.hasMessage("An intermediate step removed a match of spotless:off spotless:on"); - }); + "G H I")).isEqualTo("An intermediate step removed a match of spotless:off spotless:on"); } @Test - void andApply() throws Exception { + void andApply() { FormatterStep lowercase = FormatterStep.createNeverUpToDate("lowercase", str -> str.toLowerCase(Locale.ROOT)); FormatterStep lowercaseSometimes = PipeStepPair.named("lowercaseSometimes").openClose("", "") .buildStepWhichAppliesSubSteps(Paths.get(""), Arrays.asList(lowercase)); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java index 84d347e490..7aa0b64c00 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/FormatAnnotationsStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,26 +20,26 @@ import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; +import com.diffplug.spotless.StepHarness; -class FormatAnnotationsStepTest extends ResourceHarness { +class FormatAnnotationsStepTest { @Test - void formatAnnotations() throws Throwable { + void formatAnnotations() { FormatterStep step = FormatAnnotationsStep.create(); - assertOnResources(step, "java/formatannotations/FormatAnnotationsTestInput.test", "java/formatannotations/FormatAnnotationsTestOutput.test"); + StepHarness.forStep(step).testResource("java/formatannotations/FormatAnnotationsTestInput.test", "java/formatannotations/FormatAnnotationsTestOutput.test"); } @Test - void formatAnnotationsInComments() throws Throwable { + void formatAnnotationsInComments() { FormatterStep step = FormatAnnotationsStep.create(); - assertOnResources(step, "java/formatannotations/FormatAnnotationsInCommentsInput.test", "java/formatannotations/FormatAnnotationsInCommentsOutput.test"); + StepHarness.forStep(step).testResource("java/formatannotations/FormatAnnotationsInCommentsInput.test", "java/formatannotations/FormatAnnotationsInCommentsOutput.test"); } @Test - void formatAnnotationsAddRemove() throws Throwable { + void formatAnnotationsAddRemove() { FormatterStep step = FormatAnnotationsStep.create(Arrays.asList("Empty", "NonEmpty"), Arrays.asList("Localized")); - assertOnResources(step, "java/formatannotations/FormatAnnotationsAddRemoveInput.test", "java/formatannotations/FormatAnnotationsAddRemoveOutput.test"); + StepHarness.forStep(step).testResource("java/formatannotations/FormatAnnotationsAddRemoveInput.test", "java/formatannotations/FormatAnnotationsAddRemoveOutput.test"); } @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index 32cf0a97c0..8f3bd799bc 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -20,72 +20,73 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; +import com.diffplug.spotless.StepHarness; class ImportOrderStepTest extends ResourceHarness { @Test - void sortImportsDefault() throws Throwable { + void sortImportsDefault() { FormatterStep step = ImportOrderStep.forJava().createFrom(); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImportsDefault.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImportsDefault.test"); } @Test - void sortImportsFromArray() throws Throwable { + void sortImportsFromArray() { FormatterStep step = ImportOrderStep.forJava().createFrom("java", "javax", "org", "\\#com"); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImports.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImports.test"); } @Test - void sortImportsFromArrayWithSubgroups() throws Throwable { + void sortImportsFromArrayWithSubgroups() { FormatterStep step = ImportOrderStep.forJava().createFrom("java|javax", "org|\\#com", "\\#"); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroups.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroups.test"); } @Test - void sortImportsFromFile() throws Throwable { + void sortImportsFromFile() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImports.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImports.test"); } @Test - void sortImportsUnmatched() throws Throwable { + void sortImportsUnmatched() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import_unmatched.properties")); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImportsUnmatched.test", "java/importsorter/JavaCodeSortedImportsUnmatched.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImportsUnmatched.test", "java/importsorter/JavaCodeSortedImportsUnmatched.test"); } @Test - void sortImportsWildcardsLast() throws Throwable { + void sortImportsWildcardsLast() { FormatterStep step = ImportOrderStep.forJava().createFrom(true); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImportsWildcardsLast.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImportsWildcardsLast.test"); } @Test - void removeDuplicates() throws Throwable { + void removeDuplicates() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import_unmatched.properties")); - assertOnResources(step, "java/importsorter/JavaCodeSortedDuplicateImportsUnmatched.test", "java/importsorter/JavaCodeSortedImportsUnmatched.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeSortedDuplicateImportsUnmatched.test", "java/importsorter/JavaCodeSortedImportsUnmatched.test"); } @Test - void removeComments() throws Throwable { + void removeComments() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); - assertOnResources(step, "java/importsorter/JavaCodeImportComments.test", "java/importsorter/JavaCodeSortedImports.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeImportComments.test", "java/importsorter/JavaCodeSortedImports.test"); } @Test - void misplacedImports() throws Throwable { + void misplacedImports() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); - assertOnResources(step, "java/importsorter/JavaCodeUnsortedMisplacedImports.test", "java/importsorter/JavaCodeSortedMisplacedImports.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedMisplacedImports.test", "java/importsorter/JavaCodeSortedMisplacedImports.test"); } @Test - void empty() throws Throwable { + void empty() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); - assertOnResources(step, "java/importsorter/JavaCodeEmptyFile.test", "java/importsorter/JavaCodeEmptyFile.test"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeEmptyFile.test", "java/importsorter/JavaCodeEmptyFile.test"); } @Test - void groovyImports() throws Throwable { + void groovyImports() { FormatterStep step = ImportOrderStep.forGroovy().createFrom(createTestFile("java/importsorter/import.properties")); - assertOnResources(step, "java/importsorter/GroovyCodeUnsortedMisplacedImports.test", "java/importsorter/GroovyCodeSortedMisplacedImports.test"); + StepHarness.forStep(step).testResource("java/importsorter/GroovyCodeUnsortedMisplacedImports.test", "java/importsorter/GroovyCodeSortedMisplacedImports.test"); } @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java index 9ee76f994c..fbdb6e9a4e 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/JsonFormatterStepCommonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,10 +95,9 @@ protected StepHarness getStepHarness() { return StepHarness.forStep(createFormatterStep(INDENT, TestProvisioner.mavenCentral())); } - protected void doWithResource(String name) throws Exception { + protected void doWithResource(String name) { String before = String.format("json/%sBefore.json", name); String after = String.format("json/%sAfter.json", name); getStepHarness().testResource(before, after); } - } diff --git a/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java index b4f98e69ba..19edc1a8e8 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/JsonSimpleStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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,48 +19,115 @@ import org.junit.jupiter.api.Test; -import com.diffplug.spotless.*; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.SerializableEqualityTester; +import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.TestProvisioner; -class JsonSimpleStepTest extends JsonFormatterStepCommonTests { +class JsonSimpleStepTest { + + private static final int INDENT = 4; + + private final FormatterStep step = JsonSimpleStep.create(INDENT, TestProvisioner.mavenCentral()); + private final StepHarness stepHarness = StepHarness.forStep(step); + + @Test + void cannotProvidedNullProvisioner() { + assertThatThrownBy(() -> JsonSimpleStep.create(INDENT, null)).isInstanceOf(NullPointerException.class).hasMessage("provisioner cannot be null"); + } + + @Test + void handlesSingletonObject() { + doWithResource(stepHarness, "singletonObject"); + } + + @Test + void handlesSingletonObjectWithArray() { + doWithResource(stepHarness, "singletonObjectWithArray"); + } + + @Test + void handlesNestedObject() { + doWithResource(stepHarness, "nestedObject"); + } @Test - void handlesSingletonObject() throws Exception { - doWithResource("singletonObject"); + void handlesSingletonArray() { + doWithResource(stepHarness, "singletonArray"); } @Test - void handlesSingletonObjectWithArray() throws Exception { - doWithResource("singletonObjectWithArray"); + void handlesEmptyFile() { + doWithResource(stepHarness, "empty"); } @Test - void handlesComplexNestedObject() throws Exception { - doWithResource("cucumberJsonSample"); + void handlesComplexNestedObject() { + doWithResource(stepHarness, "cucumberJsonSample"); } @Test - void handlesObjectWithNull() throws Exception { - doWithResource("objectWithNull"); + void handlesObjectWithNull() { + doWithResource(stepHarness, "objectWithNull"); } @Test void handlesInvalidJson() { - assertThatThrownBy(() -> doWithResource("invalidJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format JSON") - .hasRootCauseMessage("Expected a ',' or '}' at 9 [character 0 line 3]"); + stepHarness.testResourceExceptionMsg("json/invalidJsonBefore.json") + .contains("Expected a ',' or '}' at 9 [character 0 line 3]"); } @Test void handlesNotJson() { - assertThatThrownBy(() -> doWithResource("notJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to determine JSON type, expected a '{' or '[' but found '#'") - .hasNoCause(); + stepHarness.testResourceExceptionMsg("json/notJsonBefore.json") + .contains("Unable to determine JSON type, expected a '{' or '[' but found '#'"); + } + + @Test + void canSetCustomIndentationLevel() { + FormatterStep step = JsonSimpleStep.create(6, TestProvisioner.mavenCentral()); + StepHarness stepHarness = StepHarness.forStep(step); + + String before = "json/singletonArrayBefore.json"; + String after = "json/singletonArrayAfter6Spaces.json"; + stepHarness.testResource(before, after); + } + + @Test + void canSetIndentationLevelTo0() { + FormatterStep step = JsonSimpleStep.create(0, TestProvisioner.mavenCentral()); + StepHarness stepHarness = StepHarness.forStep(step); + + String before = "json/singletonArrayBefore.json"; + String after = "json/singletonArrayAfter0Spaces.json"; + stepHarness.testResource(before, after); + } + + @Test + 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 JsonSimpleStep.create(spaces, TestProvisioner.mavenCentral()); + } + }.testEquals(); } - @Override - protected FormatterStep createFormatterStep(int indent, Provisioner provisioner) { - return JsonSimpleStep.create(indent, provisioner); + private static void doWithResource(StepHarness stepHarness, String name) { + String before = String.format("json/%sBefore.json", name); + String after = String.format("json/%sAfter.json", name); + stepHarness.testResource(before, after); } } diff --git a/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java index cf1fd10752..8f1d758836 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,9 @@ */ package com.diffplug.spotless.json.gson; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.io.File; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; @@ -30,54 +31,47 @@ public class GsonStepTest extends JsonFormatterStepCommonTests { private static final String DEFAULT_VERSION = "2.8.9"; @Test - void handlesComplexNestedObject() throws Exception { + void handlesComplexNestedObject() { doWithResource("cucumberJsonSampleGson"); } @Test - void handlesObjectWithNull() throws Exception { + void handlesObjectWithNull() { doWithResource("objectWithNullGson"); } @Test void handlesInvalidJson() { - assertThatThrownBy(() -> doWithResource("invalidJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format JSON") - .hasRootCauseMessage("End of input at line 3 column 1 path $.a"); + getStepHarness().testResourceExceptionMsg("json/invalidJsonBefore.json").isEqualTo("End of input at line 3 column 1 path $.a"); } @Test void handlesNotJson() { - assertThatThrownBy(() -> doWithResource("notJson")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format JSON") - .hasNoCause(); + getStepHarness().testResourceExceptionMsg("json/notJsonBefore.json").isEqualTo("Unable to format JSON"); } @Test - void handlesSortingWhenSortByKeyEnabled() throws Exception { + void handlesSortingWhenSortByKeyEnabled() { FormatterStep step = GsonStep.create(INDENT, true, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); - StepHarness stepHarness = StepHarness.forStep(step); - stepHarness.testResource("json/sortByKeysBefore.json", "json/sortByKeysAfter.json"); + StepHarness.forStep(step).testResource("json/sortByKeysBefore.json", "json/sortByKeysAfter.json"); } @Test - void doesNoSortingWhenSortByKeyDisabled() throws Exception { + void doesNoSortingWhenSortByKeyDisabled() { FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/sortByKeysBefore.json", "json/sortByKeysAfterDisabled.json"); } @Test - void handlesHtmlEscapeWhenEnabled() throws Exception { + void handlesHtmlEscapeWhenEnabled() { FormatterStep step = GsonStep.create(INDENT, false, true, DEFAULT_VERSION, TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfter.json"); } @Test - void writesRawHtmlWhenHtmlEscapeDisabled() throws Exception { + void writesRawHtmlWhenHtmlEscapeDisabled() { FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfterDisabled.json"); @@ -86,8 +80,7 @@ void writesRawHtmlWhenHtmlEscapeDisabled() throws Exception { @Test void handlesVersionIncompatibility() { FormatterStep step = GsonStep.create(INDENT, false, false, "1.7", TestProvisioner.mavenCentral()); - StepHarness stepHarness = StepHarness.forStep(step); - assertThatThrownBy(() -> stepHarness.testResource("json/cucumberJsonSampleGsonBefore.json", "json/cucumberJsonSampleGsonAfter.json")) + Assertions.assertThatThrownBy(() -> step.format("", new File(""))) .isInstanceOf(IllegalStateException.class) .hasMessage("There was a problem interacting with Gson; maybe you set an incompatible version?"); } diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index 45bf6524f1..5055f47e8d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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. @@ -25,27 +25,19 @@ import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.ResourceHarness; -import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; class DiktatStepTest extends ResourceHarness { @Test - void behavior() throws Exception { + void behavior() { FormatterStep step = DiktatStep.create(TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("There are 4 unfixed errors:" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: testlib" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + - System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + - System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); - }); + StepHarnessWithFile.forStep(this, step).testResourceExceptionMsg("kotlin/diktat/Unsolvable.kt").isEqualTo("There are 2 unfixed errors:" + + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + + System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); } @Test @@ -55,19 +47,11 @@ void behaviorConf() throws Exception { FileSignature config = signAsList(conf); FormatterStep step = DiktatStep.create("1.2.1", TestProvisioner.mavenCentral(), config); - StepHarness.forStep(step) - .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("There are 4 unfixed errors:" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: testlib" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable" + - System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + - System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + - System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); - }); + StepHarnessWithFile.forStep(this, step).testResourceExceptionMsg("kotlin/diktat/Unsolvable.kt").isEqualTo("There are 2 unfixed errors:" + + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + + System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); } @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 42e377fde5..94de314e0b 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -22,62 +22,56 @@ import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; class KtLintStepTest extends ResourceHarness { @Test - void behavior() throws Exception { + void behavior() { FormatterStep step = KtLintStep.create(TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo( + "Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } @Test - void worksShyiko() throws Exception { + void worksShyiko() { FormatterStep step = KtLintStep.create("0.31.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo( + "Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } // Regression test to ensure it works on the version it switched to Pinterest (version 0.32.0) // but before 0.34. // https://github.com/diffplug/spotless/issues/419 @Test - void worksPinterestAndPre034() throws Exception { + void worksPinterestAndPre034() { FormatterStep step = KtLintStep.create("0.32.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } // Regression test to handle alpha and 1.x version numbers // https://github.com/diffplug/spotless/issues/668 @Test - void worksAlpha1() throws Exception { + void worksAlpha1() { FormatterStep step = KtLintStep.create("0.38.0-alpha01", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); } @Test - void works0_44_0() throws Exception { + void works0_44_0() { FormatterStep step = KtLintStep.create("0.44.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); @@ -85,80 +79,68 @@ void works0_44_0() throws Exception { @Disabled("https://github.com/pinterest/ktlint/issues/1421") @Test - void works0_45_0() throws Exception { + void works0_45_0() { FormatterStep step = KtLintStep.create("0.45.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); } @Test - void works0_45_1() throws Exception { + void works0_45_1() { FormatterStep step = KtLintStep.create("0.45.1", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); } @Test - void works0_45_2() throws Exception { + void works0_45_2() { FormatterStep step = KtLintStep.create("0.45.2", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); } @Test - void works0_46_0() throws Exception { + void works0_46_0() { FormatterStep step = KtLintStep.create("0.46.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } @Test - void works0_47_0() throws Exception { + void works0_47_0() { FormatterStep step = KtLintStep.create("0.47.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } @Test - void works0_47_1() throws Exception { + void works0_47_1() { FormatterStep step = KtLintStep.create("0.47.1", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } @Test - void works0_48_0() throws Exception { + void works0_48_0() { FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceException("kotlin/ktlint/unsolvable.dirty", assertion -> { - assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - }); + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); } @Test - void equality() throws Exception { + void equality() { new SerializableEqualityTester() { String version = "0.32.0"; diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index d2d866e97d..9de75fda32 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.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. @@ -25,13 +25,14 @@ import com.diffplug.common.collect.ImmutableMap; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.tag.NpmTest; @NpmTest -class PrettierFormatterStepTest { +class PrettierFormatterStepTest extends ResourceHarness { @NpmTest @Nested @@ -96,8 +97,8 @@ void parserInferenceBasedOnFilenameIsWorking() throws Exception { npmPathResolver(), new PrettierConfig(null, Collections.emptyMap())); - try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { - stepHarness.testResource(new File("test.json"), dirtyFile, cleanFile); + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { + stepHarness.testResource("test.json", dirtyFile, cleanFile); } } @@ -109,11 +110,9 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { buildDir(), npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); - try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { - stepHarness.testResourceException("npm/prettier/filetypes/scss/scss.dirty", exception -> { - exception.hasMessageContaining("HTTP 501"); - exception.hasMessageContaining("Couldn't resolve parser \"postcss\""); - }); + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { + stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").startsWith( + "com.diffplug.spotless.npm.SimpleRestClient$SimpleRestResponseException: Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); } } } diff --git a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java index bad573e985..1714dd9e29 100644 --- a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -15,13 +15,9 @@ */ package com.diffplug.spotless.scala; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - import java.io.File; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; @@ -33,43 +29,43 @@ class ScalaFmtStepTest extends ResourceHarness { @Test - void behaviorDefaultConfig() throws Exception { + void behaviorDefaultConfig() { StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null)) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean_3.0.0"); } @Test - void behaviorCustomConfig() throws Exception { + void behaviorCustomConfig() { StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); } @Test - void behaviorDefaultConfigVersion_3_0_0() throws Exception { + void behaviorDefaultConfigVersion_3_0_0() { FormatterStep step = ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null); StepHarness.forStep(step) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost3.0.0.clean"); } @Test - void behaviorCustomConfigVersion_3_0_0() throws Exception { + void behaviorCustomConfigVersion_3_0_0() { FormatterStep step = ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf")); StepHarness.forStep(step) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basicPost3.0.0.cleanWithCustomConf"); } @Test - void equality() throws Exception { + void equality() { new SerializableEqualityTester() { - String version = "3.5.9"; + String version = "3.6.1"; File configFile = null; @Override - protected void setupTest(API api) throws IOException { + protected void setupTest(API api) { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "3.5.8"; + version = "3.0.0"; api.areDifferentThan(); // add a config file, and its different configFile = createTestFile("scala/scalafmt/scalafmt.conf"); @@ -87,12 +83,11 @@ protected FormatterStep create() { } @Test - void invalidConfiguration() throws Exception { + void invalidConfiguration() { File invalidConfFile = createTestFile("scala/scalafmt/scalafmt.invalid.conf"); Provisioner provisioner = TestProvisioner.mavenCentral(); - - InvocationTargetException exception = assertThrows(InvocationTargetException.class, - () -> StepHarness.forStep(ScalaFmtStep.create("3.0.0", provisioner, invalidConfFile)).test("", "")); - assertThat(exception.getCause().getMessage()).contains("found option 'invalidScalaFmtConfigField' which wasn't expected"); + Assertions.assertThatThrownBy(() -> { + ScalaFmtStep.create("3.0.0", provisioner, invalidConfFile).format("", new File("")); + }).cause().message().contains("found option 'invalidScalaFmtConfigField' which wasn't expected"); } } From 748fd3040b286edf521c65cb67ad8cadc0e7c96f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 2 Jan 2023 18:17:11 -0800 Subject: [PATCH 0120/1120] Update changelog. --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index cf43b4eb22..a7e3516607 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` +* Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) + * `ResourceHarness` no longer has any duplicated functionality which was also present in `StepHarness` + * `StepHarness` now operates on `Formatter` rather than a `FormatterStep` + * `StepHarnessWithFile` now takes a `ResourceHarness` in its constructor to handle the file manipulation parts + * Standardized that we test exception *messages*, not types, which will ease the transition to linting later on ## [2.31.1] - 2023-01-02 ### Fixed From 6cd1eb49e54fd4a58e78f8fc1db2e0a1998043a5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 2 Jan 2023 18:45:08 -0800 Subject: [PATCH 0121/1120] Try to fix the failing Prettier test. --- .../com/diffplug/spotless/npm/PrettierFormatterStepTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index 9de75fda32..5f14022ad8 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -111,8 +111,8 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { - stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").startsWith( - "com.diffplug.spotless.npm.SimpleRestClient$SimpleRestResponseException: Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); + stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").isEqualTo( + "Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); } } } From f0b74d8a8494a4dd188ae773882fe2faa49e425c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 2 Jan 2023 20:20:41 -0800 Subject: [PATCH 0122/1120] StepHarness needs a strict error policy for it to exercise what we want in the tests. --- testlib/src/main/java/com/diffplug/spotless/StepHarness.java | 1 + .../src/main/java/com/diffplug/spotless/StepHarnessWithFile.java | 1 + 2 files changed, 2 insertions(+) diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java index 976a80df29..71e2a663b5 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java @@ -46,6 +46,7 @@ public static StepHarness forSteps(FormatterStep... steps) { .lineEndingsPolicy(LineEnding.UNIX.createPolicy()) .encoding(StandardCharsets.UTF_8) .rootDir(Paths.get("")) + .exceptionPolicy(new FormatExceptionPolicyStrict()) .build()); } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java index 3d01a6bd44..98a709c59f 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java @@ -42,6 +42,7 @@ public static StepHarnessWithFile forStep(ResourceHarness harness, FormatterStep .lineEndingsPolicy(LineEnding.UNIX.createPolicy()) .steps(Collections.singletonList(step)) .rootDir(harness.rootFolder().toPath()) + .exceptionPolicy(new FormatExceptionPolicyStrict()) .build()); } From 5e728be5dbad1a66f04b19f62b4483c186bb727a Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 3 Jan 2023 22:33:12 +0400 Subject: [PATCH 0123/1120] Initial iteration --- plugin-maven/README.md | 50 ++++++++++++++++++- .../diffplug/spotless/maven/json/Gson.java | 45 +++++++++++++++++ .../diffplug/spotless/maven/json/Json.java | 47 +++++++++++++++++ .../diffplug/spotless/maven/json/Simple.java | 35 +++++++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 80be3dbc37..8be4149705 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -58,6 +58,7 @@ user@machine repo % mvn spotless:check - [Maven Pom](#maven-pom) ([sortPom](#sortpom)) - [Markdown](#markdown) ([flexmark](#flexmark)) - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier)) + - [JSON](#json) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) - [eclipse web tools platform](#eclipse-web-tools-platform) @@ -431,7 +432,7 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T - src/native/** + src/native/** @@ -700,6 +701,53 @@ The auto-discovery of config files (up the file tree) will not work when using t For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt. +## JSON + +- `com.diffplug.spotless.maven.json.Json` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java) + +```xml + + + + src/**/*.json + + + + + + +``` + +### simple + +Uses a JSON pretty-printer that optionally allows configuring the number of spaces that are used to pretty print objects: + +```xml + + 4 + +``` + +### Gson + +Uses Google Gson to also allow sorting by keys besides custom indentation - useful for i18n files. + +```xml + + 4 + false + false + 2.8.1 + +``` + +Notes: +* There's no option in Gson to leave HTML as-is (i.e. escaped HTML would remain escaped, raw would remain raw). Either +all HTML characters are written escaped or none. Set `escapeHtml` if you prefer the former. +* `sortByKeys` will apply lexicographic order on the keys of the input JSON. See the +[javadoc of String](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#compareTo(java.lang.String)) +for details. + ## Prettier diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java new file mode 100644 index 0000000000..9091157637 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java @@ -0,0 +1,45 @@ +/* + * 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.maven.json; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.gson.GsonStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class Gson implements FormatterStepFactory { + private static final String DEFAULT_GSON_VERSION = "2.8.9"; + + @Parameter + int indentSpaces = Json.DEFAULT_INDENTATION; + + @Parameter + boolean sortByKeys = false; + + @Parameter + boolean escapeHtml = false; + + @Parameter + String version = DEFAULT_GSON_VERSION; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + int indentSpaces = this.indentSpaces; + return GsonStep.create(indentSpaces, sortByKeys, escapeHtml, version, stepConfig.getProvisioner()); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java new file mode 100644 index 0000000000..4cd4e88a7d --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -0,0 +1,47 @@ +/* + * 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.maven.json; + +import java.util.Collections; +import java.util.Set; + +import com.diffplug.spotless.maven.FormatterFactory; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + */ +public class Json extends FormatterFactory { + public static final int DEFAULT_INDENTATION = 4; + + @Override + public Set defaultIncludes() { + return Collections.emptySet(); + } + + @Override + public String licenseHeaderDelimiter() { + return null; + } + + public void addSimple(Simple simple) { + addStepFactory(simple); + } + + public void addGson(Gson gson) { + addStepFactory(gson); + } + +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java new file mode 100644 index 0000000000..5926d22282 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java @@ -0,0 +1,35 @@ +/* + * 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.maven.json; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JsonSimpleStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class Simple implements FormatterStepFactory { + + @Parameter + int indentSpaces = Json.DEFAULT_INDENTATION; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + int indentSpaces = this.indentSpaces; + return JsonSimpleStep.create(indentSpaces, stepConfig.getProvisioner()); + } +} From a7f969c8a950b33fd609b93a77b9032fb191cf30 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 3 Jan 2023 22:34:34 +0400 Subject: [PATCH 0124/1120] Fix copyright --- .../src/main/java/com/diffplug/spotless/maven/json/Gson.java | 2 +- .../src/main/java/com/diffplug/spotless/maven/json/Json.java | 2 +- .../src/main/java/com/diffplug/spotless/maven/json/Simple.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java index 9091157637..7962ecb1f7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index 4cd4e88a7d..27f9a0b82a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java index 5926d22282..f1cc114da2 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Simple.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * 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. From 338dd161ed45c853f4b63772ee2da1d867c06521 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Tue, 3 Jan 2023 14:00:09 -0500 Subject: [PATCH 0125/1120] Prevent tool configurations from being resolved outside project When exposed they can create ambiguities when downstream projects try to automatically choose a configuration based on its attributes. --- .../java/com/diffplug/gradle/spotless/GradleProvisioner.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index 97f051cd86..65e41da42c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -118,6 +118,7 @@ private static Provisioner forConfigurationContainer(Project project, Configurat .forEach(config.getDependencies()::add); config.setDescription(mavenCoords.toString()); config.setTransitive(withTransitives); + config.setCanBeConsumed(false); config.attributes(attr -> { attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); }); From f9a70adede09876fb0b770209d89f1f11dd7108e Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Tue, 3 Jan 2023 14:05:48 -0500 Subject: [PATCH 0126/1120] Update CHANGES.md --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cac4f56567..b9e3096980 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447)) ## [6.12.1] - 2023-01-02 ### Fixed From 163fb6e347a2a45fceb5189fd8d8b47882eadd1d Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Tue, 3 Jan 2023 14:16:47 -0500 Subject: [PATCH 0127/1120] Update GradleProvisioner.java --- .../java/com/diffplug/gradle/spotless/GradleProvisioner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index 65e41da42c..bd5d8db8ca 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. From 773d59c45412a349437334a2429d675236e35396 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 00:12:32 +0100 Subject: [PATCH 0128/1120] Add changes --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index cf43b4eb22..440ea59f80 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) ### Changes * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cac4f56567..3c9b51bd5a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) ## [6.12.1] - 2023-01-02 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 84e06aa847..ae8ac7e4dd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) ## [2.29.0] - 2023-01-02 ### Added From 57be84fb8283e62ae971f25c5b3467ee5906db8a Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 21:19:47 +0100 Subject: [PATCH 0129/1120] Use FileSignature to cache changes --- .../glue/ktlint/KtlintFormatterFunc.java | 26 +++++++------------ .../diffplug/spotless/kotlin/KtLintStep.java | 7 ++--- .../gradle/spotless/KotlinExtension.java | 14 ++++++++-- .../spotless/KotlinGradleExtension.java | 13 +++++++--- .../spotless/maven/kotlin/Ktlint.java | 11 +++++--- 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 5b43bf5e14..df98b6d691 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -15,20 +15,14 @@ */ package com.diffplug.spotless.glue.ktlint; -import java.io.File; -import java.util.Map; +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.glue.ktlint.compat.*; import org.jetbrains.annotations.NotNull; -import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot31Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot32Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot34Dot2Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; +import java.io.File; +import java.util.Map; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -37,11 +31,11 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @NotNull private final KtLintCompatAdapter adapter; private final boolean useExperimental; - private final String editorConfigPath; + private final FileSignature editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, - Map editorConfigOverrideMap) { + public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, FileSignature editorConfigPath, Map userData, + Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class @@ -73,7 +67,7 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime } @Override - public String applyWithFile(String unix, File file) throws Exception { - return adapter.format(unix, file.getName(), isScript, useExperimental, editorConfigPath, userData, editorConfigOverrideMap); + public String applyWithFile(String unix, File file) { + return adapter.format(unix, file.getName(), isScript, useExperimental, editorConfigPath.getOnlyFile().getAbsolutePath(), userData, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 9291e69fde..6d4d8b07ed 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -23,6 +23,7 @@ import java.util.Objects; import java.util.TreeMap; +import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.JarState; @@ -68,7 +69,7 @@ private static FormatterStep create(String version, Provisioner provisioner, boo } public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - String editorConfig, Map userData, Map editorConfigOverride) { + FileSignature editorConfig, Map userData, Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, @@ -91,10 +92,10 @@ static final class State implements Serializable { private final TreeMap userData; private final TreeMap editorConfigOverride; private final String version; - private final String editorConfigPath; + private final FileSignature editorConfigPath; State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - String editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { + FileSignature editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { this.version = version; String coordinate; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index eddeef36d6..8af03aaefd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -71,11 +71,11 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; - private String editorConfigPath; + private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, String editorConfigPath, Map config, + KotlinFormatExtension(String version, boolean useExperimental, FileSignature editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; @@ -91,6 +91,16 @@ public KotlinFormatExtension setUseExperimental(boolean useExperimental) { return this; } + public KotlinFormatExtension setEditorConfigPath(Object editorConfigFile) throws IOException { + if (editorConfigFile == null) { + this.editorConfigPath = null; + } else { + this.editorConfigPath = FileSignature.signAsList(getProject().file(editorConfigFile)); + } + replaceStep(createStep()); + return this; + } + public KotlinFormatExtension userData(Map userData) { // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized // representation. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index 5120d88754..ca4ecc9bde 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -56,11 +56,11 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; - private String editorConfigPath; + private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, String editorConfigPath, Map config, + KotlinFormatExtension(String version, boolean useExperimental, FileSignature editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; @@ -70,8 +70,13 @@ public class KotlinFormatExtension { addStep(createStep()); } - public KotlinFormatExtension setEditorConfigPath(String editorConfigPath) { - this.editorConfigPath = editorConfigPath; + public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException { + + if (editorConfigPath == null) { + this.editorConfigPath = null; + } else { + this.editorConfigPath = FileSignature.signAsList(getProject().file(editorConfigPath)); + } replaceStep(createStep()); return this; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index ad57c47976..2825980733 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -21,7 +21,9 @@ import org.apache.maven.plugins.annotations.Parameter; +import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ThrowingEx; import com.diffplug.spotless.kotlin.KtLintStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -36,13 +38,16 @@ public class Ktlint implements FormatterStepFactory { private Map editorConfigOverride; @Override - public FormatterStep newFormatterStep(FormatterStepConfig config) { + public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { String ktlintVersion = version != null ? version : KtLintStep.defaultVersion(); - + FileSignature configPath = null; + if (editorConfigPath != null) { + configPath = ThrowingEx.get(() -> FileSignature.signAsList(stepConfig.getFileLocator().locateFile(editorConfigPath))); + } if (editorConfigOverride == null) { editorConfigOverride = new HashMap<>(); } - return KtLintStep.create(ktlintVersion, config.getProvisioner(), false, false, editorConfigPath, Collections.emptyMap(), editorConfigOverride); + return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, false, configPath, Collections.emptyMap(), editorConfigOverride); } } From bd93e17a69613f04d4eab32629862c7229a2176f Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 22:03:22 +0100 Subject: [PATCH 0130/1120] Fix NPE and contract to pass the variable --- .../glue/ktlint/KtlintFormatterFunc.java | 19 ++++++++++++------- .../diffplug/spotless/kotlin/KtLintStep.java | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index df98b6d691..cfd6ab859c 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -15,14 +15,14 @@ */ package com.diffplug.spotless.glue.ktlint; -import com.diffplug.spotless.FileSignature; -import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.glue.ktlint.compat.*; +import java.io.File; +import java.util.Map; import org.jetbrains.annotations.NotNull; -import java.io.File; -import java.util.Map; +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.glue.ktlint.compat.*; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -35,7 +35,7 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { private final Map editorConfigOverrideMap; public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, FileSignature editorConfigPath, Map userData, - Map editorConfigOverrideMap) { + Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class @@ -68,6 +68,11 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime @Override public String applyWithFile(String unix, File file) { - return adapter.format(unix, file.getName(), isScript, useExperimental, editorConfigPath.getOnlyFile().getAbsolutePath(), userData, editorConfigOverrideMap); + + String absoluteEditorConfigPath = null; + if (editorConfigPath != null) { + absoluteEditorConfigPath = editorConfigPath.getOnlyFile().getAbsolutePath(); + } + return adapter.format(unix, file.getName(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 6d4d8b07ed..4d29a01394 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -59,7 +59,7 @@ public static FormatterStep createForScript(String version, Provisioner provisio } public static FormatterStep createForScript(String version, Provisioner provisioner, boolean useExperimental, - Map userData, Map editorConfigOverride) { + FileSignature editorConfigPath, Map userData, Map editorConfigOverride) { return create(version, provisioner, true, useExperimental, userData, editorConfigOverride); } @@ -119,7 +119,7 @@ FormatterFunc createFormat() throws Exception { final ClassLoader classLoader = jarState.getClassLoader(); Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); Constructor constructor = formatterFunc.getConstructor( - String.class, boolean.class, boolean.class, String.class, Map.class, Map.class); + String.class, boolean.class, boolean.class, FileSignature.class, Map.class, Map.class); return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, useExperimental, editorConfigPath, userData, editorConfigOverride); } } From b18da45e4a88f5900c80bd6dd6f2422b194127f2 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 22:04:00 +0100 Subject: [PATCH 0131/1120] EditorConfig: Set sane default for Gradle --- .../gradle/spotless/KotlinGradleExtension.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index ca4ecc9bde..a06c640060 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -15,6 +15,7 @@ */ package com.diffplug.gradle.spotless; +import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.Map; @@ -43,12 +44,17 @@ public KotlinGradleExtension(SpotlessExtension spotless) { } /** Adds the specified version of ktlint. */ - public KotlinFormatExtension ktlint(String version) { + public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version, "version"); - return new KotlinFormatExtension(version, false, null, Collections.emptyMap(), Collections.emptyMap()); + FileSignature editorConfigPath = null; + File defaultEditorConfig = getProject().getRootProject().file(".editorConfig"); + if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { + editorConfigPath = FileSignature.signAsList(defaultEditorConfig); + } + return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); } - public KotlinFormatExtension ktlint() { + public KotlinFormatExtension ktlint() throws IOException { return ktlint(KtLintStep.defaultVersion()); } @@ -104,7 +110,7 @@ public KotlinFormatExtension editorConfigOverride(Map editorConf } private FormatterStep createStep() { - return KtLintStep.createForScript(version, provisioner(), useExperimental, userData, editorConfigOverride); + return KtLintStep.createForScript(version, provisioner(), useExperimental, editorConfigPath, userData, editorConfigOverride); } } From 79e35c1dfe3c18aca8e216749d825752cd539d3d Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Tue, 3 Jan 2023 22:07:05 +0100 Subject: [PATCH 0132/1120] EditorConfig: add documentation --- plugin-gradle/README.md | 10 +++++++++- plugin-maven/README.md | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 755d21d056..84c4e626a0 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -354,7 +354,14 @@ spotless { ### ktlint -[homepage](https://github.com/pinterest/ktlint). [changelog](https://github.com/pinterest/ktlint/releases). Spotless does not ([yet](https://github.com/diffplug/spotless/issues/142)) respect the `.editorconfig` settings ([ktlint docs](https://github.com/pinterest/ktlint#editorconfig)), but you can provide them manually as `editorConfigOverride`. +[homepage](https://github.com/pinterest/ktlint). [changelog](https://github.com/pinterest/ktlint/releases). + +Spotless respects the `.editorconfig` settings by providing `editorConfigPath` option. +([ktlint docs](https://github.com/pinterest/ktlint#editorconfig)). +Default value is the `.editorconfig` file located in the top project. +Passing `null` will clear the option. + +Additionally, `editorConfigOverride` options will override what's supplied in `.editorconfig` file. ```kotlin spotless { @@ -363,6 +370,7 @@ spotless { ktlint("0.45.2") .setUseExperimental(true) .userData(mapOf("android" to "true")) + .editorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement .editorConfigOverride(mapOf("indent_size" to 2)) } } diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 80be3dbc37..1ae8e3a195 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -354,7 +354,13 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ### ktlint -[homepage](https://github.com/pinterest/ktlint). [changelog](https://github.com/pinterest/ktlint/releases). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java). Spotless does not ([yet](https://github.com/diffplug/spotless/issues/142)) respect the `.editorconfig` settings. +[homepage](https://github.com/pinterest/ktlint). [changelog](https://github.com/pinterest/ktlint/releases). +[code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java). + +Spotless respects the `.editorconfig` settings by providing `editorConfigPath` option. +([ktlint docs](https://github.com/pinterest/ktlint#editorconfig)). + +Additionally, `editorConfigOverride` options will override what's supplied in `.editorconfig` file. ```xml From 696d50c8b49db16a27ba9222683ece55dbfc91d5 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Tue, 3 Jan 2023 16:58:31 -0500 Subject: [PATCH 0133/1120] Update GradleProvisioner.java --- .../java/com/diffplug/gradle/spotless/GradleProvisioner.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index bd5d8db8ca..e1129b3b0b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -119,6 +119,7 @@ private static Provisioner forConfigurationContainer(Project project, Configurat config.setDescription(mavenCoords.toString()); config.setTransitive(withTransitives); config.setCanBeConsumed(false); + config.setVisible(false); config.attributes(attr -> { attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); }); From 5e442db1cd30bbc299cf904939af1174e6d44361 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 3 Jan 2023 14:30:02 -0800 Subject: [PATCH 0134/1120] Tweak changelog. --- plugin-gradle/CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b9e3096980..c5f464069f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447)) +* Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) ## [6.12.1] - 2023-01-02 ### Fixed From fc938dfdd8d800ea37ac79d456e66f6a51250189 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 4 Jan 2023 11:27:01 +0400 Subject: [PATCH 0135/1120] Add changes note, Fix style --- plugin-maven/CHANGES.md | 1 + plugin-maven/README.md | 12 +++--- .../diffplug/spotless/maven/json/Json.java | 2 +- .../spotless/maven/json/JsonTest.java | 40 +++++++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 84e06aa847..b15e005a9b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.29.0] - 2023-01-02 ### Added * Added support for M2E's incremental compilation ([#1414](https://github.com/diffplug/spotless/pull/1414) fixes [#1413](https://github.com/diffplug/spotless/issues/1413)) +* Add JSON support ([#1446](https://github.com/diffplug/spotless/pull/1446)) ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) * Support `ktlint` 0.48+ ([#1432](https://github.com/diffplug/spotless/pull/1432)) fixes ([#1430](https://github.com/diffplug/spotless/issues/1430)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 8be4149705..70f3dfe1dc 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -724,8 +724,8 @@ Uses a JSON pretty-printer that optionally allows configuring the number of spac ```xml - 4 - + 4 + ``` ### Gson @@ -734,10 +734,10 @@ Uses Google Gson to also allow sorting by keys besides custom indentation - usef ```xml - 4 - false - false - 2.8.1 + 4 + false + false + 2.8.1 ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index 27f9a0b82a..c326525d0c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -25,7 +25,7 @@ */ public class Json extends FormatterFactory { public static final int DEFAULT_INDENTATION = 4; - + @Override public Set defaultIncludes() { return Collections.emptySet(); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java new file mode 100644 index 0000000000..b7e666190a --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -0,0 +1,40 @@ +/* + * 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.json; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +public class JsonTest extends MavenIntegrationHarness { + @Test + public void testFormatJson_WithSimple_defaultConfig() throws Exception { + writePomWithPomSteps(""); + + setFile("json_test.json").toResource("json/json_dirty.json"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("json_test.json").sameAsResource("json/json_clean_default.json"); + } + + @Test + public void testFormatJson_WithGson_defaultConfig() throws Exception { + writePomWithPomSteps(""); + + setFile("json_test.json").toResource("json/json_dirty.json"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("json_test.json").sameAsResource("json/json_clean_default.json"); + } +} From 49592279ad462949fb68c3643ee85be0a062d839 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 28 Nov 2022 19:55:57 +0100 Subject: [PATCH 0136/1120] extract base serve code --- .../spotless/npm/NpmResourceHelper.java | 10 +++++- .../spotless/npm/PrettierFormatterStep.java | 4 ++- .../spotless/npm/TsFmtFormatterStep.java | 4 ++- .../com/diffplug/spotless/npm/common-serve.js | 32 +++++++++++++++++++ .../diffplug/spotless/npm/prettier-serve.js | 30 ----------------- .../com/diffplug/spotless/npm/tsfmt-serve.js | 31 ------------------ 6 files changed, 47 insertions(+), 64 deletions(-) create mode 100644 lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index ad1211d717..cb6fff3290 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2022 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,9 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.time.Duration; +import java.util.Arrays; import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; import com.diffplug.spotless.ThrowingEx; @@ -45,6 +47,12 @@ static void deleteFileIfExists(File file) throws IOException { } } + static String readUtf8StringFromClasspath(Class clazz, String... resourceNames) { + return Arrays.stream(resourceNames) + .map(resourceName -> readUtf8StringFromClasspath(clazz, resourceName)) + .collect(Collectors.joining("\n")); + } + static String readUtf8StringFromClasspath(Class clazz, String resourceName) { try (InputStream input = clazz.getResourceAsStream(resourceName)) { return readUtf8StringFromInputStream(input); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 49d692d62c..5a5662eee4 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -70,7 +70,9 @@ private static class State extends NpmFormatterStepStateBase implements Serializ NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/prettier-package.json"), new TreeMap<>(devDependencies)), "prettier", - NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/prettier-serve.js"), + NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, + "/com/diffplug/spotless/npm/common-serve.js", + "/com/diffplug/spotless/npm/prettier-serve.js"), npmPathResolver.resolveNpmrcContent()), buildDir, npmPathResolver.resolveNpmExecutable()); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index 14080ecf56..e9c098d709 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -76,7 +76,9 @@ public State(String stepName, Map versions, File buildDir, NpmPa new NpmConfig( replaceDevDependencies(NpmResourceHelper.readUtf8StringFromClasspath(TsFmtFormatterStep.class, "/com/diffplug/spotless/npm/tsfmt-package.json"), new TreeMap<>(versions)), "typescript-formatter", - NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/tsfmt-serve.js"), + NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, + "/com/diffplug/spotless/npm/common-serve.js", + "/com/diffplug/spotless/npm/tsfmt-serve.js"), npmPathResolver.resolveNpmrcContent()), buildDir, npmPathResolver.resolveNpmExecutable()); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js new file mode 100644 index 0000000000..3e031cedea --- /dev/null +++ b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js @@ -0,0 +1,32 @@ +// this file will be glued to the top of the specific xy-server.js file +const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager; +const express = require("express"); +const app = express(); + +app.use(express.json({ limit: "50mb" })); + +const fs = require("fs"); + +var listener = app.listen(0, "127.0.0.1", () => { + console.log("Server running on port " + listener.address().port); + fs.writeFile("server.port.tmp", "" + listener.address().port, function(err) { + if (err) { + return console.log(err); + } else { + fs.rename("server.port.tmp", "server.port", function(err) { + if (err) { + return console.log(err); + } + }); // try to be as atomic as possible + } + }); +}); +const shutdownManager = new GracefulShutdownManager(listener); + +app.post("/shutdown", (req, res) => { + res.status(200).send("Shutting down"); + setTimeout(function() { + shutdownManager.terminate(() => console.log("graceful shutdown finished.")); + }, 200); +}); + diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js index 351ef73f9a..d4ce13bbbc 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js @@ -1,35 +1,5 @@ -const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager; -const express = require("express"); -const app = express(); - -app.use(express.json({ limit: "50mb" })); const prettier = require("prettier"); -const fs = require("fs"); - -var listener = app.listen(0, "127.0.0.1", () => { - console.log("Server running on port " + listener.address().port); - fs.writeFile("server.port.tmp", "" + listener.address().port, function(err) { - if (err) { - return console.log(err); - } else { - fs.rename("server.port.tmp", "server.port", function(err) { - if (err) { - return console.log(err); - } - }); // try to be as atomic as possible - } - }); -}); -const shutdownManager = new GracefulShutdownManager(listener); - -app.post("/shutdown", (req, res) => { - res.status(200).send("Shutting down"); - setTimeout(function() { - shutdownManager.terminate(() => console.log("graceful shutdown finished.")); - }, 200); -}); - app.post("/prettier/config-options", (req, res) => { var config_data = req.body; var prettier_config_path = config_data.prettier_config_path; diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js index b25048d410..8ec25565ff 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js @@ -1,36 +1,5 @@ -const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager; -const express = require("express"); -const app = express(); -app.use(express.json({ limit: "50mb" })); - const tsfmt = require("typescript-formatter"); -const fs = require("fs"); - -var listener = app.listen(0, "127.0.0.1", () => { - console.log("Server running on port " + listener.address().port); - fs.writeFile("server.port.tmp", "" + listener.address().port, function(err) { - if (err) { - return console.log(err); - } else { - fs.rename("server.port.tmp", "server.port", function(err) { - if (err) { - return console.log(err); - } - }); // try to be as atomic as possible - } - }); -}); - -const shutdownManager = new GracefulShutdownManager(listener); - -app.post("/shutdown", (req, res) => { - res.status(200).send("Shutting down"); - setTimeout(function() { - shutdownManager.terminate(() => console.log("graceful shutdown finished.")); - }, 200); -}); - app.post("/tsfmt/format", (req, res) => { var format_data = req.body; tsfmt.processString("spotless-format-string.ts", format_data.file_content, format_data.config_options).then(resultMap => { From c70bd347f4b855035ddc466b0d7d5361ee77f415 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 28 Nov 2022 19:56:11 +0100 Subject: [PATCH 0137/1120] upgrade express to latest --- .../resources/com/diffplug/spotless/npm/prettier-package.json | 2 +- .../main/resources/com/diffplug/spotless/npm/tsfmt-package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json index 113f20bc3f..7bda08db8a 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json @@ -9,7 +9,7 @@ }, "devDependencies": { ${devDependencies}, - "express": "4.17.1", + "express": "4.18.2", "@moebius/http-graceful-shutdown": "1.1.0" }, "dependencies": {}, diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json index d6e5eff3b2..7037bd2ec1 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json @@ -9,7 +9,7 @@ }, "devDependencies": { ${devDependencies}, - "express": "4.17.1", + "express": "4.18.2", "@moebius/http-graceful-shutdown": "1.1.0" }, "dependencies": {}, From 3884e14d7ffd9a3c4fbfbe9bdeeb1172810d0b17 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sat, 3 Dec 2022 19:50:03 +0100 Subject: [PATCH 0138/1120] extract common rest code on client side --- .../spotless/npm/BaseNpmRestService.java | 30 +++++++++++++++++++ .../spotless/npm/PrettierRestService.java | 13 ++------ .../spotless/npm/TsFmtRestService.java | 13 ++------ 3 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java new file mode 100644 index 0000000000..e8582c15ec --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java @@ -0,0 +1,30 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +abstract class BaseNpmRestService { + + protected final SimpleRestClient restClient; + + BaseNpmRestService(String baseUrl) { + this.restClient = SimpleRestClient.forBaseUrl(baseUrl); + } + + public String shutdown() { + return restClient.post("/shutdown"); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java index ced08b013f..2a62823aa0 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,12 +19,10 @@ import java.util.LinkedHashMap; import java.util.Map; -public class PrettierRestService { - - private final SimpleRestClient restClient; +public class PrettierRestService extends BaseNpmRestService { PrettierRestService(String baseUrl) { - this.restClient = SimpleRestClient.forBaseUrl(baseUrl); + super(baseUrl); } public String resolveConfig(File prettierConfigPath, Map prettierConfigOptions) { @@ -48,9 +46,4 @@ public String format(String fileContent, String configOptionsJsonString) { return restClient.postJson("/prettier/format", jsonProperties); } - - public String shutdown() { - return restClient.post("/shutdown"); - } - } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java index a47b608c36..f77510c3b6 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,10 @@ import java.util.LinkedHashMap; import java.util.Map; -public class TsFmtRestService { - - private final SimpleRestClient restClient; +public class TsFmtRestService extends BaseNpmRestService { TsFmtRestService(String baseUrl) { - this.restClient = SimpleRestClient.forBaseUrl(baseUrl); + super(baseUrl); } public String format(String fileContent, Map configOptions) { @@ -35,9 +33,4 @@ public String format(String fileContent, Map configOptions) { return restClient.postJson("/tsfmt/format", jsonProperties); } - - public String shutdown() { - return restClient.post("/shutdown"); - } - } From c20d3bb14adae3b90654b0531ac12a06d468185a Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sat, 3 Dec 2022 19:53:24 +0100 Subject: [PATCH 0139/1120] add "eslint --fix" as formatter --- .../diffplug/spotless/npm/EslintConfig.java | 61 +++++ .../spotless/npm/EslintFormatterStep.java | 219 ++++++++++++++++++ .../spotless/npm/EslintRestService.java | 46 ++++ .../spotless/npm/NpmResourceHelper.java | 11 + .../diffplug/spotless/npm/eslint-package.json | 19 ++ .../com/diffplug/spotless/npm/eslint-serve.js | 66 ++++++ .../gradle/spotless/FormatExtension.java | 87 ++++++- .../gradle/spotless/TypescriptExtension.java | 56 ++++- .../spotless/TypescriptExtensionTest.java | 21 +- .../resources/npm/eslint/config/.eslintrc.js | 38 +++ .../eslint/config/typescript.configfile.clean | 15 ++ .../eslint/config/typescript.defaults.clean | 11 + .../npm/eslint/config/typescript.dirty | 10 + .../eslint/config/typescript.override.clean | 9 + .../eslint/filetypes/typescript/.eslintrc.js | 59 +++++ .../filetypes/typescript/typescript.clean | 11 + .../filetypes/typescript/typescript.dirty | 11 + 17 files changed, 737 insertions(+), 13 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java create mode 100644 lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json create mode 100644 lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js create mode 100644 testlib/src/main/resources/npm/eslint/config/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/config/typescript.configfile.clean create mode 100644 testlib/src/main/resources/npm/eslint/config/typescript.defaults.clean create mode 100644 testlib/src/main/resources/npm/eslint/config/typescript.dirty create mode 100644 testlib/src/main/resources/npm/eslint/config/typescript.override.clean create mode 100644 testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean create mode 100644 testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java new file mode 100644 index 0000000000..a6d41f9bc0 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java @@ -0,0 +1,61 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; + +import javax.annotation.Nullable; + +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.ThrowingEx; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +public class EslintConfig implements Serializable { + + private static final long serialVersionUID = -6196834313082791248L; + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + @Nullable + private final transient File eslintConfigPath; + + @SuppressWarnings("unused") + private final FileSignature eslintConfigPathSignature; + + private final String eslintConfigJs; + + public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs) { + try { + this.eslintConfigPath = eslintConfigPath; + this.eslintConfigPathSignature = eslintConfigPath != null ? FileSignature.signAsList(this.eslintConfigPath) : FileSignature.signAsList(); + this.eslintConfigJs = eslintConfigJs; + } catch (IOException e) { + throw ThrowingEx.asRuntime(e); + } + } + + @Nullable + public File getEslintConfigPath() { + return eslintConfigPath; + } + + @Nullable + public String getEslintConfigJs() { + return eslintConfigJs; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java new file mode 100644 index 0000000000..83d60a72c1 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -0,0 +1,219 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import static java.util.Objects.requireNonNull; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; +import java.util.TreeMap; + +import javax.annotation.Nonnull; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterFunc.Closeable; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.ThrowingEx; +import com.diffplug.spotless.npm.EslintRestService.FormatOption; + +public class EslintFormatterStep { + + private static final Logger logger = LoggerFactory.getLogger(EslintFormatterStep.class); + + public static final String NAME = "eslint-format"; + + public static final String DEFAULT_ESLINT_VERSION = "8.28.0"; + + public enum PopularStyleGuide { + STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-standard-with-typescript", "23.0.0"); + dependencies.put("eslint-plugin-import", "2.26.0"); + dependencies.put("eslint-plugin-n", "15.5.1"); + dependencies.put("eslint-plugin-promise", "6.1.1"); + dependencies.put("typescript", "4.9.3"); + return dependencies; + } + }, + XO_TYPESCRIPT("xo-typescript") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-xo", "0.43.1"); + dependencies.put("eslint-config-xo-typescript", "0.55.1"); + dependencies.put("typescript", "4.9.3"); + return dependencies; + } + }; + + private final String popularStyleGuideName; + + PopularStyleGuide(String popularStyleGuideName) { + this.popularStyleGuideName = popularStyleGuideName; + } + + public String getPopularStyleGuideName() { + return popularStyleGuideName; + } + + public abstract Map devDependencies(); + + public static PopularStyleGuide fromNameOrNull(String popularStyleGuideName) { + for (PopularStyleGuide popularStyleGuide : PopularStyleGuide.values()) { + if (popularStyleGuide.popularStyleGuideName.equals(popularStyleGuideName)) { + return popularStyleGuide; + } + } + return null; + } + } + + public static Map defaultDevDependenciesForTypescript() { + return defaultDevDependenciesTypescriptWithEslint(DEFAULT_ESLINT_VERSION); + } + + public static Map defaultDevDependenciesTypescriptWithEslint(String eslintVersion) { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("@typescript-eslint/eslint-plugin", "5.45.0"); + dependencies.put("@typescript-eslint/parser", "5.45.0"); + dependencies.put("eslint", Objects.requireNonNull(eslintVersion)); + return dependencies; + } + + public static Map defaultDevDependencies() { + return defaultDevDependenciesWithEslint(DEFAULT_ESLINT_VERSION); + } + + public static Map defaultDevDependenciesWithEslint(String version) { + return Collections.singletonMap("eslint", version); + } + + public static FormatterStep create(Map devDependencies, Provisioner provisioner, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) { + requireNonNull(devDependencies); + requireNonNull(provisioner); + requireNonNull(buildDir); + return FormatterStep.createLazy(NAME, + () -> new State(NAME, devDependencies, buildDir, npmPathResolver, eslintConfig), + State::createFormatterFunc); + } + + private static class State extends NpmFormatterStepStateBase implements Serializable { + + private static final long serialVersionUID = -539537027004745812L; + private final EslintConfig eslintConfig; + + State(String stepName, Map devDependencies, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { + super(stepName, + new NpmConfig( + replaceDevDependencies( + NpmResourceHelper.readUtf8StringFromClasspath(EslintFormatterStep.class, "/com/diffplug/spotless/npm/eslint-package.json"), + new TreeMap<>(devDependencies)), + "eslint", + NpmResourceHelper.readUtf8StringFromClasspath(EslintFormatterStep.class, + "/com/diffplug/spotless/npm/common-serve.js", + "/com/diffplug/spotless/npm/eslint-serve.js"), + npmPathResolver.resolveNpmrcContent()), + buildDir, + npmPathResolver.resolveNpmExecutable()); + this.eslintConfig = localCopyFiles(requireNonNull(eslintConfig)); + } + + private EslintConfig localCopyFiles(EslintConfig orig) { + if (orig.getEslintConfigPath() == null) { + return orig; + } + // If a config file is provided, we need to make sure it is at the same location as the node modules + // as eslint will try to resolve plugin/config names relatively to the config file location + FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", orig.getEslintConfigPath(), nodeModulesDir); + File configFileCopy = NpmResourceHelper.copyFileToDir(orig.getEslintConfigPath(), nodeModulesDir); + return new EslintConfig(configFileCopy, orig.getEslintConfigJs()); + } + + @Override + @Nonnull + public FormatterFunc createFormatterFunc() { + try { + FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); + ServerProcessInfo eslintRestServer = npmRunServer(); + EslintRestService restService = new EslintRestService(eslintRestServer.getBaseUrl()); + + // String prettierConfigOptions = restService.resolveConfig(this.prettierConfig.getPrettierConfigPath(), this.prettierConfig.getOptions()); + return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(nodeModulesDir, eslintConfig, restService)); + } catch (IOException e) { + throw ThrowingEx.asRuntime(e); + } + } + + private void endServer(BaseNpmRestService restService, ServerProcessInfo restServer) throws Exception { + FormattedPrinter.SYSOUT.print("Closing formatting function (ending server)."); + try { + restService.shutdown(); + } catch (Throwable t) { + logger.info("Failed to request shutdown of rest service via api. Trying via process.", t); + } + restServer.close(); + } + + } + + private static class EslintFilePathPassingFormatterFunc implements FormatterFunc.NeedsFile { + private final File nodeModulesDir; + private final EslintConfig eslintConfig; + private final EslintRestService restService; + + public EslintFilePathPassingFormatterFunc(File nodeModulesDir, EslintConfig eslintConfig, EslintRestService restService) { + this.nodeModulesDir = nodeModulesDir; + this.eslintConfig = requireNonNull(eslintConfig); + this.restService = requireNonNull(restService); + } + + @Override + public String applyWithFile(String unix, File file) throws Exception { + FormattedPrinter.SYSOUT.print("formatting String '" + unix.substring(0, Math.min(50, unix.length())) + "[...]' in file '" + file + "'"); + + Map eslintCallOptions = new HashMap<>(); + setConfigToCallOptions(eslintCallOptions); + setFilePathToCallOptions(eslintCallOptions, file); + return restService.format(unix, eslintCallOptions); + } + + private void setFilePathToCallOptions(Map eslintCallOptions, File fileToBeFormatted) { + eslintCallOptions.put(FormatOption.FILE_PATH, fileToBeFormatted.getAbsolutePath()); + } + + private void setConfigToCallOptions(Map eslintCallOptions) { + if (eslintConfig.getEslintConfigPath() != null) { + eslintCallOptions.put(FormatOption.ESLINT_OVERRIDE_CONFIG_FILE, eslintConfig.getEslintConfigPath().getAbsolutePath()); + } + if (eslintConfig.getEslintConfigJs() != null) { + eslintCallOptions.put(FormatOption.ESLINT_OVERRIDE_CONFIG, eslintConfig.getEslintConfigJs()); + } + eslintCallOptions.put(FormatOption.NODE_MODULES_DIR, nodeModulesDir.getAbsolutePath()); + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java new file mode 100644 index 0000000000..541b77bab8 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; + +public class EslintRestService extends BaseNpmRestService { + + EslintRestService(String baseUrl) { + super(baseUrl); + } + + public String format(String fileContent, Map formatOptions) { + Map jsonProperties = new LinkedHashMap<>(); + jsonProperties.put("file_content", fileContent); + for (Entry option : formatOptions.entrySet()) { + jsonProperties.put(option.getKey().backendName, option.getValue()); + } + return restClient.postJson("/eslint/format", jsonProperties); + } + + enum FormatOption { + ESLINT_OVERRIDE_CONFIG("eslint_override_config"), ESLINT_OVERRIDE_CONFIG_FILE("eslint_override_config_file"), FILE_PATH("file_path"), NODE_MODULES_DIR("node_modules_dir"); + + private final String backendName; + + FormatOption(String backendName) { + this.backendName = backendName; + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index cb6fff3290..4f97e7e732 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -18,6 +18,7 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.time.Duration; import java.util.Arrays; import java.util.concurrent.TimeoutException; @@ -100,4 +101,14 @@ static void awaitReadableFile(File file, Duration maxWaitTime) throws TimeoutExc } } } + + static File copyFileToDir(File file, File targetDir) { + try { + File copiedFile = new File(targetDir, file.getName()); + Files.copy(file.toPath(), copiedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + return copiedFile; + } catch (IOException e) { + throw ThrowingEx.asRuntime(e); + } + } } diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json new file mode 100644 index 0000000000..dcd91e729d --- /dev/null +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json @@ -0,0 +1,19 @@ +{ + "name": "spotless-eslint-formatter-step", + "version": "2.0.0", + "description": "Spotless formatter step for running eslint as a rest service.", + "repository": "https://github.com/diffplug/spotless", + "license": "Apache-2.0", + "scripts": { + "start": "node serve.js" + }, + "devDependencies": { +${devDependencies}, + "express": "4.18.2", + "@moebius/http-graceful-shutdown": "1.1.0" + }, + "dependencies": {}, + "engines": { + "node": ">=6" + } +} diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js new file mode 100644 index 0000000000..8c56b8ef08 --- /dev/null +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -0,0 +1,66 @@ +const {ESLint} = require("eslint"); + +app.post("/eslint/format", async (req, res) => { + + const format_data = req.body; + + const ESLintOverrideConfig = format_data.eslint_override_config; + + const ESLintOverrideConfigFile = format_data.eslint_override_config_file; + + if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) { + res.status(501).send("Error while formatting: No config provided"); + return; + } + + const filePath = format_data.file_path; + + if (!filePath) { + res.status(501).send("Error while formatting: No file path provided"); + return; + } + + const ESLintOptions = { + fix: true, + useEslintrc: false, // would result in (gradle) cache issues + resolvePluginsRelativeTo: format_data.node_modules_dir + }; + + + if (ESLintOverrideConfigFile) { + ESLintOptions.overrideConfigFile = ESLintOverrideConfigFile; + } + if (ESLintOverrideConfig) { + ESLintOptions.overrideConfig = ESLintOverrideConfig; + } + + const eslint = new ESLint(ESLintOptions); + + + try { + console.log("using options: " + JSON.stringify(ESLintOptions)); + console.log("format input", format_data.file_content); + const lintTextOptions = { + filePath: filePath, + } + console.log("lintTextOptions", lintTextOptions); + // LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type + const results = await eslint.lintText(format_data.file_content, lintTextOptions); + if (results.length !== 1) { + res.status(501).send("Error while formatting: Unexpected number of results"); + return; + } + const result = results[0]; + console.log("result: " + JSON.stringify(result)); + if (result.fatalErrorCount && result.fatalErrorCount > 0) { + res.status(501).send("Fatal error while formatting: " + JSON.stringify(result.messages)); + return; + } + const formatted = result.output || result.source || format_data.file_content; + res.set("Content-Type", "text/plain"); + res.send(formatted); + } catch (err) { + console.log("error", err); + res.status(501).send("Error while formatting: " + err); + } +}); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index de0313eab4..99e21bd8c8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -16,6 +16,7 @@ package com.diffplug.gradle.spotless; import static com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull; +import static java.util.Objects.requireNonNull; import java.io.File; import java.io.Serializable; @@ -23,9 +24,9 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Random; import java.util.TreeMap; @@ -59,6 +60,8 @@ import com.diffplug.spotless.generic.ReplaceRegexStep; import com.diffplug.spotless.generic.ReplaceStep; import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; +import com.diffplug.spotless.npm.EslintConfig; +import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; @@ -71,7 +74,7 @@ public class FormatExtension { @Inject public FormatExtension(SpotlessExtension spotless) { - this.spotless = Objects.requireNonNull(spotless); + this.spotless = requireNonNull(spotless); } protected final Provisioner provisioner() { @@ -96,7 +99,7 @@ public LineEnding getLineEndings() { /** Sets the line endings to use (defaults to {@link SpotlessExtensionImpl#getLineEndings()}. */ public void setLineEndings(LineEnding lineEndings) { - this.lineEndings = Objects.requireNonNull(lineEndings); + this.lineEndings = requireNonNull(lineEndings); } Charset encoding; @@ -108,7 +111,7 @@ public Charset getEncoding() { /** Sets the encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}. */ public void setEncoding(String name) { - setEncoding(Charset.forName(Objects.requireNonNull(name))); + setEncoding(Charset.forName(requireNonNull(name))); } /** Sentinel to distinguish between "don't ratchet this format" and "use spotless parent format". */ @@ -136,19 +139,19 @@ public void ratchetFrom(String ratchetFrom) { /** Sets the encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}. */ public void setEncoding(Charset charset) { - encoding = Objects.requireNonNull(charset); + encoding = requireNonNull(charset); } final FormatExceptionPolicyStrict exceptionPolicy = new FormatExceptionPolicyStrict(); /** Ignores errors in the given step. */ public void ignoreErrorForStep(String stepName) { - exceptionPolicy.excludeStep(Objects.requireNonNull(stepName)); + exceptionPolicy.excludeStep(requireNonNull(stepName)); } /** Ignores errors for the given relative path. */ public void ignoreErrorForPath(String relativePath) { - exceptionPolicy.excludePath(Objects.requireNonNull(relativePath)); + exceptionPolicy.excludePath(requireNonNull(relativePath)); } /** Sets encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}). */ @@ -290,7 +293,7 @@ private static void relativizeIfSubdir(List relativePaths, File root, Fi /** Adds a new step. */ public void addStep(FormatterStep newStep) { - Objects.requireNonNull(newStep); + requireNonNull(newStep); int existingIdx = getExistingStepIdx(newStep.getName()); if (existingIdx != -1) { throw new GradleException("Multiple steps with name '" + newStep.getName() + "' for spotless format '" + formatName() + "'"); @@ -356,13 +359,13 @@ protected Integer calculateState() throws Exception { /** Adds a custom step. Receives a string with unix-newlines, must return a string with unix newlines. */ public void custom(String name, Closure formatter) { - Objects.requireNonNull(formatter, "formatter"); + requireNonNull(formatter, "formatter"); custom(name, formatter::call); } /** Adds a custom step. Receives a string with unix-newlines, must return a string with unix newlines. */ public void custom(String name, FormatterFunc formatter) { - Objects.requireNonNull(formatter, "formatter"); + requireNonNull(formatter, "formatter"); addStep(FormatterStep.createLazy(name, () -> globalState, unusedState -> formatter)); } @@ -560,7 +563,7 @@ public class PrettierConfig extends NpmStepConfig { final Map devDependencies; PrettierConfig(Map devDependencies) { - this.devDependencies = Objects.requireNonNull(devDependencies); + this.devDependencies = requireNonNull(devDependencies); } public PrettierConfig configFile(final Object prettierConfigFile) { @@ -605,6 +608,68 @@ public PrettierConfig prettier(Map devDependencies) { return prettierConfig; } + public class EslintFormatExtension extends NpmStepConfig { + + Map devDependencies = new LinkedHashMap<>(); + + @Nullable + Object configFilePath = null; + + @Nullable + String configJs = null; + + public EslintFormatExtension(Map devDependencies) { + this.devDependencies.putAll(requireNonNull(devDependencies)); + } + + public EslintFormatExtension devDependencies(Map devDependencies) { + this.devDependencies.putAll(devDependencies); + replaceStep(createStep()); + return this; + } + + public EslintFormatExtension configJs(String configJs) { + this.configJs = requireNonNull(configJs); + replaceStep(createStep()); + return this; + } + + public EslintFormatExtension configFile(Object configFilePath) { + this.configFilePath = requireNonNull(configFilePath); + replaceStep(createStep()); + return this; + } + + public FormatterStep createStep() { + final Project project = getProject(); + + return EslintFormatterStep.create( + devDependencies, + provisioner(), + project.getBuildDir(), + new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + eslintConfig()); + } + + private EslintConfig eslintConfig() { + return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); + } + } + + public EslintFormatExtension eslint() { + return eslint(EslintFormatterStep.defaultDevDependencies()); + } + + public EslintFormatExtension eslint(String version) { + return eslint(EslintFormatterStep.defaultDevDependenciesWithEslint(version)); + } + + public EslintFormatExtension eslint(Map devDependencies) { + EslintFormatExtension eslint = new EslintFormatExtension(devDependencies); + addStep(eslint.createStep()); + return eslint; + } + /** Uses the default version of clang-format. */ public ClangFormatConfig clangFormat() { return clangFormat(ClangFormatStep.defaultVersion()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 58b9d4acbb..e80730d5ed 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,12 @@ import static java.util.Objects.requireNonNull; +import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Objects; import java.util.TreeMap; +import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.inject.Inject; @@ -28,6 +30,8 @@ import org.gradle.api.Project; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; import com.diffplug.spotless.npm.TsConfigFileType; @@ -169,6 +173,56 @@ private void fixParserToTypescript() { } } + @Override + public TypescriptEslintFormatExtension eslint() { + return eslint(EslintFormatterStep.defaultDevDependenciesForTypescript()); + } + + @Override + public TypescriptEslintFormatExtension eslint(String version) { + return eslint(EslintFormatterStep.defaultDevDependenciesTypescriptWithEslint(version)); + } + + @Override + public TypescriptEslintFormatExtension eslint(Map devDependencies) { + TypescriptEslintFormatExtension eslint = new TypescriptEslintFormatExtension(devDependencies); + addStep(eslint.createStep()); + return eslint; + } + + public class TypescriptEslintFormatExtension extends EslintFormatExtension { + + public TypescriptEslintFormatExtension(Map devDependencies) { + super(devDependencies); + } + + @Override + public TypescriptEslintFormatExtension devDependencies(Map devDependencies) { + return (TypescriptEslintFormatExtension) super.devDependencies(devDependencies); + } + + @Override + public TypescriptEslintFormatExtension configJs(String configJs) { + return (TypescriptEslintFormatExtension) super.configJs(configJs); + } + + @Override + public TypescriptEslintFormatExtension configFile(Object configFilePath) { + return (TypescriptEslintFormatExtension) super.configFile(configFilePath); + } + + public TypescriptEslintFormatExtension styleGuide(String styleGuide) { + PopularStyleGuide popularStyleGuide = PopularStyleGuide.fromNameOrNull(styleGuide); + if (popularStyleGuide == null) { + throw new IllegalArgumentException("Unknown style guide: " + styleGuide + ". Known style guides: " + + Arrays.stream(PopularStyleGuide.values()).map(PopularStyleGuide::getPopularStyleGuideName).collect(Collectors.joining(", "))); + } + devDependencies(popularStyleGuide.devDependencies()); + replaceStep(createStep()); + return this; + } + } + @Override protected void setupTask(SpotlessTask task) { // defaults to all typescript files diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 100c4eb3b0..40da7e3536 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -141,4 +141,23 @@ void usePrettier() throws IOException { gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); assertFile("test.ts").sameAsResource("npm/prettier/filetypes/typescript/typescript.clean"); } + + @Test + void useEslint() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/filetypes/typescript/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " eslint().configFile('.eslintrc.js')", + " }", + "}"); + setFile("test.ts").toResource("npm/eslint/filetypes/typescript/typescript.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.ts").sameAsResource("npm/eslint/filetypes/typescript/typescript.clean"); + } } diff --git a/testlib/src/main/resources/npm/eslint/config/.eslintrc.js b/testlib/src/main/resources/npm/eslint/config/.eslintrc.js new file mode 100644 index 0000000000..6cb3070512 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/config/.eslintrc.js @@ -0,0 +1,38 @@ +module.exports = { + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "overrides": [ + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "indent": [ + "error", + 4 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ] + } +}; diff --git a/testlib/src/main/resources/npm/eslint/config/typescript.configfile.clean b/testlib/src/main/resources/npm/eslint/config/typescript.configfile.clean new file mode 100644 index 0000000000..0ec76369be --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/config/typescript.configfile.clean @@ -0,0 +1,15 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary + extends AbstractController + implements DisposeAware, CallbackAware { + public myValue: string[]; + + constructor( + private myService: Service, + name: string, + private field: any + ) { + super(name); + } + + //... +} diff --git a/testlib/src/main/resources/npm/eslint/config/typescript.defaults.clean b/testlib/src/main/resources/npm/eslint/config/typescript.defaults.clean new file mode 100644 index 0000000000..0155b905bd --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/config/typescript.defaults.clean @@ -0,0 +1,11 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary + extends AbstractController + implements DisposeAware, CallbackAware { + public myValue: string[]; + + constructor(private myService: Service, name: string, private field: any) { + super(name); + } + + //... +} diff --git a/testlib/src/main/resources/npm/eslint/config/typescript.dirty b/testlib/src/main/resources/npm/eslint/config/typescript.dirty new file mode 100644 index 0000000000..a3a30bf49a --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/config/typescript.dirty @@ -0,0 +1,10 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController implements DisposeAware, CallbackAware { + + +public myValue:string[]; + +constructor(private myService:Service,name:string,private field:any){ super(name) ;} + + +//... +} diff --git a/testlib/src/main/resources/npm/eslint/config/typescript.override.clean b/testlib/src/main/resources/npm/eslint/config/typescript.override.clean new file mode 100644 index 0000000000..3f3a8c30af --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/config/typescript.override.clean @@ -0,0 +1,9 @@ +export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController implements DisposeAware, CallbackAware { + public myValue: string[]; + + constructor(private myService: Service, name: string, private field: any) { + super(name); + } + + //... +} diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js b/testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js new file mode 100644 index 0000000000..e6ddff7d4c --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js @@ -0,0 +1,59 @@ +module.exports = { + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "overrides": [ + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "indent": [ + "error", + 4 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ], + "curly": [ + "error" + ], + "max-statements-per-line": [ + "error", + { "max": 1 } + ], + "object-curly-newline": [ + "error", + "always" + ], + "comma-spacing": [ + "error", + { "before": false, "after": true } + ], + "object-property-newline": [ + "error", + ], + "no-trailing-spaces": [ + "error" + ], + } +}; diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean b/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean new file mode 100644 index 0000000000..526519cae9 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean @@ -0,0 +1,11 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + + + public myValue:string[]; + + constructor(private myService:Service, name:string, private field:any){ super(name) ;} + + + //... + +} diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty b/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty new file mode 100644 index 0000000000..0a9201c2e7 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty @@ -0,0 +1,11 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + + +public myValue:string[]; + +constructor(private myService:Service,name:string,private field:any){ super(name) ;} + + +//... + +} From 4f5e4d343d08831104abd7faec86d8ff820b3125 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 7 Dec 2022 20:01:32 +0100 Subject: [PATCH 0140/1120] eslint: add support for xo standard typescript ruleset --- .../diffplug/spotless/npm/EslintConfig.java | 19 ++++++++- .../spotless/npm/EslintFormatterStep.java | 42 ++++++++++++------- .../spotless/npm/EslintRestService.java | 2 +- .../npm/NpmFormatterStepStateBase.java | 6 ++- .../spotless/npm/NpmResourceHelper.java | 17 ++++++-- .../spotless/npm/PrettierFormatterStep.java | 7 ++-- .../spotless/npm/TsFmtFormatterStep.java | 7 ++-- .../com/diffplug/spotless/npm/eslint-serve.js | 14 +++++++ .../gradle/spotless/FormatExtension.java | 32 +++++++++++++- .../gradle/spotless/TypescriptExtension.java | 11 +++++ .../spotless/TypescriptExtensionTest.java | 26 ++++++++++-- .../custom_rules}/.eslintrc.js | 0 .../custom_rules}/typescript.clean | 0 .../custom_rules}/typescript.dirty | 0 .../typescript/standard_rules_xo/.eslintrc.js | 26 ++++++++++++ .../standard_rules_xo/tsconfig.json | 18 ++++++++ .../standard_rules_xo/typescript.clean | 9 ++++ .../standard_rules_xo/typescript.dirty | 10 +++++ 18 files changed, 216 insertions(+), 30 deletions(-) rename testlib/src/main/resources/npm/eslint/{filetypes/typescript => typescript/custom_rules}/.eslintrc.js (100%) rename testlib/src/main/resources/npm/eslint/{filetypes/typescript => typescript/custom_rules}/typescript.clean (100%) rename testlib/src/main/resources/npm/eslint/{filetypes/typescript => typescript/custom_rules}/typescript.dirty (100%) create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java index a6d41f9bc0..83f5ab1a73 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java @@ -18,7 +18,12 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; +import java.util.Collections; +import java.util.Map; +import java.util.Optional; +import java.util.TreeMap; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.diffplug.spotless.FileSignature; @@ -39,11 +44,18 @@ public class EslintConfig implements Serializable { private final String eslintConfigJs; - public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs) { + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient Map> additionalConfigFiles; // key: source-file, value: target-remapping path relative to package.json (if needed) + + private final FileSignature additionalConfigFilesSignature; + + public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs, Map> additionalConfigFiles) { try { this.eslintConfigPath = eslintConfigPath; this.eslintConfigPathSignature = eslintConfigPath != null ? FileSignature.signAsList(this.eslintConfigPath) : FileSignature.signAsList(); this.eslintConfigJs = eslintConfigJs; + this.additionalConfigFiles = additionalConfigFiles != null ? new TreeMap<>(additionalConfigFiles) : Collections.emptyMap(); + this.additionalConfigFilesSignature = FileSignature.signAsList(this.additionalConfigFiles.keySet().toArray(new File[0])); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } @@ -58,4 +70,9 @@ public File getEslintConfigPath() { public String getEslintConfigJs() { return eslintConfigJs; } + + @Nonnull + public Map> getAdditionalConfigFiles() { + return additionalConfigFiles; + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 83d60a72c1..492cf0da90 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -25,6 +25,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.TreeMap; import javax.annotation.Nonnull; @@ -113,12 +114,13 @@ public static Map defaultDevDependenciesWithEslint(String versio return Collections.singletonMap("eslint", version); } - public static FormatterStep create(Map devDependencies, Provisioner provisioner, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) { + public static FormatterStep create(Map devDependencies, Provisioner provisioner, File projectDir, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) { requireNonNull(devDependencies); requireNonNull(provisioner); + requireNonNull(projectDir); requireNonNull(buildDir); return FormatterStep.createLazy(NAME, - () -> new State(NAME, devDependencies, buildDir, npmPathResolver, eslintConfig), + () -> new State(NAME, devDependencies, projectDir, buildDir, npmPathResolver, eslintConfig), State::createFormatterFunc); } @@ -127,7 +129,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ private static final long serialVersionUID = -539537027004745812L; private final EslintConfig eslintConfig; - State(String stepName, Map devDependencies, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { + State(String stepName, Map devDependencies, File projectDir, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { super(stepName, new NpmConfig( replaceDevDependencies( @@ -138,20 +140,29 @@ private static class State extends NpmFormatterStepStateBase implements Serializ "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/eslint-serve.js"), npmPathResolver.resolveNpmrcContent()), + projectDir, buildDir, npmPathResolver.resolveNpmExecutable()); this.eslintConfig = localCopyFiles(requireNonNull(eslintConfig)); } private EslintConfig localCopyFiles(EslintConfig orig) { - if (orig.getEslintConfigPath() == null) { - return orig; - } - // If a config file is provided, we need to make sure it is at the same location as the node modules - // as eslint will try to resolve plugin/config names relatively to the config file location + // If any config files are provided, we need to make sure they are at the same location as the node modules + // as eslint will try to resolve plugin/config names relatively to the config file location and some + // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", orig.getEslintConfigPath(), nodeModulesDir); File configFileCopy = NpmResourceHelper.copyFileToDir(orig.getEslintConfigPath(), nodeModulesDir); - return new EslintConfig(configFileCopy, orig.getEslintConfigJs()); + + for (Map.Entry> additionalConfigFile : orig.getAdditionalConfigFiles().entrySet()) { + FormattedPrinter.SYSOUT.print("Copying additional config file <%s> to <%s> at subpath <%s> and using the copy", additionalConfigFile.getKey(), nodeModulesDir, additionalConfigFile.getValue()); + + if (additionalConfigFile.getValue().isPresent()) { + NpmResourceHelper.copyFileToDirAtSubpath(additionalConfigFile.getKey(), nodeModulesDir, additionalConfigFile.getValue().get()); + } else { + NpmResourceHelper.copyFileToDir(additionalConfigFile.getKey(), nodeModulesDir); + } + } + return new EslintConfig(configFileCopy, orig.getEslintConfigJs(), orig.getAdditionalConfigFiles()); } @Override @@ -161,9 +172,7 @@ public FormatterFunc createFormatterFunc() { FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); ServerProcessInfo eslintRestServer = npmRunServer(); EslintRestService restService = new EslintRestService(eslintRestServer.getBaseUrl()); - - // String prettierConfigOptions = restService.resolveConfig(this.prettierConfig.getPrettierConfigPath(), this.prettierConfig.getOptions()); - return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(nodeModulesDir, eslintConfig, restService)); + return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(projectDir, nodeModulesDir, eslintConfig, restService)); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } @@ -182,12 +191,14 @@ private void endServer(BaseNpmRestService restService, ServerProcessInfo restSer } private static class EslintFilePathPassingFormatterFunc implements FormatterFunc.NeedsFile { + private final File projectDir; private final File nodeModulesDir; private final EslintConfig eslintConfig; private final EslintRestService restService; - public EslintFilePathPassingFormatterFunc(File nodeModulesDir, EslintConfig eslintConfig, EslintRestService restService) { - this.nodeModulesDir = nodeModulesDir; + public EslintFilePathPassingFormatterFunc(File projectDir, File nodeModulesDir, EslintConfig eslintConfig, EslintRestService restService) { + this.projectDir = requireNonNull(projectDir); + this.nodeModulesDir = requireNonNull(nodeModulesDir); this.eslintConfig = requireNonNull(eslintConfig); this.restService = requireNonNull(restService); } @@ -214,6 +225,9 @@ private void setConfigToCallOptions(Map eslintCallOptions) eslintCallOptions.put(FormatOption.ESLINT_OVERRIDE_CONFIG, eslintConfig.getEslintConfigJs()); } eslintCallOptions.put(FormatOption.NODE_MODULES_DIR, nodeModulesDir.getAbsolutePath()); + + // TODO (simschla, 09.12.22): maybe only add this if there is a typescript config active? (TBD: how to detect) + eslintCallOptions.put(FormatOption.TS_CONFIG_ROOT_DIR, nodeModulesDir.toPath().relativize(projectDir.toPath()).toString()); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java index 541b77bab8..d3a01621f1 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java @@ -35,7 +35,7 @@ public String format(String fileContent, Map formatOptions } enum FormatOption { - ESLINT_OVERRIDE_CONFIG("eslint_override_config"), ESLINT_OVERRIDE_CONFIG_FILE("eslint_override_config_file"), FILE_PATH("file_path"), NODE_MODULES_DIR("node_modules_dir"); + ESLINT_OVERRIDE_CONFIG("eslint_override_config"), ESLINT_OVERRIDE_CONFIG_FILE("eslint_override_config_file"), FILE_PATH("file_path"), NODE_MODULES_DIR("node_modules_dir"), TS_CONFIG_ROOT_DIR("ts_config_root_dir"); private final String backendName; diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 2e8d80e471..fc1543fd61 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -51,13 +51,17 @@ abstract class NpmFormatterStepStateBase implements Serializable { @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") private final transient File npmExecutable; + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + public final transient File projectDir; + private final NpmConfig npmConfig; private final String stepName; - protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, File buildDir, File npm) throws IOException { + protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, File projectDir, File buildDir, File npm) throws IOException { this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); + this.projectDir = requireNonNull(projectDir); this.npmExecutable = npm; NodeServerLayout layout = prepareNodeServer(buildDir); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index 4f97e7e732..48e974eec6 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -18,9 +18,12 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.time.Duration; import java.util.Arrays; +import java.util.Objects; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; @@ -103,10 +106,18 @@ static void awaitReadableFile(File file, Duration maxWaitTime) throws TimeoutExc } static File copyFileToDir(File file, File targetDir) { + return copyFileToDirAtSubpath(file, targetDir, file.getName()); + } + + static File copyFileToDirAtSubpath(File file, File targetDir, String relativePath) { + Objects.requireNonNull(relativePath); try { - File copiedFile = new File(targetDir, file.getName()); - Files.copy(file.toPath(), copiedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - return copiedFile; + // create file pointing to relativePath in targetDir + final Path relativeTargetFile = Paths.get(targetDir.getAbsolutePath(), relativePath); + assertDirectoryExists(relativeTargetFile.getParent().toFile()); + + Files.copy(file.toPath(), relativeTargetFile, StandardCopyOption.REPLACE_EXISTING); + return relativeTargetFile.toFile(); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 5a5662eee4..8489644c36 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -49,12 +49,12 @@ public static final Map defaultDevDependenciesWithPrettier(Strin return Collections.singletonMap("prettier", version); } - public static FormatterStep create(Map devDependencies, Provisioner provisioner, File buildDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) { + public static FormatterStep create(Map devDependencies, Provisioner provisioner, File projectDir, File buildDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) { requireNonNull(devDependencies); requireNonNull(provisioner); requireNonNull(buildDir); return FormatterStep.createLazy(NAME, - () -> new State(NAME, devDependencies, buildDir, npmPathResolver, prettierConfig), + () -> new State(NAME, devDependencies, projectDir, buildDir, npmPathResolver, prettierConfig), State::createFormatterFunc); } @@ -63,7 +63,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ private static final long serialVersionUID = -539537027004745812L; private final PrettierConfig prettierConfig; - State(String stepName, Map devDependencies, File buildDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) throws IOException { + State(String stepName, Map devDependencies, File projectDir, File buildDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) throws IOException { super(stepName, new NpmConfig( replaceDevDependencies( @@ -74,6 +74,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/prettier-serve.js"), npmPathResolver.resolveNpmrcContent()), + projectDir, buildDir, npmPathResolver.resolveNpmExecutable()); this.prettierConfig = requireNonNull(prettierConfig); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index e9c098d709..027af89e23 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -40,11 +40,11 @@ public class TsFmtFormatterStep { public static final String NAME = "tsfmt-format"; - public static FormatterStep create(Map versions, Provisioner provisioner, File buildDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) { + public static FormatterStep create(Map versions, Provisioner provisioner, File projectDir, File buildDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) { requireNonNull(provisioner); requireNonNull(buildDir); return FormatterStep.createLazy(NAME, - () -> new State(NAME, versions, buildDir, npmPathResolver, configFile, inlineTsFmtSettings), + () -> new State(NAME, versions, projectDir, buildDir, npmPathResolver, configFile, inlineTsFmtSettings), State::createFormatterFunc); } @@ -71,7 +71,7 @@ public static class State extends NpmFormatterStepStateBase implements Serializa @Nullable private final TypedTsFmtConfigFile configFile; - public State(String stepName, Map versions, File buildDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) throws IOException { + public State(String stepName, Map versions, File projectDir, File buildDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) throws IOException { super(stepName, new NpmConfig( replaceDevDependencies(NpmResourceHelper.readUtf8StringFromClasspath(TsFmtFormatterStep.class, "/com/diffplug/spotless/npm/tsfmt-package.json"), new TreeMap<>(versions)), @@ -80,6 +80,7 @@ public State(String stepName, Map versions, File buildDir, NpmPa "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/tsfmt-serve.js"), npmPathResolver.resolveNpmrcContent()), + projectDir, buildDir, npmPathResolver.resolveNpmExecutable()); this.buildDir = requireNonNull(buildDir); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 8c56b8ef08..15018e6cb0 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -24,8 +24,22 @@ app.post("/eslint/format", async (req, res) => { fix: true, useEslintrc: false, // would result in (gradle) cache issues resolvePluginsRelativeTo: format_data.node_modules_dir + // baseConfig: { + // parserOptions: { + // tsconfigRootDir: '../../', + // } + // } }; + if (format_data.ts_config_root_dir) { + ESLintOptions.baseConfig = { + parserOptions: { + tsconfigRootDir: format_data.ts_config_root_dir + } + }; + // res.status(501).send("Resolved ts config root dir: " + format_data.ts_config_root_dir); + } + if (ESLintOverrideConfigFile) { ESLintOptions.overrideConfigFile = ESLintOverrideConfigFile; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 99e21bd8c8..3f433afa92 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -27,8 +27,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Random; import java.util.TreeMap; +import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.inject.Inject; @@ -583,6 +585,7 @@ FormatterStep createStep() { return PrettierFormatterStep.create( devDependencies, provisioner(), + project.getProjectDir(), project.getBuildDir(), new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), new com.diffplug.spotless.npm.PrettierConfig( @@ -618,6 +621,8 @@ public class EslintFormatExtension extends NpmStepConfig @Nullable String configJs = null; + List additionalConfigs = new ArrayList<>(); + public EslintFormatExtension(Map devDependencies) { this.devDependencies.putAll(requireNonNull(devDependencies)); } @@ -640,19 +645,44 @@ public EslintFormatExtension configFile(Object configFilePath) { return this; } + protected void additionalConfigFilePath(Object sourceFile, String relativeTargetPath) { + this.additionalConfigs.add(new AdditionalEslintConfig(sourceFile, relativeTargetPath)); + } + public FormatterStep createStep() { final Project project = getProject(); return EslintFormatterStep.create( devDependencies, provisioner(), + project.getProjectDir(), project.getBuildDir(), new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), eslintConfig()); } private EslintConfig eslintConfig() { - return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); + return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs, additionalConfigs()); + } + + private Map> additionalConfigs() { + // convert additionalConfigs to a map explicitly allowing null values + + return additionalConfigs.stream() + .collect(Collectors.toMap( + config -> getProject().file(config.configFilePath), + config -> Optional.ofNullable(config.relativeTargetPath))); + } + } + + private static class AdditionalEslintConfig { + final Object configFilePath; + + final String relativeTargetPath; + + AdditionalEslintConfig(Object configFilePath, String relativeTargetPath) { + this.configFilePath = configFilePath; + this.relativeTargetPath = relativeTargetPath; } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index e80730d5ed..b126cc76c6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -113,6 +113,7 @@ public FormatterStep createStep() { return TsFmtFormatterStep.create( devDependencies, provisioner(), + project.getProjectDir(), project.getBuildDir(), new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), typedConfigFile(), @@ -221,6 +222,16 @@ public TypescriptEslintFormatExtension styleGuide(String styleGuide) { replaceStep(createStep()); return this; } + + public TypescriptEslintFormatExtension tsconfigFile(Object path) { + return tsconfigFile(path, null); + } + + public TypescriptEslintFormatExtension tsconfigFile(Object path, String remapping) { + additionalConfigFilePath(path, remapping); + replaceStep(createStep()); + return this; + } } @Override diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 40da7e3536..e7086e0c91 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -144,7 +144,7 @@ void usePrettier() throws IOException { @Test void useEslint() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/filetypes/typescript/.eslintrc.js"); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/custom_rules/.eslintrc.js"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -156,8 +156,28 @@ void useEslint() throws IOException { " eslint().configFile('.eslintrc.js')", " }", "}"); - setFile("test.ts").toResource("npm/eslint/filetypes/typescript/typescript.dirty"); + setFile("test.ts").toResource("npm/eslint/typescript/custom_rules/typescript.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertFile("test.ts").sameAsResource("npm/eslint/filetypes/typescript/typescript.clean"); + assertFile("test.ts").sameAsResource("npm/eslint/typescript/custom_rules/typescript.clean"); + } + + @Test + void useXoStandardRules() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_xo/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_xo/tsconfig.json"); // needs to be copied to! + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')//.tsconfigFile('tsconfig.json')", // TODO TODO maybe can skip the additional config files alltogether, instead provide tsConfigRootDir to eslint-serve.js via call + " }", + "}"); + setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_xo/typescript.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_xo/typescript.clean"); } } diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js b/testlib/src/main/resources/npm/eslint/typescript/custom_rules/.eslintrc.js similarity index 100% rename from testlib/src/main/resources/npm/eslint/filetypes/typescript/.eslintrc.js rename to testlib/src/main/resources/npm/eslint/typescript/custom_rules/.eslintrc.js diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean b/testlib/src/main/resources/npm/eslint/typescript/custom_rules/typescript.clean similarity index 100% rename from testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.clean rename to testlib/src/main/resources/npm/eslint/typescript/custom_rules/typescript.clean diff --git a/testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty b/testlib/src/main/resources/npm/eslint/typescript/custom_rules/typescript.dirty similarity index 100% rename from testlib/src/main/resources/npm/eslint/filetypes/typescript/typescript.dirty rename to testlib/src/main/resources/npm/eslint/typescript/custom_rules/typescript.dirty diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js new file mode 100644 index 0000000000..e1ca03f732 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js @@ -0,0 +1,26 @@ +module.exports = { + env: { + browser: true, + es2021: true, + }, + extends: 'xo/browser', + overrides: [ + { + extends: [ + 'xo-typescript', + ], + files: [ + '*.ts', + '*.tsx', + ], + }, + ], + parser: "@typescript-eslint/parser", + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: './tsconfig.json', + }, + rules: { + }, +}; diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json new file mode 100644 index 0000000000..629f834eb5 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "module": "ES6", + "noImplicitAny": true, + "outDir": "build/ide/", + "sourceMap": true, + "skipLibCheck": true, + "target": "ES6", + "baseUrl": "./", + "paths": { + }, + "lib": ["es7", "dom", "es2017"] + }, + "include": [ + "**/*" + ] +} diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean new file mode 100644 index 0000000000..5c43d7a746 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean @@ -0,0 +1,9 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + public myValue: string[]; + + constructor(private readonly myService: Service, name: string, private readonly field: any) { + super(name); + } + + // ... +} diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty new file mode 100644 index 0000000000..a8f7447af1 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty @@ -0,0 +1,10 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + +public myValue:string[]; + +constructor(private myService:Service,name:string,private field:any){ super(name) ;} + + +//... + +} From 96339675402e79f0737f70733b2224cba4345c2e Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 9 Dec 2022 21:10:40 +0100 Subject: [PATCH 0141/1120] eslint: add support for standard-with-typescript ruleset --- .../com/diffplug/spotless/npm/eslint-serve.js | 71 +++++++++---------- .../spotless/TypescriptExtensionTest.java | 24 ++++++- .../.eslintrc.js | 16 +++++ .../tsconfig.json | 18 +++++ .../typescript.clean | 7 ++ .../typescript.dirty | 10 +++ 6 files changed, 105 insertions(+), 41 deletions(-) create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean create mode 100644 testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 15018e6cb0..2804eb86dd 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -1,57 +1,50 @@ const {ESLint} = require("eslint"); app.post("/eslint/format", async (req, res) => { + try { + const format_data = req.body; - const format_data = req.body; - - const ESLintOverrideConfig = format_data.eslint_override_config; + const ESLintOverrideConfig = format_data.eslint_override_config; - const ESLintOverrideConfigFile = format_data.eslint_override_config_file; + const ESLintOverrideConfigFile = format_data.eslint_override_config_file; - if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) { - res.status(501).send("Error while formatting: No config provided"); - return; - } - - const filePath = format_data.file_path; + if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) { + res.status(501).send("Error while formatting: No config provided"); + return; + } - if (!filePath) { - res.status(501).send("Error while formatting: No file path provided"); - return; - } + const filePath = format_data.file_path; - const ESLintOptions = { - fix: true, - useEslintrc: false, // would result in (gradle) cache issues - resolvePluginsRelativeTo: format_data.node_modules_dir - // baseConfig: { - // parserOptions: { - // tsconfigRootDir: '../../', - // } - // } - }; + if (!filePath) { + res.status(501).send("Error while formatting: No file path provided"); + return; + } - if (format_data.ts_config_root_dir) { - ESLintOptions.baseConfig = { - parserOptions: { - tsconfigRootDir: format_data.ts_config_root_dir - } + const ESLintOptions = { + fix: true, + useEslintrc: false, // would result in (gradle) cache issues + resolvePluginsRelativeTo: format_data.node_modules_dir }; - // res.status(501).send("Resolved ts config root dir: " + format_data.ts_config_root_dir); - } + if (format_data.ts_config_root_dir) { + ESLintOptions.baseConfig = { + parserOptions: { + tsconfigRootDir: format_data.ts_config_root_dir + } + }; + } - if (ESLintOverrideConfigFile) { - ESLintOptions.overrideConfigFile = ESLintOverrideConfigFile; - } - if (ESLintOverrideConfig) { - ESLintOptions.overrideConfig = ESLintOverrideConfig; - } - const eslint = new ESLint(ESLintOptions); + if (ESLintOverrideConfigFile) { + ESLintOptions.overrideConfigFile = ESLintOverrideConfigFile; + } + if (ESLintOverrideConfig) { + ESLintOptions.overrideConfig = ESLintOverrideConfig; + } + + const eslint = new ESLint(ESLintOptions); - try { console.log("using options: " + JSON.stringify(ESLintOptions)); console.log("format input", format_data.file_content); const lintTextOptions = { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index e7086e0c91..0c3d10c89f 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -164,7 +164,7 @@ void useEslint() throws IOException { @Test void useXoStandardRules() throws IOException { setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_xo/.eslintrc.js"); - setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_xo/tsconfig.json"); // needs to be copied to! + setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_xo/tsconfig.json"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -173,11 +173,31 @@ void useXoStandardRules() throws IOException { "spotless {", " typescript {", " target 'test.ts'", - " eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')//.tsconfigFile('tsconfig.json')", // TODO TODO maybe can skip the additional config files alltogether, instead provide tsConfigRootDir to eslint-serve.js via call + " eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')", " }", "}"); setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_xo/typescript.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_xo/typescript.clean"); } + + @Test + void useStandardWithTypescriptRules() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " eslint().styleGuide('standard-with-typescript').configFile('.eslintrc.js')", + " }", + "}"); + setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean"); + } } diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js new file mode 100644 index 0000000000..0a86d5db86 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + env: { + browser: true, + es2021: true + }, + extends: 'standard-with-typescript', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: './tsconfig.json', + }, + rules: { + } +} diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json new file mode 100644 index 0000000000..629f834eb5 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "module": "ES6", + "noImplicitAny": true, + "outDir": "build/ide/", + "sourceMap": true, + "skipLibCheck": true, + "target": "ES6", + "baseUrl": "./", + "paths": { + }, + "lib": ["es7", "dom", "es2017"] + }, + "include": [ + "**/*" + ] +} diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean new file mode 100644 index 0000000000..cbe609b1bb --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean @@ -0,0 +1,7 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + public myValue: string[] + + constructor (private readonly myService: Service, name: string, private readonly field: any) { super(name) } + + // ... +} diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty new file mode 100644 index 0000000000..a8f7447af1 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty @@ -0,0 +1,10 @@ +export class MyController extends AbstractController implements DisposeAware, CallbackAware { + +public myValue:string[]; + +constructor(private myService:Service,name:string,private field:any){ super(name) ;} + + +//... + +} From 7022b7fa3b9337474951defff106746c280f4a58 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 15 Dec 2022 19:53:59 +0100 Subject: [PATCH 0142/1120] eslint: add unit tests, cleanup code --- .../diffplug/spotless/npm/EslintConfig.java | 23 +- .../spotless/npm/EslintFormatterStep.java | 21 +- .../spotless/npm/EslintTypescriptConfig.java | 41 ++++ .../gradle/spotless/FormatExtension.java | 30 +-- .../gradle/spotless/TypescriptExtension.java | 19 +- .../diffplug/spotless/ResourceHarness.java | 18 +- .../spotless/npm/EslintFormatterStepTest.java | 210 ++++++++++++++++++ .../npm/NpmFormatterStepCommonTests.java | 9 + .../npm/PrettierFormatterStepTest.java | 5 + .../spotless/npm/TsFmtFormatterStepTest.java | 2 + 10 files changed, 309 insertions(+), 69 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java create mode 100644 testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java index 83f5ab1a73..732111cc71 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java @@ -18,12 +18,7 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; -import java.util.Collections; -import java.util.Map; -import java.util.Optional; -import java.util.TreeMap; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.diffplug.spotless.FileSignature; @@ -44,23 +39,20 @@ public class EslintConfig implements Serializable { private final String eslintConfigJs; - @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - private final transient Map> additionalConfigFiles; // key: source-file, value: target-remapping path relative to package.json (if needed) - - private final FileSignature additionalConfigFilesSignature; - - public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs, Map> additionalConfigFiles) { + public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs) { try { this.eslintConfigPath = eslintConfigPath; this.eslintConfigPathSignature = eslintConfigPath != null ? FileSignature.signAsList(this.eslintConfigPath) : FileSignature.signAsList(); this.eslintConfigJs = eslintConfigJs; - this.additionalConfigFiles = additionalConfigFiles != null ? new TreeMap<>(additionalConfigFiles) : Collections.emptyMap(); - this.additionalConfigFilesSignature = FileSignature.signAsList(this.additionalConfigFiles.keySet().toArray(new File[0])); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } } + public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) { + return new EslintConfig(eslintConfigPath, this.eslintConfigJs); + } + @Nullable public File getEslintConfigPath() { return eslintConfigPath; @@ -70,9 +62,4 @@ public File getEslintConfigPath() { public String getEslintConfigJs() { return eslintConfigJs; } - - @Nonnull - public Map> getAdditionalConfigFiles() { - return additionalConfigFiles; - } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 492cf0da90..49bde50945 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -25,7 +25,6 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.TreeMap; import javax.annotation.Nonnull; @@ -152,17 +151,7 @@ private EslintConfig localCopyFiles(EslintConfig orig) { // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", orig.getEslintConfigPath(), nodeModulesDir); File configFileCopy = NpmResourceHelper.copyFileToDir(orig.getEslintConfigPath(), nodeModulesDir); - - for (Map.Entry> additionalConfigFile : orig.getAdditionalConfigFiles().entrySet()) { - FormattedPrinter.SYSOUT.print("Copying additional config file <%s> to <%s> at subpath <%s> and using the copy", additionalConfigFile.getKey(), nodeModulesDir, additionalConfigFile.getValue()); - - if (additionalConfigFile.getValue().isPresent()) { - NpmResourceHelper.copyFileToDirAtSubpath(additionalConfigFile.getKey(), nodeModulesDir, additionalConfigFile.getValue().get()); - } else { - NpmResourceHelper.copyFileToDir(additionalConfigFile.getKey(), nodeModulesDir); - } - } - return new EslintConfig(configFileCopy, orig.getEslintConfigJs(), orig.getAdditionalConfigFiles()); + return orig.withEslintConfigPath(configFileCopy); } @Override @@ -226,8 +215,12 @@ private void setConfigToCallOptions(Map eslintCallOptions) } eslintCallOptions.put(FormatOption.NODE_MODULES_DIR, nodeModulesDir.getAbsolutePath()); - // TODO (simschla, 09.12.22): maybe only add this if there is a typescript config active? (TBD: how to detect) - eslintCallOptions.put(FormatOption.TS_CONFIG_ROOT_DIR, nodeModulesDir.toPath().relativize(projectDir.toPath()).toString()); + if (eslintConfig instanceof EslintTypescriptConfig) { + // if we are a ts config, see if we need to use specific paths or use default projectDir + File tsConfigFilePath = ((EslintTypescriptConfig) eslintConfig).getTypescriptConfigPath(); + File tsConfigRootDir = tsConfigFilePath != null ? tsConfigFilePath.getParentFile() : projectDir; + eslintCallOptions.put(FormatOption.TS_CONFIG_ROOT_DIR, nodeModulesDir.getAbsoluteFile().toPath().relativize(tsConfigRootDir.getAbsoluteFile().toPath()).toString()); + } } } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java new file mode 100644 index 0000000000..05c8209837 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java @@ -0,0 +1,41 @@ +package com.diffplug.spotless.npm; + +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.ThrowingEx; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +import javax.annotation.Nullable; + +import java.io.File; +import java.io.IOException; + +public class EslintTypescriptConfig extends EslintConfig { + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + @Nullable + private final transient File typescriptConfigPath; + + @SuppressWarnings("unused") + private final FileSignature typescriptConfigPathSignature; + + public EslintTypescriptConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs, @Nullable File typescriptConfigPath) { + super(eslintConfigPath, eslintConfigJs); + try { + this.typescriptConfigPath = typescriptConfigPath; + this.typescriptConfigPathSignature = typescriptConfigPath != null ? FileSignature.signAsList(this.typescriptConfigPath) : FileSignature.signAsList(); + } catch (IOException e) { + throw ThrowingEx.asRuntime(e); + } + } + + @Override + public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) { + return new EslintTypescriptConfig(eslintConfigPath, this.getEslintConfigJs(), this.typescriptConfigPath); + } + + @Nullable + public File getTypescriptConfigPath() { + return typescriptConfigPath; + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 3f433afa92..6152f9009d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -621,8 +621,6 @@ public class EslintFormatExtension extends NpmStepConfig @Nullable String configJs = null; - List additionalConfigs = new ArrayList<>(); - public EslintFormatExtension(Map devDependencies) { this.devDependencies.putAll(requireNonNull(devDependencies)); } @@ -645,10 +643,6 @@ public EslintFormatExtension configFile(Object configFilePath) { return this; } - protected void additionalConfigFilePath(Object sourceFile, String relativeTargetPath) { - this.additionalConfigs.add(new AdditionalEslintConfig(sourceFile, relativeTargetPath)); - } - public FormatterStep createStep() { final Project project = getProject(); @@ -661,28 +655,8 @@ public FormatterStep createStep() { eslintConfig()); } - private EslintConfig eslintConfig() { - return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs, additionalConfigs()); - } - - private Map> additionalConfigs() { - // convert additionalConfigs to a map explicitly allowing null values - - return additionalConfigs.stream() - .collect(Collectors.toMap( - config -> getProject().file(config.configFilePath), - config -> Optional.ofNullable(config.relativeTargetPath))); - } - } - - private static class AdditionalEslintConfig { - final Object configFilePath; - - final String relativeTargetPath; - - AdditionalEslintConfig(Object configFilePath, String relativeTargetPath) { - this.configFilePath = configFilePath; - this.relativeTargetPath = relativeTargetPath; + protected EslintConfig eslintConfig() { + return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index b126cc76c6..d4dedc32eb 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -27,6 +27,10 @@ import javax.annotation.Nullable; import javax.inject.Inject; +import com.diffplug.spotless.npm.EslintConfig; + +import com.diffplug.spotless.npm.EslintTypescriptConfig; + import org.gradle.api.Project; import com.diffplug.spotless.FormatterStep; @@ -193,6 +197,9 @@ public TypescriptEslintFormatExtension eslint(Map devDependencie public class TypescriptEslintFormatExtension extends EslintFormatExtension { + @Nullable + Object typescriptConfigFilePath = null; + public TypescriptEslintFormatExtension(Map devDependencies) { super(devDependencies); } @@ -224,14 +231,16 @@ public TypescriptEslintFormatExtension styleGuide(String styleGuide) { } public TypescriptEslintFormatExtension tsconfigFile(Object path) { - return tsconfigFile(path, null); - } - - public TypescriptEslintFormatExtension tsconfigFile(Object path, String remapping) { - additionalConfigFilePath(path, remapping); + this.typescriptConfigFilePath = requireNonNull(path); replaceStep(createStep()); return this; } + + @Override + protected EslintConfig eslintConfig() { + EslintConfig config = super.eslintConfig(); + return new EslintTypescriptConfig(config.getEslintConfigPath(), config.getEslintConfigJs(), typescriptConfigFilePath != null ? getProject().file(typescriptConfigFilePath) : null); + } } @Override diff --git a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java index d4a79fe417..0304889e1f 100644 --- a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.function.Consumer; import java.util.function.UnaryOperator; @@ -86,11 +87,20 @@ protected void replace(String path, String toReplace, String replaceWith) throws /** Returns the contents of the given file from the src/test/resources directory. */ protected static String getTestResource(String filename) { - URL url = ResourceHarness.class.getResource("/" + filename); - if (url == null) { - throw new IllegalArgumentException("No such resource " + filename); + Optional resourceUrl = getTestResourceUrl(filename); + if (resourceUrl.isPresent()) { + return ThrowingEx.get(() -> LineEnding.toUnix(Resources.toString(resourceUrl.get(), StandardCharsets.UTF_8))); } - return ThrowingEx.get(() -> LineEnding.toUnix(Resources.toString(url, StandardCharsets.UTF_8))); + throw new IllegalArgumentException("No such resource " + filename); + } + + protected static boolean existsTestResource(String filename) { + return getTestResourceUrl(filename).isPresent(); + } + + private static Optional getTestResourceUrl(String filename) { + URL url = ResourceHarness.class.getResource("/" + filename); + return Optional.ofNullable(url); } /** Returns Files (in a temporary folder) which has the contents of the given file from the src/test/resources directory. */ diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java new file mode 100644 index 0000000000..afe463c1aa --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -0,0 +1,210 @@ +/* + * 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.spotless.npm; + +import com.diffplug.common.collect.ImmutableMap; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.StepHarnessWithFile; +import com.diffplug.spotless.TestProvisioner; +import com.diffplug.spotless.tag.NpmTest; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import java.io.File; +import java.util.Map; +import java.util.TreeMap; + +@NpmTest +class EslintFormatterStepTest { + + @NpmTest + @Nested + class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { + + private final Map> devDependenciesForRuleset = ImmutableMap.of( + "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), + "standard_rules_standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.STANDARD_WITH_TYPESCRIPT.devDependencies()), + "standard_rules_xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.XO_TYPESCRIPT.devDependencies()) + ); + + private final Map combine(Map m1, Map m2) { + Map combined = new TreeMap<>(m1); + combined.putAll(m2); + return combined; + } + + @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") + @ValueSource(strings = {"custom_rules", "standard_rules_standard_with_typescript", "standard_rules_xo"}) + void formattingUsingRulesetsFile(String ruleSetName) throws Exception { + String filedir = "npm/eslint/typescript/" + ruleSetName + "/"; + + String testDir = "formatting_ruleset_" + ruleSetName + "/"; +// File testDirFile = newFolder(testDir); + + final File eslintRc = createTestFile(filedir + ".eslintrc.js"); +// final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); + + //setFile(testDir + "/test.ts").toResource(filedir + "typescript.dirty"); + File tsconfigFile = null; + if (existsTestResource(filedir + "tsconfig.json")) { + tsconfigFile = setFile(testDir + "tsconfig.json").toResource(filedir + "tsconfig.json"); + } + final String dirtyFile = filedir + "typescript.dirty"; + File dirtyFileFile = setFile(testDir + "test.ts").toResource(dirtyFile); + final String cleanFile = filedir + "typescript.clean"; + + final FormatterStep formatterStep = EslintFormatterStep.create( + devDependenciesForRuleset.get(ruleSetName), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintTypescriptConfig(eslintRc, null, tsconfigFile)); + + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { + stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); + } + } + } +/* + @NpmTest + @Nested + class PrettierFormattingOfFileTypesIsWorking extends NpmFormatterStepCommonTests { + + @ParameterizedTest(name = "{index}: prettier can be applied to {0}") + @ValueSource(strings = {"html", "typescript", "json", "javascript-es5", "javascript-es6", "css", "scss", "markdown", "yaml"}) + void formattingUsingConfigFile(String fileType) throws Exception { + String filedir = "npm/prettier/filetypes/" + fileType + "/"; + + final File prettierRc = createTestFile(filedir + ".prettierrc.yml"); + final String dirtyFile = filedir + fileType + ".dirty"; + final String cleanFile = filedir + fileType + ".clean"; + + final FormatterStep formatterStep = PrettierFormatterStep.create( + PrettierFormatterStep.defaultDevDependencies(), + TestProvisioner.mavenCentral(), + buildDir(), + npmPathResolver(), + new PrettierConfig(prettierRc, null)); + + try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { + stepHarness.testResource(dirtyFile, cleanFile); + } + } + } + + @NpmTest + @Nested + class SpecificPrettierFormatterStepTests extends NpmFormatterStepCommonTests { + + @Test + void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception { + String filedir = "npm/prettier/filetypes/json/"; + + final String dirtyFile = filedir + "json.dirty"; + final String cleanFile = filedir + "json.clean"; + + final FormatterStep formatterStep = PrettierFormatterStep.create( + PrettierFormatterStep.defaultDevDependencies(), + TestProvisioner.mavenCentral(), + buildDir(), + npmPathResolver(), + new PrettierConfig(null, ImmutableMap.of("filepath", "anyname.json"))); // should select parser based on this name + + try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { + stepHarness.testResource(dirtyFile, cleanFile); + } + } + + @Test + void parserInferenceBasedOnFilenameIsWorking() throws Exception { + String filedir = "npm/prettier/filename/"; + + final String dirtyFile = filedir + "dirty.json"; + final String cleanFile = filedir + "clean.json"; + + final FormatterStep formatterStep = PrettierFormatterStep.create( + PrettierFormatterStep.defaultDevDependencies(), + TestProvisioner.mavenCentral(), + buildDir(), + npmPathResolver(), + new PrettierConfig(null, Collections.emptyMap())); + + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { + stepHarness.testResource(new File("test.json"), dirtyFile, cleanFile); + } + } + + @Test + void verifyPrettierErrorMessageIsRelayed() throws Exception { + FormatterStep formatterStep = PrettierFormatterStep.create( + PrettierFormatterStep.defaultDevDependenciesWithPrettier("2.0.5"), + TestProvisioner.mavenCentral(), + buildDir(), + npmPathResolver(), + new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); + try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { + stepHarness.testResourceException("npm/prettier/filetypes/scss/scss.dirty", exception -> { + exception.hasMessageContaining("HTTP 501"); + exception.hasMessageContaining("Couldn't resolve parser \"postcss\""); + }); + } + } + } + + @NpmTest + @Nested + class PrettierFormattingOptionsAreWorking extends NpmFormatterStepCommonTests { + + private static final String FILEDIR = "npm/prettier/config/"; + + void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exception { + + final String dirtyFile = FILEDIR + "typescript.dirty"; + final String cleanFile = FILEDIR + "typescript." + cleanFileNameSuffix + ".clean"; + + final FormatterStep formatterStep = PrettierFormatterStep.create( + PrettierFormatterStep.defaultDevDependencies(), + TestProvisioner.mavenCentral(), + buildDir(), + npmPathResolver(), + config); // should select parser based on this name + + try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { + stepHarness.testResource(dirtyFile, cleanFile); + } + } + + @Test + void defaultsAreApplied() throws Exception { + runFormatTest(new PrettierConfig(null, ImmutableMap.of("parser", "typescript")), "defaults"); + } + + @Test + void configFileOptionsAreApplied() throws Exception { + runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), null), "configfile"); + } + + @Test + void configFileOptionsCanBeOverriden() throws Exception { + runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), ImmutableMap.of("printWidth", 300)), "override"); + } + + }*/ +} diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java index 4da65cadc6..f1b5da59ff 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java @@ -42,4 +42,13 @@ protected File buildDir() throws IOException { } return this.buildDir; } + + private File projectDir = null; + + protected File projectDir() throws IOException { + if (this.projectDir == null) { + this.projectDir = newFolder("project-dir"); + } + return this.projectDir; + } } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index 5f14022ad8..9db218efb5 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -50,6 +50,7 @@ void formattingUsingConfigFile(String fileType) throws Exception { final FormatterStep formatterStep = PrettierFormatterStep.create( PrettierFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), new PrettierConfig(prettierRc, null)); @@ -74,6 +75,7 @@ void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception { final FormatterStep formatterStep = PrettierFormatterStep.create( PrettierFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("filepath", "anyname.json"))); // should select parser based on this name @@ -93,6 +95,7 @@ void parserInferenceBasedOnFilenameIsWorking() throws Exception { final FormatterStep formatterStep = PrettierFormatterStep.create( PrettierFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), new PrettierConfig(null, Collections.emptyMap())); @@ -107,6 +110,7 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { FormatterStep formatterStep = PrettierFormatterStep.create( PrettierFormatterStep.defaultDevDependenciesWithPrettier("2.0.5"), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); @@ -131,6 +135,7 @@ void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exc final FormatterStep formatterStep = PrettierFormatterStep.create( PrettierFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), config); // should select parser based on this name diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java index 2812601726..d06b902b83 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java @@ -57,6 +57,7 @@ void formattingUsingConfigFile(String formattingConfigFile) throws Exception { final FormatterStep formatterStep = TsFmtFormatterStep.create( TsFmtFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), TypedTsFmtConfigFile.named(configFileNameWithoutExtension, configFile), @@ -79,6 +80,7 @@ void formattingUsingInlineConfigWorks() throws Exception { final FormatterStep formatterStep = TsFmtFormatterStep.create( TsFmtFormatterStep.defaultDevDependencies(), TestProvisioner.mavenCentral(), + projectDir(), buildDir(), npmPathResolver(), null, From a2a5502b2ea696968c036dc89e21dedc95dd8633 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 15 Dec 2022 20:11:33 +0100 Subject: [PATCH 0143/1120] eslint: reduce required options --- .../resources/com/diffplug/spotless/npm/eslint-serve.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 2804eb86dd..3c10b048c1 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -23,7 +23,6 @@ app.post("/eslint/format", async (req, res) => { const ESLintOptions = { fix: true, useEslintrc: false, // would result in (gradle) cache issues - resolvePluginsRelativeTo: format_data.node_modules_dir }; if (format_data.ts_config_root_dir) { @@ -42,15 +41,17 @@ app.post("/eslint/format", async (req, res) => { ESLintOptions.overrideConfig = ESLintOverrideConfig; } + console.log("using options: " + JSON.stringify(ESLintOptions)); + console.log("format input: ", format_data.file_content); + const eslint = new ESLint(ESLintOptions); - console.log("using options: " + JSON.stringify(ESLintOptions)); - console.log("format input", format_data.file_content); const lintTextOptions = { filePath: filePath, } console.log("lintTextOptions", lintTextOptions); + // LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type const results = await eslint.lintText(format_data.file_content, lintTextOptions); if (results.length !== 1) { From 35b2b7ced394c1bb5c512b47edd34604e451726d Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 16 Dec 2022 06:06:07 +0100 Subject: [PATCH 0144/1120] eslint: remove unneeded configuration --- .../diffplug/spotless/npm/EslintFormatterStep.java | 2 -- .../diffplug/spotless/npm/EslintRestService.java | 2 +- .../spotless/npm/EslintFormatterStepTest.java | 13 ++++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 49bde50945..55261350b3 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -213,8 +213,6 @@ private void setConfigToCallOptions(Map eslintCallOptions) if (eslintConfig.getEslintConfigJs() != null) { eslintCallOptions.put(FormatOption.ESLINT_OVERRIDE_CONFIG, eslintConfig.getEslintConfigJs()); } - eslintCallOptions.put(FormatOption.NODE_MODULES_DIR, nodeModulesDir.getAbsolutePath()); - if (eslintConfig instanceof EslintTypescriptConfig) { // if we are a ts config, see if we need to use specific paths or use default projectDir File tsConfigFilePath = ((EslintTypescriptConfig) eslintConfig).getTypescriptConfigPath(); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java index d3a01621f1..198ee5389c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java @@ -35,7 +35,7 @@ public String format(String fileContent, Map formatOptions } enum FormatOption { - ESLINT_OVERRIDE_CONFIG("eslint_override_config"), ESLINT_OVERRIDE_CONFIG_FILE("eslint_override_config_file"), FILE_PATH("file_path"), NODE_MODULES_DIR("node_modules_dir"), TS_CONFIG_ROOT_DIR("ts_config_root_dir"); + ESLINT_OVERRIDE_CONFIG("eslint_override_config"), ESLINT_OVERRIDE_CONFIG_FILE("eslint_override_config_file"), FILE_PATH("file_path"), TS_CONFIG_ROOT_DIR("ts_config_root_dir"); private final String backendName; diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index afe463c1aa..45787e4217 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -23,6 +23,7 @@ import com.diffplug.spotless.tag.NpmTest; import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -33,6 +34,12 @@ @NpmTest class EslintFormatterStepTest { + private final Map combine(Map m1, Map m2) { + Map combined = new TreeMap<>(m1); + combined.putAll(m2); + return combined; + } + @NpmTest @Nested class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { @@ -43,11 +50,7 @@ class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { "standard_rules_xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.XO_TYPESCRIPT.devDependencies()) ); - private final Map combine(Map m1, Map m2) { - Map combined = new TreeMap<>(m1); - combined.putAll(m2); - return combined; - } + @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") @ValueSource(strings = {"custom_rules", "standard_rules_standard_with_typescript", "standard_rules_xo"}) From 016dd3adc08cfb92ef37bccf2ea59d7c48c4edcd Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 16 Dec 2022 06:06:51 +0100 Subject: [PATCH 0145/1120] eslint: test supplying inline config --- .../spotless/npm/EslintFormatterStep.java | 3 + .../com/diffplug/spotless/npm/eslint-serve.js | 2 +- .../spotless/npm/EslintFormatterStepTest.java | 161 ++++++------------ 3 files changed, 52 insertions(+), 114 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 55261350b3..91d8ef62a5 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -146,6 +146,9 @@ private static class State extends NpmFormatterStepStateBase implements Serializ } private EslintConfig localCopyFiles(EslintConfig orig) { + if (orig.getEslintConfigPath() == null) { + return orig; + } // If any config files are provided, we need to make sure they are at the same location as the node modules // as eslint will try to resolve plugin/config names relatively to the config file location and some // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 3c10b048c1..b9f3207d5f 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -38,7 +38,7 @@ app.post("/eslint/format", async (req, res) => { ESLintOptions.overrideConfigFile = ESLintOverrideConfigFile; } if (ESLintOverrideConfig) { - ESLintOptions.overrideConfig = ESLintOverrideConfig; + eval("ESLintOptions.overrideConfig = " + ESLintOverrideConfig); } console.log("using options: " + JSON.stringify(ESLintOptions)); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 45787e4217..fdf17caae7 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -85,129 +85,64 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { } } } -/* - @NpmTest - @Nested - class PrettierFormattingOfFileTypesIsWorking extends NpmFormatterStepCommonTests { - - @ParameterizedTest(name = "{index}: prettier can be applied to {0}") - @ValueSource(strings = {"html", "typescript", "json", "javascript-es5", "javascript-es6", "css", "scss", "markdown", "yaml"}) - void formattingUsingConfigFile(String fileType) throws Exception { - String filedir = "npm/prettier/filetypes/" + fileType + "/"; - - final File prettierRc = createTestFile(filedir + ".prettierrc.yml"); - final String dirtyFile = filedir + fileType + ".dirty"; - final String cleanFile = filedir + fileType + ".clean"; - - final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), - TestProvisioner.mavenCentral(), - buildDir(), - npmPathResolver(), - new PrettierConfig(prettierRc, null)); - - try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { - stepHarness.testResource(dirtyFile, cleanFile); - } - } - } @NpmTest @Nested - class SpecificPrettierFormatterStepTests extends NpmFormatterStepCommonTests { + class EslintInlineConfigFormattingStepTest extends NpmFormatterStepCommonTests { - @Test - void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception { - String filedir = "npm/prettier/filetypes/json/"; - - final String dirtyFile = filedir + "json.dirty"; - final String cleanFile = filedir + "json.clean"; - - final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), - TestProvisioner.mavenCentral(), - buildDir(), - npmPathResolver(), - new PrettierConfig(null, ImmutableMap.of("filepath", "anyname.json"))); // should select parser based on this name - - try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { - stepHarness.testResource(dirtyFile, cleanFile); - } - } @Test - void parserInferenceBasedOnFilenameIsWorking() throws Exception { - String filedir = "npm/prettier/filename/"; - - final String dirtyFile = filedir + "dirty.json"; - final String cleanFile = filedir + "clean.json"; + void formattingUsingInlineXoConfig() throws Exception { + String filedir = "npm/eslint/typescript/standard_rules_xo/"; + + String testDir = "formatting_ruleset_xo_inline_config/"; + + + final String esLintConfig = String.join("\n", + "{", + " env: {", + " browser: true,", + " es2021: true,", + " },", + " extends: 'xo/browser',", + " overrides: [", + " {", + " extends: [", + " 'xo-typescript',", + " ],", + " files: [", + " '*.ts',", + " '*.tsx',", + " ],", + " },", + " ],", + " parser: '@typescript-eslint/parser',", + " parserOptions: {", + " ecmaVersion: 'latest',", + " sourceType: 'module',", + " project: './tsconfig.json',", + " },", + " rules: {", + " },", + "}" + ); + + File tsconfigFile = setFile(testDir + "tsconfig.json").toResource(filedir + "tsconfig.json"); + final String dirtyFile = filedir + "typescript.dirty"; + File dirtyFileFile = setFile(testDir + "test.ts").toResource(dirtyFile); + final String cleanFile = filedir + "typescript.clean"; - final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), - TestProvisioner.mavenCentral(), - buildDir(), - npmPathResolver(), - new PrettierConfig(null, Collections.emptyMap())); + final FormatterStep formatterStep = EslintFormatterStep.create( + combine(EslintFormatterStep.PopularStyleGuide.XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintTypescriptConfig(null, esLintConfig, tsconfigFile)); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { - stepHarness.testResource(new File("test.json"), dirtyFile, cleanFile); - } - } - - @Test - void verifyPrettierErrorMessageIsRelayed() throws Exception { - FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependenciesWithPrettier("2.0.5"), - TestProvisioner.mavenCentral(), - buildDir(), - npmPathResolver(), - new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); - try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { - stepHarness.testResourceException("npm/prettier/filetypes/scss/scss.dirty", exception -> { - exception.hasMessageContaining("HTTP 501"); - exception.hasMessageContaining("Couldn't resolve parser \"postcss\""); - }); + stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); } } } - - @NpmTest - @Nested - class PrettierFormattingOptionsAreWorking extends NpmFormatterStepCommonTests { - - private static final String FILEDIR = "npm/prettier/config/"; - - void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exception { - - final String dirtyFile = FILEDIR + "typescript.dirty"; - final String cleanFile = FILEDIR + "typescript." + cleanFileNameSuffix + ".clean"; - - final FormatterStep formatterStep = PrettierFormatterStep.create( - PrettierFormatterStep.defaultDevDependencies(), - TestProvisioner.mavenCentral(), - buildDir(), - npmPathResolver(), - config); // should select parser based on this name - - try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) { - stepHarness.testResource(dirtyFile, cleanFile); - } - } - - @Test - void defaultsAreApplied() throws Exception { - runFormatTest(new PrettierConfig(null, ImmutableMap.of("parser", "typescript")), "defaults"); - } - - @Test - void configFileOptionsAreApplied() throws Exception { - runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), null), "configfile"); - } - - @Test - void configFileOptionsCanBeOverriden() throws Exception { - runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), ImmutableMap.of("printWidth", 300)), "override"); - } - - }*/ } From a9f89d8e51e8c969a40f1bf78b668852ffa69ddc Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 16 Dec 2022 19:57:48 +0100 Subject: [PATCH 0146/1120] eslint: adding javascript formatting (part 1) --- .../spotless/npm/EslintFormatterStep.java | 40 ++++++++++++- .../spotless/TypescriptExtensionTest.java | 16 +++--- .../javascript/custom_rules/.eslintrc.js | 31 ++++++++++ .../custom_rules/javascript-es6.clean | 21 +++++++ .../custom_rules/javascript-es6.dirty | 21 +++++++ .../javascript/styleguide/airbnb/.eslintrc.js | 15 +++++ .../styleguide/airbnb/javascript-es6.clean | 17 ++++++ .../styleguide/airbnb/javascript-es6.dirty | 21 +++++++ .../javascript/styleguide/google/.eslintrc.js | 15 +++++ .../styleguide/google/javascript-es6.clean | 25 +++++++++ .../styleguide/google/javascript-es6.dirty | 21 +++++++ .../styleguide/standard/.eslintrc.js | 15 +++++ .../styleguide/standard/javascript-es6.clean | 19 +++++++ .../styleguide/standard/javascript-es6.dirty | 21 +++++++ .../javascript/styleguide/xo/.eslintrc.js | 15 +++++ .../styleguide/xo/javascript-es6.clean | 20 +++++++ .../styleguide/xo/javascript-es6.dirty | 21 +++++++ .../standard_with_typescript}/.eslintrc.js | 0 .../standard_with_typescript}/tsconfig.json | 0 .../typescript.clean | 0 .../typescript.dirty | 0 .../xo}/.eslintrc.js | 0 .../xo}/tsconfig.json | 0 .../xo}/typescript.clean | 0 .../xo}/typescript.dirty | 0 .../spotless/npm/EslintFormatterStepTest.java | 56 ++++++++++++++++--- 26 files changed, 393 insertions(+), 17 deletions(-) create mode 100644 testlib/src/main/resources/npm/eslint/javascript/custom_rules/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.clean create mode 100644 testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.dirty create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.clean create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/google/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.clean create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.dirty create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.clean create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.dirty create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/.eslintrc.js create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.clean create mode 100644 testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.dirty rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_standard_with_typescript => styleguide/standard_with_typescript}/.eslintrc.js (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_standard_with_typescript => styleguide/standard_with_typescript}/tsconfig.json (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_standard_with_typescript => styleguide/standard_with_typescript}/typescript.clean (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_standard_with_typescript => styleguide/standard_with_typescript}/typescript.dirty (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_xo => styleguide/xo}/.eslintrc.js (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_xo => styleguide/xo}/tsconfig.json (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_xo => styleguide/xo}/typescript.clean (100%) rename testlib/src/main/resources/npm/eslint/typescript/{standard_rules_xo => styleguide/xo}/typescript.dirty (100%) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 91d8ef62a5..14bc99a243 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -48,7 +48,7 @@ public class EslintFormatterStep { public static final String DEFAULT_ESLINT_VERSION = "8.28.0"; public enum PopularStyleGuide { - STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { + TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); @@ -60,7 +60,7 @@ public Map devDependencies() { return dependencies; } }, - XO_TYPESCRIPT("xo-typescript") { + TS_XO_TYPESCRIPT("xo-typescript") { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); @@ -69,6 +69,42 @@ public Map devDependencies() { dependencies.put("typescript", "4.9.3"); return dependencies; } + }, + JS_AIRBNB("airbnb") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-airbnb-base", "15.0.0"); + dependencies.put("eslint-plugin-import", "2.26.0"); + return dependencies; + } + }, + JS_GOOGLE("google") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-google", "0.14.0"); + return dependencies; + } + }, + JS_STANDARD("standard") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-standard", "17.0.0"); + dependencies.put("eslint-plugin-import", "2.26.0"); + dependencies.put("eslint-plugin-n", "15.6.0"); + dependencies.put("eslint-plugin-promise", "6.1.1"); + return dependencies; + } + }, + JS_XO("xo") { + @Override + public Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-xo", "0.43.1"); + return dependencies; + } }; private final String popularStyleGuideName; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 0c3d10c89f..7d715998f6 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -163,8 +163,8 @@ void useEslint() throws IOException { @Test void useXoStandardRules() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_xo/.eslintrc.js"); - setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_xo/tsconfig.json"); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/xo/tsconfig.json"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -176,15 +176,15 @@ void useXoStandardRules() throws IOException { " eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')", " }", "}"); - setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_xo/typescript.dirty"); + setFile("test.ts").toResource("npm/eslint/typescript/styleguide/xo/typescript.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_xo/typescript.clean"); + assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/xo/typescript.clean"); } @Test void useStandardWithTypescriptRules() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js"); - setFile("tsconfig.json").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json"); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -196,8 +196,8 @@ void useStandardWithTypescriptRules() throws IOException { " eslint().styleGuide('standard-with-typescript').configFile('.eslintrc.js')", " }", "}"); - setFile("test.ts").toResource("npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty"); + setFile("test.ts").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertFile("test.ts").sameAsResource("npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean"); + assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean"); } } diff --git a/testlib/src/main/resources/npm/eslint/javascript/custom_rules/.eslintrc.js b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/.eslintrc.js new file mode 100644 index 0000000000..60c5c19f5b --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/.eslintrc.js @@ -0,0 +1,31 @@ +module.exports = { + "env": { + "browser": true, + "es2021": true + }, + "extends": "eslint:recommended", + "overrides": [ + ], + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "rules": { + "indent": [ + "error", + 2 + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ] + } +}; diff --git a/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.clean b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.clean new file mode 100644 index 0000000000..8bbeb50cf3 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.clean @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: "Peter", + last : "Pan", + get fullName() { return this.first + " " + this.last; } +}; + +const str = "Hello, world!" +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = "Hello \ +World" +; + +function test (a, b = "world") { let combined =a+ b; return combined;} + +test ("Hello"); diff --git a/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.dirty b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.dirty new file mode 100644 index 0000000000..36a514cc30 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/custom_rules/javascript-es6.dirty @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: 'Peter', + last : 'Pan', + get fullName() { return this.first + ' ' + this.last; } +}; + +const str = 'Hello, world!' +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = 'Hello \ +World' +; + +function test (a, b = 'world') { let combined =a+ b; return combined}; + +test ('Hello'); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/.eslintrc.js b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/.eslintrc.js new file mode 100644 index 0000000000..d93248ee88 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + env: { + browser: true, + es2021: true, + }, + extends: 'airbnb-base', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + rules: { + }, +}; diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.clean b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.clean new file mode 100644 index 0000000000..c8dda3d33f --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.clean @@ -0,0 +1,17 @@ +const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, +]; + +const p = { + first: 'Peter', + last: 'Pan', + get fullName() { return `${this.first} ${this.last}`; }, +}; + +const str = 'Hello, world!'; +const str2 = str.charAt(3) + str[0]; + +const multilinestr = 'Hello \ +World'; +function test(a, b = 'world') { const combined = a + b; return combined; } + +test('Hello'); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty new file mode 100644 index 0000000000..08ebafc1a2 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: "Peter", + last : "Pan", + get fullName() { return this.first + " " + this.last; } +}; + +const str = "Hello, world!" +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = "Hello \ +World" +; + +function test (a, b = "world") { let combined =a+ b; return combined}; + +test ("Hello"); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/.eslintrc.js b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/.eslintrc.js new file mode 100644 index 0000000000..71b0c47016 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + 'env': { + 'browser': true, + 'es2021': true, + }, + 'extends': 'google', + 'overrides': [ + ], + 'parserOptions': { + 'ecmaVersion': 'latest', + 'sourceType': 'module', + }, + 'rules': { + }, +}; diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.clean b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.clean new file mode 100644 index 0000000000..f960a984c2 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.clean @@ -0,0 +1,25 @@ +const numbers=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, +]; + +const p = { + first: 'Peter', + last: 'Pan', + get fullName() { + return this.first + ' ' + this.last; + }, +}; + +const str = 'Hello, world!' +; + +const str2=str.charAt(3)+str[0]; + +const multilinestr = 'Hello \ +World' +; + +function test(a, b = 'world') { + const combined =a+ b; return combined; +}; + +test('Hello'); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.dirty b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.dirty new file mode 100644 index 0000000000..08ebafc1a2 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/google/javascript-es6.dirty @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: "Peter", + last : "Pan", + get fullName() { return this.first + " " + this.last; } +}; + +const str = "Hello, world!" +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = "Hello \ +World" +; + +function test (a, b = "world") { let combined =a+ b; return combined}; + +test ("Hello"); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/.eslintrc.js b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/.eslintrc.js new file mode 100644 index 0000000000..cbed25aab9 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + env: { + browser: true, + es2021: true + }, + extends: 'standard', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module' + }, + rules: { + } +} diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.clean b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.clean new file mode 100644 index 0000000000..757d330a7f --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.clean @@ -0,0 +1,19 @@ +const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 +] + +const p = { + first: 'Peter', + last: 'Pan', + get fullName () { return this.first + ' ' + this.last } +} + +const str = 'Hello, world!' + +const str2 = str.charAt(3) + str[0] + +const multilinestr = 'Hello \ +World' + +function test (a, b = 'world') { const combined = a + b; return combined }; + +test('Hello') diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.dirty b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.dirty new file mode 100644 index 0000000000..08ebafc1a2 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/standard/javascript-es6.dirty @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: "Peter", + last : "Pan", + get fullName() { return this.first + " " + this.last; } +}; + +const str = "Hello, world!" +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = "Hello \ +World" +; + +function test (a, b = "world") { let combined =a+ b; return combined}; + +test ("Hello"); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/.eslintrc.js b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/.eslintrc.js new file mode 100644 index 0000000000..844e843c41 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + env: { + browser: true, + es2021: true, + }, + extends: 'xo', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + rules: { + }, +}; diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.clean b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.clean new file mode 100644 index 0000000000..3cd1bd0865 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.clean @@ -0,0 +1,20 @@ +const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]; + +const p = { + first: 'Peter', + last: 'Pan', + get fullName() { + return this.first + ' ' + this.last; + }, +}; + +const str = 'Hello, world!'; +const str2 = str.charAt(3) + str[0]; + +const multilinestr = 'Hello \ +World'; +function test(a, b = 'world') { + const combined = a + b; return combined; +} + +test('Hello'); diff --git a/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.dirty b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.dirty new file mode 100644 index 0000000000..08ebafc1a2 --- /dev/null +++ b/testlib/src/main/resources/npm/eslint/javascript/styleguide/xo/javascript-es6.dirty @@ -0,0 +1,21 @@ +var numbers=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, +]; + +const p = { + first: "Peter", + last : "Pan", + get fullName() { return this.first + " " + this.last; } +}; + +const str = "Hello, world!" +; + +var str2=str.charAt(3)+str[0]; + +var multilinestr = "Hello \ +World" +; + +function test (a, b = "world") { let combined =a+ b; return combined}; + +test ("Hello"); diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js b/testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/.eslintrc.js rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json b/testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/tsconfig.json rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean b/testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.clean rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty b/testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_standard_with_typescript/typescript.dirty rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js b/testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/.eslintrc.js similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/.eslintrc.js rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/.eslintrc.js diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json b/testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/tsconfig.json similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/tsconfig.json rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/tsconfig.json diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean b/testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/typescript.clean similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.clean rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/typescript.clean diff --git a/testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty b/testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/typescript.dirty similarity index 100% rename from testlib/src/main/resources/npm/eslint/typescript/standard_rules_xo/typescript.dirty rename to testlib/src/main/resources/npm/eslint/typescript/styleguide/xo/typescript.dirty diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index fdf17caae7..3a8bfc7fd6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -17,7 +17,6 @@ import com.diffplug.common.collect.ImmutableMap; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.tag.NpmTest; @@ -40,24 +39,67 @@ private final Map combine(Map m1, Map> devDependenciesForRuleset = ImmutableMap.of( + "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), + "styleguide/airbnb", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_AIRBNB.devDependencies()), + "styleguide/google", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_GOOGLE.devDependencies()), + "styleguide/standard", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_STANDARD.devDependencies()), + "styleguide/xo", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_XO.devDependencies()) + ); + + @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") + @ValueSource(strings = {"custom_rules", "styleguide/airbnb", "styleguide/google", "styleguide/standard", "styleguide/xo"}) + void formattingUsingRulesetsFile(String ruleSetName) throws Exception { + String filedir = "npm/eslint/javascript/" + ruleSetName + "/"; + + String testDir = "formatting_ruleset_" + ruleSetName.replace('/', '_') + "/"; +// File testDirFile = newFolder(testDir); + + final File eslintRc = createTestFile(filedir + ".eslintrc.js"); +// final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); + + final String dirtyFile = filedir + "javascript-es6.dirty"; + File dirtyFileFile = setFile(testDir + "test.js").toResource(dirtyFile); + final String cleanFile = filedir + "javascript-es6.clean"; + + final FormatterStep formatterStep = EslintFormatterStep.create( + devDependenciesForRuleset.get(ruleSetName), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintConfig(eslintRc, null)); + + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { + stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); + } + } + } + + + @NpmTest @Nested class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { private final Map> devDependenciesForRuleset = ImmutableMap.of( "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), - "standard_rules_standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.STANDARD_WITH_TYPESCRIPT.devDependencies()), - "standard_rules_xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.XO_TYPESCRIPT.devDependencies()) + "styleguide/standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_STANDARD_WITH_TYPESCRIPT.devDependencies()), + "styleguide/xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies()) ); @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") - @ValueSource(strings = {"custom_rules", "standard_rules_standard_with_typescript", "standard_rules_xo"}) + @ValueSource(strings = {"custom_rules", "styleguide/standard_with_typescript", "styleguide/xo"}) void formattingUsingRulesetsFile(String ruleSetName) throws Exception { String filedir = "npm/eslint/typescript/" + ruleSetName + "/"; - String testDir = "formatting_ruleset_" + ruleSetName + "/"; + String testDir = "formatting_ruleset_" + ruleSetName.replace('/', '_') + "/"; // File testDirFile = newFolder(testDir); final File eslintRc = createTestFile(filedir + ".eslintrc.js"); @@ -88,7 +130,7 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { @NpmTest @Nested - class EslintInlineConfigFormattingStepTest extends NpmFormatterStepCommonTests { + class EslintInlineConfigTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { @Test @@ -133,7 +175,7 @@ void formattingUsingInlineXoConfig() throws Exception { final String cleanFile = filedir + "typescript.clean"; final FormatterStep formatterStep = EslintFormatterStep.create( - combine(EslintFormatterStep.PopularStyleGuide.XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), + combine(EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), TestProvisioner.mavenCentral(), projectDir(), buildDir(), From 4efc19b200face1697512e18ed906524df444177 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 18 Dec 2022 20:43:16 +0100 Subject: [PATCH 0147/1120] eslint: introduce separate javascript extension --- .../spotless/npm/EslintTypescriptConfig.java | 25 ++- .../gradle/spotless/FormatExtension.java | 100 +++-------- .../gradle/spotless/JavascriptExtension.java | 156 ++++++++++++++++++ .../gradle/spotless/SpotlessExtension.java | 5 + .../gradle/spotless/TypescriptExtension.java | 84 +++++----- .../spotless/npm/EslintFormatterStepTest.java | 139 ++++++++-------- .../npm/NpmFormatterStepCommonTests.java | 2 +- .../spotless/npm/TsFmtFormatterStepTest.java | 2 +- 8 files changed, 313 insertions(+), 200 deletions(-) create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java index 05c8209837..f8c213a0a9 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java @@ -1,15 +1,30 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.npm; +import java.io.File; +import java.io.IOException; + +import javax.annotation.Nullable; + import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.ThrowingEx; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import javax.annotation.Nullable; - -import java.io.File; -import java.io.IOException; - public class EslintTypescriptConfig extends EslintConfig { @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 6152f9009d..08e713a921 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -24,13 +24,11 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Random; import java.util.TreeMap; -import java.util.stream.Collectors; +import java.util.function.Consumer; import javax.annotation.Nullable; import javax.inject.Inject; @@ -62,8 +60,6 @@ import com.diffplug.spotless.generic.ReplaceRegexStep; import com.diffplug.spotless.generic.ReplaceStep; import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; -import com.diffplug.spotless.npm.EslintConfig; -import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; @@ -518,23 +514,32 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile, String de return config; } - public abstract class NpmStepConfig> { + public abstract static class NpmStepConfig> { @Nullable protected Object npmFile; @Nullable protected Object npmrcFile; + protected Project project; + + private Consumer replaceStep; + + public NpmStepConfig(Project project, Consumer replaceStep) { + this.project = requireNonNull(project); + this.replaceStep = requireNonNull(replaceStep); + } + @SuppressWarnings("unchecked") public T npmExecutable(final Object npmFile) { this.npmFile = npmFile; - replaceStep(createStep()); + replaceStep(); return (T) this; } public T npmrc(final Object npmrcFile) { this.npmrcFile = npmrcFile; - replaceStep(createStep()); + replaceStep(); return (T) this; } @@ -547,10 +552,14 @@ File npmrcFileOrNull() { } private File fileOrNull(Object npmFile) { - return npmFile != null ? getProject().file(npmFile) : null; + return npmFile != null ? project.file(npmFile) : null; } - abstract FormatterStep createStep(); + protected void replaceStep() { + replaceStep.accept(createStep()); + } + + abstract protected FormatterStep createStep(); } @@ -565,22 +574,24 @@ public class PrettierConfig extends NpmStepConfig { final Map devDependencies; PrettierConfig(Map devDependencies) { + super(getProject(), FormatExtension.this::replaceStep); this.devDependencies = requireNonNull(devDependencies); } public PrettierConfig configFile(final Object prettierConfigFile) { this.prettierConfigFile = prettierConfigFile; - replaceStep(createStep()); + replaceStep(); return this; } public PrettierConfig config(final Map prettierConfig) { this.prettierConfig = new TreeMap<>(prettierConfig); - replaceStep(createStep()); + replaceStep(); return this; } - FormatterStep createStep() { + @Override + protected FormatterStep createStep() { final Project project = getProject(); return PrettierFormatterStep.create( devDependencies, @@ -611,69 +622,6 @@ public PrettierConfig prettier(Map devDependencies) { return prettierConfig; } - public class EslintFormatExtension extends NpmStepConfig { - - Map devDependencies = new LinkedHashMap<>(); - - @Nullable - Object configFilePath = null; - - @Nullable - String configJs = null; - - public EslintFormatExtension(Map devDependencies) { - this.devDependencies.putAll(requireNonNull(devDependencies)); - } - - public EslintFormatExtension devDependencies(Map devDependencies) { - this.devDependencies.putAll(devDependencies); - replaceStep(createStep()); - return this; - } - - public EslintFormatExtension configJs(String configJs) { - this.configJs = requireNonNull(configJs); - replaceStep(createStep()); - return this; - } - - public EslintFormatExtension configFile(Object configFilePath) { - this.configFilePath = requireNonNull(configFilePath); - replaceStep(createStep()); - return this; - } - - public FormatterStep createStep() { - final Project project = getProject(); - - return EslintFormatterStep.create( - devDependencies, - provisioner(), - project.getProjectDir(), - project.getBuildDir(), - new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), - eslintConfig()); - } - - protected EslintConfig eslintConfig() { - return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); - } - } - - public EslintFormatExtension eslint() { - return eslint(EslintFormatterStep.defaultDevDependencies()); - } - - public EslintFormatExtension eslint(String version) { - return eslint(EslintFormatterStep.defaultDevDependenciesWithEslint(version)); - } - - public EslintFormatExtension eslint(Map devDependencies) { - EslintFormatExtension eslint = new EslintFormatExtension(devDependencies); - addStep(eslint.createStep()); - return eslint; - } - /** Uses the default version of clang-format. */ public ClangFormatConfig clangFormat() { return clangFormat(ClangFormatStep.defaultVersion()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java new file mode 100644 index 0000000000..348ed5f37e --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -0,0 +1,156 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import static java.util.Objects.requireNonNull; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import javax.annotation.Nullable; +import javax.inject.Inject; + +import org.gradle.api.Project; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.npm.EslintConfig; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; +import com.diffplug.spotless.npm.NpmPathResolver; + +public class JavascriptExtension extends FormatExtension { + + static final String NAME = "javascript"; + + @Inject + public JavascriptExtension(SpotlessExtension spotless) { + super(spotless); + } + + public JavascriptEslintConfig eslint() { + return eslint(EslintFormatterStep.defaultDevDependenciesForTypescript()); + } + + public JavascriptEslintConfig eslint(String version) { + return eslint(EslintFormatterStep.defaultDevDependenciesTypescriptWithEslint(version)); + } + + public JavascriptEslintConfig eslint(Map devDependencies) { + JavascriptEslintConfig eslint = new JavascriptEslintConfig(devDependencies); + addStep(eslint.createStep()); + return eslint; + } + + // TODO: make the configs static so that they do not need to have a hierarchy symmetric to the extensions + + public static abstract class EslintBaseConfig> extends NpmStepConfig> { + Map devDependencies = new LinkedHashMap<>(); + + @Nullable + Object configFilePath = null; + + @Nullable + String configJs = null; + + public EslintBaseConfig(Project project, Consumer replaceStep, Map devDependencies) { + super(project, replaceStep); + this.devDependencies.putAll(requireNonNull(devDependencies)); + } + + @SuppressWarnings("unchecked") + public T devDependencies(Map devDependencies) { + this.devDependencies.putAll(devDependencies); + replaceStep(); + return (T) this; + } + + @SuppressWarnings("unchecked") + public T configJs(String configJs) { + this.configJs = requireNonNull(configJs); + replaceStep(); + return (T) this; + } + + @SuppressWarnings("unchecked") + public T configFile(Object configFilePath) { + this.configFilePath = requireNonNull(configFilePath); + replaceStep(); + return (T) this; + } + + @SuppressWarnings("unchecked") + public T styleGuide(String styleGuide) { + PopularStyleGuide popularStyleGuide = PopularStyleGuide.fromNameOrNull(styleGuide); + + verifyStyleGuideIsSupported(styleGuide, popularStyleGuide); + devDependencies(popularStyleGuide.devDependencies()); + replaceStep(); + return (T) this; + } + + protected abstract void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide); + } + + public class JavascriptEslintConfig extends EslintBaseConfig { + + public JavascriptEslintConfig(Map devDependencies) { + super(getProject(), JavascriptExtension.this::replaceStep, devDependencies); + } + + public FormatterStep createStep() { + final Project project = getProject(); + + return EslintFormatterStep.create( + devDependencies, + provisioner(), + project.getProjectDir(), + project.getBuildDir(), + new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + eslintConfig()); + } + + @Override + protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { + if (!isJsStyleGuide(popularStyleGuide)) { + throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known javascript style guides: " + + Arrays.stream(PopularStyleGuide.values()) + .filter(this::isJsStyleGuide) + .map(PopularStyleGuide::getPopularStyleGuideName) + .sorted() + .collect(Collectors.joining(", "))); + } + } + + private boolean isJsStyleGuide(PopularStyleGuide popularStyleGuide) { + return popularStyleGuide != null && popularStyleGuide.name().startsWith("JS_"); + } + + protected EslintConfig eslintConfig() { + return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); + } + } + + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + throw noDefaultTargetException(); + } + super.setupTask(task); + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java index 57aa3b2d83..3fe5721b5d 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 @@ -167,6 +167,11 @@ public void cpp(Action closure) { format(CppExtension.NAME, CppExtension.class, closure); } + /** Configures the special javascript-specific extension for javascript files. */ + public void javascript(Action closure) { + format(JavascriptExtension.NAME, JavascriptExtension.class, closure); + } + /** Configures the special typescript-specific extension for typescript files. */ public void typescript(Action closure) { format(TypescriptExtension.NAME, TypescriptExtension.class, closure); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index d4dedc32eb..f318dd89c8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -27,15 +27,13 @@ import javax.annotation.Nullable; import javax.inject.Inject; -import com.diffplug.spotless.npm.EslintConfig; - -import com.diffplug.spotless.npm.EslintTypescriptConfig; - import org.gradle.api.Project; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; +import com.diffplug.spotless.npm.EslintTypescriptConfig; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; import com.diffplug.spotless.npm.TsConfigFileType; @@ -81,12 +79,13 @@ public class TypescriptFormatExtension extends NpmStepConfig devDependencies; TypescriptFormatExtension(Map devDependencies) { + super(getProject(), TypescriptExtension.this::replaceStep); this.devDependencies = Objects.requireNonNull(devDependencies); } public void config(final Map config) { this.config = new TreeMap<>(requireNonNull(config)); - replaceStep(createStep()); + replaceStep(); } public void tsconfigFile(final Object path) { @@ -108,7 +107,7 @@ public void tsfmtFile(final Object path) { private void configFile(TsConfigFileType filetype, Object path) { this.configFileType = requireNonNull(filetype); this.configFilePath = requireNonNull(path); - replaceStep(createStep()); + replaceStep(); } public FormatterStep createStep() { @@ -161,7 +160,7 @@ public class TypescriptPrettierConfig extends PrettierConfig { } @Override - FormatterStep createStep() { + protected FormatterStep createStep() { fixParserToTypescript(); return super.createStep(); } @@ -178,74 +177,73 @@ private void fixParserToTypescript() { } } - @Override - public TypescriptEslintFormatExtension eslint() { + public TypescriptEslintConfig eslint() { return eslint(EslintFormatterStep.defaultDevDependenciesForTypescript()); } - @Override - public TypescriptEslintFormatExtension eslint(String version) { + public TypescriptEslintConfig eslint(String version) { return eslint(EslintFormatterStep.defaultDevDependenciesTypescriptWithEslint(version)); } - @Override - public TypescriptEslintFormatExtension eslint(Map devDependencies) { - TypescriptEslintFormatExtension eslint = new TypescriptEslintFormatExtension(devDependencies); + public TypescriptEslintConfig eslint(Map devDependencies) { + TypescriptEslintConfig eslint = new TypescriptEslintConfig(devDependencies); addStep(eslint.createStep()); return eslint; } - public class TypescriptEslintFormatExtension extends EslintFormatExtension { + public class TypescriptEslintConfig extends JavascriptExtension.EslintBaseConfig { @Nullable Object typescriptConfigFilePath = null; - public TypescriptEslintFormatExtension(Map devDependencies) { - super(devDependencies); + public TypescriptEslintConfig(Map devDependencies) { + super(getProject(), TypescriptExtension.this::replaceStep, devDependencies); } - @Override - public TypescriptEslintFormatExtension devDependencies(Map devDependencies) { - return (TypescriptEslintFormatExtension) super.devDependencies(devDependencies); + public TypescriptEslintConfig tsconfigFile(Object path) { + this.typescriptConfigFilePath = requireNonNull(path); + replaceStep(); + return this; } @Override - public TypescriptEslintFormatExtension configJs(String configJs) { - return (TypescriptEslintFormatExtension) super.configJs(configJs); + protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { + if (!isTsStyleGuide(popularStyleGuide)) { + throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known typescript style guides: " + + Arrays.stream(EslintFormatterStep.PopularStyleGuide.values()) + .filter(this::isTsStyleGuide) + .map(PopularStyleGuide::getPopularStyleGuideName) + .sorted() + .collect(Collectors.joining(", "))); + } } - @Override - public TypescriptEslintFormatExtension configFile(Object configFilePath) { - return (TypescriptEslintFormatExtension) super.configFile(configFilePath); + private boolean isTsStyleGuide(PopularStyleGuide popularStyleGuide) { + return popularStyleGuide != null && popularStyleGuide.name().startsWith("TS_"); } - public TypescriptEslintFormatExtension styleGuide(String styleGuide) { - PopularStyleGuide popularStyleGuide = PopularStyleGuide.fromNameOrNull(styleGuide); - if (popularStyleGuide == null) { - throw new IllegalArgumentException("Unknown style guide: " + styleGuide + ". Known style guides: " - + Arrays.stream(PopularStyleGuide.values()).map(PopularStyleGuide::getPopularStyleGuideName).collect(Collectors.joining(", "))); - } - devDependencies(popularStyleGuide.devDependencies()); - replaceStep(createStep()); - return this; - } + public FormatterStep createStep() { + final Project project = getProject(); - public TypescriptEslintFormatExtension tsconfigFile(Object path) { - this.typescriptConfigFilePath = requireNonNull(path); - replaceStep(createStep()); - return this; + return EslintFormatterStep.create( + devDependencies, + provisioner(), + project.getProjectDir(), + project.getBuildDir(), + new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + eslintConfig()); } - @Override protected EslintConfig eslintConfig() { - EslintConfig config = super.eslintConfig(); - return new EslintTypescriptConfig(config.getEslintConfigPath(), config.getEslintConfigJs(), typescriptConfigFilePath != null ? getProject().file(typescriptConfigFilePath) : null); + return new EslintTypescriptConfig( + configFilePath != null ? getProject().file(configFilePath) : null, + configJs, + typescriptConfigFilePath != null ? getProject().file(typescriptConfigFilePath) : null); } } @Override protected void setupTask(SpotlessTask task) { - // defaults to all typescript files if (target == null) { throw noDefaultTargetException(); } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 3a8bfc7fd6..95298db0ea 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,20 +15,20 @@ */ package com.diffplug.spotless.npm; -import com.diffplug.common.collect.ImmutableMap; -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.StepHarnessWithFile; -import com.diffplug.spotless.TestProvisioner; -import com.diffplug.spotless.tag.NpmTest; +import java.io.File; +import java.util.Map; +import java.util.TreeMap; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import java.io.File; -import java.util.Map; -import java.util.TreeMap; +import com.diffplug.common.collect.ImmutableMap; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.StepHarnessWithFile; +import com.diffplug.spotless.TestProvisioner; +import com.diffplug.spotless.tag.NpmTest; @NpmTest class EslintFormatterStepTest { @@ -44,12 +44,11 @@ private final Map combine(Map m1, Map> devDependenciesForRuleset = ImmutableMap.of( - "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), - "styleguide/airbnb", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_AIRBNB.devDependencies()), - "styleguide/google", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_GOOGLE.devDependencies()), - "styleguide/standard", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_STANDARD.devDependencies()), - "styleguide/xo", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_XO.devDependencies()) - ); + "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), + "styleguide/airbnb", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_AIRBNB.devDependencies()), + "styleguide/google", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_GOOGLE.devDependencies()), + "styleguide/standard", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_STANDARD.devDependencies()), + "styleguide/xo", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_XO.devDependencies())); @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") @ValueSource(strings = {"custom_rules", "styleguide/airbnb", "styleguide/google", "styleguide/standard", "styleguide/xo"}) @@ -57,22 +56,22 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { String filedir = "npm/eslint/javascript/" + ruleSetName + "/"; String testDir = "formatting_ruleset_" + ruleSetName.replace('/', '_') + "/"; -// File testDirFile = newFolder(testDir); + // File testDirFile = newFolder(testDir); final File eslintRc = createTestFile(filedir + ".eslintrc.js"); -// final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); + // final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); final String dirtyFile = filedir + "javascript-es6.dirty"; File dirtyFileFile = setFile(testDir + "test.js").toResource(dirtyFile); final String cleanFile = filedir + "javascript-es6.clean"; final FormatterStep formatterStep = EslintFormatterStep.create( - devDependenciesForRuleset.get(ruleSetName), - TestProvisioner.mavenCentral(), - projectDir(), - buildDir(), - npmPathResolver(), - new EslintConfig(eslintRc, null)); + devDependenciesForRuleset.get(ruleSetName), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintConfig(eslintRc, null)); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); @@ -80,19 +79,14 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { } } - - @NpmTest @Nested class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { private final Map> devDependenciesForRuleset = ImmutableMap.of( - "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), - "styleguide/standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_STANDARD_WITH_TYPESCRIPT.devDependencies()), - "styleguide/xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies()) - ); - - + "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), + "styleguide/standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_STANDARD_WITH_TYPESCRIPT.devDependencies()), + "styleguide/xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies())); @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") @ValueSource(strings = {"custom_rules", "styleguide/standard_with_typescript", "styleguide/xo"}) @@ -100,10 +94,10 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { String filedir = "npm/eslint/typescript/" + ruleSetName + "/"; String testDir = "formatting_ruleset_" + ruleSetName.replace('/', '_') + "/"; -// File testDirFile = newFolder(testDir); + // File testDirFile = newFolder(testDir); final File eslintRc = createTestFile(filedir + ".eslintrc.js"); -// final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); + // final File eslintRc = setFile(buildDir().getPath() + "/.eslintrc.js").toResource(filedir + ".eslintrc.js"); //setFile(testDir + "/test.ts").toResource(filedir + "typescript.dirty"); File tsconfigFile = null; @@ -115,12 +109,12 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { final String cleanFile = filedir + "typescript.clean"; final FormatterStep formatterStep = EslintFormatterStep.create( - devDependenciesForRuleset.get(ruleSetName), - TestProvisioner.mavenCentral(), - projectDir(), - buildDir(), - npmPathResolver(), - new EslintTypescriptConfig(eslintRc, null, tsconfigFile)); + devDependenciesForRuleset.get(ruleSetName), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintTypescriptConfig(eslintRc, null, tsconfigFile)); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); @@ -132,42 +126,39 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { @Nested class EslintInlineConfigTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { - @Test void formattingUsingInlineXoConfig() throws Exception { String filedir = "npm/eslint/typescript/standard_rules_xo/"; String testDir = "formatting_ruleset_xo_inline_config/"; - final String esLintConfig = String.join("\n", - "{", - " env: {", - " browser: true,", - " es2021: true,", - " },", - " extends: 'xo/browser',", - " overrides: [", - " {", - " extends: [", - " 'xo-typescript',", - " ],", - " files: [", - " '*.ts',", - " '*.tsx',", - " ],", - " },", - " ],", - " parser: '@typescript-eslint/parser',", - " parserOptions: {", - " ecmaVersion: 'latest',", - " sourceType: 'module',", - " project: './tsconfig.json',", - " },", - " rules: {", - " },", - "}" - ); + "{", + " env: {", + " browser: true,", + " es2021: true,", + " },", + " extends: 'xo/browser',", + " overrides: [", + " {", + " extends: [", + " 'xo-typescript',", + " ],", + " files: [", + " '*.ts',", + " '*.tsx',", + " ],", + " },", + " ],", + " parser: '@typescript-eslint/parser',", + " parserOptions: {", + " ecmaVersion: 'latest',", + " sourceType: 'module',", + " project: './tsconfig.json',", + " },", + " rules: {", + " },", + "}"); File tsconfigFile = setFile(testDir + "tsconfig.json").toResource(filedir + "tsconfig.json"); final String dirtyFile = filedir + "typescript.dirty"; @@ -175,12 +166,12 @@ void formattingUsingInlineXoConfig() throws Exception { final String cleanFile = filedir + "typescript.clean"; final FormatterStep formatterStep = EslintFormatterStep.create( - combine(EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), - TestProvisioner.mavenCentral(), - projectDir(), - buildDir(), - npmPathResolver(), - new EslintTypescriptConfig(null, esLintConfig, tsconfigFile)); + combine(EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), + TestProvisioner.mavenCentral(), + projectDir(), + buildDir(), + npmPathResolver(), + new EslintTypescriptConfig(null, esLintConfig, tsconfigFile)); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java index f1b5da59ff..1ed6e9bbe8 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java index d06b902b83..474c664486 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 0206246cee0de58aac3b3477da69f98d8b1c2426 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 20 Dec 2022 19:38:34 +0100 Subject: [PATCH 0148/1120] eslint: adding tests for js --- .../diffplug/spotless/npm/EslintConfig.java | 7 + .../spotless/npm/EslintFormatterStep.java | 4 +- .../gradle/spotless/JavascriptExtension.java | 61 ++++- .../spotless/JavascriptExtensionTest.java | 221 ++++++++++++++++++ .../spotless/TypescriptExtensionTest.java | 25 +- 5 files changed, 312 insertions(+), 6 deletions(-) create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java index 732111cc71..4e1848856a 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java @@ -62,4 +62,11 @@ public File getEslintConfigPath() { public String getEslintConfigJs() { return eslintConfigJs; } + + public EslintConfig verify() { + if (eslintConfigPath == null && eslintConfigJs == null) { + throw new IllegalArgumentException("ESLint must be configured using either a configFile or a configJs - but both are null."); + } + return this; + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 14bc99a243..0e5e618e1e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -183,14 +183,14 @@ private static class State extends NpmFormatterStepStateBase implements Serializ private EslintConfig localCopyFiles(EslintConfig orig) { if (orig.getEslintConfigPath() == null) { - return orig; + return orig.verify(); } // If any config files are provided, we need to make sure they are at the same location as the node modules // as eslint will try to resolve plugin/config names relatively to the config file location and some // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", orig.getEslintConfigPath(), nodeModulesDir); File configFileCopy = NpmResourceHelper.copyFileToDir(orig.getEslintConfigPath(), nodeModulesDir); - return orig.withEslintConfigPath(configFileCopy); + return orig.withEslintConfigPath(configFileCopy).verify(); } @Override diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index 348ed5f37e..fb05387f49 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -18,6 +18,7 @@ import static java.util.Objects.requireNonNull; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Consumer; @@ -28,11 +29,13 @@ import org.gradle.api.Project; +import com.diffplug.common.collect.ImmutableList; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; import com.diffplug.spotless.npm.NpmPathResolver; +import com.diffplug.spotless.npm.PrettierFormatterStep; public class JavascriptExtension extends FormatExtension { @@ -57,8 +60,6 @@ public JavascriptEslintConfig eslint(Map devDependencies) { return eslint; } - // TODO: make the configs static so that they do not need to have a hierarchy symmetric to the extensions - public static abstract class EslintBaseConfig> extends NpmStepConfig> { Map devDependencies = new LinkedHashMap<>(); @@ -146,6 +147,62 @@ protected EslintConfig eslintConfig() { } } + /** Uses the default version of prettier. */ + @Override + public PrettierConfig prettier() { + return prettier(PrettierFormatterStep.defaultDevDependencies()); + } + + /** Uses the specified version of prettier. */ + @Override + public PrettierConfig prettier(String version) { + return prettier(PrettierFormatterStep.defaultDevDependenciesWithPrettier(version)); + } + + /** Uses exactly the npm packages specified in the map. */ + @Override + public PrettierConfig prettier(Map devDependencies) { + PrettierConfig prettierConfig = new JavascriptPrettierConfig(devDependencies); + addStep(prettierConfig.createStep()); + return prettierConfig; + } + + private static final String DEFAULT_PRETTIER_JS_PARSER = "babel"; + private static final ImmutableList PRETTIER_JS_PARSERS = ImmutableList.of(DEFAULT_PRETTIER_JS_PARSER, "babel-flow", "flow"); + + /** + * Overrides the parser to be set to a js parser. + */ + public class JavascriptPrettierConfig extends PrettierConfig { + + JavascriptPrettierConfig(Map devDependencies) { + super(devDependencies); + } + + @Override + protected FormatterStep createStep() { + fixParserToJavascript(); + return super.createStep(); + } + + private void fixParserToJavascript() { + if (this.prettierConfig == null) { + this.prettierConfig = Collections.singletonMap("parser", DEFAULT_PRETTIER_JS_PARSER); + } else { + final Object currentParser = this.prettierConfig.get("parser"); + if (PRETTIER_JS_PARSERS.contains(String.valueOf(currentParser))) { + getProject().getLogger().debug("Already javascript parser set, not overriding."); + } else { + this.prettierConfig.put("parser", DEFAULT_PRETTIER_JS_PARSER); + if (currentParser != null) { + getProject().getLogger().warn("Overriding parser option to '{}'. (Was set to '{}'.) Set it to another js parser if you have problems with '{}'.", DEFAULT_PRETTIER_JS_PARSER, currentParser, DEFAULT_PRETTIER_JS_PARSER); + } + } + + } + } + } + @Override protected void setupTask(SpotlessTask task) { if (target == null) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java new file mode 100644 index 0000000000..af203936f3 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java @@ -0,0 +1,221 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.io.IOException; + +import org.assertj.core.api.Assertions; +import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import com.diffplug.spotless.tag.NpmTest; + +@NpmTest +class JavascriptExtensionTest extends GradleIntegrationHarness { + + @NpmTest + @Nested + class EslintGeneralJavascriptTests extends GradleIntegrationHarness { + @Test + void supportsEslintFormattingForJavascript() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint().configFile('.eslintrc.js').styleGuide('standard')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); + } + + @Test + void eslintDoesNotAllowToUseTsStyleGuideForJavascript() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint().configFile('.eslintrc.js').styleGuide('xo-typescript')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + Assertions.assertThat(spotlessApply.getOutput()).contains("Unknown style guide: xo-typescript"); + } + + @Test + void eslintAllowsToSpecifyEslintVersionForJavascript() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint('8.28.0').configFile('.eslintrc.js').styleGuide('standard')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); + } + + @Test + void esllintAllowsToSpecifyInlineConfig() throws IOException { + final String eslintConfigJs = String.join("\n", + "{", + " env: {", + " browser: true,", + " es2021: true", + " },", + " extends: 'standard',", + " overrides: [", + " ],", + " parserOptions: {", + " ecmaVersion: 'latest',", + " sourceType: 'module'", + " },", + " rules: {", + " }", + "}"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint().configJs('''" + eslintConfigJs + "''').styleGuide('standard')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); + } + + @Test + void eslintRequiresAnExplicitEslintConfig() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint().styleGuide('standard')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + Assertions.assertThat(spotlessApply.getOutput()).contains("ESLint must be configured"); + } + + @Test + void eslintAllowsSpecifyingCustomLibraryVersions() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint([", + " 'eslint': '8.28.0',", + " 'eslint-config-standard': '17.0.0',", + " 'eslint-plugin-import': '2.26.0',", + " 'eslint-plugin-n': '15.6.0',", + " 'eslint-plugin-promise': '6.1.1'", + " ]).configFile('.eslintrc.js')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); + } + + } + + @NpmTest + @Nested + class EslintPopularJsStyleGuideTests extends GradleIntegrationHarness { + @ParameterizedTest(name = "{index}: eslint can be applied using styleguide {0}") + @ValueSource(strings = {"airbnb", "google", "standard", "xo"}) + void formattingUsingStyleguide(String styleguide) throws Exception { + + final String styleguidePath = "npm/eslint/javascript/styleguide/" + styleguide + "/"; + + setFile(".eslintrc.js").toResource(styleguidePath + ".eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " eslint().configFile('.eslintrc.js').styleGuide('" + styleguide + "')", + " }", + "}"); + setFile("test.js").toResource(styleguidePath + "javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource(styleguidePath + "javascript-es6.clean"); + } + } + + @NpmTest + @Nested + class JavascriptPrettierTests extends GradleIntegrationHarness { + @Test + void supportsPrettierFormattingForJavascript() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target 'test.js'", + " prettier()", + " }", + "}"); + setFile("test.js").toResource("npm/prettier/filetypes/javascript-es6/javascript-es6.dirty"); + gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertFile("test.js").sameAsResource("npm/prettier/filetypes/javascript-es6/javascript-es6.clean"); + } + } + +} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 7d715998f6..da9fa03905 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -17,6 +17,8 @@ import java.io.IOException; +import org.assertj.core.api.Assertions; +import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Test; import com.diffplug.spotless.tag.NpmTest; @@ -162,7 +164,7 @@ void useEslint() throws IOException { } @Test - void useXoStandardRules() throws IOException { + void useEslintXoStandardRules() throws IOException { setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js"); setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/xo/tsconfig.json"); setFile("build.gradle").toLines( @@ -182,7 +184,7 @@ void useXoStandardRules() throws IOException { } @Test - void useStandardWithTypescriptRules() throws IOException { + void useEslintStandardWithTypescriptRules() throws IOException { setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js"); setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json"); setFile("build.gradle").toLines( @@ -200,4 +202,23 @@ void useStandardWithTypescriptRules() throws IOException { gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean"); } + + @Test + void useEslintForTypescriptDoesNotAllowUsingJsStyleguide() throws IOException { + setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/airbnb/.eslintrc.js"); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " eslint().styleGuide('airbnb').configFile('.eslintrc.js')", + " }", + "}"); + setFile("test.js").toResource("npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty"); + BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + Assertions.assertThat(spotlessApply.getOutput()).contains("Unknown style guide: airbnb"); + } } From 393a4c4424e66466cf1a698ab8716c331ec7e493 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 20 Dec 2022 19:37:54 +0100 Subject: [PATCH 0149/1120] eslint: bumping version numbers --- .../spotless/npm/EslintFormatterStep.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 0e5e618e1e..8589819540 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -45,18 +45,17 @@ public class EslintFormatterStep { public static final String NAME = "eslint-format"; - public static final String DEFAULT_ESLINT_VERSION = "8.28.0"; + public static final String DEFAULT_ESLINT_VERSION = "^8.30.0"; public enum PopularStyleGuide { TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard-with-typescript", "23.0.0"); - dependencies.put("eslint-plugin-import", "2.26.0"); - dependencies.put("eslint-plugin-n", "15.5.1"); - dependencies.put("eslint-plugin-promise", "6.1.1"); - dependencies.put("typescript", "4.9.3"); + dependencies.put("eslint-config-standard-with-typescript", "^24.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); + dependencies.put("eslint-plugin-n", "^15.6.0"); + dependencies.put("eslint-plugin-promise", "^6.1.1"); return dependencies; } }, @@ -64,9 +63,8 @@ public Map devDependencies() { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-xo", "0.43.1"); - dependencies.put("eslint-config-xo-typescript", "0.55.1"); - dependencies.put("typescript", "4.9.3"); + dependencies.put("eslint-config-xo", "^0.43.1"); + dependencies.put("eslint-config-xo-typescript", "^0.55.1"); return dependencies; } }, @@ -74,8 +72,8 @@ public Map devDependencies() { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-airbnb-base", "15.0.0"); - dependencies.put("eslint-plugin-import", "2.26.0"); + dependencies.put("eslint-config-airbnb-base", "^15.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); return dependencies; } }, @@ -83,7 +81,7 @@ public Map devDependencies() { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-google", "0.14.0"); + dependencies.put("eslint-config-google", "^0.14.0"); return dependencies; } }, @@ -91,10 +89,10 @@ public Map devDependencies() { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard", "17.0.0"); - dependencies.put("eslint-plugin-import", "2.26.0"); - dependencies.put("eslint-plugin-n", "15.6.0"); - dependencies.put("eslint-plugin-promise", "6.1.1"); + dependencies.put("eslint-config-standard", "^17.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); + dependencies.put("eslint-plugin-n", "^15.6.0"); + dependencies.put("eslint-plugin-promise", "^6.1.1"); return dependencies; } }, @@ -102,7 +100,7 @@ public Map devDependencies() { @Override public Map devDependencies() { Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-xo", "0.43.1"); + dependencies.put("eslint-config-xo", "^0.43.1"); return dependencies; } }; @@ -135,8 +133,9 @@ public static Map defaultDevDependenciesForTypescript() { public static Map defaultDevDependenciesTypescriptWithEslint(String eslintVersion) { Map dependencies = new LinkedHashMap<>(); - dependencies.put("@typescript-eslint/eslint-plugin", "5.45.0"); - dependencies.put("@typescript-eslint/parser", "5.45.0"); + dependencies.put("@typescript-eslint/eslint-plugin", "^5.47.0"); + dependencies.put("@typescript-eslint/parser", "^5.47.0"); + dependencies.put("typescript", "^4.9.4"); dependencies.put("eslint", Objects.requireNonNull(eslintVersion)); return dependencies; } From 8dc740ef3723d38687222c2dfcd9b68bae3edce0 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 20 Dec 2022 19:53:57 +0100 Subject: [PATCH 0150/1120] eslint: adapt to extended api on maven side --- .../java/com/diffplug/spotless/maven/generic/Prettier.java | 7 ++++--- .../java/com/diffplug/spotless/maven/typescript/Tsfmt.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index 85684e85cd..5bdce32c47 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,8 +105,9 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { // create the format step PrettierConfig prettierConfig = new PrettierConfig(configFileHandler, configInline); File buildDir = stepConfig.getFileLocator().getBuildDir(); - NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, stepConfig.getFileLocator().getBaseDir()); - return PrettierFormatterStep.create(devDependencies, stepConfig.getProvisioner(), buildDir, npmPathResolver, prettierConfig); + File baseDir = stepConfig.getFileLocator().getBaseDir(); + NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, baseDir); + return PrettierFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, prettierConfig); } private boolean moreThanOneNonNull(Object... objects) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java index 9ebb9ac503..e41231818c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -120,8 +120,9 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { } File buildDir = stepConfig.getFileLocator().getBuildDir(); - NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, stepConfig.getFileLocator().getBaseDir()); - return TsFmtFormatterStep.create(devDependencies, stepConfig.getProvisioner(), buildDir, npmPathResolver, configFile, configInline); + File baseDir = stepConfig.getFileLocator().getBaseDir(); + NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, baseDir); + return TsFmtFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, configFile, configInline); } private static IllegalArgumentException onlyOneConfig() { From cb3dd5536febc8fccb0b71ee1103225d6fd9eafb Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 21 Dec 2022 16:28:32 +0100 Subject: [PATCH 0151/1120] eslint: speedup npm install --- lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index e1bf8c8673..28db79b726 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ class NpmProcess { } void install() { - npmAwait("install", "--no-audit", "--no-package-lock"); + npmAwait("install", "--no-audit", "--no-package-lock", "--prefer-offline"); } Process start() { From e12c5efb5f64b4133228e7d102baebd67191da32 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 21 Dec 2022 16:31:18 +0100 Subject: [PATCH 0152/1120] eslint: speedup npmrc tests we intend them to timeout, but please fail quicker. --- .../gradle/spotless/PrettierIntegrationTest.java | 12 +++++++++--- .../maven/prettier/PrettierFormatStepTest.java | 14 +++++++++++--- .../maven/typescript/TypescriptFormatStepTest.java | 14 +++++++++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index 404ccf88c8..6f55312bd5 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -163,7 +163,10 @@ void usePhpCommunityPlugin() throws IOException { @Test void autodetectNpmrcFileConfig() throws IOException { setFile(".npmrc").toLines( - "registry=https://i.do.no.exist.com"); + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -186,7 +189,10 @@ void autodetectNpmrcFileConfig() throws IOException { @Test void pickupNpmrcFileConfig() throws IOException { setFile(".custom_npmrc").toLines( - "registry=https://i.do.no.exist.com"); + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index 130bbde600..8fce61b5d8 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -145,7 +145,11 @@ void autodetect_parser_based_on_filename() throws Exception { @Test void autodetect_npmrc_file() throws Exception { - setFile(".npmrc").toLines("registry=https://i.do.no.exist.com"); + setFile(".npmrc").toLines( + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); String suffix = "ts"; writePomWithPrettierSteps("**/*." + suffix, "", @@ -158,7 +162,11 @@ void autodetect_npmrc_file() throws Exception { @Test void select_configured_npmrc_file() throws Exception { - setFile(".custom_npmrc").toLines("registry=https://i.do.no.exist.com"); + setFile(".custom_npmrc").toLines( + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); String suffix = "ts"; writePomWithPrettierSteps("**/*." + suffix, "", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index 600f9818d1..3b21f972ed 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -114,7 +114,11 @@ void testTypescript_2_Configs() throws Exception { @Test void testNpmrcIsAutoPickedUp() throws Exception { - setFile(".npmrc").toLines("registry=https://i.do.no.exist.com"); + setFile(".npmrc").toLines( + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); writePomWithTypescriptSteps( "", " ${basedir}/tslint.json", @@ -126,7 +130,11 @@ void testNpmrcIsAutoPickedUp() throws Exception { @Test void testNpmrcIsConfigurativelyPickedUp() throws Exception { - setFile(".custom_npmrc").toLines("registry=https://i.do.no.exist.com"); + setFile(".custom_npmrc").toLines( + "registry=https://i.do.not.exist.com", + "fetch-timeout=250", + "fetch-retry-mintimeout=250", + "fetch-retry-maxtimeout=250"); writePomWithTypescriptSteps( "", " ${basedir}/tslint.json", From 218db79b6ff8d0a1ea8c00a83cf38e21b8a19689 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 21 Dec 2022 16:31:51 +0100 Subject: [PATCH 0153/1120] eslint: extract base properties to a common base class --- .../spotless/maven/generic/Prettier.java | 20 ++----- .../npm/AbstractNpmFormatterStepFactory.java | 55 +++++++++++++++++++ .../spotless/maven/typescript/Tsfmt.java | 20 ++----- 3 files changed, 65 insertions(+), 30 deletions(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index 5bdce32c47..b45f802653 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -23,12 +23,12 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; -import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierConfig; import com.diffplug.spotless.npm.PrettierFormatterStep; -public class Prettier implements FormatterStepFactory { +public class Prettier extends AbstractNpmFormatterStepFactory { public static final String ERROR_MESSAGE_ONLY_ONE_CONFIG = "must specify exactly one prettierVersion, devDependencies or devDependencyProperties"; @@ -47,12 +47,6 @@ public class Prettier implements FormatterStepFactory { @Parameter private String configFile; - @Parameter - private String npmExecutable; - - @Parameter - private String npmrc; - @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { @@ -70,10 +64,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { this.devDependencies = dependencyPropertiesAsMap(); } - File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; - - File npmrcFile = npmrc != null ? stepConfig.getFileLocator().locateFile(npmrc) : null; - // process config file or inline config File configFileHandler; if (this.configFile != null) { @@ -103,10 +93,10 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { } // create the format step + File baseDir = baseDir(stepConfig); + File buildDir = buildDir(stepConfig); PrettierConfig prettierConfig = new PrettierConfig(configFileHandler, configInline); - File buildDir = stepConfig.getFileLocator().getBuildDir(); - File baseDir = stepConfig.getFileLocator().getBaseDir(); - NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, baseDir); + NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); return PrettierFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, prettierConfig); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java new file mode 100644 index 0000000000..8bc0f8f715 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java @@ -0,0 +1,55 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.npm; + +import java.io.File; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.npm.NpmPathResolver; + +public abstract class AbstractNpmFormatterStepFactory implements FormatterStepFactory { + + @Parameter + private String npmExecutable; + + @Parameter + private String npmrc; + + protected File npm(FormatterStepConfig stepConfig) { + File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; + return npm; + } + + protected File npmrc(FormatterStepConfig stepConfig) { + File npmrc = this.npmrc != null ? stepConfig.getFileLocator().locateFile(this.npmrc) : null; + return npmrc; + } + + protected File buildDir(FormatterStepConfig stepConfig) { + return stepConfig.getFileLocator().getBuildDir(); + } + + protected File baseDir(FormatterStepConfig stepConfig) { + return stepConfig.getFileLocator().getBaseDir(); + } + + protected NpmPathResolver npmPathResolver(FormatterStepConfig stepConfig) { + return new NpmPathResolver(npm(stepConfig), npmrc(stepConfig), baseDir(stepConfig)); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java index e41231818c..6c60c02cc6 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java @@ -23,13 +23,13 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; -import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.TsConfigFileType; import com.diffplug.spotless.npm.TsFmtFormatterStep; import com.diffplug.spotless.npm.TypedTsFmtConfigFile; -public class Tsfmt implements FormatterStepFactory { +public class Tsfmt extends AbstractNpmFormatterStepFactory { @Parameter private String tslintFile; @@ -52,12 +52,6 @@ public class Tsfmt implements FormatterStepFactory { @Parameter private String tslintVersion; - @Parameter - private String npmExecutable; - - @Parameter - private String npmrc; - @Parameter private Map config; @@ -74,10 +68,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { devDependencies.put("tslint", tslintVersion); } - File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; - - File npmrcFile = npmrc != null ? stepConfig.getFileLocator().locateFile(npmrc) : null; - TypedTsFmtConfigFile configFile; Map configInline; // check that there is only 1 config file or inline config @@ -119,9 +109,9 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { throw onlyOneConfig(); } - File buildDir = stepConfig.getFileLocator().getBuildDir(); - File baseDir = stepConfig.getFileLocator().getBaseDir(); - NpmPathResolver npmPathResolver = new NpmPathResolver(npm, npmrcFile, baseDir); + File buildDir = buildDir(stepConfig); + File baseDir = baseDir(stepConfig); + NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); return TsFmtFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, configFile, configInline); } From 31462a224d9b54c21ce75366e5d40ce5ea59f540 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 22 Dec 2022 07:52:03 +0100 Subject: [PATCH 0154/1120] eslint: initial maven support --- .../spotless/npm/EslintFormatterStep.java | 25 +++-- .../gradle/spotless/JavascriptExtension.java | 14 +-- .../gradle/spotless/TypescriptExtension.java | 9 +- .../spotless/maven/AbstractSpotlessMojo.java | 4 + .../spotless/maven/javascript/EslintJs.java | 98 +++++++++++++++++++ .../spotless/maven/javascript/Javascript.java | 42 ++++++++ .../spotless/maven/typescript/EslintTs.java | 48 +++++++++ .../spotless/maven/typescript/Typescript.java | 8 +- .../spotless/npm/EslintFormatterStepTest.java | 2 +- 9 files changed, 221 insertions(+), 29 deletions(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 8589819540..820283aae4 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -20,12 +20,14 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; import java.util.TreeMap; +import java.util.function.Predicate; import javax.annotation.Nonnull; @@ -50,7 +52,7 @@ public class EslintFormatterStep { public enum PopularStyleGuide { TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-standard-with-typescript", "^24.0.0"); dependencies.put("eslint-plugin-import", "^2.26.0"); @@ -61,7 +63,7 @@ public Map devDependencies() { }, TS_XO_TYPESCRIPT("xo-typescript") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-xo", "^0.43.1"); dependencies.put("eslint-config-xo-typescript", "^0.55.1"); @@ -70,7 +72,7 @@ public Map devDependencies() { }, JS_AIRBNB("airbnb") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-airbnb-base", "^15.0.0"); dependencies.put("eslint-plugin-import", "^2.26.0"); @@ -79,7 +81,7 @@ public Map devDependencies() { }, JS_GOOGLE("google") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-google", "^0.14.0"); return dependencies; @@ -87,7 +89,7 @@ public Map devDependencies() { }, JS_STANDARD("standard") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-standard", "^17.0.0"); dependencies.put("eslint-plugin-import", "^2.26.0"); @@ -98,7 +100,7 @@ public Map devDependencies() { }, JS_XO("xo") { @Override - public Map devDependencies() { + public @Nonnull Map devDependencies() { Map dependencies = new LinkedHashMap<>(); dependencies.put("eslint-config-xo", "^0.43.1"); return dependencies; @@ -115,7 +117,7 @@ public String getPopularStyleGuideName() { return popularStyleGuideName; } - public abstract Map devDependencies(); + public abstract @Nonnull Map devDependencies(); public static PopularStyleGuide fromNameOrNull(String popularStyleGuideName) { for (PopularStyleGuide popularStyleGuide : PopularStyleGuide.values()) { @@ -125,6 +127,15 @@ public static PopularStyleGuide fromNameOrNull(String popularStyleGuideName) { } return null; } + + public static String getPopularStyleGuideNames(Predicate filter) { + // collect matching style guide names using stream + return Arrays.stream(PopularStyleGuide.values()) + .filter(filter) + .map(PopularStyleGuide::getPopularStyleGuideName) + .sorted() + .collect(java.util.stream.Collectors.joining(", ")); + } } public static Map defaultDevDependenciesForTypescript() { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index fb05387f49..cbe0040a83 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -17,12 +17,10 @@ import static java.util.Objects.requireNonNull; -import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Consumer; -import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.inject.Inject; @@ -100,9 +98,8 @@ public T styleGuide(String styleGuide) { PopularStyleGuide popularStyleGuide = PopularStyleGuide.fromNameOrNull(styleGuide); verifyStyleGuideIsSupported(styleGuide, popularStyleGuide); - devDependencies(popularStyleGuide.devDependencies()); - replaceStep(); - return (T) this; + assert popularStyleGuide != null; + return devDependencies(popularStyleGuide.devDependencies()); } protected abstract void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide); @@ -129,12 +126,7 @@ public FormatterStep createStep() { @Override protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { if (!isJsStyleGuide(popularStyleGuide)) { - throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known javascript style guides: " - + Arrays.stream(PopularStyleGuide.values()) - .filter(this::isJsStyleGuide) - .map(PopularStyleGuide::getPopularStyleGuideName) - .sorted() - .collect(Collectors.joining(", "))); + throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known javascript style guides: " + PopularStyleGuide.getPopularStyleGuideNames(this::isJsStyleGuide)); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index f318dd89c8..79ae056bdc 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -17,12 +17,10 @@ import static java.util.Objects.requireNonNull; -import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Objects; import java.util.TreeMap; -import java.util.stream.Collectors; import javax.annotation.Nullable; import javax.inject.Inject; @@ -209,12 +207,7 @@ public TypescriptEslintConfig tsconfigFile(Object path) { @Override protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { if (!isTsStyleGuide(popularStyleGuide)) { - throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known typescript style guides: " - + Arrays.stream(EslintFormatterStep.PopularStyleGuide.values()) - .filter(this::isTsStyleGuide) - .map(PopularStyleGuide::getPopularStyleGuideName) - .sorted() - .collect(Collectors.joining(", "))); + throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known typescript style guides: " + PopularStyleGuide.getPopularStyleGuideNames(this::isTsStyleGuide)); } } 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 e4fdc7dcd0..f13f9b200d 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 @@ -64,6 +64,7 @@ import com.diffplug.spotless.maven.incremental.UpToDateChecker; import com.diffplug.spotless.maven.incremental.UpToDateChecking; import com.diffplug.spotless.maven.java.Java; +import com.diffplug.spotless.maven.javascript.Javascript; import com.diffplug.spotless.maven.kotlin.Kotlin; import com.diffplug.spotless.maven.markdown.Markdown; import com.diffplug.spotless.maven.pom.Pom; @@ -152,6 +153,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Typescript typescript; + @Parameter + private Javascript javascript; + @Parameter private Antlr4 antlr4; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java new file mode 100644 index 0000000000..91de2136a1 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -0,0 +1,98 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.javascript; + +import java.io.File; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory; +import com.diffplug.spotless.npm.EslintConfig; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.NpmPathResolver; + +public class EslintJs extends AbstractNpmFormatterStepFactory { + + @Parameter + private String configFile; + + @Parameter + private String configJs; + + @Parameter + private String styleGuide; + + @Parameter + protected String eslintVersion; + + @Parameter + private Map devDependencies; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + Map devDependencies = new TreeMap<>(); + if (this.devDependencies != null) { + devDependencies.putAll(this.devDependencies); + } else { + Map defaultDependencies = createDefaultDependencies(); + devDependencies.putAll(defaultDependencies); + } + + addStyleGuideDevDependencies(devDependencies); + + File buildDir = buildDir(stepConfig); + File baseDir = baseDir(stepConfig); + NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); + return EslintFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, eslintConfig(stepConfig)); + } + + protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { + return new EslintConfig(this.configFile != null ? stepConfig.getFileLocator().locateFile(this.configFile) : null, this.configJs); + } + + private void addStyleGuideDevDependencies(Map devDependencies) { + if (this.styleGuide != null) { + EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.valueOf(this.styleGuide); + validateStyleGuide(styleGuide); + devDependencies.putAll(styleGuide.devDependencies()); + } + } + + private void validateStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { + if (styleGuide == null) { + throw new IllegalArgumentException("StyleGuide '" + this.styleGuide + "' is not supported. Supported style guides: " + supportedStyleGuides()); + } + if (!isValidStyleGuide(styleGuide)) { + throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide + ". Use one of the following: " + supportedStyleGuides()); + } + } + + private String supportedStyleGuides() { + return EslintFormatterStep.PopularStyleGuide.getPopularStyleGuideNames(this::isValidStyleGuide); + } + + protected boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { + return styleGuide.name().startsWith("JS_"); + } + + protected Map createDefaultDependencies() { + return eslintVersion == null ? EslintFormatterStep.defaultDevDependencies() : EslintFormatterStep.defaultDevDependenciesWithEslint(eslintVersion); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java new file mode 100644 index 0000000000..db7049ff0d --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.javascript; + +import java.util.Collections; +import java.util.Set; + +import com.diffplug.spotless.maven.FormatterFactory; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + *

+ * It defines a formatter for typescript source files. + */ +public class Javascript extends FormatterFactory { + @Override + public Set defaultIncludes() { + return Collections.emptySet(); + } + + @Override + public String licenseHeaderDelimiter() { + return null; + } + + public void addEslint(EslintJs eslint) { + addStepFactory(eslint); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java new file mode 100644 index 0000000000..0fe834ffde --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.typescript; + +import java.util.Map; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.javascript.EslintJs; +import com.diffplug.spotless.npm.EslintConfig; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintTypescriptConfig; + +public class EslintTs extends EslintJs { + + @Parameter + private String tsconfigFile; + + @Override + protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { + EslintConfig jsConfig = super.eslintConfig(stepConfig); + return new EslintTypescriptConfig(jsConfig.getEslintConfigPath(), jsConfig.getEslintConfigJs(), tsconfigFile != null ? stepConfig.getFileLocator().locateFile(tsconfigFile) : null); + } + + @Override + protected boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { + return styleGuide.name().startsWith("TS_"); + } + + @Override + protected Map createDefaultDependencies() { + return this.eslintVersion == null ? EslintFormatterStep.defaultDevDependenciesForTypescript() : EslintFormatterStep.defaultDevDependenciesTypescriptWithEslint(this.eslintVersion); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index da6e6ddd91..1320cac2d8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ /** * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. *

- * It defines a formatter for typescript source files. + * It defines formatters for typescript source files. */ public class Typescript extends FormatterFactory { @Override @@ -39,4 +39,8 @@ public String licenseHeaderDelimiter() { public void addTsfmt(Tsfmt tsfmt) { addStepFactory(tsfmt); } + + public void addEslint(EslintTs eslint) { + addStepFactory(eslint); + } } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 95298db0ea..15ebb0cc0d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -128,7 +128,7 @@ class EslintInlineConfigTypescriptFormattingStepTest extends NpmFormatterStepCom @Test void formattingUsingInlineXoConfig() throws Exception { - String filedir = "npm/eslint/typescript/standard_rules_xo/"; + String filedir = "npm/eslint/typescript/styleguide/xo/"; String testDir = "formatting_ruleset_xo_inline_config/"; From dd5ae78fcd05300f64a6a85a1823402fe1891045 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 22 Dec 2022 20:04:16 +0100 Subject: [PATCH 0155/1120] eslint: tests for maven integration into typescript --- .../com/diffplug/spotless/npm/eslint-serve.js | 2 +- .../spotless/maven/javascript/EslintJs.java | 4 +- .../maven/MavenIntegrationHarness.java | 4 +- .../typescript/TypescriptFormatStepTest.java | 107 +++++++++++++++--- 4 files changed, 96 insertions(+), 21 deletions(-) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index b9f3207d5f..1f1b1fab5a 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -55,7 +55,7 @@ app.post("/eslint/format", async (req, res) => { // LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type const results = await eslint.lintText(format_data.file_content, lintTextOptions); if (results.length !== 1) { - res.status(501).send("Error while formatting: Unexpected number of results"); + res.status(501).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results)); return; } const result = results[0]; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java index 91de2136a1..589e2f3f0c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -69,7 +69,7 @@ protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { private void addStyleGuideDevDependencies(Map devDependencies) { if (this.styleGuide != null) { - EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.valueOf(this.styleGuide); + EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.fromNameOrNull(this.styleGuide); validateStyleGuide(styleGuide); devDependencies.putAll(styleGuide.devDependencies()); } @@ -80,7 +80,7 @@ private void validateStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide throw new IllegalArgumentException("StyleGuide '" + this.styleGuide + "' is not supported. Supported style guides: " + supportedStyleGuides()); } if (!isValidStyleGuide(styleGuide)) { - throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide + ". Use one of the following: " + supportedStyleGuides()); + throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide.getPopularStyleGuideName() + ". Use one of the following: " + supportedStyleGuides()); } } 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 939940a315..61d9c80a37 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 @@ -136,8 +136,8 @@ protected void writePomWithCppSteps(String... steps) throws IOException { writePom(groupWithSteps("cpp", steps)); } - protected void writePomWithTypescriptSteps(String... steps) throws IOException { - writePom(groupWithSteps("typescript", including("**/*.ts"), steps)); + protected void writePomWithTypescriptSteps(String includes, String... steps) throws IOException { + writePom(groupWithSteps("typescript", including(includes), steps)); } protected void writePomWithSqlSteps(String... steps) throws IOException { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index 3b21f972ed..b57a2a97a6 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -21,84 +21,95 @@ import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; import com.diffplug.spotless.maven.MavenRunner.Result; import com.diffplug.spotless.tag.NpmTest; @NpmTest class TypescriptFormatStepTest extends MavenIntegrationHarness { - private void run(String kind) throws IOException, InterruptedException { - String path = prepareRun(kind); + + private static final String TEST_FILE_PATH = "src/main/typescript/test.ts"; + + private void runTsfmt(String kind) throws IOException, InterruptedException { + String path = prepareRunTsfmt(kind); mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(path).sameAsResource("npm/tsfmt/" + kind + "/" + kind + ".clean"); } - private String prepareRun(String kind) throws IOException { - String path = "src/main/typescript/test.ts"; - setFile(path).toResource("npm/tsfmt/" + kind + "/" + kind + ".dirty"); - return path; + private String prepareRunTsfmt(String kind) throws IOException { + setFile(TEST_FILE_PATH).toResource("npm/tsfmt/" + kind + "/" + kind + ".dirty"); + return TEST_FILE_PATH; } - private Result runExpectingError(String kind) throws IOException, InterruptedException { - prepareRun(kind); + private Result runExpectingErrorTsfmt(String kind) throws IOException, InterruptedException { + prepareRunTsfmt(kind); return mavenRunner().withArguments("spotless:apply").runHasError(); } @Test void tslint() throws Exception { writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${basedir}/tslint.json", ""); setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json"); - run("tslint"); + runTsfmt("tslint"); } @Test void vscode() throws Exception { writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${basedir}/vscode.json", ""); setFile("vscode.json").toResource("npm/tsfmt/vscode/vscode.json"); - run("vscode"); + runTsfmt("vscode"); } @Test void tsfmt() throws Exception { writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${basedir}/tsfmt.json", ""); setFile("tsfmt.json").toResource("npm/tsfmt/tsfmt/tsfmt.json"); - run("tsfmt"); + runTsfmt("tsfmt"); } @Test void tsfmtInline() throws Exception { writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ", " 1", " true", " ", ""); - run("tsfmt"); + runTsfmt("tsfmt"); } @Test void tsconfig() throws Exception { writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${project.basedir}/tsconfig.json", ""); setFile("tsconfig.json").toResource("npm/tsfmt/tsconfig/tsconfig.json"); - run("tsconfig"); + runTsfmt("tsconfig"); } @Test void testTypescript_2_Configs() throws Exception { + String path = "src/main/typescript/test.ts"; + writePomWithTypescriptSteps( + path, "", " ${basedir}/tslint.json", " ${basedir}/tslint.json", @@ -106,7 +117,6 @@ void testTypescript_2_Configs() throws Exception { setFile("vscode.json").toResource("npm/tsfmt/vscode/vscode.json"); setFile("tsfmt.json").toResource("npm/tsfmt/tsfmt/tsfmt.json"); - String path = "src/main/typescript/test.ts"; setFile(path).toResource("npm/tsfmt/tsfmt/tsfmt.dirty"); Result result = mavenRunner().withArguments("spotless:apply").runHasError(); assertThat(result.output()).contains("must specify exactly one configFile or config"); @@ -120,11 +130,12 @@ void testNpmrcIsAutoPickedUp() throws Exception { "fetch-retry-mintimeout=250", "fetch-retry-maxtimeout=250"); writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${basedir}/tslint.json", ""); setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json"); - Result result = runExpectingError("tslint"); + Result result = runExpectingErrorTsfmt("tslint"); assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } @@ -136,12 +147,76 @@ void testNpmrcIsConfigurativelyPickedUp() throws Exception { "fetch-retry-mintimeout=250", "fetch-retry-maxtimeout=250"); writePomWithTypescriptSteps( + TEST_FILE_PATH, "", " ${basedir}/tslint.json", " ${basedir}/.custom_npmrc", ""); setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json"); - Result result = runExpectingError("tslint"); + Result result = runExpectingErrorTsfmt("tslint"); assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } + + @Test + void eslintConfigFile() throws Exception { + writePomWithTypescriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + ""); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/custom_rules/.eslintrc.js"); + setFile(TEST_FILE_PATH).toResource("npm/eslint/typescript/custom_rules/typescript.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/typescript/custom_rules/typescript.clean"); + } + + @Test + void eslintConfigJs() throws Exception { + final String configJs = ResourceHarness.getTestResource("npm/eslint/typescript/custom_rules/.eslintrc.js") + .replace("module.exports = ", ""); + writePomWithTypescriptSteps( + TEST_FILE_PATH, + "", + " " + configJs + "", + ""); + setFile(TEST_FILE_PATH).toResource("npm/eslint/typescript/custom_rules/typescript.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/typescript/custom_rules/typescript.clean"); + } + + @Test + void eslintStyleguideStandardWithTypescript() throws Exception { + writePomWithTypescriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + " standard-with-typescript", + " ${basedir}/tsconfig.json", + ""); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/tsconfig.json"); + setFile(TEST_FILE_PATH).toResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean"); + } + + @Test + void eslintStyleguideXo() throws Exception { + writePomWithTypescriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + " xo-typescript", + " ${basedir}/tsconfig.json", + ""); + setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js"); + setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/xo/tsconfig.json"); + setFile(TEST_FILE_PATH).toResource("npm/eslint/typescript/styleguide/xo/typescript.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/typescript/styleguide/xo/typescript.clean"); + } } From 7d2e5adc131e6458bb71e8e9cb694dffce1ae502 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 23 Dec 2022 07:53:57 +0100 Subject: [PATCH 0156/1120] eslint: adding maven javascript tests --- .../spotless/maven/AbstractSpotlessMojo.java | 2 +- .../maven/javascript/AbstractEslint.java | 92 +++++++++++++++ .../spotless/maven/javascript/EslintJs.java | 65 +--------- .../spotless/maven/typescript/EslintTs.java | 10 +- .../maven/MavenIntegrationHarness.java | 4 + .../javascript/JavascriptFormatStepTest.java | 111 ++++++++++++++++++ 6 files changed, 216 insertions(+), 68 deletions(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java 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 f13f9b200d..647535a590 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 @@ -335,7 +335,7 @@ private FileLocator getFileLocator() { } private List getFormatterFactories() { - return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, antlr4, pom, sql, python, markdown)) + return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, javascript, antlr4, pom, sql, python, markdown)) .filter(Objects::nonNull) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java new file mode 100644 index 0000000000..735a25c0c5 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java @@ -0,0 +1,92 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.javascript; + +import java.io.File; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory; +import com.diffplug.spotless.npm.EslintConfig; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.NpmPathResolver; + +public abstract class AbstractEslint extends AbstractNpmFormatterStepFactory { + + @Parameter + protected String configFile; + + @Parameter + protected String configJs; + + @Parameter + protected String styleGuide; + + @Parameter + protected String eslintVersion; + + @Parameter + protected Map devDependencies; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + Map devDependencies = new TreeMap<>(); + if (this.devDependencies != null) { + devDependencies.putAll(this.devDependencies); + } else { + Map defaultDependencies = createDefaultDependencies(); + devDependencies.putAll(defaultDependencies); + } + + addStyleGuideDevDependencies(devDependencies); + + File buildDir = buildDir(stepConfig); + File baseDir = baseDir(stepConfig); + NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); + return EslintFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, eslintConfig(stepConfig)); + } + + protected abstract EslintConfig eslintConfig(FormatterStepConfig stepConfig); + + private void addStyleGuideDevDependencies(Map devDependencies) { + if (this.styleGuide != null) { + EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.fromNameOrNull(this.styleGuide); + validateStyleGuide(styleGuide); + devDependencies.putAll(styleGuide.devDependencies()); + } + } + + private void validateStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { + if (styleGuide == null) { + throw new IllegalArgumentException("StyleGuide '" + this.styleGuide + "' is not supported. Supported style guides: " + supportedStyleGuides()); + } + if (!isValidStyleGuide(styleGuide)) { + throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide.getPopularStyleGuideName() + ". Use one of the following: " + supportedStyleGuides()); + } + } + + private String supportedStyleGuides() { + return EslintFormatterStep.PopularStyleGuide.getPopularStyleGuideNames(this::isValidStyleGuide); + } + + protected abstract boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide); + + protected abstract Map createDefaultDependencies(); +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java index 589e2f3f0c..f6c7beaff4 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -15,84 +15,23 @@ */ package com.diffplug.spotless.maven.javascript; -import java.io.File; import java.util.Map; -import java.util.TreeMap; -import org.apache.maven.plugins.annotations.Parameter; - -import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; -import com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; -import com.diffplug.spotless.npm.NpmPathResolver; - -public class EslintJs extends AbstractNpmFormatterStepFactory { - - @Parameter - private String configFile; - - @Parameter - private String configJs; - - @Parameter - private String styleGuide; - - @Parameter - protected String eslintVersion; - - @Parameter - private Map devDependencies; - - @Override - public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - Map devDependencies = new TreeMap<>(); - if (this.devDependencies != null) { - devDependencies.putAll(this.devDependencies); - } else { - Map defaultDependencies = createDefaultDependencies(); - devDependencies.putAll(defaultDependencies); - } - addStyleGuideDevDependencies(devDependencies); - - File buildDir = buildDir(stepConfig); - File baseDir = baseDir(stepConfig); - NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); - return EslintFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, eslintConfig(stepConfig)); - } +public class EslintJs extends AbstractEslint { protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { return new EslintConfig(this.configFile != null ? stepConfig.getFileLocator().locateFile(this.configFile) : null, this.configJs); } - private void addStyleGuideDevDependencies(Map devDependencies) { - if (this.styleGuide != null) { - EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.fromNameOrNull(this.styleGuide); - validateStyleGuide(styleGuide); - devDependencies.putAll(styleGuide.devDependencies()); - } - } - - private void validateStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { - if (styleGuide == null) { - throw new IllegalArgumentException("StyleGuide '" + this.styleGuide + "' is not supported. Supported style guides: " + supportedStyleGuides()); - } - if (!isValidStyleGuide(styleGuide)) { - throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide.getPopularStyleGuideName() + ". Use one of the following: " + supportedStyleGuides()); - } - } - - private String supportedStyleGuides() { - return EslintFormatterStep.PopularStyleGuide.getPopularStyleGuideNames(this::isValidStyleGuide); - } - protected boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { return styleGuide.name().startsWith("JS_"); } protected Map createDefaultDependencies() { - return eslintVersion == null ? EslintFormatterStep.defaultDevDependencies() : EslintFormatterStep.defaultDevDependenciesWithEslint(eslintVersion); + return this.eslintVersion == null ? EslintFormatterStep.defaultDevDependencies() : EslintFormatterStep.defaultDevDependenciesWithEslint(this.eslintVersion); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java index 0fe834ffde..f69f17f41e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java @@ -20,20 +20,22 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.maven.FormatterStepConfig; -import com.diffplug.spotless.maven.javascript.EslintJs; +import com.diffplug.spotless.maven.javascript.AbstractEslint; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintTypescriptConfig; -public class EslintTs extends EslintJs { +public class EslintTs extends AbstractEslint { @Parameter private String tsconfigFile; @Override protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { - EslintConfig jsConfig = super.eslintConfig(stepConfig); - return new EslintTypescriptConfig(jsConfig.getEslintConfigPath(), jsConfig.getEslintConfigJs(), tsconfigFile != null ? stepConfig.getFileLocator().locateFile(tsconfigFile) : null); + return new EslintTypescriptConfig( + configFile != null ? stepConfig.getFileLocator().locateFile(configFile) : null, + configJs, + tsconfigFile != null ? stepConfig.getFileLocator().locateFile(tsconfigFile) : null); } @Override 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 61d9c80a37..7a8073925d 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 @@ -136,6 +136,10 @@ protected void writePomWithCppSteps(String... steps) throws IOException { writePom(groupWithSteps("cpp", steps)); } + protected void writePomWithJavascriptSteps(String includes, String... steps) throws IOException { + writePom(groupWithSteps("javascript", including(includes), steps)); + } + protected void writePomWithTypescriptSteps(String includes, String... steps) throws IOException { writePom(groupWithSteps("typescript", including(includes), steps)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java new file mode 100644 index 0000000000..0f6d0d275f --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -0,0 +1,111 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.maven.javascript; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.maven.MavenIntegrationHarness; +import com.diffplug.spotless.maven.MavenRunner.Result; +import com.diffplug.spotless.tag.NpmTest; + +@NpmTest +class JavascriptFormatStepTest extends MavenIntegrationHarness { + + private static final String TEST_FILE_PATH = "src/main/javascript/test.js"; + + @NpmTest + @Nested + class EslintCustomRulesTest extends MavenIntegrationHarness { + + @Test + void eslintConfigFile() throws Exception { + writePomWithJavascriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + ""); + setFile(".eslintrc.js").toResource("npm/eslint/javascript/custom_rules/.eslintrc.js"); + setFile(TEST_FILE_PATH).toResource("npm/eslint/javascript/custom_rules/javascript-es6.dirty"); + + Result result = mavenRunner().withArguments("spotless:apply").runNoError(); + System.out.println(result.output()); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/javascript/custom_rules/javascript-es6.clean"); + } + + @Test + void eslintConfigJs() throws Exception { + final String configJs = ResourceHarness.getTestResource("npm/eslint/javascript/custom_rules/.eslintrc.js") + .replace("module.exports = ", ""); + writePomWithJavascriptSteps( + TEST_FILE_PATH, + "", + " " + configJs + "", + ""); + setFile(TEST_FILE_PATH).toResource("npm/eslint/javascript/custom_rules/javascript-es6.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/javascript/custom_rules/javascript-es6.clean"); + } + + } + + @NpmTest + @Nested + class EslintStyleguidesTest extends MavenIntegrationHarness { + + @ParameterizedTest(name = "{index}: eslint js formatting with configFile using styleguide {0}") + @ValueSource(strings = {"airbnb", "google", "standard", "xo"}) + void eslintJsStyleguideUsingConfigFile(String styleGuide) throws Exception { + final String styleGuidePath = "npm/eslint/javascript/styleguide/" + styleGuide; + + writePomWithJavascriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + " " + styleGuide + "", + ""); + setFile(".eslintrc.js").toResource(styleGuidePath + "/.eslintrc.js"); + setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource(styleGuidePath + "/javascript-es6.clean"); + } + + @ParameterizedTest(name = "{index}: eslint js formatting with inline config using styleguide {0}") + @ValueSource(strings = {"airbnb", "google", "standard", "xo"}) + void eslintJsStyleguideUsingInlineConfig(String styleGuide) throws Exception { + final String styleGuidePath = "npm/eslint/javascript/styleguide/" + styleGuide; + + final String escapedInlineConfig = ResourceHarness.getTestResource(styleGuidePath + "/.eslintrc.js") + .replace("<", "<") + .replace(">", ">"); + writePomWithJavascriptSteps( + TEST_FILE_PATH, + "", + " " + escapedInlineConfig + "", + " " + styleGuide + "", + ""); + setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource(styleGuidePath + "/javascript-es6.clean"); + } + } +} From 1d164d3528c8b9763217637665e9a84587a85002 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 23 Dec 2022 08:22:07 +0100 Subject: [PATCH 0157/1120] eslint: also test custom devDependencies case --- .../javascript/JavascriptFormatStepTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java index 0f6d0d275f..379208b9e4 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -107,5 +107,29 @@ void eslintJsStyleguideUsingInlineConfig(String styleGuide) throws Exception { mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(TEST_FILE_PATH).sameAsResource(styleGuidePath + "/javascript-es6.clean"); } + + @Test + void provideCustomDependenciesForStyleguideStandard() throws Exception { + final String styleGuidePath = "npm/eslint/javascript/styleguide/standard"; + + writePomWithJavascriptSteps( + TEST_FILE_PATH, + "", + " .eslintrc.js", + " ", + " 8.28.0", + " 17.0.0", + " 2.26.0", + " 15.6.0", + " 6.1.1", + " ", + ""); + setFile(".eslintrc.js").toResource(styleGuidePath + "/.eslintrc.js"); + + setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(TEST_FILE_PATH).sameAsResource(styleGuidePath + "/javascript-es6.clean"); + } } } From 3f3705395fac64a7f083facd13896e5d26243e38 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 09:55:35 +0100 Subject: [PATCH 0158/1120] eslint: adding readme (common and plugin-gradle) --- CHANGES.md | 3 + README.md | 2 + plugin-gradle/CHANGES.md | 2 + plugin-gradle/README.md | 120 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 126 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a7e3516607..3efdec3b67 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,9 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) + ### Changes * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` diff --git a/README.md b/README.md index 605305bd29..ddc3c2391c 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}} lib('kotlin.DiktatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('markdown.FreshMarkStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('npm.EslintFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', @@ -113,6 +114,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`npm.EslintFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c5f464069f..d668f69483 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 755d21d056..6f498059b9 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -69,7 +69,8 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [eslint](#eslint--typescript-)) + - [Javascript](#javascript) ([prettier](#prettier), [eslint](#eslint--javascript-)) - [JSON](#json) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) @@ -576,6 +577,7 @@ spotless { tsfmt() // has its own section below prettier() // has its own section below + eslint() // has its own section below licenseHeader '/* (C) $YEAR */', '(import|const|declare|export|var) ' // or licenseHeaderFile // note the '(import|const|...' argument - this is a regex which identifies the top @@ -608,6 +610,122 @@ spotless { For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt. +### eslint (Typescript) + +[npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* +The auto-discovery of config files (up the file tree) will not work when using eslint within spotless, +hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. + +The configuration is very similar to the [eslint (Javascript)](#eslint--javascript-) configuration. It differs in supported +styleguides and the requirement for a tsconfigFile. + +```gradle +spotless { + typescript { + eslint('8.30.0') // version is optional + eslint(['my-eslint-fork': '1.2.3', 'my-eslint-plugin': '1.2.1']) // can specify exactly which npm packages to use + + eslint() + // optional: use a popular eslint styleguide for typescript + .styleGuide('standard-with-typescript') // or 'xo-typescript' + // configuration is mandatory. Provide inline config or a config file. + // a) inline-configuration + .configJs(''' + { + env: { + browser: true, + es2021: true + }, + extends: 'standard-with-typescript', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: './tsconfig.json', + }, + rules: { + } + } + ''') + // b) config file + .configFile('.eslintrc.js') + // recommended: provide a tsconfig.json - especially when using the styleguides + .tsconfigFile('tsconfig.json') + } +} +``` + +**Prerequisite: eslint requires a working NodeJS version** + +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to eslint. + +## Javascript + +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) + +```gradle +spotless { + javascript { + target 'src/**/*.js' // you have to set the target manually + + prettier() // has its own section below + eslint() // has its own section below + + licenseHeader '/* (C) $YEAR */', 'REGEX_TO_DEFINE_TOP_OF_FILE' // or licenseHeaderFile + } +} +``` + +### eslint (Javascript) + +[npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* +The auto-discovery of config files (up the file tree) will not work when using eslint within spotless, +hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. + +The configuration is very similar to the [eslint (Typescript)](#eslint--typescript-) configuration. It differs in supported +styleguides and no requirement for a tsconfig (of course). + +```gradle + +```gradle +spotless { + javascript { + eslint('8.30.0') // version is optional + eslint(['my-eslint-fork': '1.2.3', 'my-eslint-plugin': '1.2.1']) // can specify exactly which npm packages to use + + eslint() + // optional: use a popular eslint styleguide for javascript + .styleGuide('standard') // or 'airbnb', 'google', 'xo' + // configuration is mandatory. Provide inline config or a config file. + // a) inline-configuration + .configJs(''' + { + env: { + browser: true, + es2021: true + }, + extends: 'standard', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module' + }, + rules: { + } + } + ''') + // b) config file + .configFile('.eslintrc.js') + } +} +``` + +**Prerequisite: eslint requires a working NodeJS version** + +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to eslint. + ## JSON - `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) From bb843ce0cf741b809ea8cf022ae5556464789ac5 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 09:56:22 +0100 Subject: [PATCH 0159/1120] eslint: apply spotless --- .../spotless/npm/BaseNpmRestService.java | 2 +- .../diffplug/spotless/npm/EslintConfig.java | 2 +- .../spotless/npm/EslintFormatterStep.java | 2 +- .../spotless/npm/EslintRestService.java | 2 +- .../spotless/npm/EslintTypescriptConfig.java | 2 +- .../npm/NpmFormatterStepStateBase.java | 2 +- .../com/diffplug/spotless/npm/NpmProcess.java | 2 +- .../spotless/npm/NpmResourceHelper.java | 2 +- .../spotless/npm/PrettierFormatterStep.java | 2 +- .../spotless/npm/PrettierRestService.java | 2 +- .../spotless/npm/TsFmtFormatterStep.java | 2 +- .../spotless/npm/TsFmtRestService.java | 2 +- .../gradle/spotless/FormatExtension.java | 2 +- .../gradle/spotless/JavascriptExtension.java | 2 +- .../gradle/spotless/SpotlessExtension.java | 2 +- .../gradle/spotless/TypescriptExtension.java | 2 +- .../spotless/JavascriptExtensionTest.java | 2 +- .../spotless/PrettierIntegrationTest.java | 2 +- .../spotless/TypescriptExtensionTest.java | 2 +- .../spotless/maven/AbstractSpotlessMojo.java | 2 +- .../spotless/maven/generic/Prettier.java | 2 +- .../maven/javascript/AbstractEslint.java | 2 +- .../spotless/maven/javascript/EslintJs.java | 2 +- .../spotless/maven/javascript/Javascript.java | 2 +- .../npm/AbstractNpmFormatterStepFactory.java | 2 +- .../spotless/maven/typescript/EslintTs.java | 2 +- .../spotless/maven/typescript/Tsfmt.java | 2 +- .../spotless/maven/typescript/Typescript.java | 2 +- .../maven/MavenIntegrationHarness.java | 2 +- .../javascript/JavascriptFormatStepTest.java | 24 +++++++++---------- .../prettier/PrettierFormatStepTest.java | 2 +- .../typescript/TypescriptFormatStepTest.java | 2 +- .../spotless/npm/EslintFormatterStepTest.java | 2 +- .../npm/NpmFormatterStepCommonTests.java | 2 +- .../spotless/npm/TsFmtFormatterStepTest.java | 2 +- 35 files changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java index e8582c15ec..a6d93182a1 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java index 4e1848856a..3499b3face 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 820283aae4..ac3ee05345 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java index 198ee5389c..e17237ecbf 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java index f8c213a0a9..fc45f8bd7b 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index fc1543fd61..49a166e45c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index 28db79b726..e2fd07682c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index 48e974eec6..2acf3a180d 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 8489644c36..a83fc07674 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java index 2a62823aa0..ccdc189d27 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index 027af89e23..98d694ec33 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java index f77510c3b6..704d2b47af 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 08e713a921..c72c9339a0 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index cbe0040a83..862c7566ee 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. 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 3fe5721b5d..1c65fad310 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 79ae056bdc..5de1bb1ac3 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java index af203936f3..331e17f28e 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index 6f55312bd5..bc8ad1148e 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index da9fa03905..598ff7dc14 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. 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 647535a590..5ad96ece46 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index b45f802653..ffe384b4d9 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java index 735a25c0c5..b5fc156a57 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java index f6c7beaff4..f9954ab0c8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java index db7049ff0d..7ca35dd258 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java index 8bc0f8f715..22ee5e0dba 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java index f69f17f41e..72f3735d97 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java index 6c60c02cc6..685d473072 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index 1320cac2d8..6f0d7f91b2 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. 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 7a8073925d..d9a23cdb74 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java index 379208b9e4..7ebc592add 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -113,17 +113,17 @@ void provideCustomDependenciesForStyleguideStandard() throws Exception { final String styleGuidePath = "npm/eslint/javascript/styleguide/standard"; writePomWithJavascriptSteps( - TEST_FILE_PATH, - "", - " .eslintrc.js", - " ", - " 8.28.0", - " 17.0.0", - " 2.26.0", - " 15.6.0", - " 6.1.1", - " ", - ""); + TEST_FILE_PATH, + "", + " .eslintrc.js", + " ", + " 8.28.0", + " 17.0.0", + " 2.26.0", + " 15.6.0", + " 6.1.1", + " ", + ""); setFile(".eslintrc.js").toResource(styleGuidePath + "/.eslintrc.js"); setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index 8fce61b5d8..c0a9267b93 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index b57a2a97a6..ac925cc9b6 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 15ebb0cc0d..5f53c9effa 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java index 1ed6e9bbe8..dff105108a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java index 474c664486..a774c7c1ee 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. From 508dd69b8c328cf537809025ca0134e65c7587b0 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 10:02:13 +0100 Subject: [PATCH 0160/1120] bumping default prettier version --- CHANGES.md | 3 ++- .../spotless/npm/PrettierFormatterStep.java | 2 +- .../config/typescript.configfile.clean | 3 ++- .../prettier/config/typescript.defaults.clean | 3 ++- .../javascript-es5/javascript-es5.clean | 24 +++---------------- .../javascript-es6/javascript-es6.clean | 24 +++---------------- 6 files changed, 13 insertions(+), 46 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3efdec3b67..bf1798d7c2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,8 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) - ### Changes +* Bump default Version for `prettier` from `2.0.5` to `2.8.1` * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) @@ -22,6 +22,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `StepHarnessWithFile` now takes a `ResourceHarness` in its constructor to handle the file manipulation parts * Standardized that we test exception *messages*, not types, which will ease the transition to linting later on + ## [2.31.1] - 2023-01-02 ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index a83fc07674..22a162eb0b 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -42,7 +42,7 @@ public class PrettierFormatterStep { public static final String NAME = "prettier-format"; public static final Map defaultDevDependencies() { - return defaultDevDependenciesWithPrettier("2.0.5"); + return defaultDevDependenciesWithPrettier("2.8.1"); } public static final Map defaultDevDependenciesWithPrettier(String version) { diff --git a/testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean b/testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean index 0ec76369be..dfe71bf0a9 100644 --- a/testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean +++ b/testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean @@ -1,6 +1,7 @@ export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController - implements DisposeAware, CallbackAware { + implements DisposeAware, CallbackAware +{ public myValue: string[]; constructor( diff --git a/testlib/src/main/resources/npm/prettier/config/typescript.defaults.clean b/testlib/src/main/resources/npm/prettier/config/typescript.defaults.clean index 0155b905bd..61d8e020d6 100644 --- a/testlib/src/main/resources/npm/prettier/config/typescript.defaults.clean +++ b/testlib/src/main/resources/npm/prettier/config/typescript.defaults.clean @@ -1,6 +1,7 @@ export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController - implements DisposeAware, CallbackAware { + implements DisposeAware, CallbackAware +{ public myValue: string[]; constructor(private myService: Service, name: string, private field: any) { diff --git a/testlib/src/main/resources/npm/prettier/filetypes/javascript-es5/javascript-es5.clean b/testlib/src/main/resources/npm/prettier/filetypes/javascript-es5/javascript-es5.clean index 29002f6b05..0cfac613f1 100644 --- a/testlib/src/main/resources/npm/prettier/filetypes/javascript-es5/javascript-es5.clean +++ b/testlib/src/main/resources/npm/prettier/filetypes/javascript-es5/javascript-es5.clean @@ -1,24 +1,5 @@ var numbers = [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ]; var p = { @@ -32,7 +13,8 @@ var p = { var str = "Hello, world!"; var str2 = str.charAt(3) + str[0]; -var multilinestr = "Hello \ +var multilinestr = + "Hello \ World"; function test(a, b) { return a + b; diff --git a/testlib/src/main/resources/npm/prettier/filetypes/javascript-es6/javascript-es6.clean b/testlib/src/main/resources/npm/prettier/filetypes/javascript-es6/javascript-es6.clean index d4e982d69f..1935faa03c 100644 --- a/testlib/src/main/resources/npm/prettier/filetypes/javascript-es6/javascript-es6.clean +++ b/testlib/src/main/resources/npm/prettier/filetypes/javascript-es6/javascript-es6.clean @@ -1,24 +1,5 @@ var numbers = [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ]; const p = { @@ -32,7 +13,8 @@ const p = { const str = "Hello, world!"; var str2 = str.charAt(3) + str[0]; -var multilinestr = "Hello \ +var multilinestr = + "Hello \ World"; function test(a, b = "world") { let combined = a + b; From 67a0a0510e9f55c911c4bc7f519756c49767d88d Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 12:56:45 +0100 Subject: [PATCH 0161/1120] eslint: update readme for maven --- plugin-maven/CHANGES.md | 2 + plugin-maven/README.md | 140 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 141 insertions(+), 1 deletion(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 84e06aa847..f57a8dbbd4 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) ## [2.29.0] - 2023-01-02 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 80be3dbc37..b246bcb035 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -57,7 +57,8 @@ user@machine repo % mvn spotless:check - [Sql](#sql) ([dbeaver](#dbeaver)) - [Maven Pom](#maven-pom) ([sortPom](#sortpom)) - [Markdown](#markdown) ([flexmark](#flexmark)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint--typescript-)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint--javascript-)) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) - [eclipse web tools platform](#eclipse-web-tools-platform) @@ -660,6 +661,7 @@ Currently, none of the available options can be configured yet. It uses only the + /* (C)$YEAR */ @@ -700,8 +702,144 @@ The auto-discovery of config files (up the file tree) will not work when using t For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt. +### ESLint (typescript) + +[npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* +The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, +hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. + +The configuration is very similar to the [ESLint (Javascript)](#eslint--javascript-) configuration. It differs in supported +styleguides and the requirement for a tsconfigFile. + +```xml + + + 8.30.0 + + 8.30.0 + 1.2.1 + + + + eslint + 8.30.0 + + + @eslint/my-plugin-typescript + 0.14.2 + + + + standard-with-typescript + + ${project.basedir}/.eslintrc.js + + { + env: { + browser: true, + es2021: true + }, + extends: 'standard-with-typescript', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + project: './tsconfig.json', + }, + rules: { + } + } + + + ${project.basedir}/tsconfig.json + +``` + +**Prerequisite: ESLint requires a working NodeJS version** + +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. + +## Javascript + +[code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java). [available steps](https://github.com/diffplug/spotless/tree/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript). + +```xml + + + + src/**/*.js + + + + + + + /* (C)$YEAR */ + REGEX_TO_DEFINE_TOP_OF_FILE + + + +``` + + +### ESLint (Javascript) + +[npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* +The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, +hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. + +The configuration is very similar to the [ESLint (Typescript)](#eslint--typescript-) configuration. It differs in supported +styleguides and no requirement for a tsconfig (of course). + +```xml + + + 8.30.0 + + 8.30.0 + 1.2.1 + + + + eslint + 8.30.0 + + + @eslint/my-plugin-javascript + 0.14.2 + + + + standard + + ${project.basedir}/.eslintrc.js + + { + env: { + browser: true, + es2021: true + }, + extends: 'standard', + overrides: [ + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module' + }, + rules: { + } + } + + +``` + +**Prerequisite: ESLint requires a working NodeJS version** + +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. + ## 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, ...). From e07082a5526e370b5355606d90298d70b8d8d32f Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 12:56:56 +0100 Subject: [PATCH 0162/1120] eslint: unify naming in documentation --- plugin-gradle/README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 6f498059b9..edd6c43bb6 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -69,8 +69,8 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [eslint](#eslint--typescript-)) - - [Javascript](#javascript) ([prettier](#prettier), [eslint](#eslint--javascript-)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint--typescript-)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint--javascript-)) - [JSON](#json) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) @@ -610,13 +610,13 @@ spotless { For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt. -### eslint (Typescript) +### ESLint (Typescript) [npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* -The auto-discovery of config files (up the file tree) will not work when using eslint within spotless, +The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [eslint (Javascript)](#eslint--javascript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Javascript)](#eslint--javascript-) configuration. It differs in supported styleguides and the requirement for a tsconfigFile. ```gradle @@ -656,9 +656,9 @@ spotless { } ``` -**Prerequisite: eslint requires a working NodeJS version** +**Prerequisite: ESLint requires a working NodeJS version** -For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to eslint. +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. ## Javascript @@ -677,13 +677,13 @@ spotless { } ``` -### eslint (Javascript) +### ESLint (Javascript) [npm](https://www.npmjs.com/package/eslint). [changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md). *Please note:* -The auto-discovery of config files (up the file tree) will not work when using eslint within spotless, +The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [eslint (Typescript)](#eslint--typescript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Typescript)](#eslint--typescript-) configuration. It differs in supported styleguides and no requirement for a tsconfig (of course). ```gradle @@ -722,9 +722,9 @@ spotless { } ``` -**Prerequisite: eslint requires a working NodeJS version** +**Prerequisite: ESLint requires a working NodeJS version** -For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to eslint. +For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. ## JSON From 2943c661623dddfd34c8a532fbdad8f1fdf32469 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 13:41:44 +0100 Subject: [PATCH 0163/1120] eslint: adapt to api changes in TestResource --- .../spotless/npm/EslintFormatterStepTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 5f53c9effa..a993f43090 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -19,6 +19,8 @@ import java.util.Map; import java.util.TreeMap; +import com.diffplug.spotless.ResourceHarness; + import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -73,8 +75,8 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { npmPathResolver(), new EslintConfig(eslintRc, null)); - try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { - stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { + stepHarness.test(dirtyFileFile, ResourceHarness.getTestResource(dirtyFile), ResourceHarness.getTestResource(cleanFile)); } } } @@ -116,8 +118,8 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { npmPathResolver(), new EslintTypescriptConfig(eslintRc, null, tsconfigFile)); - try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { - stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { + stepHarness.test(dirtyFileFile, ResourceHarness.getTestResource(dirtyFile), ResourceHarness.getTestResource(cleanFile)); } } } @@ -173,8 +175,8 @@ void formattingUsingInlineXoConfig() throws Exception { npmPathResolver(), new EslintTypescriptConfig(null, esLintConfig, tsconfigFile)); - try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(formatterStep)) { - stepHarness.testResource(dirtyFileFile, dirtyFile, cleanFile); + try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { + stepHarness.test(dirtyFileFile, ResourceHarness.getTestResource(dirtyFile), ResourceHarness.getTestResource(cleanFile)); } } } From ce21de7bbe2108a04b8b9b1c02a43cf01d889faf Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 13:44:21 +0100 Subject: [PATCH 0164/1120] eslint: adapt PR number --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bf1798d7c2..95a657e334 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Changes * Bump default Version for `prettier` from `2.0.5` to `2.8.1` * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d668f69483..7ed1bc7a20 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) +* Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f57a8dbbd4..a58bb2a30f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1433](https://github.com/diffplug/spotless/pull/1433)) +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ## [2.29.0] - 2023-01-02 ### Added From 3a1d43bca5274dd83fe5f7667d85afe14c8d4400 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 13:53:53 +0100 Subject: [PATCH 0165/1120] eslint: add default version bump to CHANGES --- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7ed1bc7a20..bb05d07554 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,6 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) +### Changes +* Bump default Version for `prettier` from `2.0.5` to `2.8.1` ## [6.12.1] - 2023-01-02 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a58bb2a30f..4f5d30cb74 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) +### Changes +* Bump default Version for `prettier` from `2.0.5` to `2.8.1` ## [2.29.0] - 2023-01-02 ### Added From b4f76b4f8cca59803ef720b651c39d00e88e0617 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 14:04:21 +0100 Subject: [PATCH 0166/1120] eslint: adapt maven code to match documentation --- .../spotless/maven/generic/Prettier.java | 16 +-------------- .../maven/javascript/AbstractEslint.java | 17 ++++++++++++++++ .../npm/AbstractNpmFormatterStepFactory.java | 20 +++++++++++++++++++ .../spotless/npm/EslintFormatterStepTest.java | 3 +-- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index ffe384b4d9..01ce2a5394 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -61,7 +61,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { if (prettierVersion != null && !prettierVersion.isEmpty()) { this.devDependencies = PrettierFormatterStep.defaultDevDependenciesWithPrettier(prettierVersion); } else if (devDependencyProperties != null) { - this.devDependencies = dependencyPropertiesAsMap(); + this.devDependencies = propertiesAsMap(this.devDependencyProperties); } // process config file or inline config @@ -100,20 +100,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { return PrettierFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, prettierConfig); } - private boolean moreThanOneNonNull(Object... objects) { - return Arrays.stream(objects) - .filter(Objects::nonNull) - .filter(o -> !(o instanceof String) || !((String) o).isEmpty()) // if it is a string, it should not be empty - .count() > 1; - } - - private Map dependencyPropertiesAsMap() { - return this.devDependencyProperties.stringPropertyNames() - .stream() - .map(name -> new AbstractMap.SimpleEntry<>(name, this.devDependencyProperties.getProperty(name))) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } - private static IllegalArgumentException onlyOneConfig() { return new IllegalArgumentException(ERROR_MESSAGE_ONLY_ONE_CONFIG); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java index b5fc156a57..1829f91b4e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java @@ -17,6 +17,7 @@ import java.io.File; import java.util.Map; +import java.util.Properties; import java.util.TreeMap; import org.apache.maven.plugins.annotations.Parameter; @@ -30,6 +31,8 @@ public abstract class AbstractEslint extends AbstractNpmFormatterStepFactory { + public static final String ERROR_MESSAGE_ONLY_ONE_CONFIG = "must specify exactly one eslintVersion, devDependencies or devDependencyProperties"; + @Parameter protected String configFile; @@ -45,11 +48,21 @@ public abstract class AbstractEslint extends AbstractNpmFormatterStepFactory { @Parameter protected Map devDependencies; + @Parameter + protected Properties devDependencyProperties; + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + // check if config is only setup in one way + if (moreThanOneNonNull(this.eslintVersion, this.devDependencies, this.devDependencyProperties)) { + throw onlyOneConfig(); + } + Map devDependencies = new TreeMap<>(); if (this.devDependencies != null) { devDependencies.putAll(this.devDependencies); + } else if (this.devDependencyProperties != null) { + devDependencies.putAll(propertiesAsMap(this.devDependencyProperties)); } else { Map defaultDependencies = createDefaultDependencies(); devDependencies.putAll(defaultDependencies); @@ -63,6 +76,10 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { return EslintFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, eslintConfig(stepConfig)); } + private static IllegalArgumentException onlyOneConfig() { + return new IllegalArgumentException(ERROR_MESSAGE_ONLY_ONE_CONFIG); + } + protected abstract EslintConfig eslintConfig(FormatterStepConfig stepConfig); private void addStyleGuideDevDependencies(Map devDependencies) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java index 22ee5e0dba..5467f4c3bc 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java @@ -16,6 +16,12 @@ package com.diffplug.spotless.maven.npm; import java.io.File; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.stream.Collectors; import org.apache.maven.plugins.annotations.Parameter; @@ -52,4 +58,18 @@ protected File baseDir(FormatterStepConfig stepConfig) { protected NpmPathResolver npmPathResolver(FormatterStepConfig stepConfig) { return new NpmPathResolver(npm(stepConfig), npmrc(stepConfig), baseDir(stepConfig)); } + + protected boolean moreThanOneNonNull(Object... objects) { + return Arrays.stream(objects) + .filter(Objects::nonNull) + .filter(o -> !(o instanceof String) || !((String) o).isEmpty()) // if it is a string, it should not be empty + .count() > 1; + } + + protected Map propertiesAsMap(Properties devDependencyProperties) { + return devDependencyProperties.stringPropertyNames() + .stream() + .map(name -> new AbstractMap.SimpleEntry<>(name, devDependencyProperties.getProperty(name))) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index a993f43090..19f6e8c223 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -19,8 +19,6 @@ import java.util.Map; import java.util.TreeMap; -import com.diffplug.spotless.ResourceHarness; - import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -28,6 +26,7 @@ import com.diffplug.common.collect.ImmutableMap; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.tag.NpmTest; From 45983197c3098f163dc6abf5c751684b21cbc6cc Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 4 Jan 2023 14:04:31 +0100 Subject: [PATCH 0167/1120] eslint: spotlessApply --- .../src/main/java/com/diffplug/spotless/extra/GitRatchet.java | 2 +- plugin-gradle/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java index 31f2f597f9..037d4d847b 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index edd6c43bb6..1e34cdc88a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -662,7 +662,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { From f01b03891d980e06f215ae2706c39a5f2d20753e Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 4 Jan 2023 18:24:17 +0400 Subject: [PATCH 0168/1120] Fix tests --- .../spotless/maven/MavenIntegrationHarness.java | 4 ++++ .../com/diffplug/spotless/maven/json/JsonTest.java | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) 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 939940a315..1976d577bb 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 @@ -156,6 +156,10 @@ protected void writePomWithMarkdownSteps(String... steps) throws IOException { writePom(groupWithSteps("markdown", including("**/*.md"), steps)); } + protected void writePomWithJsonSteps(String... steps) throws IOException { + writePom(groupWithSteps("json", including("**/*.json"), steps)); + } + protected void writePom(String... configuration) throws IOException { writePom(null, configuration, null); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index b7e666190a..fe6560cbec 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -22,19 +22,19 @@ public class JsonTest extends MavenIntegrationHarness { @Test public void testFormatJson_WithSimple_defaultConfig() throws Exception { - writePomWithPomSteps(""); + writePomWithJsonSteps(""); - setFile("json_test.json").toResource("json/json_dirty.json"); + setFile("json_test.json").toResource("json/sortByKeysBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("json_test.json").sameAsResource("json/json_clean_default.json"); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled.json"); } @Test public void testFormatJson_WithGson_defaultConfig() throws Exception { - writePomWithPomSteps(""); + writePomWithJsonSteps(""); - setFile("json_test.json").toResource("json/json_dirty.json"); + setFile("json_test.json").toResource("json/sortByKeysBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("json_test.json").sameAsResource("json/json_clean_default.json"); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled.json"); } } From 1d2290d61e019edc01f86c2ee838a00107935ac4 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 4 Jan 2023 18:29:05 +0400 Subject: [PATCH 0169/1120] Fix 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 70f3dfe1dc..dcc18a5dd6 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -703,7 +703,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.spotless.maven.json.Json` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java) +- `com.diffplug.spotless.maven.json.Json` [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/json.java) ```xml From a4899012b2cc08c176264567e829979de1d33095 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 4 Jan 2023 18:47:39 +0400 Subject: [PATCH 0170/1120] Fix style --- .../com/diffplug/spotless/maven/MavenIntegrationHarness.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1976d577bb..9e9495da65 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. From cf8bc0853f7cfa1364a12d076368bc099f9a9ef2 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Wed, 4 Jan 2023 21:15:57 +0100 Subject: [PATCH 0171/1120] =?UTF-8?q?rename=20skipLinesPattern=20to=20skip?= =?UTF-8?q?=C3=85LinesMatching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spotless/generic/LicenseHeaderStep.java | 36 +++++++++---------- .../gradle/spotless/FormatExtension.java | 4 +-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index d1fdf86e3e..8a46e08bda 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -60,16 +60,16 @@ public static LicenseHeaderStep headerDelimiter(ThrowingEx.Supplier head final String delimiter; final String yearSeparator; final Supplier yearMode; - final @Nullable String skipLinesPattern; + final @Nullable String skipLinesMatching; - private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode, @Nullable String skipLinesPattern) { + private LicenseHeaderStep(@Nullable String name, @Nullable String contentPattern, ThrowingEx.Supplier headerLazy, String delimiter, String yearSeparator, Supplier yearMode, @Nullable String skipLinesMatching) { this.name = sanitizeName(name); this.contentPattern = sanitizePattern(contentPattern); this.headerLazy = Objects.requireNonNull(headerLazy); this.delimiter = Objects.requireNonNull(delimiter); this.yearSeparator = Objects.requireNonNull(yearSeparator); this.yearMode = Objects.requireNonNull(yearMode); - this.skipLinesPattern = sanitizePattern(skipLinesPattern); + this.skipLinesMatching = sanitizePattern(skipLinesMatching); } public String getName() { @@ -77,11 +77,11 @@ public String getName() { } public LicenseHeaderStep withName(String name) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withContentPattern(String contentPattern) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withHeaderString(String header) { @@ -89,15 +89,15 @@ public LicenseHeaderStep withHeaderString(String header) { } public LicenseHeaderStep withHeaderLazy(ThrowingEx.Supplier headerLazy) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withDelimiter(String delimiter) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withYearSeparator(String yearSeparator) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public LicenseHeaderStep withYearMode(YearMode yearMode) { @@ -105,11 +105,11 @@ public LicenseHeaderStep withYearMode(YearMode yearMode) { } public LicenseHeaderStep withYearModeLazy(Supplier yearMode) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } - public LicenseHeaderStep withSkipLinesPattern(String skipLinesPattern) { - return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesPattern); + public LicenseHeaderStep withSkipLinesMatching(String skipLinesMatching) { + return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } public FormatterStep build() { @@ -118,7 +118,7 @@ public FormatterStep build() { if (yearMode.get() == YearMode.SET_FROM_GIT) { formatterStep = FormatterStep.createNeverUpToDateLazy(name, () -> { boolean updateYear = false; // doesn't matter - Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); + Runtime runtime = new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesMatching); return FormatterFunc.needsFile(runtime::setLicenseHeaderYearsFromGitHistory); }); } else { @@ -136,7 +136,7 @@ public FormatterStep build() { default: throw new IllegalStateException(yearMode.toString()); } - return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesPattern); + return new Runtime(headerLazy.get(), delimiter, yearSeparator, updateYear, skipLinesMatching); }, step -> step::format); } @@ -201,7 +201,7 @@ private static class Runtime implements Serializable { private static final long serialVersionUID = 1475199492829130965L; private final Pattern delimiterPattern; - private final @Nullable Pattern skipLinesPattern; + private final @Nullable Pattern skipLinesMatching; private final String yearSepOrFull; private final @Nullable String yearToday; private final @Nullable String beforeYear; @@ -210,7 +210,7 @@ private static class Runtime implements Serializable { private final boolean licenseHeaderWithRange; /** The license that we'd like enforced. */ - private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest, @Nullable String skipLinesPattern) { + private Runtime(String licenseHeader, String delimiter, String yearSeparator, boolean updateYearWithLatest, @Nullable String skipLinesMatching) { if (delimiter.contains("\n")) { throw new IllegalArgumentException("The delimiter must not contain any newlines."); } @@ -220,7 +220,7 @@ private Runtime(String licenseHeader, String delimiter, String yearSeparator, bo licenseHeader = licenseHeader + "\n"; } this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE); - this.skipLinesPattern = skipLinesPattern == null ? null : Pattern.compile(skipLinesPattern); + this.skipLinesMatching = skipLinesMatching == null ? null : Pattern.compile(skipLinesMatching); Optional yearToken = getYearToken(licenseHeader); if (yearToken.isPresent()) { @@ -262,7 +262,7 @@ private static Optional getYearToken(String licenseHeader) { /** Formats the given string. */ private String format(String raw) { - if (skipLinesPattern == null) { + if (skipLinesMatching == null) { return addOrUpdateLicenseHeader(raw); } else { String[] lines = raw.split("\n"); @@ -271,7 +271,7 @@ private String format(String raw) { boolean lastMatched = true; for (String line : lines) { if (lastMatched) { - Matcher matcher = skipLinesPattern.matcher(line); + Matcher matcher = skipLinesMatching.matcher(line); if (matcher.find()) { skippedLinesBuilder.append(line).append('\n'); } else { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 9c1e239d39..b8344c385f 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -462,8 +462,8 @@ public LicenseHeaderConfig yearSeparator(String yearSeparator) { return this; } - public LicenseHeaderConfig skipLinesPattern(String skipLinesPattern) { - builder = builder.withSkipLinesPattern(skipLinesPattern); + public LicenseHeaderConfig skipLinesMatching(String skipLinesMatching) { + builder = builder.withSkipLinesMatching(skipLinesMatching); replaceStep(createStep()); return this; } From 6dc01fa90418ca7eb995bfa42f7ef2eb207643fc Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:06:51 -0700 Subject: [PATCH 0172/1120] Fix ktlint 0.48 --- gradle.properties | 2 + lib/build.gradle | 16 +++-- .../KtLintCompat0Dot48Dot1Adapter.java} | 64 ++++++++++++++----- .../glue/ktlint/KtlintFormatterFunc.java | 4 +- .../diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../KtLintCompat0Dot48Dot1AdapterTest.java | 48 ++++++++++++++ .../resources/empty_class_body.kt | 3 + .../resources/fails_no_semicolons.kt | 3 + .../spotless/kotlin/KtLintStepTest.java | 4 +- 9 files changed, 119 insertions(+), 27 deletions(-) rename lib/src/{compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java => compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java} (57%) create mode 100644 lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java create mode 100644 lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt create mode 100644 lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt diff --git a/gradle.properties b/gradle.properties index 577ed87535..001197ff4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,7 @@ # To fix metaspace errors org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8 +org.gradle.parallel=true +org.gradle.caching=true name=spotless description=Spotless - keep your code spotless with Gradle org=diffplug diff --git a/lib/build.gradle b/lib/build.gradle index 0cc258afca..826abf70a7 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -34,7 +34,7 @@ versionCompatibility { '0.45.2', '0.46.0', '0.47.0', - '0.48.0', + '0.48.1', ] targetSourceSetName = 'ktlint' } @@ -91,9 +91,9 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' + compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.1' + compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.1' + compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.1' String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" @@ -105,10 +105,16 @@ dependencies { flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' } +configurations.named('testCompatKtLint0Dot48Dot1Implementation').configure { + extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot1CompileOnly) +} + // we'll hold the core lib to a high standard spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) -test { useJUnitPlatform() } +tasks.withType(Test).configureEach { + useJUnitPlatform() +} jar { for (glue in NEEDS_GLUE) { diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java similarity index 57% rename from lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java rename to lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java index 8235c535a5..e47f950a1b 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java @@ -15,6 +15,9 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -23,15 +26,21 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.KtLintRuleEngine; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.Rule; import com.pinterest.ktlint.core.RuleProvider; -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; import com.pinterest.ktlint.core.api.EditorConfigDefaults; import com.pinterest.ktlint.core.api.EditorConfigOverride; import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; +import com.pinterest.ktlint.core.api.editorconfig.CodeStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.DisabledRulesEditorConfigPropertyKt; import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty; +import com.pinterest.ktlint.core.api.editorconfig.IndentSizeEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.IndentStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; @@ -39,7 +48,23 @@ import kotlin.Unit; import kotlin.jvm.functions.Function2; -public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter { +public class KtLintCompat0Dot48Dot1Adapter implements KtLintCompatAdapter { + + private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; + + static { + List> list = new ArrayList<>(); + list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); + //noinspection deprecation + list.add(DisabledRulesEditorConfigPropertyKt.getDISABLED_RULES_PROPERTY()); + //noinspection KotlinInternalInJava,deprecation + list.add(DisabledRulesEditorConfigPropertyKt.getKTLINT_DISABLED_RULES_PROPERTY()); + list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); + list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); + list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); + list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); + DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + } static class FormatterCallback implements Function2 { @Override @@ -47,7 +72,7 @@ public Unit invoke(LintError lint, Boolean corrected) { if (!corrected) { KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); } - return null; + return Unit.INSTANCE; } } @@ -66,7 +91,7 @@ public String format(final String text, final String name, final boolean isScrip EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); } else { editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( RuleProvider::createNewRuleInstance).collect( @@ -74,17 +99,10 @@ public String format(final String text, final String name, final boolean isScrip editorConfigOverrideMap); } - return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, - text, - allRuleProviders, - userData, - formatterCallback, - isScript, - false, - EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(), - editorConfigOverride, - false)); + EditorConfigDefaults editorConfigDefaults = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); + boolean isInvokedFromCli = false; + KtLintRuleEngine ktLintRuleEngine = new KtLintRuleEngine(allRuleProviders, editorConfigDefaults, editorConfigOverride, isInvokedFromCli); + return ktLintRuleEngine.format(text, Paths.get(name), formatterCallback); } /** @@ -98,7 +116,7 @@ private static EditorConfigOverride createEditorConfigOverride(final List // Create a mapping of properties to their names based on rule properties and default properties Map> supportedProperties = Stream - .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) + .concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream()) .distinct() .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); @@ -109,6 +127,18 @@ private static EditorConfigOverride createEditorConfigOverride(final List EditorConfigProperty property = supportedProperties.get(entry.getKey()); if (property != null) { return new Pair<>(property, entry.getValue()); + } else if (entry.getKey().startsWith("ktlint_")) { + String[] parts = entry.getKey().substring(7).split("_", 2); + if (parts.length == 1) { + // convert ktlint_{ruleset} to {ruleset} + String qualifiedRuleId = parts[0]; + property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(qualifiedRuleId); + } else { + // convert ktlint_{ruleset}_{rulename} to {ruleset}:{rulename} + String qualifiedRuleId = parts[0] + ":" + parts[1]; + property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(qualifiedRuleId); + } + return new Pair<>(property, entry.getValue()); } else { return null; } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index fc64cdb23e..5be69e819c 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -27,7 +27,7 @@ import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot1Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -44,7 +44,7 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class - this.adapter = new KtLintCompat0Dot48Dot0Adapter(); + this.adapter = new KtLintCompat0Dot48Dot1Adapter(); } else if (minorVersion == 47) { // rename RuleSet to RuleProvider this.adapter = new KtLintCompat0Dot47Dot0Adapter(); diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index b444f0f1a7..7efbb911e3 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -33,7 +33,7 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.48.0"; + private static final String DEFAULT_VERSION = "0.48.1"; static final String NAME = "ktlint"; static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java new file mode 100644 index 0000000000..d4416d83f3 --- /dev/null +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -0,0 +1,48 @@ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class KtLintCompat0Dot48Dot1AdapterTest { + @Test + public void testDefaults(@TempDir Path path) throws IOException { + KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { + Files.copy(is, path.resolve("empty_class_body.kt")); + } + String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt"))); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + + String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "empty_class_body.kt", false, false, userData, editorConfigOverrideMap); + assertEquals("class empty_class_body\n", formatted); + } + + @Test + public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { + KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { + Files.copy(is, path.resolve("fails_no_semicolons.kt")); + } + String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt"))); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + + String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); + assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); + } +} diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt b/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt new file mode 100644 index 0000000000..b84774d572 --- /dev/null +++ b/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt @@ -0,0 +1,3 @@ +class empty_class_body { + +} diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt b/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt new file mode 100644 index 0000000000..20ab460913 --- /dev/null +++ b/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt @@ -0,0 +1,3 @@ +class fails_no_semicolons { + val i = 0; +} diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 94de314e0b..4ad9620d48 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -130,8 +130,8 @@ void works0_47_1() { } @Test - void works0_48_0() { - FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); + void works0_48_1() { + FormatterStep step = KtLintStep.create("0.48.1", TestProvisioner.mavenCentral()); StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + From 4550b66e70910b4733500a6fa4534197fbaa0dd6 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:13:36 -0700 Subject: [PATCH 0173/1120] Add change to changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index a7e3516607..d595ff8df6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes +* Fix ktlint 0.48.x and bump to ktlint 0.48.1 * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) From 2936d3cbd6493cab8a2fd27d797b6f8fd2d920eb Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:14:54 -0700 Subject: [PATCH 0174/1120] Add link to issue in changelog --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d595ff8df6..ee73f019a5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Fix ktlint 0.48.x and bump to ktlint 0.48.1 +* Fix ktlint 0.48.x and bump to ktlint 0.48.1 ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) From 3a3583b836815c6b431fdce0ddd9a9ea3af03a81 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Wed, 4 Jan 2023 22:16:49 +0100 Subject: [PATCH 0175/1120] add maven support --- .../java/com/diffplug/spotless/generic/LicenseHeaderStep.java | 2 +- .../com/diffplug/spotless/maven/generic/LicenseHeader.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 8a46e08bda..46312ca07a 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -108,7 +108,7 @@ public LicenseHeaderStep withYearModeLazy(Supplier yearMode) { return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } - public LicenseHeaderStep withSkipLinesMatching(String skipLinesMatching) { + public LicenseHeaderStep withSkipLinesMatching(@Nullable String skipLinesMatching) { return new LicenseHeaderStep(name, contentPattern, headerLazy, delimiter, yearSeparator, yearMode, skipLinesMatching); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java index ee2ae4fda0..22386c6892 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java @@ -37,6 +37,9 @@ public class LicenseHeader implements FormatterStepFactory { @Parameter private String delimiter; + @Parameter + private String skipLinesMatching; + @Override public final FormatterStep newFormatterStep(FormatterStepConfig config) { String delimiterString = delimiter != null ? delimiter : config.getLicenseHeaderDelimiter(); @@ -53,6 +56,7 @@ public final FormatterStep newFormatterStep(FormatterStepConfig config) { } return LicenseHeaderStep.headerDelimiter(() -> readFileOrContent(config), delimiterString) .withYearMode(yearMode) + .withSkipLinesMatching(skipLinesMatching) .build() .filterByFile(LicenseHeaderStep.unsupportedJvmFilesFilter()); } else { From 41c3fe9f07ddfa7145e1e582de923537393e0c67 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:21:19 -0700 Subject: [PATCH 0176/1120] Update all change logs --- CHANGES.md | 4 +++- plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ee73f019a5..50e4d83141 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,8 +10,9 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) ### Changes -* Fix ktlint 0.48.x and bump to ktlint 0.48.1 ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) @@ -19,6 +20,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `StepHarness` now operates on `Formatter` rather than a `FormatterStep` * `StepHarnessWithFile` now takes a `ResourceHarness` in its constructor to handle the file manipulation parts * Standardized that we test exception *messages*, not types, which will ease the transition to linting later on + * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) ## [2.31.1] - 2023-01-02 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c5f464069f..56ed8d6c1e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) +* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) ## [6.12.1] - 2023-01-02 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 84e06aa847..bc706437fd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) ## [2.29.0] - 2023-01-02 ### Added From 954e6b58b5c02bbab86b0998cc1232717cba0c7f Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:33:30 -0700 Subject: [PATCH 0177/1120] Run spotless --- .../KtLintCompat0Dot48Dot1AdapterTest.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java index d4416d83f3..a49de57a97 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -1,5 +1,22 @@ +/* + * 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.ktlint.compat; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -10,8 +27,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class KtLintCompat0Dot48Dot1AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { From 1a19da11f18dcdf60d821abda4ebd77a0a4e4648 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 15:34:22 -0700 Subject: [PATCH 0178/1120] Use older format function that doesn't load .editorconfig --- .../compat/KtLintCompat0Dot48Dot1Adapter.java | 18 ++++++++++++------ .../KtLintCompat0Dot48Dot1AdapterTest.java | 1 + .../spotless/kotlin/KtLintStepTest.java | 10 ++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java index e47f950a1b..4329c18db9 100644 --- a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.glue.ktlint.compat; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; @@ -26,7 +25,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import com.pinterest.ktlint.core.KtLintRuleEngine; +import com.pinterest.ktlint.core.KtLint; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.Rule; import com.pinterest.ktlint.core.RuleProvider; @@ -99,10 +98,17 @@ public String format(final String text, final String name, final boolean isScrip editorConfigOverrideMap); } - EditorConfigDefaults editorConfigDefaults = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); - boolean isInvokedFromCli = false; - KtLintRuleEngine ktLintRuleEngine = new KtLintRuleEngine(allRuleProviders, editorConfigDefaults, editorConfigOverride, isInvokedFromCli); - return ktLintRuleEngine.format(text, Paths.get(name), formatterCallback); + return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( + name, + text, + allRuleProviders, + userData, + formatterCallback, + isScript, + false, + EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(), + editorConfigOverride, + false)); } /** diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java index a49de57a97..31e6caf824 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -55,6 +55,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { Map userData = new HashMap<>(); Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 4ad9620d48..1be0c7b72f 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -129,6 +129,16 @@ void works0_47_1() { "Wildcard import"); } + @Test + void works0_48_0() { + FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); + StepHarnessWithFile.forStep(this, step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); + } + @Test void works0_48_1() { FormatterStep step = KtLintStep.create("0.48.1", TestProvisioner.mavenCentral()); From 11971ab599ee730d3c1fc6b995198a31f7525f6a Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 15:43:03 -0700 Subject: [PATCH 0179/1120] Fix UTF-8 encoder errors --- .../ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java index 31e6caf824..ca9d603e5c 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; @@ -34,7 +35,7 @@ public void testDefaults(@TempDir Path path) throws IOException { try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { Files.copy(is, path.resolve("empty_class_body.kt")); } - String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt"))); + String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt")), StandardCharsets.UTF_8); Map userData = new HashMap<>(); @@ -50,7 +51,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { Files.copy(is, path.resolve("fails_no_semicolons.kt")); } - String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt"))); + String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt")), StandardCharsets.UTF_8); Map userData = new HashMap<>(); From b853169fb7650db131b6cc8efa9b538c4613cde2 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 15:56:42 -0700 Subject: [PATCH 0180/1120] Remove org.gradle settings --- gradle.properties | 2 -- 1 file changed, 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 001197ff4c..577ed87535 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,5 @@ # To fix metaspace errors org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8 -org.gradle.parallel=true -org.gradle.caching=true name=spotless description=Spotless - keep your code spotless with Gradle org=diffplug From 3540242e98591391c2e766656d5e9ed53f6ca746 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 5 Jan 2023 07:00:51 +0100 Subject: [PATCH 0181/1120] eslint: reduce log-noise, cleanup error codes --- .../com/diffplug/spotless/npm/NpmProcess.java | 6 +++++- .../com/diffplug/spotless/npm/common-serve.js | 13 ++++++++++--- .../com/diffplug/spotless/npm/eslint-serve.js | 18 +++++++++--------- .../diffplug/spotless/npm/prettier-serve.js | 2 +- .../com/diffplug/spotless/npm/tsfmt-serve.js | 2 +- .../npm/PrettierFormatterStepTest.java | 2 +- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index e2fd07682c..8be94a9ea3 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -34,7 +34,11 @@ class NpmProcess { } void install() { - npmAwait("install", "--no-audit", "--no-package-lock", "--prefer-offline"); + npmAwait("install", + "--no-audit", + "--no-package-lock", + "--no-fund", + "--prefer-offline"); } Process start() { diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js index 3e031cedea..c1c9d62757 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js @@ -1,4 +1,5 @@ -// this file will be glued to the top of the specific xy-server.js file +// this file will be glued to the top of the specific xy-serve.js file +const debug_serve = false; // set to true for debug log output in node process const GracefulShutdownManager = require("@moebius/http-graceful-shutdown").GracefulShutdownManager; const express = require("express"); const app = express(); @@ -7,8 +8,14 @@ app.use(express.json({ limit: "50mb" })); const fs = require("fs"); +function debugLog() { + if (debug_serve) { + console.log.apply(this, arguments) + } +} + var listener = app.listen(0, "127.0.0.1", () => { - console.log("Server running on port " + listener.address().port); + debugLog("Server running on port " + listener.address().port); fs.writeFile("server.port.tmp", "" + listener.address().port, function(err) { if (err) { return console.log(err); @@ -26,7 +33,7 @@ const shutdownManager = new GracefulShutdownManager(listener); app.post("/shutdown", (req, res) => { res.status(200).send("Shutting down"); setTimeout(function() { - shutdownManager.terminate(() => console.log("graceful shutdown finished.")); + shutdownManager.terminate(() => debugLog("graceful shutdown finished.")); }, 200); }); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js index 1f1b1fab5a..8b60e56dc8 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-serve.js @@ -9,14 +9,14 @@ app.post("/eslint/format", async (req, res) => { const ESLintOverrideConfigFile = format_data.eslint_override_config_file; if (!ESLintOverrideConfig && !ESLintOverrideConfigFile) { - res.status(501).send("Error while formatting: No config provided"); + res.status(400).send("Error while formatting: No config provided"); return; } const filePath = format_data.file_path; if (!filePath) { - res.status(501).send("Error while formatting: No file path provided"); + res.status(400).send("Error while formatting: No file path provided"); return; } @@ -41,8 +41,8 @@ app.post("/eslint/format", async (req, res) => { eval("ESLintOptions.overrideConfig = " + ESLintOverrideConfig); } - console.log("using options: " + JSON.stringify(ESLintOptions)); - console.log("format input: ", format_data.file_content); + debugLog("using options: " + JSON.stringify(ESLintOptions)); + debugLog("format input: ", format_data.file_content); const eslint = new ESLint(ESLintOptions); @@ -50,18 +50,18 @@ app.post("/eslint/format", async (req, res) => { const lintTextOptions = { filePath: filePath, } - console.log("lintTextOptions", lintTextOptions); + debugLog("lintTextOptions", lintTextOptions); // LintResult[] // https://eslint.org/docs/latest/developer-guide/nodejs-api#-lintresult-type const results = await eslint.lintText(format_data.file_content, lintTextOptions); if (results.length !== 1) { - res.status(501).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results)); + res.status(500).send("Error while formatting: Unexpected number of results: " + JSON.stringify(results)); return; } const result = results[0]; - console.log("result: " + JSON.stringify(result)); + debugLog("result: " + JSON.stringify(result)); if (result.fatalErrorCount && result.fatalErrorCount > 0) { - res.status(501).send("Fatal error while formatting: " + JSON.stringify(result.messages)); + res.status(500).send("Fatal error while formatting: " + JSON.stringify(result.messages)); return; } const formatted = result.output || result.source || format_data.file_content; @@ -69,6 +69,6 @@ app.post("/eslint/format", async (req, res) => { res.send(formatted); } catch (err) { console.log("error", err); - res.status(501).send("Error while formatting: " + err); + res.status(500).send("Error while formatting: " + err); } }); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js index d4ce13bbbc..b60daaaa77 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js @@ -27,7 +27,7 @@ app.post("/prettier/format", (req, res) => { try { formatted_file_content = prettier.format(format_data.file_content, format_data.config_options); } catch(err) { - res.status(501).send("Error while formatting: " + err); + res.status(500).send("Error while formatting: " + err); return; } res.set("Content-Type", "text/plain"); diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js index 8ec25565ff..b9f20a1472 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-serve.js @@ -25,6 +25,6 @@ app.post("/tsfmt/format", (req, res) => { res.set("Content-Type", "text/plain"); res.send(resultMap.dest); }).catch(reason => { - res.status(501).send(reason); + res.status(500).send(reason); }); }); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index 9db218efb5..acc756fa31 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -116,7 +116,7 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { stepHarness.testResourceExceptionMsg("npm/prettier/filetypes/scss/scss.dirty").isEqualTo( - "Unexpected response status code at /prettier/format [HTTP 501] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); + "Unexpected response status code at /prettier/format [HTTP 500] -- (Error while formatting: Error: Couldn't resolve parser \"postcss\")"); } } } From 98c023b8f972ac37574f0bdae5d407bc502b50f0 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 5 Jan 2023 09:35:10 +0100 Subject: [PATCH 0182/1120] eslint: spotbugs fix --- .../java/com/diffplug/spotless/npm/EslintTypescriptConfig.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java index fc45f8bd7b..ea3e2046b3 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintTypescriptConfig.java @@ -27,6 +27,8 @@ public class EslintTypescriptConfig extends EslintConfig { + private static final long serialVersionUID = -126864670181617006L; + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") @Nullable private final transient File typescriptConfigPath; From 667eef943c0f89ca2415e913cf6d8206ff8c5585 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 5 Jan 2023 13:14:32 +0100 Subject: [PATCH 0183/1120] Pass editor config and filenames correctly --- .../glue/ktlint/KtlintFormatterFunc.java | 2 +- .../diffplug/spotless/kotlin/KtLintStep.java | 57 +++++++++++++++---- .../gradle/spotless/KotlinExtension.java | 16 ++++-- .../spotless/KotlinGradleExtension.java | 12 +++- 4 files changed, 68 insertions(+), 19 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index cfd6ab859c..034a782be6 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -73,6 +73,6 @@ public String applyWithFile(String unix, File file) { if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().getAbsolutePath(); } - return adapter.format(unix, file.getName(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); + return adapter.format(unix, file.getAbsolutePath(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 4d29a01394..20e7d885e1 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -23,6 +23,8 @@ import java.util.Objects; import java.util.TreeMap; +import javax.annotation.Nullable; + import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; @@ -51,25 +53,50 @@ public static FormatterStep create(String version, Provisioner provisioner) { public static FormatterStep create(String version, Provisioner provisioner, boolean useExperimental, Map userData, Map editorConfigOverride) { - return create(version, provisioner, false, useExperimental, userData, editorConfigOverride); + return create(version, provisioner, false, useExperimental, null, userData, editorConfigOverride); } public static FormatterStep createForScript(String version, Provisioner provisioner) { - return create(version, provisioner, true, false, Collections.emptyMap(), Collections.emptyMap()); + return create(version, provisioner, true, false, null, Collections.emptyMap(), Collections.emptyMap()); } - public static FormatterStep createForScript(String version, Provisioner provisioner, boolean useExperimental, - FileSignature editorConfigPath, Map userData, Map editorConfigOverride) { - return create(version, provisioner, true, useExperimental, userData, editorConfigOverride); + public static FormatterStep createForScript(String version, + Provisioner provisioner, + boolean useExperimental, + @Nullable FileSignature editorConfigPath, + Map userData, + Map editorConfigOverride) { + return create(version, + provisioner, + true, + useExperimental, + editorConfigPath, + userData, + editorConfigOverride); } - private static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - Map userData, Map editorConfigOverride) { - return create(version, provisioner, useExperimental, userData, editorConfigOverride); + private static FormatterStep create(String version, + Provisioner provisioner, + boolean isScript, + boolean useExperimental, + Map userData, + Map editorConfigOverride) { + return create(version, + provisioner, + useExperimental, + isScript, + null, + userData, + editorConfigOverride); } - public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - FileSignature editorConfig, Map userData, Map editorConfigOverride) { + public static FormatterStep create(String version, + Provisioner provisioner, + boolean isScript, + boolean useExperimental, + @Nullable FileSignature editorConfig, + Map userData, + Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, @@ -92,10 +119,16 @@ static final class State implements Serializable { private final TreeMap userData; private final TreeMap editorConfigOverride; private final String version; + @Nullable private final FileSignature editorConfigPath; - State(String version, Provisioner provisioner, boolean isScript, boolean useExperimental, - FileSignature editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { + State(String version, + Provisioner provisioner, + boolean isScript, + boolean useExperimental, + @Nullable FileSignature editorConfigPath, + Map userData, + Map editorConfigOverride) throws IOException { this.version = version; String coordinate; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 8af03aaefd..9ebc290219 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -17,12 +17,14 @@ import static com.diffplug.spotless.kotlin.KotlinConstants.LICENSE_HEADER_DELIMITER; +import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.Map; import java.util.Objects; import java.util.function.Consumer; +import javax.annotation.Nullable; import javax.inject.Inject; import org.gradle.api.GradleException; @@ -58,12 +60,17 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { } /** Adds the specified version of ktlint. */ - public KotlinFormatExtension ktlint(String version) { + public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version); - return new KotlinFormatExtension(version, false, null, Collections.emptyMap(), Collections.emptyMap()); + FileSignature editorConfigPath = null; + File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); + if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { + editorConfigPath = FileSignature.signAsList(defaultEditorConfig); + } + return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); } - public KotlinFormatExtension ktlint() { + public KotlinFormatExtension ktlint() throws IOException { return ktlint(KtLintStep.defaultVersion()); } @@ -71,11 +78,12 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; + @Nullable private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, FileSignature editorConfigPath, Map config, + KotlinFormatExtension(String version, boolean useExperimental, @Nullable FileSignature editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; this.useExperimental = useExperimental; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index a06c640060..ec645a8972 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -22,6 +22,7 @@ import java.util.Objects; import java.util.function.Consumer; +import javax.annotation.Nullable; import javax.inject.Inject; import com.diffplug.common.collect.ImmutableSortedMap; @@ -47,7 +48,7 @@ public KotlinGradleExtension(SpotlessExtension spotless) { public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version, "version"); FileSignature editorConfigPath = null; - File defaultEditorConfig = getProject().getRootProject().file(".editorConfig"); + File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { editorConfigPath = FileSignature.signAsList(defaultEditorConfig); } @@ -62,6 +63,7 @@ public class KotlinFormatExtension { private final String version; private boolean useExperimental; + @Nullable private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; @@ -110,7 +112,13 @@ public KotlinFormatExtension editorConfigOverride(Map editorConf } private FormatterStep createStep() { - return KtLintStep.createForScript(version, provisioner(), useExperimental, editorConfigPath, userData, editorConfigOverride); + return KtLintStep.createForScript( + version, + provisioner(), + useExperimental, + editorConfigPath, + userData, + editorConfigOverride); } } From 03eae65e91b89d8ccc3ff71c6a5b2a4b4d243748 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 5 Jan 2023 13:17:23 +0100 Subject: [PATCH 0184/1120] EditorConfig: Use Path for files for KtLint --- .../ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java | 9 +++++---- .../ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java | 9 +++++---- .../ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java | 11 ++++++----- .../ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java | 11 ++++++----- .../ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java | 11 ++++++----- .../ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java | 10 +++++----- .../ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java | 10 +++++----- .../glue/ktlint/compat/KtLintCompatAdapter.java | 5 +++-- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 2 +- 9 files changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java index a10bf9be0e..42d6e0c5bd 100644 --- a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -41,10 +42,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java index 3f98abe3b3..11d3c0d8e5 100644 --- a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -41,10 +42,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java index 0352a8e1f0..63d59ff74e 100644 --- a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -41,10 +42,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); @@ -55,7 +56,7 @@ public String format(final String text, final String name, final boolean isScrip } return KtLint.INSTANCE.format(new KtLint.Params( - name, + path.toFile().getAbsolutePath(), text, rulesets, userData, diff --git a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java index 15c2238d5d..b7b2435d93 100644 --- a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -49,10 +50,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); @@ -70,7 +71,7 @@ public String format(final String text, final String name, final boolean isScrip } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, + path.toFile().getAbsolutePath(), text, rulesets, userData, diff --git a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java index 28eba672a0..198ce7ef9c 100644 --- a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -49,10 +50,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); @@ -70,7 +71,7 @@ public String format(final String text, final String name, final boolean isScrip } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, + path.toFile().getAbsolutePath(), text, rulesets, userData, diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 3445a688b1..0d4f65936a 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -56,10 +56,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = new LinkedHashSet<>( @@ -84,7 +84,7 @@ public String format(final String text, final String name, final boolean isScrip editorConfigFilePath = new File(editorConfigPath).toPath(); } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, + path.toFile().getAbsolutePath(), text, emptySet(), allRuleProviders, diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 3efc8c085d..2cc580ea6a 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -54,10 +54,10 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, final String name, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = new LinkedHashSet<>( @@ -82,7 +82,7 @@ public String format(final String text, final String name, final boolean isScrip editorConfigFilePath = new File(editorConfigPath).toPath(); } return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, + path.toFile().getAbsolutePath(), text, allRuleProviders, userData, diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index b3e5d1817a..1693025688 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -15,10 +15,11 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Path; import java.util.Map; public interface KtLintCompatAdapter { - String format(String text, String name, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, - Map editorConfigOverrideMap); + String format(String text, Path path, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, + Map editorConfigOverrideMap); } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 034a782be6..1fe296143c 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -73,6 +73,6 @@ public String applyWithFile(String unix, File file) { if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().getAbsolutePath(); } - return adapter.format(unix, file.getAbsolutePath(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); + return adapter.format(unix, file.toPath(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); } } From 5f4417ede83573d9d91e48b2ad0a136617d65f1b Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 5 Jan 2023 13:58:00 +0100 Subject: [PATCH 0185/1120] EditorConfig: Using KtLintRuleEngine for KtLint 0.48.x --- .../compat/KtLintCompat0Dot31Dot0Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot32Dot0Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot34Dot2Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot45Dot2Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot46Dot0Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot47Dot0Adapter.java | 6 +++--- .../compat/KtLintCompat0Dot48Dot0Adapter.java | 19 +++++++------------ .../ktlint/compat/KtLintCompatAdapter.java | 2 +- 8 files changed, 26 insertions(+), 31 deletions(-) diff --git a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java index 42d6e0c5bd..b9147345e2 100644 --- a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java @@ -43,9 +43,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java index 11d3c0d8e5..de77d027f6 100644 --- a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java @@ -43,9 +43,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java index 63d59ff74e..ae86e55e40 100644 --- a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java @@ -43,9 +43,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java index b7b2435d93..06fbf8cdbd 100644 --- a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java @@ -51,9 +51,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java index 198ce7ef9c..8c41157946 100644 --- a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java @@ -51,9 +51,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); final List rulesets = new ArrayList<>(); diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 0d4f65936a..441f4636fa 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -57,9 +57,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = new LinkedHashSet<>( diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 2cc580ea6a..51a1b283c6 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -25,7 +25,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.KtLintRuleEngine; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.Rule; import com.pinterest.ktlint.core.RuleProvider; @@ -55,9 +55,9 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - String editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + final boolean useExperimental, + String editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = new LinkedHashSet<>( @@ -81,17 +81,12 @@ public String format(final String text, Path path, final boolean isScript, } else { editorConfigFilePath = new File(editorConfigPath).toPath(); } - return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - path.toFile().getAbsolutePath(), - text, + return new KtLintRuleEngine( allRuleProviders, - userData, - formatterCallback, - isScript, - false, EditorConfigDefaults.Companion.load(editorConfigFilePath), editorConfigOverride, - false)); + false) + .format(path, formatterCallback); } /** diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 1693025688..9d5cc8b06e 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -21,5 +21,5 @@ public interface KtLintCompatAdapter { String format(String text, Path path, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, - Map editorConfigOverrideMap); + Map editorConfigOverrideMap); } From 5cd53a9bb9fa709af695ef61272bb3f9977d5571 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 5 Jan 2023 14:02:05 +0100 Subject: [PATCH 0186/1120] EditorConfig: pass Path to an implementation --- .../ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java | 2 +- .../ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java | 2 +- .../ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java | 4 ++-- .../ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java | 4 ++-- .../ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java | 4 ++-- .../ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java | 12 +++--------- .../ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java | 12 +++--------- .../glue/ktlint/compat/KtLintCompatAdapter.java | 2 +- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 5 +++-- 9 files changed, 18 insertions(+), 29 deletions(-) diff --git a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java index b9147345e2..7a956de86a 100644 --- a/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot31Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot31Dot0Adapter.java @@ -44,7 +44,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java index de77d027f6..94c41c3716 100644 --- a/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot32Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot32Dot0Adapter.java @@ -44,7 +44,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java index ae86e55e40..8926a8e21f 100644 --- a/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot34Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot34Dot2Adapter.java @@ -44,7 +44,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -62,7 +62,7 @@ public String format(final String text, Path path, final boolean isScript, userData, formatterCallback, isScript, - editorConfigPath, + editorConfigPath.toFile().getAbsolutePath(), false)); } } diff --git a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java index 06fbf8cdbd..c90cf59d2b 100644 --- a/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java +++ b/lib/src/compatKtLint0Dot45Dot2/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot45Dot2Adapter.java @@ -52,7 +52,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -77,7 +77,7 @@ public String format(final String text, Path path, final boolean isScript, userData, formatterCallback, isScript, - editorConfigPath, + editorConfigPath.toFile().getAbsolutePath(), false, editorConfigOverride, false)); diff --git a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java index 8c41157946..54b34296a4 100644 --- a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java @@ -52,7 +52,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -77,7 +77,7 @@ public String format(final String text, Path path, final boolean isScript, userData, formatterCallback, isScript, - editorConfigPath, + editorConfigPath.toFile().getAbsolutePath(), false, editorConfigOverride, false)); diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java index 441f4636fa..20b87eeb17 100644 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java @@ -17,7 +17,6 @@ import static java.util.Collections.emptySet; -import java.io.File; import java.nio.file.Path; import java.util.ArrayList; import java.util.LinkedHashSet; @@ -58,7 +57,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -77,12 +76,7 @@ public String format(final String text, Path path, final boolean isScript, Collectors.toList()), editorConfigOverrideMap); } - Path editorConfigFilePath; - if (editorConfigPath == null) { - editorConfigFilePath = null; - } else { - editorConfigFilePath = new File(editorConfigPath).toPath(); - } + return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( path.toFile().getAbsolutePath(), text, @@ -93,7 +87,7 @@ public String format(final String text, Path path, final boolean isScript, isScript, null, false, - EditorConfigDefaults.Companion.load(editorConfigFilePath), + EditorConfigDefaults.Companion.load(editorConfigPath), editorConfigOverride, false)); } diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 51a1b283c6..be7f161251 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.glue.ktlint.compat; -import java.io.File; import java.nio.file.Path; import java.util.LinkedHashSet; import java.util.List; @@ -56,7 +55,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, final boolean useExperimental, - String editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); @@ -75,15 +74,10 @@ public String format(final String text, Path path, final boolean isScript, Collectors.toList()), editorConfigOverrideMap); } - Path editorConfigFilePath; - if (editorConfigPath == null) { - editorConfigFilePath = null; - } else { - editorConfigFilePath = new File(editorConfigPath).toPath(); - } + return new KtLintRuleEngine( allRuleProviders, - EditorConfigDefaults.Companion.load(editorConfigFilePath), + EditorConfigDefaults.Companion.load(editorConfigPath), editorConfigOverride, false) .format(path, formatterCallback); diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 9d5cc8b06e..68a65eb6c8 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -20,6 +20,6 @@ public interface KtLintCompatAdapter { - String format(String text, Path path, boolean isScript, boolean useExperimental, String editorConfigPath, Map userData, + String format(String text, Path path, boolean isScript, boolean useExperimental, Path editorConfigPath, Map userData, Map editorConfigOverrideMap); } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 1fe296143c..e6f3715d25 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -16,6 +16,7 @@ package com.diffplug.spotless.glue.ktlint; import java.io.File; +import java.nio.file.Path; import java.util.Map; import org.jetbrains.annotations.NotNull; @@ -69,9 +70,9 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime @Override public String applyWithFile(String unix, File file) { - String absoluteEditorConfigPath = null; + Path absoluteEditorConfigPath = null; if (editorConfigPath != null) { - absoluteEditorConfigPath = editorConfigPath.getOnlyFile().getAbsolutePath(); + absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } return adapter.format(unix, file.toPath(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); } From f4c2a1d84e2cb82aa36415ae514a93cc60b59ace Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Thu, 5 Jan 2023 16:28:35 +0100 Subject: [PATCH 0187/1120] EditorConfig: Use default path without checking (KtLint will check them anyway) --- .../java/com/diffplug/gradle/spotless/KotlinExtension.java | 5 +---- .../com/diffplug/gradle/spotless/KotlinGradleExtension.java | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 9ebc290219..5d1c484521 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -62,11 +62,8 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version); - FileSignature editorConfigPath = null; File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); - if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { - editorConfigPath = FileSignature.signAsList(defaultEditorConfig); - } + FileSignature editorConfigPath = FileSignature.signAsList(defaultEditorConfig); return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index ec645a8972..82a8edd9a5 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -47,11 +47,8 @@ public KotlinGradleExtension(SpotlessExtension spotless) { /** Adds the specified version of ktlint. */ public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version, "version"); - FileSignature editorConfigPath = null; File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); - if (defaultEditorConfig.exists() && defaultEditorConfig.isFile()) { - editorConfigPath = FileSignature.signAsList(defaultEditorConfig); - } + FileSignature editorConfigPath = FileSignature.signAsList(defaultEditorConfig); return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); } From b6e90739d5deac7b356eaad74307b3c2dc061a0c Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Fri, 6 Jan 2023 10:45:59 -0700 Subject: [PATCH 0188/1120] Change back to 0.48.0 --- lib/build.gradle | 12 ++++++------ .../compat/KtLintCompat0Dot48Dot0Adapter.java} | 2 +- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 4 ++-- .../compat/KtLintCompat0Dot48Dot0AdapterTest.java} | 14 +++++++------- .../resources/empty_class_body.kt | 0 .../resources/fails_no_semicolons.kt | 0 6 files changed, 16 insertions(+), 16 deletions(-) rename lib/src/{compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java => compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java} (99%) rename lib/src/{testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java => testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java} (81%) rename lib/src/{testCompatKtLint0Dot48Dot1 => testCompatKtLint0Dot48Dot0}/resources/empty_class_body.kt (100%) rename lib/src/{testCompatKtLint0Dot48Dot1 => testCompatKtLint0Dot48Dot0}/resources/fails_no_semicolons.kt (100%) diff --git a/lib/build.gradle b/lib/build.gradle index 826abf70a7..4cf4c66332 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -34,7 +34,7 @@ versionCompatibility { '0.45.2', '0.46.0', '0.47.0', - '0.48.1', + '0.48.0', ] targetSourceSetName = 'ktlint' } @@ -91,9 +91,9 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' - compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.1' - compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.1' - compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.1' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" @@ -105,8 +105,8 @@ dependencies { flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' } -configurations.named('testCompatKtLint0Dot48Dot1Implementation').configure { - extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot1CompileOnly) +configurations.named('testCompatKtLint0Dot48Dot0Implementation').configure { + extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot0CompileOnly) } // we'll hold the core lib to a high standard diff --git a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java similarity index 99% rename from lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java rename to lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 4329c18db9..f910576971 100644 --- a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -47,7 +47,7 @@ import kotlin.Unit; import kotlin.jvm.functions.Function2; -public class KtLintCompat0Dot48Dot1Adapter implements KtLintCompatAdapter { +public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter { private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 5be69e819c..fc64cdb23e 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -27,7 +27,7 @@ import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot1Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -44,7 +44,7 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class - this.adapter = new KtLintCompat0Dot48Dot1Adapter(); + this.adapter = new KtLintCompat0Dot48Dot0Adapter(); } else if (minorVersion == 47) { // rename RuleSet to RuleProvider this.adapter = new KtLintCompat0Dot47Dot0Adapter(); diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java similarity index 81% rename from lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java rename to lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index ca9d603e5c..cccf71da12 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -28,11 +28,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -public class KtLintCompat0Dot48Dot1AdapterTest { +public class KtLintCompat0Dot48Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); - try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { + KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { Files.copy(is, path.resolve("empty_class_body.kt")); } String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt")), StandardCharsets.UTF_8); @@ -41,14 +41,14 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "empty_class_body.kt", false, false, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, "empty_class_body.kt", false, false, userData, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); - try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { + KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { Files.copy(is, path.resolve("fails_no_semicolons.kt")); } String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt")), StandardCharsets.UTF_8); @@ -59,7 +59,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } } diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt b/lib/src/testCompatKtLint0Dot48Dot0/resources/empty_class_body.kt similarity index 100% rename from lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt rename to lib/src/testCompatKtLint0Dot48Dot0/resources/empty_class_body.kt diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt b/lib/src/testCompatKtLint0Dot48Dot0/resources/fails_no_semicolons.kt similarity index 100% rename from lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt rename to lib/src/testCompatKtLint0Dot48Dot0/resources/fails_no_semicolons.kt From 8d52fb28f73c7a772b9097a05e00e73df967c69d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 6 Jan 2023 17:56:29 +0000 Subject: [PATCH 0189/1120] fix(deps): update dependency org.assertj:assertj-core to v3.24.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 577ed87535..e966c09437 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ VER_SLF4J=[1.6,2.0[ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.1 -VER_ASSERTJ=3.23.1 +VER_ASSERTJ=3.24.1 VER_MOCKITO=4.11.0 # Used for Maven Plugin From 6b2e2c397f4405ff9c1ed264dcd78138d2e8bb87 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Fri, 6 Jan 2023 11:10:29 -0700 Subject: [PATCH 0190/1120] Use testCommonImplementation configuration --- lib/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 4cf4c66332..e8c22d28b6 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -45,9 +45,9 @@ dependencies { compileOnly 'org.slf4j:slf4j-api:2.0.0' // zero runtime reqs is a hard requirements for spotless-lib // if you need a dep, put it in lib-extra - testImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" - testImplementation "org.assertj:assertj-core:$VER_ASSERTJ" - testImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" + testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" + testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ" + testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" // used for pom sorting sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' @@ -106,7 +106,7 @@ dependencies { } configurations.named('testCompatKtLint0Dot48Dot0Implementation').configure { - extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot0CompileOnly) + extendsFrom(configurations.compatKtLint0Dot48Dot0CompileOnly) } // we'll hold the core lib to a high standard From 3125f972f1b9883a9452c0ef8abb65cdea43ebac Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 7 Jan 2023 08:56:44 -0800 Subject: [PATCH 0191/1120] Our java example was ordered such that the import order would get wiped out by gjf, leading to confusion in #1417. --- plugin-maven/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index dcc18a5dd6..da39543cc4 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -179,6 +179,10 @@ any other maven phase (i.e. compile) then it can be configured as below; src/test/java/**/*.java + + + + false @@ -188,10 +192,6 @@ any other maven phase (i.e. compile) then it can be configured as below; - - - - From bd562c1365e1b603d7202d66d1d34657ae9baebb Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 7 Jan 2023 09:06:34 -0800 Subject: [PATCH 0192/1120] Emphasize that order matters to the Maven users. --- plugin-maven/README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index da39543cc4..8440a4368e 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -129,7 +129,16 @@ To use it in your pom, just [add the Spotless dependency](https://search.maven.o Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: - a `target` (the files to format), which you set with [`includes` and `excludes`](https://github.com/diffplug/spotless/blob/989abbecff4d8373c6111c1a98f359eadc532429/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java#L51-L55) - a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Replace.java), [`replaceRegex`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/ReplaceRegex.java), [`trimTrailingWhitespace`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/TrimTrailingWhitespace.java), [`indent`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Indent.java), [`prettier`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java), [`eclipseWtp`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/EclipseWtp.java), and [`licenseHeader`](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/LicenseHeader.java). - +- **order matters**, and this is good! (More info [here](https://github.com/diffplug/spotless/blob/main/PADDEDCELL.md) and [here](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-spotless-works)) + - For example, `googleJavaFormat` always indents with spaces, but some wish it had a tab mode + - ```xml + // this works + true2 + ``` + - ```xml + true2 + // the tab indentation gets overwritten + ``` ### Requirements From 8e1fb53059778d37e67d8814c3eb4e7f8fabbc2f Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sat, 7 Jan 2023 21:50:46 +0100 Subject: [PATCH 0193/1120] add test for skipLinesMatching setting of license header step --- testlib/src/main/resources/license/SkipLines.test | 9 +++++++++ .../main/resources/license/SkipLinesHasLicense.test | 13 +++++++++++++ .../spotless/generic/LicenseHeaderStepTest.java | 7 +++++++ 3 files changed, 29 insertions(+) create mode 100644 testlib/src/main/resources/license/SkipLines.test create mode 100644 testlib/src/main/resources/license/SkipLinesHasLicense.test diff --git a/testlib/src/main/resources/license/SkipLines.test b/testlib/src/main/resources/license/SkipLines.test new file mode 100644 index 0000000000..4048868ac6 --- /dev/null +++ b/testlib/src/main/resources/license/SkipLines.test @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/testlib/src/main/resources/license/SkipLinesHasLicense.test b/testlib/src/main/resources/license/SkipLinesHasLicense.test new file mode 100644 index 0000000000..f645c5b2e2 --- /dev/null +++ b/testlib/src/main/resources/license/SkipLinesHasLicense.test @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java index 137937beb9..785c1c528a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java @@ -122,6 +122,13 @@ void should_remove_header_when_empty() throws Throwable { .test(getTestResource("license/HasLicense.test"), getTestResource("license/MissingLicense.test")); } + @Test + void should_skip_lines_matching_predefined_pattern() throws Throwable { + StepHarness.forStep(LicenseHeaderStep.headerDelimiter("", "^(?!", "^(?! + **/*.yaml + **/*.yml + + + + + +``` + +### jackson + +Uses Jackson and YAMLFactory to pretty print objects: + +```xml + + 2.13.4 + + INDENT_OUTPUT + + + DEFAULT_HAS_TO_DISABLED_FEATURE + + +``` + + + ## 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-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java index 90892f969a..86b52aac7d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java @@ -31,7 +31,7 @@ public class JacksonYaml implements FormatterStepFactory { private String version = YamlJacksonStep.defaultVersion(); @Parameter - private String[] enabledFeatures = new String[] { "INDENT_OUTPUT" }; + private String[] enabledFeatures = new String[]{"INDENT_OUTPUT"}; @Parameter private String[] disabledFeatures = new String[0]; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java index a6ceaaa592..20e609ceb4 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java @@ -15,9 +15,9 @@ */ package com.diffplug.spotless.maven.yaml; -import java.util.Collections; import java.util.Set; +import com.diffplug.common.collect.Sets; import com.diffplug.spotless.maven.FormatterFactory; /** @@ -26,7 +26,7 @@ public class Yaml extends FormatterFactory { @Override public Set defaultIncludes() { - return Collections.emptySet(); + return Sets.newHashSet("**/*.yaml", "**/*.yml"); } @Override 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 9e9495da65..5dbd3e0075 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 @@ -160,6 +160,10 @@ protected void writePomWithJsonSteps(String... steps) throws IOException { writePom(groupWithSteps("json", including("**/*.json"), steps)); } + protected void writePomWithYamlSteps(String... steps) throws IOException { + writePom(groupWithSteps("yaml", steps)); + } + protected void writePom(String... configuration) throws IOException { writePom(null, configuration, null); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java new file mode 100644 index 0000000000..8b9bab6cbb --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -0,0 +1,31 @@ +/* + * 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.yaml; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +public class YamlTest extends MavenIntegrationHarness { + @Test + public void testFormatJson_WithSimple_defaultConfig() throws Exception { + writePomWithJsonSteps(""); + + setFile("yaml_test.json").toResource("yaml/separator_comments.yaml"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("yaml_test.json").sameAsResource("yaml/separator_comments.clean.yaml"); + } +} From 3244f2defe92773733c7d600c0c9f4440506de65 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 10 Jan 2023 10:05:31 +0400 Subject: [PATCH 0226/1120] Add unit-tests --- .../spotless/maven/yaml/YamlTest.java | 20 ++++++++++++++++++- .../yaml/array_with_bracket.clean.yaml | 8 ++++++++ .../resources/yaml/array_with_bracket.yaml | 5 +++++ .../yaml/multiple_document.clean.yaml | 8 ++++++++ .../resources/yaml/multiple_document.yaml | 10 ++++++++++ .../resources/yaml/separator_comments.yaml | 1 + 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 testlib/src/main/resources/yaml/array_with_bracket.clean.yaml create mode 100644 testlib/src/main/resources/yaml/array_with_bracket.yaml create mode 100644 testlib/src/main/resources/yaml/multiple_document.clean.yaml create mode 100644 testlib/src/main/resources/yaml/multiple_document.yaml diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 8b9bab6cbb..b2168ff05f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -21,11 +21,29 @@ public class YamlTest extends MavenIntegrationHarness { @Test - public void testFormatJson_WithSimple_defaultConfig() throws Exception { + public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws Exception { writePomWithJsonSteps(""); setFile("yaml_test.json").toResource("yaml/separator_comments.yaml"); mavenRunner().withArguments("spotless:apply").runNoError().error(); assertFile("yaml_test.json").sameAsResource("yaml/separator_comments.clean.yaml"); } + + @Test + public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exception { + writePomWithJsonSteps(""); + + setFile("yaml_test.json").toResource("yaml/array_with_bracket.yaml"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("yaml_test.json").sameAsResource("yaml/array_with_bracket.clean.yaml"); + } + + @Test + public void testFormatYaml_WithJackson_defaultConfig_multipleComments() throws Exception { + writePomWithJsonSteps(""); + + setFile("yaml_test.json").toResource("yaml/multiple_documents.yaml"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("yaml_test.json").sameAsResource("yaml/multiple_documents.clean.yaml"); + } } diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml new file mode 100644 index 0000000000..bf46f753c0 --- /dev/null +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml @@ -0,0 +1,8 @@ +--- +hr: + - Mark McGwire + # Following node labeled SS + - &SS Sammy Sosa +rbi: + - *SS # Subsequent occurrence + - Ken Griffey \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/array_with_bracket.yaml b/testlib/src/main/resources/yaml/array_with_bracket.yaml new file mode 100644 index 0000000000..c83e381e6b --- /dev/null +++ b/testlib/src/main/resources/yaml/array_with_bracket.yaml @@ -0,0 +1,5 @@ +hr: [Mark McGwire, Sammy Sosa] + + + +rbi: [Sammy Sosa, Ken Griffey] \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/multiple_document.clean.yaml b/testlib/src/main/resources/yaml/multiple_document.clean.yaml new file mode 100644 index 0000000000..bf46f753c0 --- /dev/null +++ b/testlib/src/main/resources/yaml/multiple_document.clean.yaml @@ -0,0 +1,8 @@ +--- +hr: + - Mark McGwire + # Following node labeled SS + - &SS Sammy Sosa +rbi: + - *SS # Subsequent occurrence + - Ken Griffey \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/multiple_document.yaml b/testlib/src/main/resources/yaml/multiple_document.yaml new file mode 100644 index 0000000000..51f14a5862 --- /dev/null +++ b/testlib/src/main/resources/yaml/multiple_document.yaml @@ -0,0 +1,10 @@ +document: this is document 1 +--- + +document: this is document 2 + + +--- + + +document: this is document 3 \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/separator_comments.yaml b/testlib/src/main/resources/yaml/separator_comments.yaml index bf46f753c0..0213e66406 100644 --- a/testlib/src/main/resources/yaml/separator_comments.yaml +++ b/testlib/src/main/resources/yaml/separator_comments.yaml @@ -1,3 +1,4 @@ + --- hr: - Mark McGwire From 43078663dbf2b7cf1fcdf55f1c25b41d272684ad Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 10 Jan 2023 10:06:36 +0400 Subject: [PATCH 0227/1120] Improve testcases --- .../main/resources/yaml/array_with_bracket.clean.yaml | 10 ++-------- .../src/main/resources/yaml/array_with_bracket.yaml | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml index bf46f753c0..8e9d80065e 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml @@ -1,8 +1,2 @@ ---- -hr: - - Mark McGwire - # Following node labeled SS - - &SS Sammy Sosa -rbi: - - *SS # Subsequent occurrence - - Ken Griffey \ No newline at end of file +episodes: [1, 2, 3, 4, 5, 6, 7] +best-jedi: {name: Obi-Wan, side: light} \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/array_with_bracket.yaml b/testlib/src/main/resources/yaml/array_with_bracket.yaml index c83e381e6b..e28373163d 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.yaml @@ -1,5 +1,5 @@ -hr: [Mark McGwire, Sammy Sosa] +episodes: [1, 2, 3, 4, 5, 6, 7] -rbi: [Sammy Sosa, Ken Griffey] \ No newline at end of file +best-jedi: {name: Obi-Wan, side: light} \ No newline at end of file From d4d91cb97975a8a29e7a067a3c64af15460b7bef Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 10 Jan 2023 08:35:14 +0100 Subject: [PATCH 0228/1120] eslint: remove direct api support for styleguides --- .../spotless/npm/EslintFormatterStep.java | 93 +------------- plugin-gradle/README.md | 4 - .../gradle/spotless/JavascriptExtension.java | 25 +--- .../gradle/spotless/TypescriptExtension.java | 15 +-- .../spotless/JavascriptExtensionTest.java | 41 ++---- .../spotless/TypescriptExtensionTest.java | 32 ++--- plugin-maven/README.md | 4 - .../maven/javascript/AbstractEslint.java | 28 ---- .../spotless/maven/javascript/EslintJs.java | 4 - .../spotless/maven/typescript/EslintTs.java | 5 - .../javascript/JavascriptFormatStepTest.java | 10 +- .../typescript/TypescriptFormatStepTest.java | 10 +- .../spotless/npm/EslintStyleGuide.java | 120 ++++++++++++++++++ .../spotless/npm/EslintFormatterStepTest.java | 21 +-- 14 files changed, 170 insertions(+), 242 deletions(-) create mode 100644 testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index ac3ee05345..81c5b6ce78 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -20,14 +20,12 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; import java.util.TreeMap; -import java.util.function.Predicate; import javax.annotation.Nonnull; @@ -47,96 +45,7 @@ public class EslintFormatterStep { public static final String NAME = "eslint-format"; - public static final String DEFAULT_ESLINT_VERSION = "^8.30.0"; - - public enum PopularStyleGuide { - TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard-with-typescript", "^24.0.0"); - dependencies.put("eslint-plugin-import", "^2.26.0"); - dependencies.put("eslint-plugin-n", "^15.6.0"); - dependencies.put("eslint-plugin-promise", "^6.1.1"); - return dependencies; - } - }, - TS_XO_TYPESCRIPT("xo-typescript") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-xo", "^0.43.1"); - dependencies.put("eslint-config-xo-typescript", "^0.55.1"); - return dependencies; - } - }, - JS_AIRBNB("airbnb") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-airbnb-base", "^15.0.0"); - dependencies.put("eslint-plugin-import", "^2.26.0"); - return dependencies; - } - }, - JS_GOOGLE("google") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-google", "^0.14.0"); - return dependencies; - } - }, - JS_STANDARD("standard") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-standard", "^17.0.0"); - dependencies.put("eslint-plugin-import", "^2.26.0"); - dependencies.put("eslint-plugin-n", "^15.6.0"); - dependencies.put("eslint-plugin-promise", "^6.1.1"); - return dependencies; - } - }, - JS_XO("xo") { - @Override - public @Nonnull Map devDependencies() { - Map dependencies = new LinkedHashMap<>(); - dependencies.put("eslint-config-xo", "^0.43.1"); - return dependencies; - } - }; - - private final String popularStyleGuideName; - - PopularStyleGuide(String popularStyleGuideName) { - this.popularStyleGuideName = popularStyleGuideName; - } - - public String getPopularStyleGuideName() { - return popularStyleGuideName; - } - - public abstract @Nonnull Map devDependencies(); - - public static PopularStyleGuide fromNameOrNull(String popularStyleGuideName) { - for (PopularStyleGuide popularStyleGuide : PopularStyleGuide.values()) { - if (popularStyleGuide.popularStyleGuideName.equals(popularStyleGuideName)) { - return popularStyleGuide; - } - } - return null; - } - - public static String getPopularStyleGuideNames(Predicate filter) { - // collect matching style guide names using stream - return Arrays.stream(PopularStyleGuide.values()) - .filter(filter) - .map(PopularStyleGuide::getPopularStyleGuideName) - .sorted() - .collect(java.util.stream.Collectors.joining(", ")); - } - } + public static final String DEFAULT_ESLINT_VERSION = "^8.31.0"; public static Map defaultDevDependenciesForTypescript() { return defaultDevDependenciesTypescriptWithEslint(DEFAULT_ESLINT_VERSION); diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 1ed2b942b5..8a06351bed 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -634,8 +634,6 @@ spotless { eslint(['my-eslint-fork': '1.2.3', 'my-eslint-plugin': '1.2.1']) // can specify exactly which npm packages to use eslint() - // optional: use a popular eslint styleguide for typescript - .styleGuide('standard-with-typescript') // or 'xo-typescript' // configuration is mandatory. Provide inline config or a config file. // a) inline-configuration .configJs(''' @@ -703,8 +701,6 @@ spotless { eslint(['my-eslint-fork': '1.2.3', 'my-eslint-plugin': '1.2.1']) // can specify exactly which npm packages to use eslint() - // optional: use a popular eslint styleguide for javascript - .styleGuide('standard') // or 'airbnb', 'google', 'xo' // configuration is mandatory. Provide inline config or a config file. // a) inline-configuration .configJs(''' diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index 862c7566ee..dd476b6a69 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -31,7 +31,6 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; -import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; @@ -73,7 +72,7 @@ public EslintBaseConfig(Project project, Consumer replaceStep, Ma } @SuppressWarnings("unchecked") - public T devDependencies(Map devDependencies) { + protected T devDependencies(Map devDependencies) { this.devDependencies.putAll(devDependencies); replaceStep(); return (T) this; @@ -92,17 +91,6 @@ public T configFile(Object configFilePath) { replaceStep(); return (T) this; } - - @SuppressWarnings("unchecked") - public T styleGuide(String styleGuide) { - PopularStyleGuide popularStyleGuide = PopularStyleGuide.fromNameOrNull(styleGuide); - - verifyStyleGuideIsSupported(styleGuide, popularStyleGuide); - assert popularStyleGuide != null; - return devDependencies(popularStyleGuide.devDependencies()); - } - - protected abstract void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide); } public class JavascriptEslintConfig extends EslintBaseConfig { @@ -123,17 +111,6 @@ public FormatterStep createStep() { eslintConfig()); } - @Override - protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { - if (!isJsStyleGuide(popularStyleGuide)) { - throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known javascript style guides: " + PopularStyleGuide.getPopularStyleGuideNames(this::isJsStyleGuide)); - } - } - - private boolean isJsStyleGuide(PopularStyleGuide popularStyleGuide) { - return popularStyleGuide != null && popularStyleGuide.name().startsWith("JS_"); - } - protected EslintConfig eslintConfig() { return new EslintConfig(configFilePath != null ? getProject().file(configFilePath) : null, configJs); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 5de1bb1ac3..0824caa769 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -27,10 +27,10 @@ import org.gradle.api.Project; +import com.diffplug.gradle.spotless.JavascriptExtension.EslintBaseConfig; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.npm.EslintConfig; import com.diffplug.spotless.npm.EslintFormatterStep; -import com.diffplug.spotless.npm.EslintFormatterStep.PopularStyleGuide; import com.diffplug.spotless.npm.EslintTypescriptConfig; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; @@ -189,7 +189,7 @@ public TypescriptEslintConfig eslint(Map devDependencies) { return eslint; } - public class TypescriptEslintConfig extends JavascriptExtension.EslintBaseConfig { + public class TypescriptEslintConfig extends EslintBaseConfig { @Nullable Object typescriptConfigFilePath = null; @@ -204,17 +204,6 @@ public TypescriptEslintConfig tsconfigFile(Object path) { return this; } - @Override - protected void verifyStyleGuideIsSupported(String styleGuideName, PopularStyleGuide popularStyleGuide) { - if (!isTsStyleGuide(popularStyleGuide)) { - throw new IllegalArgumentException("Unknown style guide: " + styleGuideName + ". Known typescript style guides: " + PopularStyleGuide.getPopularStyleGuideNames(this::isTsStyleGuide)); - } - } - - private boolean isTsStyleGuide(PopularStyleGuide popularStyleGuide) { - return popularStyleGuide != null && popularStyleGuide.name().startsWith("TS_"); - } - public FormatterStep createStep() { final Project project = getProject(); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java index 331e17f28e..26354b93be 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java @@ -24,11 +24,17 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @NpmTest class JavascriptExtensionTest extends GradleIntegrationHarness { + private static String styleGuideMapString(String styleGuideName) { + return EslintStyleGuide.fromNameOrNull(styleGuideName).asGradleMapStringMergedWith(EslintFormatterStep.defaultDevDependencies()); + } + @NpmTest @Nested class EslintGeneralJavascriptTests extends GradleIntegrationHarness { @@ -43,7 +49,7 @@ void supportsEslintFormattingForJavascript() throws IOException { "spotless {", " javascript {", " target 'test.js'", - " eslint().configFile('.eslintrc.js').styleGuide('standard')", + " eslint(" + styleGuideMapString("standard") + ").configFile('.eslintrc.js')", " }", "}"); setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); @@ -51,28 +57,9 @@ void supportsEslintFormattingForJavascript() throws IOException { assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); } - @Test - void eslintDoesNotAllowToUseTsStyleGuideForJavascript() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " javascript {", - " target 'test.js'", - " eslint().configFile('.eslintrc.js').styleGuide('xo-typescript')", - " }", - "}"); - setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); - Assertions.assertThat(spotlessApply.getOutput()).contains("Unknown style guide: xo-typescript"); - } - @Test void eslintAllowsToSpecifyEslintVersionForJavascript() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/standard/.eslintrc.js"); + setFile(".eslintrc.js").toResource("npm/eslint/javascript/custom_rules/.eslintrc.js"); setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -81,12 +68,12 @@ void eslintAllowsToSpecifyEslintVersionForJavascript() throws IOException { "spotless {", " javascript {", " target 'test.js'", - " eslint('8.28.0').configFile('.eslintrc.js').styleGuide('standard')", + " eslint('8.28.0').configFile('.eslintrc.js')", " }", "}"); - setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); + setFile("test.js").toResource("npm/eslint/javascript/custom_rules/javascript-es6.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - assertFile("test.js").sameAsResource("npm/eslint/javascript/styleguide/standard/javascript-es6.clean"); + assertFile("test.js").sameAsResource("npm/eslint/javascript/custom_rules/javascript-es6.clean"); } @Test @@ -115,7 +102,7 @@ void esllintAllowsToSpecifyInlineConfig() throws IOException { "spotless {", " javascript {", " target 'test.js'", - " eslint().configJs('''" + eslintConfigJs + "''').styleGuide('standard')", + " eslint(" + styleGuideMapString("standard") + ").configJs('''" + eslintConfigJs + "''')", " }", "}"); setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); @@ -134,7 +121,7 @@ void eslintRequiresAnExplicitEslintConfig() throws IOException { "spotless {", " javascript {", " target 'test.js'", - " eslint().styleGuide('standard')", + " eslint(" + styleGuideMapString("standard") + ")", " }", "}"); setFile("test.js").toResource("npm/eslint/javascript/styleguide/standard/javascript-es6.dirty"); @@ -187,7 +174,7 @@ void formattingUsingStyleguide(String styleguide) throws Exception { "spotless {", " javascript {", " target 'test.js'", - " eslint().configFile('.eslintrc.js').styleGuide('" + styleguide + "')", + " eslint(" + styleGuideMapString(styleguide) + ").configFile('.eslintrc.js')", " }", "}"); setFile("test.js").toResource(styleguidePath + "javascript-es6.dirty"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 598ff7dc14..9b4ec8372e 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -17,14 +17,19 @@ import java.io.IOException; -import org.assertj.core.api.Assertions; -import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Test; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @NpmTest class TypescriptExtensionTest extends GradleIntegrationHarness { + + private static String styleGuideMapString(String styleGuideName) { + return EslintStyleGuide.fromNameOrNull(styleGuideName).asGradleMapStringMergedWith(EslintFormatterStep.defaultDevDependencies()); + } + @Test void allowToSpecifyFormatterVersion() throws IOException { setFile("build.gradle").toLines( @@ -175,7 +180,7 @@ void useEslintXoStandardRules() throws IOException { "spotless {", " typescript {", " target 'test.ts'", - " eslint().styleGuide('xo-typescript').configFile('.eslintrc.js')", + " eslint(" + styleGuideMapString("xo-typescript") + ").configFile('.eslintrc.js')", " }", "}"); setFile("test.ts").toResource("npm/eslint/typescript/styleguide/xo/typescript.dirty"); @@ -195,30 +200,11 @@ void useEslintStandardWithTypescriptRules() throws IOException { "spotless {", " typescript {", " target 'test.ts'", - " eslint().styleGuide('standard-with-typescript').configFile('.eslintrc.js')", + " eslint(" + styleGuideMapString("standard-with-typescript") + ").configFile('.eslintrc.js')", " }", "}"); setFile("test.ts").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.dirty"); gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); assertFile("test.ts").sameAsResource("npm/eslint/typescript/styleguide/standard_with_typescript/typescript.clean"); } - - @Test - void useEslintForTypescriptDoesNotAllowUsingJsStyleguide() throws IOException { - setFile(".eslintrc.js").toResource("npm/eslint/javascript/styleguide/airbnb/.eslintrc.js"); - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " typescript {", - " target 'test.ts'", - " eslint().styleGuide('airbnb').configFile('.eslintrc.js')", - " }", - "}"); - setFile("test.js").toResource("npm/eslint/javascript/styleguide/airbnb/javascript-es6.dirty"); - BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); - Assertions.assertThat(spotlessApply.getOutput()).contains("Unknown style guide: airbnb"); - } } diff --git a/plugin-maven/README.md b/plugin-maven/README.md index dcf9df45d9..2a2aa31010 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -745,8 +745,6 @@ styleguides and the requirement for a tsconfigFile. 0.14.2 - - standard-with-typescript ${project.basedir}/.eslintrc.js @@ -826,8 +824,6 @@ styleguides and no requirement for a tsconfig (of course). 0.14.2 - - standard ${project.basedir}/.eslintrc.js diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java index 1829f91b4e..b06d3079e7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java @@ -39,9 +39,6 @@ public abstract class AbstractEslint extends AbstractNpmFormatterStepFactory { @Parameter protected String configJs; - @Parameter - protected String styleGuide; - @Parameter protected String eslintVersion; @@ -68,8 +65,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { devDependencies.putAll(defaultDependencies); } - addStyleGuideDevDependencies(devDependencies); - File buildDir = buildDir(stepConfig); File baseDir = baseDir(stepConfig); NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); @@ -82,28 +77,5 @@ private static IllegalArgumentException onlyOneConfig() { protected abstract EslintConfig eslintConfig(FormatterStepConfig stepConfig); - private void addStyleGuideDevDependencies(Map devDependencies) { - if (this.styleGuide != null) { - EslintFormatterStep.PopularStyleGuide styleGuide = EslintFormatterStep.PopularStyleGuide.fromNameOrNull(this.styleGuide); - validateStyleGuide(styleGuide); - devDependencies.putAll(styleGuide.devDependencies()); - } - } - - private void validateStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { - if (styleGuide == null) { - throw new IllegalArgumentException("StyleGuide '" + this.styleGuide + "' is not supported. Supported style guides: " + supportedStyleGuides()); - } - if (!isValidStyleGuide(styleGuide)) { - throw new IllegalArgumentException("StyleGuide must be of correct type but is: " + styleGuide.getPopularStyleGuideName() + ". Use one of the following: " + supportedStyleGuides()); - } - } - - private String supportedStyleGuides() { - return EslintFormatterStep.PopularStyleGuide.getPopularStyleGuideNames(this::isValidStyleGuide); - } - - protected abstract boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide); - protected abstract Map createDefaultDependencies(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java index f9954ab0c8..483d38ae1e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -27,10 +27,6 @@ protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { return new EslintConfig(this.configFile != null ? stepConfig.getFileLocator().locateFile(this.configFile) : null, this.configJs); } - protected boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { - return styleGuide.name().startsWith("JS_"); - } - protected Map createDefaultDependencies() { return this.eslintVersion == null ? EslintFormatterStep.defaultDevDependencies() : EslintFormatterStep.defaultDevDependenciesWithEslint(this.eslintVersion); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java index 72f3735d97..dc43185dcd 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/EslintTs.java @@ -38,11 +38,6 @@ protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { tsconfigFile != null ? stepConfig.getFileLocator().locateFile(tsconfigFile) : null); } - @Override - protected boolean isValidStyleGuide(EslintFormatterStep.PopularStyleGuide styleGuide) { - return styleGuide.name().startsWith("TS_"); - } - @Override protected Map createDefaultDependencies() { return this.eslintVersion == null ? EslintFormatterStep.defaultDevDependenciesForTypescript() : EslintFormatterStep.defaultDevDependenciesTypescriptWithEslint(this.eslintVersion); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java index 7ebc592add..5c8a5f04b3 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -23,6 +23,8 @@ import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; import com.diffplug.spotless.maven.MavenRunner.Result; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @NpmTest @@ -30,6 +32,10 @@ class JavascriptFormatStepTest extends MavenIntegrationHarness { private static final String TEST_FILE_PATH = "src/main/javascript/test.js"; + private static String styleGuideDevDependenciesString(String styleGuideName) { + return EslintStyleGuide.fromNameOrNull(styleGuideName).asMavenXmlStringMergedWith(EslintFormatterStep.defaultDevDependencies()); + } + @NpmTest @Nested class EslintCustomRulesTest extends MavenIntegrationHarness { @@ -79,7 +85,7 @@ void eslintJsStyleguideUsingConfigFile(String styleGuide) throws Exception { TEST_FILE_PATH, "", " .eslintrc.js", - " " + styleGuide + "", + " " + styleGuideDevDependenciesString(styleGuide), ""); setFile(".eslintrc.js").toResource(styleGuidePath + "/.eslintrc.js"); setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); @@ -100,7 +106,7 @@ void eslintJsStyleguideUsingInlineConfig(String styleGuide) throws Exception { TEST_FILE_PATH, "", " " + escapedInlineConfig + "", - " " + styleGuide + "", + " " + styleGuideDevDependenciesString(styleGuide), ""); setFile(TEST_FILE_PATH).toResource(styleGuidePath + "/javascript-es6.dirty"); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index ac925cc9b6..95097fe467 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -24,6 +24,8 @@ import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; import com.diffplug.spotless.maven.MavenRunner.Result; +import com.diffplug.spotless.npm.EslintFormatterStep; +import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @NpmTest @@ -31,6 +33,10 @@ class TypescriptFormatStepTest extends MavenIntegrationHarness { private static final String TEST_FILE_PATH = "src/main/typescript/test.ts"; + private static String styleGuideDevDependenciesString(String styleGuideName) { + return EslintStyleGuide.fromNameOrNull(styleGuideName).asMavenXmlStringMergedWith(EslintFormatterStep.defaultDevDependencies()); + } + private void runTsfmt(String kind) throws IOException, InterruptedException { String path = prepareRunTsfmt(kind); mavenRunner().withArguments("spotless:apply").runNoError(); @@ -192,7 +198,7 @@ void eslintStyleguideStandardWithTypescript() throws Exception { TEST_FILE_PATH, "", " .eslintrc.js", - " standard-with-typescript", + " " + styleGuideDevDependenciesString("standard-with-typescript"), " ${basedir}/tsconfig.json", ""); setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/standard_with_typescript/.eslintrc.js"); @@ -209,7 +215,7 @@ void eslintStyleguideXo() throws Exception { TEST_FILE_PATH, "", " .eslintrc.js", - " xo-typescript", + " " + styleGuideDevDependenciesString("xo-typescript"), " ${basedir}/tsconfig.json", ""); setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js"); diff --git a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java new file mode 100644 index 0000000000..62d0b0aa00 --- /dev/null +++ b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java @@ -0,0 +1,120 @@ +/* + * 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.npm; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.annotation.Nonnull; + +/** + * A helper class to create dev dependencies for eslint when using one of the popular styleguides in testing. + */ +public enum EslintStyleGuide { + TS_STANDARD_WITH_TYPESCRIPT("standard-with-typescript") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-standard-with-typescript", "^24.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); + dependencies.put("eslint-plugin-n", "^15.6.0"); + dependencies.put("eslint-plugin-promise", "^6.1.1"); + return dependencies; + } + }, + TS_XO_TYPESCRIPT("xo-typescript") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-xo", "^0.43.1"); + dependencies.put("eslint-config-xo-typescript", "^0.55.1"); + return dependencies; + } + }, + JS_AIRBNB("airbnb") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-airbnb-base", "^15.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); + return dependencies; + } + }, + JS_GOOGLE("google") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-google", "^0.14.0"); + return dependencies; + } + }, + JS_STANDARD("standard") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-standard", "^17.0.0"); + dependencies.put("eslint-plugin-import", "^2.26.0"); + dependencies.put("eslint-plugin-n", "^15.6.0"); + dependencies.put("eslint-plugin-promise", "^6.1.1"); + return dependencies; + } + }, + JS_XO("xo") { + @Override + public @Nonnull Map devDependencies() { + Map dependencies = new LinkedHashMap<>(); + dependencies.put("eslint-config-xo", "^0.43.1"); + return dependencies; + } + }; + + private final String popularStyleGuideName; + + EslintStyleGuide(String popularStyleGuideName) { + this.popularStyleGuideName = popularStyleGuideName; + } + + public abstract @Nonnull Map devDependencies(); + + public static EslintStyleGuide fromNameOrNull(String popularStyleGuideName) { + for (EslintStyleGuide popularStyleGuide : EslintStyleGuide.values()) { + if (popularStyleGuide.popularStyleGuideName.equals(popularStyleGuideName)) { + return popularStyleGuide; + } + } + return null; + } + + public Map mergedWith(Map devDependencies) { + Map merged = new LinkedHashMap<>(devDependencies); + merged.putAll(devDependencies()); + return merged; + } + + public String asGradleMapStringMergedWith(Map devDependencies) { + return mergedWith(devDependencies).entrySet().stream() + .map(entry -> "'" + entry.getKey() + "': '" + entry.getValue() + "'") + .collect(Collectors.joining(", ", "[", "]")); + } + + public String asMavenXmlStringMergedWith(Map devDependencies) { + return mergedWith(devDependencies).entrySet().stream() + .map(entry -> "<" + entry.getKey() + ">" + entry.getValue() + "") + .collect(Collectors.joining("", "", "")); + } + +} diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 19f6e8c223..1bc0915ed3 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -17,7 +17,6 @@ import java.io.File; import java.util.Map; -import java.util.TreeMap; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -34,22 +33,16 @@ @NpmTest class EslintFormatterStepTest { - private final Map combine(Map m1, Map m2) { - Map combined = new TreeMap<>(m1); - combined.putAll(m2); - return combined; - } - @NpmTest @Nested class EslintJavascriptFormattingStepTest extends NpmFormatterStepCommonTests { private final Map> devDependenciesForRuleset = ImmutableMap.of( "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), - "styleguide/airbnb", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_AIRBNB.devDependencies()), - "styleguide/google", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_GOOGLE.devDependencies()), - "styleguide/standard", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_STANDARD.devDependencies()), - "styleguide/xo", combine(EslintFormatterStep.defaultDevDependencies(), EslintFormatterStep.PopularStyleGuide.JS_XO.devDependencies())); + "styleguide/airbnb", EslintStyleGuide.JS_AIRBNB.mergedWith(EslintFormatterStep.defaultDevDependencies()), + "styleguide/google", EslintStyleGuide.JS_GOOGLE.mergedWith(EslintFormatterStep.defaultDevDependencies()), + "styleguide/standard", EslintStyleGuide.JS_STANDARD.mergedWith(EslintFormatterStep.defaultDevDependencies()), + "styleguide/xo", EslintStyleGuide.JS_XO.mergedWith(EslintFormatterStep.defaultDevDependencies())); @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") @ValueSource(strings = {"custom_rules", "styleguide/airbnb", "styleguide/google", "styleguide/standard", "styleguide/xo"}) @@ -86,8 +79,8 @@ class EslintTypescriptFormattingStepTest extends NpmFormatterStepCommonTests { private final Map> devDependenciesForRuleset = ImmutableMap.of( "custom_rules", EslintFormatterStep.defaultDevDependenciesForTypescript(), - "styleguide/standard_with_typescript", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_STANDARD_WITH_TYPESCRIPT.devDependencies()), - "styleguide/xo", combine(EslintFormatterStep.defaultDevDependenciesForTypescript(), EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies())); + "styleguide/standard_with_typescript", EslintStyleGuide.TS_STANDARD_WITH_TYPESCRIPT.mergedWith(EslintFormatterStep.defaultDevDependenciesForTypescript()), + "styleguide/xo", EslintStyleGuide.TS_XO_TYPESCRIPT.mergedWith(EslintFormatterStep.defaultDevDependenciesForTypescript())); @ParameterizedTest(name = "{index}: eslint can be applied using ruleset {0}") @ValueSource(strings = {"custom_rules", "styleguide/standard_with_typescript", "styleguide/xo"}) @@ -167,7 +160,7 @@ void formattingUsingInlineXoConfig() throws Exception { final String cleanFile = filedir + "typescript.clean"; final FormatterStep formatterStep = EslintFormatterStep.create( - combine(EslintFormatterStep.PopularStyleGuide.TS_XO_TYPESCRIPT.devDependencies(), EslintFormatterStep.defaultDevDependenciesForTypescript()), + EslintStyleGuide.TS_XO_TYPESCRIPT.mergedWith(EslintFormatterStep.defaultDevDependenciesForTypescript()), TestProvisioner.mavenCentral(), projectDir(), buildDir(), From 6577e29cdbd735b310143057372b1a0709c5219f Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 10 Jan 2023 09:43:04 +0100 Subject: [PATCH 0229/1120] eslint: fix anchor navigation --- plugin-gradle/README.md | 8 ++++---- plugin-maven/README.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 8a06351bed..878885f645 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -69,8 +69,8 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint--typescript-)) - - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint--javascript-)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript)) - [JSON](#json) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) @@ -624,7 +624,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Javascript)](#eslint--javascript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. It differs in supported styleguides and the requirement for a tsconfigFile. ```gradle @@ -689,7 +689,7 @@ spotless { The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Typescript)](#eslint--typescript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. It differs in supported styleguides and no requirement for a tsconfig (of course). ```gradle diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2a2aa31010..e74e1b27cf 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -57,8 +57,8 @@ user@machine repo % mvn spotless:check - [Sql](#sql) ([dbeaver](#dbeaver)) - [Maven Pom](#maven-pom) ([sortPom](#sortpom)) - [Markdown](#markdown) ([flexmark](#flexmark)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint--typescript-)) - - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint--javascript-)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript)) - [JSON](#json) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) @@ -724,7 +724,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Javascript)](#eslint--javascript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. It differs in supported styleguides and the requirement for a tsconfigFile. ```xml @@ -803,7 +803,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Typescript)](#eslint--typescript-) configuration. It differs in supported +The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. It differs in supported styleguides and no requirement for a tsconfig (of course). ```xml From 04a6bcbf46bca245bf5e6bead7218b38ae6a3845 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 10 Jan 2023 13:06:39 +0000 Subject: [PATCH 0230/1120] Update dependency org.junit.jupiter:junit-jupiter to v5.9.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e966c09437..71f755522f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r -VER_JUNIT=5.9.1 +VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.1 VER_MOCKITO=4.11.0 From 0227e89d641ab85dc8f2e48f715867c0992add06 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 10 Jan 2023 15:09:03 +0100 Subject: [PATCH 0231/1120] eslint: cleanup doc --- plugin-gradle/README.md | 8 ++++---- plugin-maven/README.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 878885f645..b44d79ef3d 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -624,8 +624,8 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. It differs in supported -styleguides and the requirement for a tsconfigFile. +The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. In typescript, a +reference to a `tsconfig.json` is required. ```gradle spotless { @@ -689,8 +689,8 @@ spotless { The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. It differs in supported -styleguides and no requirement for a tsconfig (of course). +The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. In javascript, *no* +`tsconfig.json` is supported. ```gradle diff --git a/plugin-maven/README.md b/plugin-maven/README.md index e74e1b27cf..3ec338bf10 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -724,8 +724,8 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. It differs in supported -styleguides and the requirement for a tsconfigFile. +The configuration is very similar to the [ESLint (Javascript)](#eslint-javascript) configuration. In typescript, a +reference to a `tsconfig.json` is required. ```xml @@ -803,8 +803,8 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n The auto-discovery of config files (up the file tree) will not work when using ESLint within spotless, hence you are required to provide resolvable file paths for config files, or alternatively provide the configuration inline. -The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. It differs in supported -styleguides and no requirement for a tsconfig (of course). +The configuration is very similar to the [ESLint (Typescript)](#eslint-typescript) configuration. In javascript, *no* +`tsconfig.json` is supported. ```xml From 4438d1845f94cfa25f01576f1f9f60850de4690e Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 10 Jan 2023 21:43:13 +0400 Subject: [PATCH 0232/1120] Small fixes --- plugin-maven/README.md | 11 +++++----- .../spotless/maven/AbstractSpotlessMojo.java | 12 +++++++++-- .../yaml/{JacksonYaml.java => Jackson.java} | 2 +- .../diffplug/spotless/maven/yaml/Yaml.java | 6 +++--- .../maven/MavenIntegrationHarness.java | 2 +- .../spotless/maven/json/JsonTest.java | 4 ++-- .../spotless/maven/yaml/YamlTest.java | 20 +++++++++---------- .../yaml/multiple_document.clean.yaml | 8 -------- .../yaml/multiple_documents.clean.yaml | 8 ++++++++ ..._document.yaml => multiple_documents.yaml} | 0 .../yaml/separator_comments.clean.yaml | 1 + 11 files changed, 41 insertions(+), 33 deletions(-) rename plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/{JacksonYaml.java => Jackson.java} (96%) delete mode 100644 testlib/src/main/resources/yaml/multiple_document.clean.yaml create mode 100644 testlib/src/main/resources/yaml/multiple_documents.clean.yaml rename testlib/src/main/resources/yaml/{multiple_document.yaml => multiple_documents.yaml} (100%) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 9255594375..0fe8bb52b4 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -768,9 +768,8 @@ for details. ```xml - - **/*.yaml - **/*.yml + + src/**/*.yaml @@ -785,11 +784,11 @@ Uses Jackson and YAMLFactory to pretty print objects: ```xml 2.13.4 - + INDENT_OUTPUT - - DEFAULT_HAS_TO_DISABLED_FEATURE + + DEFAULT_HAS_NO_DISABLED_FEATURE ``` 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 e4fdc7dcd0..31fd5fd5e3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -64,6 +64,7 @@ import com.diffplug.spotless.maven.incremental.UpToDateChecker; import com.diffplug.spotless.maven.incremental.UpToDateChecking; import com.diffplug.spotless.maven.java.Java; +import com.diffplug.spotless.maven.json.Json; import com.diffplug.spotless.maven.kotlin.Kotlin; import com.diffplug.spotless.maven.markdown.Markdown; import com.diffplug.spotless.maven.pom.Pom; @@ -71,6 +72,7 @@ import com.diffplug.spotless.maven.scala.Scala; import com.diffplug.spotless.maven.sql.Sql; import com.diffplug.spotless.maven.typescript.Typescript; +import com.diffplug.spotless.maven.yaml.Yaml; public abstract class AbstractSpotlessMojo extends AbstractMojo { private static final String DEFAULT_INDEX_FILE_NAME = "spotless-index"; @@ -167,6 +169,12 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Markdown markdown; + @Parameter + private Json json; + + @Parameter + private Yaml yaml; + @Parameter(property = "spotlessFiles") private String filePatterns; @@ -331,7 +339,7 @@ private FileLocator getFileLocator() { } private List getFormatterFactories() { - return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, antlr4, pom, sql, python, markdown)) + return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, antlr4, pom, sql, python, markdown, json, yaml)) .filter(Objects::nonNull) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java similarity index 96% rename from plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java rename to plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java index 86b52aac7d..2bc7617a38 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java @@ -25,7 +25,7 @@ import com.diffplug.spotless.maven.FormatterStepFactory; import com.diffplug.spotless.yaml.YamlJacksonStep; -public class JacksonYaml implements FormatterStepFactory { +public class Jackson implements FormatterStepFactory { @Parameter private String version = YamlJacksonStep.defaultVersion(); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java index 20e609ceb4..6cba1b2ebd 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java @@ -15,9 +15,9 @@ */ package com.diffplug.spotless.maven.yaml; +import java.util.Collections; import java.util.Set; -import com.diffplug.common.collect.Sets; import com.diffplug.spotless.maven.FormatterFactory; /** @@ -26,7 +26,7 @@ public class Yaml extends FormatterFactory { @Override public Set defaultIncludes() { - return Sets.newHashSet("**/*.yaml", "**/*.yml"); + return Collections.emptySet(); } @Override @@ -34,7 +34,7 @@ public String licenseHeaderDelimiter() { return null; } - public void addJackson(JacksonYaml jackson) { + public void addJackson(Jackson jackson) { addStepFactory(jackson); } 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 5dbd3e0075..a008a8bf4f 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 @@ -161,7 +161,7 @@ protected void writePomWithJsonSteps(String... steps) throws IOException { } protected void writePomWithYamlSteps(String... steps) throws IOException { - writePom(groupWithSteps("yaml", steps)); + writePom(groupWithSteps("yaml", including("**/*.yaml"), steps)); } protected void writePom(String... configuration) throws IOException { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index fe6560cbec..f63dc708e9 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -22,7 +22,7 @@ public class JsonTest extends MavenIntegrationHarness { @Test public void testFormatJson_WithSimple_defaultConfig() throws Exception { - writePomWithJsonSteps(""); + writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError().error(); @@ -31,7 +31,7 @@ public void testFormatJson_WithSimple_defaultConfig() throws Exception { @Test public void testFormatJson_WithGson_defaultConfig() throws Exception { - writePomWithJsonSteps(""); + writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError().error(); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index b2168ff05f..4614b42f22 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -22,28 +22,28 @@ public class YamlTest extends MavenIntegrationHarness { @Test public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws Exception { - writePomWithJsonSteps(""); + writePomWithYamlSteps(""); - setFile("yaml_test.json").toResource("yaml/separator_comments.yaml"); + setFile("yaml_test.yaml").toResource("yaml/separator_comments.yaml"); mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("yaml_test.json").sameAsResource("yaml/separator_comments.clean.yaml"); + assertFile("yaml_test.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); } @Test public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exception { - writePomWithJsonSteps(""); + writePomWithYamlSteps(""); - setFile("yaml_test.json").toResource("yaml/array_with_bracket.yaml"); + setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml"); mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("yaml_test.json").sameAsResource("yaml/array_with_bracket.clean.yaml"); + assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.yaml"); } @Test - public void testFormatYaml_WithJackson_defaultConfig_multipleComments() throws Exception { - writePomWithJsonSteps(""); + public void testFormatYaml_WithJackson_defaultConfig_multipleDocuments() throws Exception { + writePomWithYamlSteps(""); - setFile("yaml_test.json").toResource("yaml/multiple_documents.yaml"); + setFile("yaml_test.yaml").toResource("yaml/multiple_documents.yaml"); mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("yaml_test.json").sameAsResource("yaml/multiple_documents.clean.yaml"); + assertFile("yaml_test.yaml").sameAsResource("yaml/multiple_documents.clean.yaml"); } } diff --git a/testlib/src/main/resources/yaml/multiple_document.clean.yaml b/testlib/src/main/resources/yaml/multiple_document.clean.yaml deleted file mode 100644 index bf46f753c0..0000000000 --- a/testlib/src/main/resources/yaml/multiple_document.clean.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -hr: - - Mark McGwire - # Following node labeled SS - - &SS Sammy Sosa -rbi: - - *SS # Subsequent occurrence - - Ken Griffey \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/multiple_documents.clean.yaml b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml new file mode 100644 index 0000000000..612497c0ab --- /dev/null +++ b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml @@ -0,0 +1,8 @@ +document: this is document 1 +--- + +document: this is document 2 + +--- + +document: this is document 3 \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/multiple_document.yaml b/testlib/src/main/resources/yaml/multiple_documents.yaml similarity index 100% rename from testlib/src/main/resources/yaml/multiple_document.yaml rename to testlib/src/main/resources/yaml/multiple_documents.yaml diff --git a/testlib/src/main/resources/yaml/separator_comments.clean.yaml b/testlib/src/main/resources/yaml/separator_comments.clean.yaml index bf46f753c0..98160e910f 100644 --- a/testlib/src/main/resources/yaml/separator_comments.clean.yaml +++ b/testlib/src/main/resources/yaml/separator_comments.clean.yaml @@ -1,4 +1,5 @@ --- + hr: - Mark McGwire # Following node labeled SS From dcf727c4ceb1c1c1cff88d3dc4e5c38a1f6ab99e Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 11 Jan 2023 08:46:12 +0400 Subject: [PATCH 0233/1120] Add not trivial json tests --- .../spotless/maven/json/JsonTest.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index f63dc708e9..45607807b1 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -21,7 +21,7 @@ public class JsonTest extends MavenIntegrationHarness { @Test - public void testFormatJson_WithSimple_defaultConfig() throws Exception { + public void testFormatJson_WithSimple_defaultConfig_sortByKeys() throws Exception { writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); @@ -30,11 +30,30 @@ public void testFormatJson_WithSimple_defaultConfig() throws Exception { } @Test - public void testFormatJson_WithGson_defaultConfig() throws Exception { + public void testFormatJson_WithSimple_defaultConfig_nestedObject() throws Exception { + writePomWithJsonSteps(""); + + setFile("json_test.json").toResource("json/nestedObjectBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("json_test.json").sameAsResource("json/nestedObjectAfter.json"); + } + + @Test + public void testFormatJson_WithGson_defaultConfig_sortByKeys() throws Exception { writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError().error(); assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled.json"); } + + @Test + public void testFormatJson_WithGson_sortByKeys() throws Exception { + writePomWithJsonSteps("true"); + + setFile("json_test.json").toResource("json/sortByKeysBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); + } + } From 0d6e8ea33bd4f77c60acfafe8c4b7c3c0df9b701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Sier=C5=BC=C4=99ga?= Date: Wed, 11 Jan 2023 09:20:52 +0100 Subject: [PATCH 0234/1120] Docs: additional info about Eclipse formatter version --- plugin-maven/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 3ec338bf10..5197f92255 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -241,7 +241,7 @@ any other maven phase (i.e. compile) then it can be configured as below; ```xml - 4.13.0 + 4.13.0 ${project.basedir}/eclipse-formatter.xml ``` @@ -316,7 +316,7 @@ These mechanisms already exist for the Gradle plugin. ```xml - 4.13.0 + 4.13.0 ${project.basedir}/greclipse.properties ``` @@ -466,7 +466,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```xml - 4.13.0 + 4.13.0 ${project.basedir}/eclipse-cdt.xml ``` @@ -1052,7 +1052,7 @@ Alternatively you can supply spotless with a location of the `.npmrc` file to us ${project.basedir}/xml.prefs ${project.basedir}/additional.properties - 4.13.0 + 4.13.0 From e9c840f9b15bffa7a377c35df07a489f6744e9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Sier=C5=BC=C4=99ga?= Date: Wed, 11 Jan 2023 09:22:09 +0100 Subject: [PATCH 0235/1120] Docs: update version of Eclipse formatter (4.13.0 -> 4.21.0) 4.21.0 is the latest supported version. --- plugin-maven/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 5197f92255..0e2c2982b5 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -241,7 +241,7 @@ any other maven phase (i.e. compile) then it can be configured as below; ```xml - 4.13.0 + 4.21.0 ${project.basedir}/eclipse-formatter.xml ``` @@ -316,7 +316,7 @@ These mechanisms already exist for the Gradle plugin. ```xml - 4.13.0 + 4.21.0 ${project.basedir}/greclipse.properties ``` @@ -466,7 +466,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```xml - 4.13.0 + 4.21.0 ${project.basedir}/eclipse-cdt.xml ``` @@ -1052,7 +1052,7 @@ Alternatively you can supply spotless with a location of the `.npmrc` file to us ${project.basedir}/xml.prefs ${project.basedir}/additional.properties - 4.13.0 + 4.21.0 From a43274a225331fa753a5d70980fb33bcaaacdafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Sier=C5=BC=C4=99ga?= Date: Wed, 11 Jan 2023 09:25:27 +0100 Subject: [PATCH 0236/1120] Docs: fixed broken link to Eclipse WTP compatible versions --- 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 0e2c2982b5..c159e1ca45 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1035,7 +1035,7 @@ Alternatively you can supply spotless with a location of the `.npmrc` file to us ## Eclipse web tools platform -[changelog](https://www.eclipse.org/webtools/). [compatible versions](https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatters). +[changelog](https://www.eclipse.org/webtools/). [compatible versions](https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_wtp_formatter). ```xml From 5041562dfa5e24bbc8f6cb9d3d85008d8e8e5ad1 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 11 Jan 2023 14:48:22 +0400 Subject: [PATCH 0237/1120] Fix reflection on stringToObject --- .../main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java index 4e76bb2941..b29c6ad267 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java @@ -132,7 +132,7 @@ FormatterFunc toFormatter() { private String format(Object objectMapper, Method stringToObject, Method objectToString, String s) throws IllegalAccessException, IllegalArgumentException { try { - Object parsed = stringToObject.invoke(s, Object.class); + Object parsed = stringToObject.invoke(objectMapper, s, Object.class); return (String) objectToString.invoke(objectMapper, parsed); } catch (InvocationTargetException ex) { throw new AssertionError("Unable to format YAML", ex.getCause()); From dcb82ae3d82437252cf93d70e3ccb8c7016b467c Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 11 Jan 2023 15:55:48 +0400 Subject: [PATCH 0238/1120] Fix cleaned YAML given limitations of Jackson --- .../resources/yaml/array_with_bracket.clean.yaml | 14 ++++++++++++-- .../resources/yaml/multiple_documents.clean.yaml | 4 ++-- .../resources/yaml/separator_comments.clean.yaml | 6 ++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml index 8e9d80065e..88fc8fd541 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml @@ -1,2 +1,12 @@ -episodes: [1, 2, 3, 4, 5, 6, 7] -best-jedi: {name: Obi-Wan, side: light} \ No newline at end of file +--- +episodes: +- 1 +- 2 +- 3 +- 4 +- 5 +- 6 +- 7 +best-jedi: + name: Obi-Wan + side: light \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/multiple_documents.clean.yaml b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml index 612497c0ab..45e0b0916b 100644 --- a/testlib/src/main/resources/yaml/multiple_documents.clean.yaml +++ b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml @@ -1,8 +1,8 @@ -document: this is document 1 --- +document: this is document 1 +--- document: this is document 2 --- - document: this is document 3 \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/separator_comments.clean.yaml b/testlib/src/main/resources/yaml/separator_comments.clean.yaml index 98160e910f..7dac8a279f 100644 --- a/testlib/src/main/resources/yaml/separator_comments.clean.yaml +++ b/testlib/src/main/resources/yaml/separator_comments.clean.yaml @@ -1,9 +1,7 @@ --- - hr: - Mark McGwire - # Following node labeled SS - - &SS Sammy Sosa + - Sammy Sosa rbi: - - *SS # Subsequent occurrence + - Sammy Sosa - Ken Griffey \ No newline at end of file From fb3bb169b6d0df3322b30fa585511bb952a2163b Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 11 Jan 2023 16:42:03 +0400 Subject: [PATCH 0239/1120] Fix cleaned YAMLs --- .../src/main/resources/yaml/array_with_bracket.clean.yaml | 4 ++-- .../src/main/resources/yaml/separator_comments.clean.yaml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml index 88fc8fd541..c6f891b9de 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.yaml @@ -8,5 +8,5 @@ episodes: - 6 - 7 best-jedi: - name: Obi-Wan - side: light \ No newline at end of file + name: "Obi-Wan" + side: "light" \ No newline at end of file diff --git a/testlib/src/main/resources/yaml/separator_comments.clean.yaml b/testlib/src/main/resources/yaml/separator_comments.clean.yaml index 7dac8a279f..35bb8717dd 100644 --- a/testlib/src/main/resources/yaml/separator_comments.clean.yaml +++ b/testlib/src/main/resources/yaml/separator_comments.clean.yaml @@ -1,7 +1,7 @@ --- hr: - - Mark McGwire - - Sammy Sosa +- "Mark McGwire" +- "Sammy Sosa" rbi: - - Sammy Sosa - - Ken Griffey \ No newline at end of file +- "SS" +- "Ken Griffey" \ No newline at end of file From 13d9d3cd19eaa8812191c44db045aee754df569b Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 12 Jan 2023 11:06:03 +0400 Subject: [PATCH 0240/1120] Fix YAML and JSON tests --- .gitignore | 3 + .java-version | 1 - lib/build.gradle | 6 +- .../glue/yaml/YamlJacksonFormatterFunc.java | 99 +++++++++++++++++++ .../spotless/yaml/YamlJacksonStep.java | 31 ++++-- .../spotless/yaml/YamlJacksonV2Step.java | 77 +++++++++++++++ .../diffplug/spotless/maven/yaml/Jackson.java | 3 +- .../spotless/maven/json/JsonTest.java | 26 ++++- .../spotless/maven/yaml/YamlTest.java | 18 +++- .../json/sortByKeysAfterDisabled_Simple.json | 19 ++++ .../multiple_documents.clean.jackson.yaml | 2 + 11 files changed, 263 insertions(+), 22 deletions(-) delete mode 100644 .java-version create mode 100644 lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java create mode 100644 lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java create mode 100644 testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json create mode 100644 testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml diff --git a/.gitignore b/.gitignore index 1a95765d37..138bb77159 100644 --- a/.gitignore +++ b/.gitignore @@ -121,3 +121,6 @@ nbdist/ nbactions.xml nb-configuration.xml .nb-gradle/ + +# MacOS jenv +.java-version diff --git a/.java-version b/.java-version deleted file mode 100644 index 2dbc24b32d..0000000000 --- a/.java-version +++ /dev/null @@ -1 +0,0 @@ -11.0 diff --git a/lib/build.gradle b/lib/build.gradle index 115d27195f..0cf07f9531 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -14,7 +14,8 @@ def NEEDS_GLUE = [ 'ktlint', 'flexmark', 'diktat', - 'scalafmt' + 'scalafmt', + 'jackson' ] for (glue in NEEDS_GLUE) { sourceSets.register(glue) { @@ -55,6 +56,9 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm + // used jackson-based formatters + jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.4' + String VER_KTFMT = '0.42' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java new file mode 100644 index 0000000000..604ad048c8 --- /dev/null +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java @@ -0,0 +1,99 @@ +/* + * 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. + * 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.yaml; + +import java.io.IOException; +import java.util.List; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; + +import com.diffplug.spotless.FormatterFunc; + +public class YamlJacksonFormatterFunc implements FormatterFunc { + private List enabledFeatures; + private List disabledFeatures; + + // private static final Logger logger = LoggerFactory.getLogger(YamlJacksonFormatterFunc.class); + + public YamlJacksonFormatterFunc(List enabledFeatures, List disabledFeatures) { + this.enabledFeatures = enabledFeatures; + this.disabledFeatures = disabledFeatures; + } + + @Override + public String apply(String input) throws Exception { + ObjectMapper objectMapper = makeObjectMapper(); + + return format(objectMapper, input); + } + + protected ObjectMapper makeObjectMapper() { + YAMLFactory yamlFactory = new YAMLFactory(); + ObjectMapper objectMapper = new ObjectMapper(yamlFactory); + + // Configure the ObjectMapper + // https://github.com/FasterXML/jackson-databind#commonly-used-features + for (String rawFeature : enabledFeatures) { + // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection + SerializationFeature feature = SerializationFeature.valueOf(rawFeature); + + objectMapper.enable(feature); + } + + for (String rawFeature : disabledFeatures) { + // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection + SerializationFeature feature = SerializationFeature.valueOf(rawFeature); + + objectMapper.disable(feature); + } + return objectMapper; + } + + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + // We may consider adding manually an initial '---' prefix to help management of multiple documents + // if (!input.trim().startsWith("---")) { + // input = "---" + "\n" + input; + // } + + try { + // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson + // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 + // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' + // JsonParser yamlParser = objectMapper.getFactory().createParser(input); + // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); + // return objectMapper.writeValueAsString(docs); + + // 2023-01: This returns JSON instead of YAML + // This will transit with a JsonNode + // A JsonNode may keep the comments from the input node + // JsonNode jsonNode = objectMapper.readTree(input); + //Not 'toPrettyString' as one could require no INDENT_OUTPUT + // return jsonNode.toPrettyString(); + ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); + return objectMapper.writeValueAsString(objectNode); + } catch (JsonProcessingException e) { + throw new AssertionError("Unable to format YAML. input='" + input + "'", e); + } + } + + // Spotbugs + private static class ObjectNodeTypeReference extends TypeReference {} +} diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java index b29c6ad267..c0c660694b 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java @@ -31,9 +31,10 @@ /** * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. */ +// https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson public final class YamlJacksonStep { - private static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; - private static final String DEFAULT_VERSION = "2.13.4"; + static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; + static final String DEFAULT_VERSION = "2.13.4"; public static String defaultVersion() { return DEFAULT_VERSION; @@ -80,8 +81,8 @@ FormatterFunc toFormatter() { Method enableFeature; Method disableFeature; - Method stringToObject; - Method objectToString; + Method stringToNode; + Method nodeToString; try { ClassLoader classLoader = jarState.getClassLoader(); jsonFactoryClass = classLoader.loadClass("com.fasterxml.jackson.core.JsonFactory"); @@ -97,8 +98,18 @@ FormatterFunc toFormatter() { disableFeature = objectMapperClass.getMethod("disable", serializationFeatureClass); } - stringToObject = objectMapperClass.getMethod("readValue", String.class, Class.class); - objectToString = objectMapperClass.getMethod("writeValueAsString", Object.class); + // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson + // List docs = mapper + // .readValues(yamlParser, new TypeReference {}) + // .readAll(); + + Class jsonNodeClass = classLoader.loadClass("com.fasterxml.jackson.databind.JsonNode"); + + // This will transit with a JsonNode + // A JsonNode may keep the comments from the input node + stringToNode = objectMapperClass.getMethod("readTree", String.class); + // Not 'toPrettyString' as one could require no INDENT_OUTPUT + nodeToString = jsonNodeClass.getMethod("toPrettyString"); } catch (ClassNotFoundException | NoSuchMethodException e) { throw new IllegalStateException("There was a problem preparing org.json dependencies", e); } @@ -125,15 +136,15 @@ FormatterFunc toFormatter() { disableFeature.invoke(objectMapper, indentOutput); } - return format(objectMapper, stringToObject, objectToString, s); + return format(objectMapper, stringToNode, nodeToString, s); }; } - private String format(Object objectMapper, Method stringToObject, Method objectToString, String s) + private String format(Object objectMapper, Method stringToNode, Method nodeToString, String s) throws IllegalAccessException, IllegalArgumentException { try { - Object parsed = stringToObject.invoke(objectMapper, s, Object.class); - return (String) objectToString.invoke(objectMapper, parsed); + Object node = stringToNode.invoke(objectMapper, s); + return (String) nodeToString.invoke(node); } catch (InvocationTargetException ex) { throw new AssertionError("Unable to format YAML", ex.getCause()); } diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java new file mode 100644 index 0000000000..f9b1d6b7dc --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java @@ -0,0 +1,77 @@ +/* + * 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. + * 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.yaml; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.List; +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 YamlJacksonV2Step { + private YamlJacksonV2Step() {} + + public static String defaultVersion() { + return YamlJacksonStep.DEFAULT_VERSION; + } + + public static FormatterStep create(List enabledFeatures, + List disabledFeatures, + String jacksonVersion, + Provisioner provisioner) { + Objects.requireNonNull(provisioner, "provisioner cannot be null"); + return FormatterStep.createLazy("yaml", + () -> new State(enabledFeatures, disabledFeatures, jacksonVersion, provisioner), + State::toFormatter); + } + + public static FormatterStep create(Provisioner provisioner) { + return create(Arrays.asList("INDENT_OUTPUT"), Arrays.asList(), defaultVersion(), provisioner); + } + + private static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + private final List enabledFeatures; + private final List disabledFeatures; + + private final JarState jarState; + + private State(List enabledFeatures, + List disabledFeatures, + String jacksonVersion, + Provisioner provisioner) throws IOException { + this.enabledFeatures = enabledFeatures; + this.disabledFeatures = disabledFeatures; + + this.jarState = JarState.from(YamlJacksonStep.MAVEN_COORDINATE + jacksonVersion, provisioner); + } + + FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + InstantiationException, IllegalAccessException { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.YamlJacksonFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(List.class, List.class); + return (FormatterFunc) constructor.newInstance(enabledFeatures, disabledFeatures); + } + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java index 2bc7617a38..28fdf5809c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java @@ -24,6 +24,7 @@ import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; import com.diffplug.spotless.yaml.YamlJacksonStep; +import com.diffplug.spotless.yaml.YamlJacksonV2Step; public class Jackson implements FormatterStepFactory { @@ -40,7 +41,7 @@ public class Jackson implements FormatterStepFactory { public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { List enabledFeaturesAsList = Arrays.asList(enabledFeatures); List disabledFeaturesAsList = Arrays.asList(disabledFeatures); - return YamlJacksonStep + return YamlJacksonV2Step .create(enabledFeaturesAsList, disabledFeaturesAsList, version, stepConfig.getProvisioner()); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index 45607807b1..e492109faa 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -16,17 +16,21 @@ package com.diffplug.spotless.maven.json; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.diffplug.spotless.maven.MavenIntegrationHarness; public class JsonTest extends MavenIntegrationHarness { + private static final Logger LOGGER = LoggerFactory.getLogger(JsonTest.class); + @Test public void testFormatJson_WithSimple_defaultConfig_sortByKeys() throws Exception { writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled_Simple.json"); } @Test @@ -34,7 +38,7 @@ public void testFormatJson_WithSimple_defaultConfig_nestedObject() throws Except writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/nestedObjectBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("json_test.json").sameAsResource("json/nestedObjectAfter.json"); } @@ -43,7 +47,7 @@ public void testFormatJson_WithGson_defaultConfig_sortByKeys() throws Exception writePomWithJsonSteps(""); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("json_test.json").sameAsResource("json/sortByKeysAfterDisabled.json"); } @@ -52,8 +56,20 @@ public void testFormatJson_WithGson_sortByKeys() throws Exception { writePomWithJsonSteps("true"); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + + String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); + LOGGER.error(output); + System.err.println(output); assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); } + @Test + public void testFormatJson_WithGson_defaultConfig_nestedObject() throws Exception { + writePomWithJsonSteps(""); + + setFile("json_test.json").toResource("json/nestedObjectBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("json_test.json").sameAsResource("json/nestedObjectAfter.json"); + } + } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 4614b42f22..b5a417c536 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -15,17 +15,27 @@ */ package com.diffplug.spotless.maven.yaml; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.diffplug.spotless.maven.MavenIntegrationHarness; +import com.diffplug.spotless.maven.MavenRunner.Result; public class YamlTest extends MavenIntegrationHarness { + private static final Logger LOGGER = LoggerFactory.getLogger(YamlTest.class); + @Test public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws Exception { writePomWithYamlSteps(""); setFile("yaml_test.yaml").toResource("yaml/separator_comments.yaml"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + Result runNoError = mavenRunner().withArguments("spotless:apply").runNoError(); + LOGGER.error("result: {}", runNoError); + assertThat(runNoError.exitValue()).as("Run without error %s", runNoError).isEqualTo(0); + LOGGER.error("GOGO"); assertFile("yaml_test.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); } @@ -34,7 +44,7 @@ public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exce writePomWithYamlSteps(""); setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.yaml"); } @@ -43,7 +53,7 @@ public void testFormatYaml_WithJackson_defaultConfig_multipleDocuments() throws writePomWithYamlSteps(""); setFile("yaml_test.yaml").toResource("yaml/multiple_documents.yaml"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); - assertFile("yaml_test.yaml").sameAsResource("yaml/multiple_documents.clean.yaml"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("yaml_test.yaml").sameAsResource("yaml/multiple_documents.clean.jackson.yaml"); } } diff --git a/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json b/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json new file mode 100644 index 0000000000..d2d3612fbd --- /dev/null +++ b/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json @@ -0,0 +1,19 @@ +{ + "A": 1, + "a": 3, + "c": 4, + "x": 5, + "X": 2, + "z": { + "A": 1, + "a": 3, + "c": 4, + "x": 5, + "X": 2 + }, + "_arraysNotSorted": [ + 3, + 2, + 1 + ] +} diff --git a/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml b/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml new file mode 100644 index 0000000000..aa731919b4 --- /dev/null +++ b/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml @@ -0,0 +1,2 @@ +--- +document: "this is document 1" From fa203e4ebb2606383f8c5253e5fa52a6b9ab9099 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 12 Jan 2023 11:15:40 +0400 Subject: [PATCH 0241/1120] Remove reflection impl to rely on glue impl --- lib/build.gradle | 2 +- .../glue/yaml/YamlJacksonFormatterFunc.java | 2 - .../spotless/yaml/YamlJacksonStep.java | 96 +++---------------- .../spotless/yaml/YamlJacksonV2Step.java | 77 --------------- plugin-maven/README.md | 2 +- .../diffplug/spotless/maven/yaml/Jackson.java | 3 +- 6 files changed, 15 insertions(+), 167 deletions(-) delete mode 100644 lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java diff --git a/lib/build.gradle b/lib/build.gradle index 0cf07f9531..3ef2064765 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -57,7 +57,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm // used jackson-based formatters - jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.4' + jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1' String VER_KTFMT = '0.42' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java index 604ad048c8..30cf538159 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java @@ -31,8 +31,6 @@ public class YamlJacksonFormatterFunc implements FormatterFunc { private List enabledFeatures; private List disabledFeatures; - // private static final Logger logger = LoggerFactory.getLogger(YamlJacksonFormatterFunc.class); - public YamlJacksonFormatterFunc(List enabledFeatures, List disabledFeatures) { this.enabledFeatures = enabledFeatures; this.disabledFeatures = disabledFeatures; diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java index c0c660694b..db2525ab97 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java @@ -17,8 +17,8 @@ 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.Arrays; import java.util.List; import java.util.Objects; @@ -32,9 +32,12 @@ * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. */ // https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson -public final class YamlJacksonStep { +public class YamlJacksonStep { static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; - static final String DEFAULT_VERSION = "2.13.4"; + // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml + static final String DEFAULT_VERSION = "2.14.1"; + + private YamlJacksonStep() {} public static String defaultVersion() { return DEFAULT_VERSION; @@ -69,89 +72,14 @@ private State(List enabledFeatures, this.enabledFeatures = enabledFeatures; this.disabledFeatures = disabledFeatures; - this.jarState = JarState.from(MAVEN_COORDINATE + jacksonVersion, provisioner); + this.jarState = JarState.from(YamlJacksonStep.MAVEN_COORDINATE + jacksonVersion, provisioner); } - FormatterFunc toFormatter() { - Class jsonFactoryClass; - Class yamlFactoryClass; - Class objectMapperClass; - - Class serializationFeatureClass; - Method enableFeature; - Method disableFeature; - - Method stringToNode; - Method nodeToString; - try { - ClassLoader classLoader = jarState.getClassLoader(); - jsonFactoryClass = classLoader.loadClass("com.fasterxml.jackson.core.JsonFactory"); - yamlFactoryClass = classLoader.loadClass("com.fasterxml.jackson.dataformat.yaml.YAMLFactory"); - - objectMapperClass = classLoader.loadClass("com.fasterxml.jackson.databind.ObjectMapper"); - - // Configure the ObjectMapper - // https://github.com/FasterXML/jackson-databind#commonly-used-features - { - serializationFeatureClass = classLoader.loadClass("com.fasterxml.jackson.databind.SerializationFeature"); - enableFeature = objectMapperClass.getMethod("enable", serializationFeatureClass); - disableFeature = objectMapperClass.getMethod("disable", serializationFeatureClass); - } - - // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson - // List docs = mapper - // .readValues(yamlParser, new TypeReference {}) - // .readAll(); - - Class jsonNodeClass = classLoader.loadClass("com.fasterxml.jackson.databind.JsonNode"); - - // This will transit with a JsonNode - // A JsonNode may keep the comments from the input node - stringToNode = objectMapperClass.getMethod("readTree", String.class); - // Not 'toPrettyString' as one could require no INDENT_OUTPUT - nodeToString = jsonNodeClass.getMethod("toPrettyString"); - } catch (ClassNotFoundException | NoSuchMethodException e) { - throw new IllegalStateException("There was a problem preparing org.json dependencies", e); - } - - return s -> { - if (s.isEmpty()) { - return s; - } - - Object yamlFactory = yamlFactoryClass.getConstructor().newInstance(); - Object objectMapper = objectMapperClass.getConstructor(jsonFactoryClass).newInstance(yamlFactory); - - for (String feature : enabledFeatures) { - // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - Object indentOutput = Enum.valueOf(serializationFeatureClass.asSubclass(Enum.class), feature); - - enableFeature.invoke(objectMapper, indentOutput); - } - - for (String feature : disabledFeatures) { - // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - Object indentOutput = Enum.valueOf(serializationFeatureClass.asSubclass(Enum.class), feature); - - disableFeature.invoke(objectMapper, indentOutput); - } - - return format(objectMapper, stringToNode, nodeToString, s); - }; + FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + InstantiationException, IllegalAccessException { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.YamlJacksonFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(List.class, List.class); + return (FormatterFunc) constructor.newInstance(enabledFeatures, disabledFeatures); } - - private String format(Object objectMapper, Method stringToNode, Method nodeToString, String s) - throws IllegalAccessException, IllegalArgumentException { - try { - Object node = stringToNode.invoke(objectMapper, s); - return (String) nodeToString.invoke(node); - } catch (InvocationTargetException ex) { - throw new AssertionError("Unable to format YAML", ex.getCause()); - } - } - } - - private YamlJacksonStep() { - // cannot be directly instantiated } } diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java b/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java deleted file mode 100644 index f9b1d6b7dc..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonV2Step.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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. - * 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.yaml; - -import java.io.IOException; -import java.io.Serializable; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.List; -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 YamlJacksonV2Step { - private YamlJacksonV2Step() {} - - public static String defaultVersion() { - return YamlJacksonStep.DEFAULT_VERSION; - } - - public static FormatterStep create(List enabledFeatures, - List disabledFeatures, - String jacksonVersion, - Provisioner provisioner) { - Objects.requireNonNull(provisioner, "provisioner cannot be null"); - return FormatterStep.createLazy("yaml", - () -> new State(enabledFeatures, disabledFeatures, jacksonVersion, provisioner), - State::toFormatter); - } - - public static FormatterStep create(Provisioner provisioner) { - return create(Arrays.asList("INDENT_OUTPUT"), Arrays.asList(), defaultVersion(), provisioner); - } - - private static final class State implements Serializable { - private static final long serialVersionUID = 1L; - - private final List enabledFeatures; - private final List disabledFeatures; - - private final JarState jarState; - - private State(List enabledFeatures, - List disabledFeatures, - String jacksonVersion, - Provisioner provisioner) throws IOException { - this.enabledFeatures = enabledFeatures; - this.disabledFeatures = disabledFeatures; - - this.jarState = JarState.from(YamlJacksonStep.MAVEN_COORDINATE + jacksonVersion, provisioner); - } - - FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, - InstantiationException, IllegalAccessException { - Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.YamlJacksonFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(List.class, List.class); - return (FormatterFunc) constructor.newInstance(enabledFeatures, disabledFeatures); - } - } -} diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 720c9bfee7..c5c5cf0ac3 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -923,7 +923,7 @@ Uses Jackson and YAMLFactory to pretty print objects: ```xml - 2.13.4 + 2.14.1 INDENT_OUTPUT diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java index 28fdf5809c..2bc7617a38 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java @@ -24,7 +24,6 @@ import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; import com.diffplug.spotless.yaml.YamlJacksonStep; -import com.diffplug.spotless.yaml.YamlJacksonV2Step; public class Jackson implements FormatterStepFactory { @@ -41,7 +40,7 @@ public class Jackson implements FormatterStepFactory { public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { List enabledFeaturesAsList = Arrays.asList(enabledFeatures); List disabledFeaturesAsList = Arrays.asList(disabledFeatures); - return YamlJacksonV2Step + return YamlJacksonStep .create(enabledFeaturesAsList, disabledFeaturesAsList, version, stepConfig.getProvisioner()); } } From e4dd33a852949b79acc1a59e9352cade6cdb8e02 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 09:29:43 -0800 Subject: [PATCH 0242/1120] Miinor readme and changelog updates to #1478. --- README.md | 2 ++ plugin-maven/CHANGES.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8171886965..637781d894 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ lib('python.BlackStep') +'{{yes}} | {{no}} lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', +lib('yaml.YamlJacksonStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', '| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} | {{no}} |', ].join('\n'); --> @@ -122,6 +123,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | +| [`yaml.YamlJacksonStep`](lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | | [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: | :white_large_square: | diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ed87752a98..15d83725ea 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) -* **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. + * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)) * Add JSON support ([#1446](https://github.com/diffplug/spotless/pull/1446)) * Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478)) From 2785f17c1b4d8c3f27d675c661f03101d182e5bd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 09:42:45 -0800 Subject: [PATCH 0243/1120] Fix GPG key name. --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7f93bb01f6..c271788c20 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,7 +2,7 @@ # NEXUS_USER # NEXUS_PASS # GPG_PASSPHRASE -# GPG_KEY (base64) +# GPG_KEY64 (base64) # gpg --export-secret-keys --armor KEY_ID | openssl base64 | pbcopy # GRADLE_PORTAL_KEY # GRADLE_PORTAL_SECRET @@ -31,7 +31,7 @@ jobs: ORG_GRADLE_PROJECT_nexus_user: ${{ secrets.NEXUS_USER }} ORG_GRADLE_PROJECT_nexus_pass: ${{ secrets.NEXUS_PASS }} ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} - ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY }} + ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }} gradle_key steps: From a0a35b2fdbda2f92b394f005ffe69dbacd8f905d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 10:16:04 -0800 Subject: [PATCH 0244/1120] Fix nonsense characters polluting gpg_key64. --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c271788c20..c7e184e890 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,8 +32,6 @@ jobs: ORG_GRADLE_PROJECT_nexus_pass: ${{ secrets.NEXUS_PASS }} ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }} - - gradle_key steps: - uses: actions/checkout@v3 - name: jdk 11 From 3d7dde729e835efbec122601890dbd4d5697ff1a Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 12 Jan 2023 19:09:57 +0100 Subject: [PATCH 0245/1120] eslint: move eslint addition to "Added" part --- CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1c6f0781ef..36911cc6ee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,9 +15,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)). * Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478)) +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) -* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 15d83725ea..2f95b164b9 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -9,9 +9,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)) * Add JSON support ([#1446](https://github.com/diffplug/spotless/pull/1446)) * Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478)) +* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) -* Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) From 27686d4402a4b038d2d4a8ddc924c78e6ffa98ac Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 10:55:54 -0800 Subject: [PATCH 0246/1120] Try base64 encoding the nexus password also. --- .github/workflows/deploy.yml | 2 +- gradle/java-publish.gradle | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c7e184e890..67d9449e9b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,7 +29,7 @@ jobs: env: gh_token: ${{ secrets.GH_TOKEN }} ORG_GRADLE_PROJECT_nexus_user: ${{ secrets.NEXUS_USER }} - ORG_GRADLE_PROJECT_nexus_pass: ${{ secrets.NEXUS_PASS }} + ORG_GRADLE_PROJECT_nexus_pass64: ${{ secrets.NEXUS_PASS64 }} ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }} steps: diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 78e73a351f..17819c8da9 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -1,6 +1,20 @@ +import java.nio.charset.StandardCharsets + +def decode64(String varNam) { + String envValue = System.env['ORG_GRADLE_PROJECT_nexus_user'] + if (envValue == null) { + return "" + } else { + return new String(envValue.decodeBase64(), "UTF-8") + } +} if (project.parent == null) { group = 'com.diffplug.spotless' + def pass = System.env['ORG_GRADLE_PROJECT_nexus_pass64'] + if (pass != null) { + pass = pass.decodeBase64() + } // it's the root project apply plugin: 'io.github.gradle-nexus.publish-plugin' nexusPublishing { @@ -9,7 +23,7 @@ if (project.parent == null) { nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) username = System.env['ORG_GRADLE_PROJECT_nexus_user'] - password = System.env['ORG_GRADLE_PROJECT_nexus_pass'] + password = decode64('ORG_GRADLE_PROJECT_nexus_pass64') } } } @@ -158,7 +172,7 @@ model { if (!version.endsWith('-SNAPSHOT')) { signing { - String gpg_key = new String(System.env['ORG_GRADLE_PROJECT_gpg_key64'].decodeBase64()) + String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64') useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase']) sign(publishing.publications) } From 8f8951ed6db38e8b117a194f01fb181d8a6ec296 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 11:52:12 -0800 Subject: [PATCH 0247/1120] Fix stupid mistake in our publishing. --- gradle/java-publish.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 17819c8da9..3d1ddd1c4f 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -1,7 +1,7 @@ import java.nio.charset.StandardCharsets -def decode64(String varNam) { - String envValue = System.env['ORG_GRADLE_PROJECT_nexus_user'] +def decode64(String varName) { + String envValue = System.env[varName] if (envValue == null) { return "" } else { From fd9b2af6acbcefb36a58c6614decc584da11122c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 11:59:44 -0800 Subject: [PATCH 0248/1120] Update changelogs. --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 36911cc6ee..28a857950b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,9 +16,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)). * Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478)) * Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) +* Better suggested messages when user's default is set by JVM limitation. ([#995](https://github.com/diffplug/spotless/pull/995)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) - ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7ca75d1b34..d8b9c26275 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,6 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)) * Added support for npm-based [ESLint](https://eslint.org/) formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) +* Better suggested messages when user's default is set by JVM limitation. ([#995](https://github.com/diffplug/spotless/pull/995)) ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 2f95b164b9..03a2a0b018 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add JSON support ([#1446](https://github.com/diffplug/spotless/pull/1446)) * Add YAML support through Jackson ([#1478](https://github.com/diffplug/spotless/pull/1478)) * Added support for npm-based [ESLint](https://eslint.org/)-formatter for javascript and typescript ([#1453](https://github.com/diffplug/spotless/pull/1453)) +* Better suggested messages when user's default is set by JVM limitation. ([#995](https://github.com/diffplug/spotless/pull/995)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) ### Changes From 445971c68f42aaa0651c08613ba7a74737ed4bd2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 12:09:53 -0800 Subject: [PATCH 0249/1120] Fixup test and spotless. --- lib/src/main/java/com/diffplug/spotless/Jvm.java | 2 +- testlib/src/test/java/com/diffplug/spotless/JvmTest.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Jvm.java b/lib/src/main/java/com/diffplug/spotless/Jvm.java index 0f7e1ff1a6..c9c71b72df 100644 --- a/lib/src/main/java/com/diffplug/spotless/Jvm.java +++ b/lib/src/main/java/com/diffplug/spotless/Jvm.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java index 2bb374d0ed..737c058b37 100644 --- a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/JvmTest.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. @@ -140,9 +140,9 @@ void supportProposesFormatterUpgrade() { throw new Exception("Some test exception"); }).apply(""); }).getMessage(); - assertThat(proposal).contains("not using latest version"); - assertThat(proposal).contains(String.format("on JVM %d+", requiredJvm)); - assertThat(proposal).contains(String.format("upgrade to %s %s", TEST_NAME, "2")); + assertThat(proposal).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" + + "My Test Formatter 2 is the recommended version, which may have fixed this problem.\n" + + "My Test Formatter 2 requires JVM 10+."); } } From 8de6dd574a9a85bb160dc9e0c078cd8bec994d4d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 12:24:32 -0800 Subject: [PATCH 0250/1120] Fix JvmTest on other JVMs. --- testlib/src/test/java/com/diffplug/spotless/JvmTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java index 737c058b37..2f4cf3a806 100644 --- a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java @@ -142,7 +142,7 @@ void supportProposesFormatterUpgrade() { }).getMessage(); assertThat(proposal).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" + "My Test Formatter 2 is the recommended version, which may have fixed this problem.\n" + - "My Test Formatter 2 requires JVM 10+."); + "My Test Formatter 2 requires JVM " + (requiredJvm) + "+."); } } From 66b8dd27c2169cf8dd6a95136183c1568bec2566 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 12 Jan 2023 13:05:59 -0800 Subject: [PATCH 0251/1120] Fix newlines in JvmTest. --- testlib/src/test/java/com/diffplug/spotless/JvmTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java index 2f4cf3a806..ca7fb71305 100644 --- a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java @@ -140,7 +140,7 @@ void supportProposesFormatterUpgrade() { throw new Exception("Some test exception"); }).apply(""); }).getMessage(); - assertThat(proposal).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" + + assertThat(proposal.replace("\r", "")).isEqualTo("My Test Formatter " + fmtVersion + " is currently being used, but outdated.\n" + "My Test Formatter 2 is the recommended version, which may have fixed this problem.\n" + "My Test Formatter 2 requires JVM " + (requiredJvm) + "+."); } From e2f82c4ec56c422c501957b8e55468a81b815511 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 13 Jan 2023 13:18:44 +0800 Subject: [PATCH 0252/1120] Fix subgroups leading catch all matcher Signed-off-by: tison --- .../main/java/com/diffplug/spotless/java/ImportSorterImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index 0390d99c1b..8ed263a780 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -45,7 +45,7 @@ private static class ImportsGroup { private final List subGroups; public ImportsGroup(String importOrder) { - this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR)) + this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR, -1)) .map(this::normalizeStatic) .collect(Collectors.toList()); } From c2d60ba1aa2e9076842c8a1cabc963be524a7297 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 13 Jan 2023 13:23:01 +0800 Subject: [PATCH 0253/1120] Add sortImportsFromArrayWithSubgroupsLeadingCatchAll test case Signed-off-by: tison --- ...aCodeSortedImportsSubgroupsLeadingCatchAll.test | 14 ++++++++++++++ .../spotless/java/ImportOrderStepTest.java | 6 ++++++ 2 files changed, 20 insertions(+) create mode 100644 testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test b/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test new file mode 100644 index 0000000000..62efc65e21 --- /dev/null +++ b/testlib/src/main/resources/java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test @@ -0,0 +1,14 @@ +import static com.foo.Bar; +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static java.lang.Exception.*; +import static java.lang.Runnable.*; +import static org.hamcrest.Matchers.*; +import java.awt.*; +import java.lang.Runnable; +import java.lang.Thread; +import java.util.*; +import java.util.List; +import javax.annotation.Nullable; +import javax.inject.Inject; +import org.dooda.Didoo; diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index 8f3bd799bc..ca6bd39825 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java @@ -41,6 +41,12 @@ void sortImportsFromArrayWithSubgroups() { StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroups.test"); } + @Test + void sortImportsFromArrayWithSubgroupsLeadingCatchAll() { + FormatterStep step = ImportOrderStep.forJava().createFrom("\\#|"); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImportsSubgroups.test", "java/importsorter/JavaCodeSortedImportsSubgroupsLeadingCatchAll.test"); + } + @Test void sortImportsFromFile() { FormatterStep step = ImportOrderStep.forJava().createFrom(createTestFile("java/importsorter/import.properties")); From 6688e3f0a9c12b5d6b38c8991af00bc89fa72e27 Mon Sep 17 00:00:00 2001 From: tison Date: Fri, 13 Jan 2023 13:24:57 +0800 Subject: [PATCH 0254/1120] Update CHANGES files Signed-off-by: tison --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index f0db002dc1..035c636e0e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added `skipLinesMatching` option to `licenseHeader` to support formats where license header cannot be immediately added to the top of the file (e.g. xml, sh). ([#1441](https://github.com/diffplug/spotless/pull/1441)). ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +* Fix subgroups leading catch all matcher. ### Changes * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e8758188b6..39cbb07ad4 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +* Fix subgroups leading catch all matcher. ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index cb38f95de1..dfa7a39a45 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add JSON support ([#1446](https://github.com/diffplug/spotless/pull/1446)) ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +* Fix subgroups leading catch all matcher. ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) From 109ffa6b65e71027787e11c8f66187d8c7b888da Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 12:08:56 -0800 Subject: [PATCH 0255/1120] spotlessApply --- .../main/java/com/diffplug/spotless/java/ImportSorterImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index 8ed263a780..1f014ba95e 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. From 49e370b92772c0a6ef9ac1959b60738dd60e9028 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 14:49:39 -0800 Subject: [PATCH 0256/1120] Published lib/2.32.0 --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 95c4897c7a..c08ca86796 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.32.0] - 2023-01-13 ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. @@ -33,7 +35,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Switch our publishing infrastructure from CircleCI to GitHub Actions ([#1462](https://github.com/diffplug/spotless/pull/1462)). * Help wanted for moving our tests too ([#1472](https://github.com/diffplug/spotless/issues/1472)) - ## [2.31.1] - 2023-01-02 ### Fixed * Improve memory usage when using git ratchet ([#1426](https://github.com/diffplug/spotless/pull/1426)) From 49505b819ca756e510cc20c9f7f912c62d1fc994 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 14:50:44 -0800 Subject: [PATCH 0257/1120] Improve deploy.yml docs since we're actually using Base64. --- .github/workflows/deploy.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 67d9449e9b..ce7b82f820 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,6 +1,9 @@ # GH_TOKEN # NEXUS_USER -# NEXUS_PASS +# NEXUS_PASS64 (base64 NOTE: `base64` and `openssl base64` failed, had to use Java +# byte[] data = "{{password}}".getBytes(StandardCharsets.UTF_8); +# String encoded = new String(Base64.getEncoder().encode(data), StandardCharsets.UTF_8); +# System.out.println(encoded); # GPG_PASSPHRASE # GPG_KEY64 (base64) # gpg --export-secret-keys --armor KEY_ID | openssl base64 | pbcopy From 84b42b46e850009936359d57a04ee7f25835de96 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 15:10:12 -0800 Subject: [PATCH 0258/1120] Fix deprecation in how gradle plugins are published. --- plugin-gradle/build.gradle | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index ba60eb450f..6a7f7dca01 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -38,12 +38,31 @@ apply from: rootProject.file('gradle/special-tests.gradle') // GRADLE PLUGIN PORTAL // ////////////////////////// gradlePlugin { + website = "https://github.com/diffplug/spotless" + vcsUrl = "https://github.com/diffplug/spotless" plugins { spotlessPlugin { id = 'com.diffplug.spotless' implementationClass = 'com.diffplug.gradle.spotless.SpotlessPlugin' displayName = 'Spotless formatting plugin' description = project.description + tags.set([ + 'format', + 'style', + 'license', + 'header', + 'google-java-format', + 'eclipse', + 'ktlint', + 'ktfmt', + 'diktat', + 'tsfmt', + 'prettier', + 'scalafmt', + 'scalafix', + 'black', + 'clang-format' + ]) } spotlessPluginLegacy { id = 'com.diffplug.gradle.spotless' @@ -55,29 +74,6 @@ gradlePlugin { } if (version.endsWith('-SNAPSHOT')) { publishPlugins.enabled = false -} else { - pluginBundle { - // These settings are set for the whole plugin bundle - website = "https://github.com/diffplug/spotless" - vcsUrl = "https://github.com/diffplug/spotless" - tags = [ - 'format', - 'style', - 'license', - 'header', - 'google-java-format', - 'eclipse', - 'ktlint', - 'ktfmt', - 'diktat', - 'tsfmt', - 'prettier', - 'scalafmt', - 'scalafix', - 'black', - 'clang-format' - ] - } } // have to apply java-publish after setting up the pluginBundle From be90ffcf49cb9fce8224ce91b11631fc391c83c6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 15:13:41 -0800 Subject: [PATCH 0259/1120] Oops, fix the gradle plugin build. --- .github/workflows/deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ce7b82f820..9a1dcdf609 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,8 +7,8 @@ # GPG_PASSPHRASE # GPG_KEY64 (base64) # gpg --export-secret-keys --armor KEY_ID | openssl base64 | pbcopy -# GRADLE_PORTAL_KEY -# GRADLE_PORTAL_SECRET +# GRADLE_KEY +# GRADLE_SECRET name: deploy on: @@ -49,12 +49,12 @@ jobs: if: "${{ github.event.inputs.to_publish == 'all' }}" run: | ./gradlew :changelogPush -Prelease=true --stacktrace --warning-mode all - ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_PORTAL_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PORTAL_SECRET }} --stacktrace --warning-mode all + ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_SECRET }} --stacktrace --warning-mode all ./gradlew :plugin-maven:changelogPush -Prelease=true --stacktrace --warning-mode all - name: publish just plugin-gradle if: "${{ github.event.inputs.to_publish == 'plugin-gradle' }}" run: | - ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_PORTAL_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PORTAL_SECRET }} --stacktrace --warning-mode all + ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_SECRET }} --stacktrace --warning-mode all - name: publish just plugin-maven if: "${{ github.event.inputs.to_publish == 'plugin-maven' }}" run: | From 5c10387fa94d90277bf665bc321e1ad3cdd647a3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 15:19:40 -0800 Subject: [PATCH 0260/1120] Bump plugin-maven changelog. --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6f59030a8e..05cc349e9f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.30.0] - 2023-01-13 ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. From 54bcc6068debe62d87c489532821bd284786d2da Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 13 Jan 2023 15:43:36 -0800 Subject: [PATCH 0261/1120] spotlessApply --- plugin-maven/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 60975f1e52..4232f76e39 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.29.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.29.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.30.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.30.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 8734c3b1f27302c504b0c33e817f887deb5e2d44 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 14 Jan 2023 11:53:17 +0000 Subject: [PATCH 0262/1120] Update dependency org.mockito:mockito-core to v5 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 71f755522f..23ec1efd7a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.1 -VER_MOCKITO=4.11.0 +VER_MOCKITO=5.0.0 # Used for Maven Plugin VER_MAVEN_API=3.0 From 5d73b3ba2313d2d511cc51a18d746031f2ee47d1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 15:01:55 -0800 Subject: [PATCH 0263/1120] Fix bug in gradle publishing. --- plugin-gradle/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 6a7f7dca01..e65bda9f70 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -69,6 +69,7 @@ gradlePlugin { implementationClass = 'com.diffplug.gradle.spotless.SpotlessPluginRedirect' displayName = 'Spotless formatting plugin (legacy)' description = project.description + tags.set(['format']) } } } From fdb58d79c7952e8fcf55ff049fefd84faeb5f01c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 15:04:02 -0800 Subject: [PATCH 0264/1120] Published plugin-gradle/6.13.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 48 +++++++++++++++++++------------------- plugin-gradle/build.gradle | 4 +++- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f6210ce8de..e2e32680fe 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.13.0] - 2023-01-14 ### Added * **POTENTIALLY BREAKING** `ktlint` step now supports `.editorconfig` ([#1442](https://github.com/diffplug/spotless/pull/1442) implements [#142](https://github.com/diffplug/spotless/issues/142)) * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index b44d79ef3d..f2567a5924 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.12.1-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.13.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -129,10 +129,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -144,7 +144,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -268,8 +268,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -320,8 +320,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -392,7 +392,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -424,7 +424,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -456,7 +456,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -490,7 +490,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -511,7 +511,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -536,7 +536,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -576,7 +576,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -668,7 +668,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -732,7 +732,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -957,7 +957,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1030,9 +1030,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1065,11 +1065,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.12.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index e65bda9f70..8a3260d943 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -69,7 +69,9 @@ gradlePlugin { implementationClass = 'com.diffplug.gradle.spotless.SpotlessPluginRedirect' displayName = 'Spotless formatting plugin (legacy)' description = project.description - tags.set(['format']) + tags.set([ + 'format' + ]) } } } From 67f0db5c53b3877627e018c0b79bd93559cd9277 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:06:41 -0800 Subject: [PATCH 0265/1120] First steps in adapting #1477 to match #1472. --- .github/workflows/build-ci.yml | 67 ---------------------------------- .github/workflows/ci.yml | 43 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 67 deletions(-) delete mode 100644 .github/workflows/build-ci.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml deleted file mode 100644 index ea12b03764..0000000000 --- a/.github/workflows/build-ci.yml +++ /dev/null @@ -1,67 +0,0 @@ -on: - push: - branches: - - main - pull_request: - types: [assigned, opened, synchronize, reopened] - -jobs: - buildTest: - name: Build CI - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - java_version: [11, 17] - distribution: ["temurin"] - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} - uses: actions/setup-java@v3.9.0 - with: - distribution: ${{ matrix.distribution }} - java-version: ${{ matrix.java_version }} - cache: gradle - - name: Build project - run: ./gradlew build -x spotlessCheck -S - spotless: - name: Check Spotless - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - java_version: [11] - distribution: ["temurin"] - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} - uses: actions/setup-java@v3.9.0 - with: - distribution: ${{ matrix.distribution }} - java-version: ${{ matrix.java_version }} - cache: gradle - - name: Check spotless - run: ./gradlew spotlessCheck -S - buildTestOnWindows: - name: Build on Windows CI - runs-on: windows-latest - strategy: - fail-fast: false - matrix: - java_version: [11, 17] - distribution: ["temurin"] - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} - uses: actions/setup-java@v3.9.0 - with: - distribution: ${{ matrix.distribution }} - java-version: ${{ matrix.java_version }} - cache: gradle - - name: Build project - run: ./gradlew build -x spotlessCheck -S diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..53a1f49cf6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +# BUILDCACHE_USER +# BUILDCACHE_PASS +# - rw access to buildcache.diffplug.com + +on: [push, pull_request] +jobs: + testClasses: + name: spotlessCheck assemble testClasses + runs-on: ubuntu-latest + env: + buildcacheuser: ${{ secrets.BUILDCACHE_USER }} + buildcachepass: ${{ secrets.BUILDCACHE_PASS }} + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install JDK 11 + uses: actions/setup-java@v3 + with: + distribution: "temurin" + java-version: 11 + cache: gradle + - name: Build project + run: ./gradlew spotlessCheck assemble testClasses --build-cache + test_windows: + needs: testClasses + name: test_windows + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + java_version: [17] + distribution: ["temurin"] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} + uses: actions/setup-java@v3 + with: + distribution: ${{ matrix.distribution }} + java-version: ${{ matrix.java_version }} + cache: gradle + - name: Build project + run: ./gradlew test --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true From b513d23dbe5839ba65ee04a05f58724f4a9cad1c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:09:21 -0800 Subject: [PATCH 0266/1120] Fix spotless ratchetFrom --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53a1f49cf6..1282ef2a20 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Install JDK 11 uses: actions/setup-java@v3 with: From 8a69785b16cfccde04450a4454b2e9277d61bab5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:26:31 -0800 Subject: [PATCH 0267/1120] Start running our tests also. --- .github/workflows/ci.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1282ef2a20..c6974d8de8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,15 +23,13 @@ jobs: cache: gradle - name: Build project run: ./gradlew spotlessCheck assemble testClasses --build-cache - test_windows: + check: needs: testClasses - name: test_windows - runs-on: windows-latest strategy: fail-fast: false - matrix: - java_version: [17] - distribution: ["temurin"] + maven_or_gradle: [maven, gradle] + os: [ubuntu-latest, windows-latest] + jre: [11, 17] steps: - name: Checkout uses: actions/checkout@v3 @@ -41,5 +39,9 @@ jobs: distribution: ${{ matrix.distribution }} java-version: ${{ matrix.java_version }} cache: gradle - - name: Build project - run: ./gradlew test --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true + - name: check maven + if: matrix.maven_or_gradle == 'maven' + run: ./gradlew :plugin-maven:check -x spotlessCheck --build-cache + - name: check everything but maven + if: matrix.maven_or_gradle == 'gradle' + run: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew check -x spotlessCheck --build-cache From 0a120eceb177f4a3e78158a42bbc1fea66e250a3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:28:05 -0800 Subject: [PATCH 0268/1120] Oops. Fix the matrix syntax. --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6974d8de8..7f0d8d5f7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,9 +27,10 @@ jobs: needs: testClasses strategy: fail-fast: false - maven_or_gradle: [maven, gradle] - os: [ubuntu-latest, windows-latest] - jre: [11, 17] + matrix: + maven_or_gradle: [maven, gradle] + os: [ubuntu-latest, windows-latest] + jre: [11, 17] steps: - name: Checkout uses: actions/checkout@v3 From 136f96d350529407e860c665fb460d83b61dd4b3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:33:07 -0800 Subject: [PATCH 0269/1120] Try again. --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f0d8d5f7f..16952dca28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,14 +31,15 @@ jobs: maven_or_gradle: [maven, gradle] os: [ubuntu-latest, windows-latest] jre: [11, 17] + runs-on: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v3 - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} uses: actions/setup-java@v3 with: - distribution: ${{ matrix.distribution }} - java-version: ${{ matrix.java_version }} + distribution: "temurin" + java-version: ${{ matrix.jre }} cache: gradle - name: check maven if: matrix.maven_or_gradle == 'maven' From d0af06ef766bb8482c122749027a2f232a2e0cf0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:43:57 -0800 Subject: [PATCH 0270/1120] Exclude maven from the assemble testClasses because it's not cacheable anyway. --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16952dca28..3bc9de5157 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,8 +21,11 @@ jobs: distribution: "temurin" java-version: 11 cache: gradle - - name: Build project - run: ./gradlew spotlessCheck assemble testClasses --build-cache + - name: spotlessCheck + run: ./gradlew spotlessCheck --build-cache + - name: assemble testClasses + run: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew assemble testClasses --build-cache + # If this gets resolved, remove the EXCLUDE_MAVEN https://github.com/diffplug/spotless/issues/554 check: needs: testClasses strategy: From 692ad62635ab05b03955dea17406157f92ebb11d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:54:41 -0800 Subject: [PATCH 0271/1120] Add java8 and npm tests. --- .github/workflows/ci.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3bc9de5157..b14769569b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,16 +24,16 @@ jobs: - name: spotlessCheck run: ./gradlew spotlessCheck --build-cache - name: assemble testClasses - run: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew assemble testClasses --build-cache + run: ./gradlew assemble testClasses --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true # If this gets resolved, remove the EXCLUDE_MAVEN https://github.com/diffplug/spotless/issues/554 check: needs: testClasses strategy: fail-fast: false matrix: - maven_or_gradle: [maven, gradle] + kind: [maven, gradle, npm] os: [ubuntu-latest, windows-latest] - jre: [11, 17] + jre: [8, 11, 17] runs-on: ${{ matrix.os }} steps: - name: Checkout @@ -45,8 +45,11 @@ jobs: java-version: ${{ matrix.jre }} cache: gradle - name: check maven - if: matrix.maven_or_gradle == 'maven' + if: matrix.kind == 'maven' run: ./gradlew :plugin-maven:check -x spotlessCheck --build-cache - name: check everything but maven - if: matrix.maven_or_gradle == 'gradle' - run: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew check -x spotlessCheck --build-cache + if: matrix.kind == 'gradle' + run: ./gradlew check -x spotlessCheck --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true + - name: check npm + if: matrix.kind == 'npm' + run: ./gradlew testNpm --build-cache From a6c5dd48b902dcd013bed91d15f764ddd783458a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 16:58:38 -0800 Subject: [PATCH 0272/1120] Change the matrix order a bit. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b14769569b..ac9d5be617 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,8 +32,8 @@ jobs: fail-fast: false matrix: kind: [maven, gradle, npm] - os: [ubuntu-latest, windows-latest] jre: [8, 11, 17] + os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - name: Checkout From 35a2dc9640b358f8dd74b3807434310ef76718e5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 17:01:21 -0800 Subject: [PATCH 0273/1120] No more double-build by building only pushes to master. --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac9d5be617..9a34e0d42d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,10 @@ # BUILDCACHE_PASS # - rw access to buildcache.diffplug.com -on: [push, pull_request] +on: + pull_request: + push: + branches: [main] jobs: testClasses: name: spotlessCheck assemble testClasses From 71d0e85724beaede77f6c1d116ea2f1e7e13a2c2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 17:09:08 -0800 Subject: [PATCH 0274/1120] Cancel in-progress builds that aren't working for us. --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a34e0d42d..ed526a16ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: pull_request: push: branches: [main] +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: testClasses: name: spotlessCheck assemble testClasses From d0faac2dda2c586e589f2f42e6754ebc7f789240 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 17:22:02 -0800 Subject: [PATCH 0275/1120] Switch from `check` to `build` --- .github/workflows/ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed526a16ca..4ce6347755 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: - testClasses: + sanityCheck: name: spotlessCheck assemble testClasses runs-on: ubuntu-latest env: @@ -32,8 +32,8 @@ jobs: - name: assemble testClasses run: ./gradlew assemble testClasses --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true # If this gets resolved, remove the EXCLUDE_MAVEN https://github.com/diffplug/spotless/issues/554 - check: - needs: testClasses + build: + needs: sanityCheck strategy: fail-fast: false matrix: @@ -50,12 +50,12 @@ jobs: distribution: "temurin" java-version: ${{ matrix.jre }} cache: gradle - - name: check maven + - name: build (maven-only) if: matrix.kind == 'maven' - run: ./gradlew :plugin-maven:check -x spotlessCheck --build-cache - - name: check everything but maven + run: ./gradlew :plugin-maven:build -x spotlessCheck --build-cache + - name: build (everything-but-maven) if: matrix.kind == 'gradle' - run: ./gradlew check -x spotlessCheck --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true - - name: check npm + run: ./gradlew build -x spotlessCheck --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true + - name: testNpm if: matrix.kind == 'npm' run: ./gradlew testNpm --build-cache From 707719668fc04fbcd626c725cd35cb4e87fb4745 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 17:26:41 -0800 Subject: [PATCH 0276/1120] Revert "Update dependency org.mockito:mockito-core to v5" (#1487) b/c it breaks Java 8 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 23ec1efd7a..71f755522f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,7 +28,7 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.1 -VER_MOCKITO=5.0.0 +VER_MOCKITO=4.11.0 # Used for Maven Plugin VER_MAVEN_API=3.0 From 549558e05f661aab8ea2f2bf361f7a18af52ce51 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 17:50:06 -0800 Subject: [PATCH 0277/1120] Grab JUnit reports. --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ce6347755..63fc565b4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,6 +56,12 @@ jobs: - name: build (everything-but-maven) if: matrix.kind == 'gradle' run: ./gradlew build -x spotlessCheck --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true - - name: testNpm + - name: test npm if: matrix.kind == 'npm' run: ./gradlew testNpm --build-cache + - name: junit result + uses: mikepenz/action-junit-report@v3 + if: always() # always run even if the previous step fails + with: + check_name: JUnit ${{ matrix.kind }} ${{ matrix.jre }} ${{ matrix.os }} + report_paths: '*/build/test-results/*/TEST-*.xml' From 9cae4966b8b30c976c330c201d64ee6b453227d6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 18:05:36 -0800 Subject: [PATCH 0278/1120] Be more efficient with runner minutes. --- .github/workflows/ci.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63fc565b4a..2e302e6637 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,9 +37,21 @@ jobs: strategy: fail-fast: false matrix: - kind: [maven, gradle, npm] + kind: [maven, gradle] jre: [8, 11, 17] - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] + include: + # test windows at the diagonals of the above matrix + - kind: maven + jre: 8 + os: windows-latest + - kind: gradle + jre: 17 + os: windows-latest + # npm on linux only (crazy slow on windows) + - kind: npm + jre: 8 + os: ubuntu-latest runs-on: ${{ matrix.os }} steps: - name: Checkout From 6b67bf17b0d7b1887b0df1a3fb6d656b487ba9e8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 14 Jan 2023 18:06:39 -0800 Subject: [PATCH 0279/1120] Fully remove CircleCI. --- .circleci/config.yml | 161 ------------------------------------------- 1 file changed, 161 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index b9f91766c9..0000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,161 +0,0 @@ -version: 2.1 -orbs: - win: circleci/windows@5.0.0 - -anchors: - env_gradle: &env_gradle - environment: - # we're only allowed to use 2 vCPUs - GRADLE_OPTS: "-Dorg.gradle.workers.max=2" - docker: - - image: cimg/openjdk:11.0 - env_gradle_large: &env_gradle_large - << : *env_gradle - resource_class: large # https://circleci.com/docs/2.0/configuration-reference/#resource_class - environment: - GRADLE_OPTS: "-Dorg.gradle.workers.max=4" - - restore_cache_wrapper: &restore_cache_wrapper - restore_cache: - key: gradle-wrapper2-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} - restore_cache_deps: &restore_cache_deps - restore_cache: - keys: - - gradle-deps3-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }} - - gradle-deps3- - set_git_origin_to_https: &set_git_origin_to_https - run: - name: set git origin to https - command: git remote set-url --push origin https://github.com/diffplug/spotless - - test_nomaven: &test_nomaven - steps: - - checkout - - *restore_cache_wrapper - - *restore_cache_deps - - run: - name: gradlew check -x spotlessCheck - command: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew check -x spotlessCheck --build-cache - - store_test_results: - path: testlib/build/test-results/test - - store_test_results: - path: lib-extra/build/test-results/test - - store_test_results: - path: plugin-gradle/build/test-results/test - - store_artifacts: - path: lib/build/spotbugs - - store_artifacts: - path: lib-extra/build/spotbugs - - store_artifacts: - path: testlib/build/spotbugs - - store_artifacts: - path: plugin-gradle/build/spotbugs - -jobs: - # gradlew spotlessCheck assemble testClasses - assemble_testClasses: - <<: *env_gradle_large - steps: - - checkout - - *restore_cache_wrapper - - *restore_cache_deps - - run: - name: gradlew spotlessCheck assemble testClasses - command: ./gradlew spotlessCheck assemble testClasses --build-cache - - save_cache: - paths: - - ~/.gradle/wrapper - key: gradle-wrapper2-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }} - - save_cache: - paths: - - ~/.gradle/caches - - ~/.m2 - key: gradle-deps3-{{ checksum "build.gradle" }}-{{ checksum "gradle.properties" }} - test_nomaven_11: - # latest LTS version - <<: *env_gradle_large - docker: - - image: cimg/openjdk:11.0 - <<: *test_nomaven - test_nomaven_17: - # latest JDK - <<: *env_gradle_large - docker: - - image: cimg/openjdk:17.0 - <<: *test_nomaven - test_justmaven_11: - << : *env_gradle - steps: - - checkout - - *restore_cache_wrapper - - *restore_cache_deps - - run: - name: gradlew :plugin-maven:check - command: ./gradlew :plugin-maven:check --build-cache - - store_test_results: - path: plugin-maven/build/test-results/test - test_npm_8: - << : *env_gradle - environment: - # java doesn't play nice with containers, it tries to hog the entire machine - # https://circleci.com/blog/how-to-handle-java-oom-errors/ - # try the experimental JVM option - _JAVA_OPTIONS: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" - docker: - - image: cimg/openjdk:8.0-node - steps: - - checkout - - *restore_cache_wrapper - - *restore_cache_deps - - run: - name: gradlew testNpm - command: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew testNpm --build-cache - - store_test_results: - path: testlib/build/test-results/testNpm - - store_test_results: - path: plugin-maven/build/test-results/testNpm - - store_test_results: - path: plugin-gradle/build/test-results/testNpm - - run: - name: gradlew test - command: export SPOTLESS_EXCLUDE_MAVEN=true && ./gradlew test --build-cache - - store_test_results: - path: testlib/build/test-results/test - - store_test_results: - path: lib-extra/build/test-results/test - - store_test_results: - path: plugin-gradle/build/test-results/test - test_windows: - executor: - name: win/default - shell: cmd.exe - steps: - - checkout - - run: - name: gradlew test - command: gradlew test --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true - - store_test_results: - path: testlib/build/test-results/test - - store_test_results: - path: lib-extra/build/test-results/test - - store_test_results: - path: plugin-gradle/build/test-results/test - -workflows: - version: 2 - assemble_and_test: - jobs: - - test_windows - - assemble_testClasses - - test_justmaven_11: - requires: - - assemble_testClasses - - test_nomaven_11: - requires: - - assemble_testClasses - - test_nomaven_17: - requires: - - assemble_testClasses - - test_npm_8: - requires: - - assemble_testClasses From c238f0c672a7d0a5702818b3ac90000ed3f654e0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:09:45 +0000 Subject: [PATCH 0280/1120] Update plugin com.diffplug.spotless to v6.13.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 741e4b6ccc..57498bf23f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { plugins { - id 'com.diffplug.spotless' version '6.12.1' + id 'com.diffplug.spotless' version '6.13.0' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.1.0' // https://github.com/gradle-nexus/publish-plugin/releases From 33cafc069ed8b5c5fc6258458ebcf0084639cc16 Mon Sep 17 00:00:00 2001 From: tison Date: Sun, 15 Jan 2023 17:20:23 +0800 Subject: [PATCH 0281/1120] docs: Correct espace syntax Maven XML can interpret `\#` correctly, `\\#` will mismatch code internal. --- plugin-maven/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 4232f76e39..2a455dfe07 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -197,8 +197,8 @@ any other maven phase (i.e. compile) then it can be configured as below; false - java|javax,org,com,com.diffplug,,\\#com.diffplug,\\# - + java|javax,org,com,com.diffplug,,\#com.diffplug,\# + @@ -298,8 +298,8 @@ These mechanisms already exist for the Gradle plugin. - java|javax,org,com,com.diffplug,,\\#com.diffplug,\\# - + java|javax,org,com,com.diffplug,,\#com.diffplug,\# + From eae8ffc0fc20997bda6e540b4da448bf00a0d8d7 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 15 Jan 2023 16:52:19 +0400 Subject: [PATCH 0282/1120] Add JSON jackson step, Refactor with Yaml, enable endWithEol, features are defined in a Map -> boolean --- lib/build.gradle | 1 + .../glue/json/JsonJacksonFormatterFunc.java | 103 ++++++++++++++++++ .../glue/yaml/YamlJacksonFormatterFunc.java | 77 ++----------- .../diffplug/spotless/json/JacksonConfig.java | 71 ++++++++++++ .../spotless/json/JacksonJsonStep.java | 79 ++++++++++++++ ...lJacksonStep.java => JacksonYamlStep.java} | 31 +++--- .../Jackson.java => json/JacksonJson.java} | 34 ++++-- .../diffplug/spotless/maven/json/Json.java | 4 + .../spotless/maven/yaml/JacksonYaml.java | 60 ++++++++++ .../diffplug/spotless/maven/yaml/Yaml.java | 2 +- .../spotless/maven/json/JsonTest.java | 23 +++- .../spotless/maven/yaml/YamlTest.java | 9 ++ .../json/sortByKeysAfter_Jackson.json | 19 ++++ ...fter_Jackson_noSpaceAfterKeySeparator.json | 19 ++++ .../array_with_bracket.clean_with_eol.yaml | 12 ++ 15 files changed, 441 insertions(+), 103 deletions(-) create mode 100644 lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java rename lib/src/main/java/com/diffplug/spotless/yaml/{YamlJacksonStep.java => JacksonYamlStep.java} (70%) rename plugin-maven/src/main/java/com/diffplug/spotless/maven/{yaml/Jackson.java => json/JacksonJson.java} (51%) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java create mode 100644 testlib/src/main/resources/json/sortByKeysAfter_Jackson.json create mode 100644 testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json create mode 100644 testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml diff --git a/lib/build.gradle b/lib/build.gradle index 3ef2064765..3c36aa0188 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -57,6 +57,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm // used jackson-based formatters + jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.1' jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1' String VER_KTFMT = '0.42' diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java new file mode 100644 index 0000000000..0a13ab6626 --- /dev/null +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java @@ -0,0 +1,103 @@ +/* + * 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. + * 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.json; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.json.JacksonConfig; + +/** + * A {@link FormatterFunc} based on Jackson library + */ +// https://github.com/FasterXML/jackson-dataformats-text/issues/372 +public class JsonJacksonFormatterFunc implements FormatterFunc { + private JacksonConfig jacksonConfig; + + public JsonJacksonFormatterFunc(JacksonConfig jacksonConfig) { + this.jacksonConfig = jacksonConfig; + } + + @Override + public String apply(String input) throws Exception { + ObjectMapper objectMapper = makeObjectMapper(); + + return format(objectMapper, input); + } + + /** + * @return a {@link JsonFactory}. May be overridden to handle alternative formats. + * @see jackson-dataformats-text + */ + protected JsonFactory makeJsonFactory() { + return new JsonFactory(); + } + + protected ObjectMapper makeObjectMapper() { + JsonFactory jsonFactory = makeJsonFactory(); + ObjectMapper objectMapper = new ObjectMapper(jsonFactory); + + // Configure the ObjectMapper + // https://github.com/FasterXML/jackson-databind#commonly-used-features + jacksonConfig.getFeatureToToggle().forEach((rawFeature, toggle) -> { + // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection + SerializationFeature feature = SerializationFeature.valueOf(rawFeature); + + objectMapper.configure(feature, toggle); + }); + + return objectMapper; + } + + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + // We may consider adding manually an initial '---' prefix to help management of multiple documents + // if (!input.trim().startsWith("---")) { + // input = "---" + "\n" + input; + // } + + try { + // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson + // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 + // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' + // JsonParser yamlParser = objectMapper.getFactory().createParser(input); + // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); + // return objectMapper.writeValueAsString(docs); + + // 2023-01: This returns JSON instead of YAML + // This will transit with a JsonNode + // A JsonNode may keep the comments from the input node + // JsonNode jsonNode = objectMapper.readTree(input); + //Not 'toPrettyString' as one could require no INDENT_OUTPUT + // return jsonNode.toPrettyString(); + ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); + String outputFromjackson = objectMapper.writeValueAsString(objectNode); + + if (jacksonConfig.isEndWithEol() && !outputFromjackson.endsWith("\n")) { + outputFromjackson += "\n"; + } + + return outputFromjackson; + } catch (JsonProcessingException e) { + throw new AssertionError("Unable to format. input='" + input + "'", e); + } + } +} diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java index 30cf538159..eda2675985 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java @@ -15,83 +15,20 @@ */ package com.diffplug.spotless.glue.yaml; -import java.io.IOException; -import java.util.List; +import com.diffplug.spotless.glue.json.JsonJacksonFormatterFunc; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.json.JacksonConfig; -public class YamlJacksonFormatterFunc implements FormatterFunc { - private List enabledFeatures; - private List disabledFeatures; +public class YamlJacksonFormatterFunc extends JsonJacksonFormatterFunc { - public YamlJacksonFormatterFunc(List enabledFeatures, List disabledFeatures) { - this.enabledFeatures = enabledFeatures; - this.disabledFeatures = disabledFeatures; + public YamlJacksonFormatterFunc(JacksonConfig jacksonConfig) { + super(jacksonConfig); } @Override - public String apply(String input) throws Exception { - ObjectMapper objectMapper = makeObjectMapper(); - - return format(objectMapper, input); - } - - protected ObjectMapper makeObjectMapper() { - YAMLFactory yamlFactory = new YAMLFactory(); - ObjectMapper objectMapper = new ObjectMapper(yamlFactory); - - // Configure the ObjectMapper - // https://github.com/FasterXML/jackson-databind#commonly-used-features - for (String rawFeature : enabledFeatures) { - // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - SerializationFeature feature = SerializationFeature.valueOf(rawFeature); - - objectMapper.enable(feature); - } - - for (String rawFeature : disabledFeatures) { - // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - SerializationFeature feature = SerializationFeature.valueOf(rawFeature); - - objectMapper.disable(feature); - } - return objectMapper; - } - - protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - // We may consider adding manually an initial '---' prefix to help management of multiple documents - // if (!input.trim().startsWith("---")) { - // input = "---" + "\n" + input; - // } - - try { - // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson - // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 - // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' - // JsonParser yamlParser = objectMapper.getFactory().createParser(input); - // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); - // return objectMapper.writeValueAsString(docs); - - // 2023-01: This returns JSON instead of YAML - // This will transit with a JsonNode - // A JsonNode may keep the comments from the input node - // JsonNode jsonNode = objectMapper.readTree(input); - //Not 'toPrettyString' as one could require no INDENT_OUTPUT - // return jsonNode.toPrettyString(); - ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - return objectMapper.writeValueAsString(objectNode); - } catch (JsonProcessingException e) { - throw new AssertionError("Unable to format YAML. input='" + input + "'", e); - } + protected YAMLFactory makeJsonFactory() { + return new YAMLFactory(); } - - // Spotbugs - private static class ObjectNodeTypeReference extends TypeReference {} } diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java new file mode 100644 index 0000000000..526e235eb7 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -0,0 +1,71 @@ +/* + * 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.json; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * A DTO holding the options for Jackson-based formatters + */ +public class JacksonConfig { + + private static final Map DEFAULT_FEATURE_TOGGLES; + + static { + Map defaultFeatureToggles = new LinkedHashMap<>(); + // We activate by default the PrettyPrinter from Jackson + defaultFeatureToggles.put("INDENT_OUTPUT", true); + DEFAULT_FEATURE_TOGGLES = defaultFeatureToggles; + } + + protected Map featureToToggle; + + // https://github.com/revelc/formatter-maven-plugin/pull/405 + protected boolean endWithEol = false; + + // https://github.com/revelc/formatter-maven-plugin/pull/280 + protected boolean spaceBeforeSeparator = false; + + public Map getFeatureToToggle() { + return Collections.unmodifiableMap(featureToToggle); + } + + public void setFeatureToToggle(Map featureToToggle) { + this.featureToToggle = featureToToggle; + } + + public void appendFeatureToToggle(Map features) { + this.featureToToggle.putAll(features); + } + + public boolean isEndWithEol() { + return endWithEol; + } + + public void setEndWithEol(boolean endWithEol) { + this.endWithEol = endWithEol; + } + + public boolean isSpaceBeforeSeparator() { + return spaceBeforeSeparator; + } + + public void setSpaceBeforeSeparator(boolean spaceBeforeSeparator) { + this.spaceBeforeSeparator = spaceBeforeSeparator; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java new file mode 100644 index 0000000000..0fe1ab057b --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java @@ -0,0 +1,79 @@ +/* + * 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. + * 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.json; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Objects; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Provisioner; + +/** + * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. + */ +// https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson +public class JacksonJsonStep { + static final String MAVEN_COORDINATE = "com.fasterxml.jackson.core:jackson-databind:"; + // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind + static final String DEFAULT_VERSION = "2.14.1"; + + private JacksonJsonStep() {} + + public static String defaultVersion() { + return DEFAULT_VERSION; + } + + public static FormatterStep create(JacksonConfig jacksonConfig, + String jacksonVersion, + Provisioner provisioner) { + Objects.requireNonNull(provisioner, "provisioner cannot be null"); + return FormatterStep.createLazy("json", + () -> new State(jacksonConfig, jacksonVersion, provisioner), + State::toFormatter); + } + + public static FormatterStep create(Provisioner provisioner) { + return create(new JacksonConfig(), defaultVersion(), provisioner); + } + + private static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + private final JacksonConfig jacksonConfig; + + private final JarState jarState; + + private State(JacksonConfig jacksonConfig, + String jacksonVersion, + Provisioner provisioner) throws IOException { + this.jacksonConfig = jacksonConfig; + + this.jarState = JarState.from(JacksonJsonStep.MAVEN_COORDINATE + jacksonVersion, provisioner); + } + + FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + InstantiationException, IllegalAccessException { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.json.JacksonJsonFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(JacksonConfig.class); + return (FormatterFunc) constructor.newInstance(jacksonConfig); + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java similarity index 70% rename from lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java rename to lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java index db2525ab97..944d90e6c9 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java @@ -19,67 +19,62 @@ import java.io.Serializable; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.List; import java.util.Objects; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.JarState; import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.json.JacksonConfig; /** * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. */ // https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson -public class YamlJacksonStep { +public class JacksonYamlStep { static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml static final String DEFAULT_VERSION = "2.14.1"; - private YamlJacksonStep() {} + private JacksonYamlStep() {} public static String defaultVersion() { return DEFAULT_VERSION; } - public static FormatterStep create(List enabledFeatures, - List disabledFeatures, + public static FormatterStep create(JacksonConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); return FormatterStep.createLazy("yaml", - () -> new State(enabledFeatures, disabledFeatures, jacksonVersion, provisioner), + () -> new State(jacksonConfig, jacksonVersion, provisioner), State::toFormatter); } public static FormatterStep create(Provisioner provisioner) { - return create(Arrays.asList("INDENT_OUTPUT"), Arrays.asList(), defaultVersion(), provisioner); + return create(new JacksonConfig(), defaultVersion(), provisioner); } private static final class State implements Serializable { private static final long serialVersionUID = 1L; - private final List enabledFeatures; - private final List disabledFeatures; + private final JacksonConfig jacksonConfig; private final JarState jarState; - private State(List enabledFeatures, - List disabledFeatures, + private State(JacksonConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) throws IOException { - this.enabledFeatures = enabledFeatures; - this.disabledFeatures = disabledFeatures; + this.jacksonConfig = jacksonConfig; - this.jarState = JarState.from(YamlJacksonStep.MAVEN_COORDINATE + jacksonVersion, provisioner); + this.jarState = JarState.from(JacksonYamlStep.MAVEN_COORDINATE + jacksonVersion, provisioner); } FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { - Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.YamlJacksonFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(List.class, List.class); - return (FormatterFunc) constructor.newInstance(enabledFeatures, disabledFeatures); + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.JacksonYamlFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(JacksonConfig.class); + return (FormatterFunc) constructor.newInstance(jacksonConfig); } } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java similarity index 51% rename from plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java rename to plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java index 2bc7617a38..cf03ef21ca 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Jackson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java @@ -13,34 +13,44 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.maven.yaml; +package com.diffplug.spotless.maven.json; -import java.util.Arrays; -import java.util.List; +import java.util.Collections; +import java.util.Map; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonStep; +import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; -import com.diffplug.spotless.yaml.YamlJacksonStep; -public class Jackson implements FormatterStepFactory { +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + */ +public class JacksonJson implements FormatterStepFactory { @Parameter - private String version = YamlJacksonStep.defaultVersion(); + String version = JacksonJsonStep.defaultVersion(); @Parameter - private String[] enabledFeatures = new String[]{"INDENT_OUTPUT"}; + boolean endWithEol = new JacksonConfig().isEndWithEol(); @Parameter - private String[] disabledFeatures = new String[0]; + private Map features = Collections.emptyMap(); @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - List enabledFeaturesAsList = Arrays.asList(enabledFeatures); - List disabledFeaturesAsList = Arrays.asList(disabledFeatures); - return YamlJacksonStep - .create(enabledFeaturesAsList, disabledFeaturesAsList, version, stepConfig.getProvisioner()); + JacksonConfig jacksonConfig = new JacksonConfig(); + + if (features != null) { + jacksonConfig.appendFeatureToToggle(features); + } + jacksonConfig.setEndWithEol(endWithEol); + + return JacksonJsonStep + .create(jacksonConfig, version, stepConfig.getProvisioner()); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index c326525d0c..852088278a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -44,4 +44,8 @@ public void addGson(Gson gson) { addStepFactory(gson); } + public void addJackson(JacksonJson jackson) { + addStepFactory(jackson); + } + } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java new file mode 100644 index 0000000000..d3d9558cf4 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.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.maven.yaml; + +import java.util.Collections; +import java.util.Map; + +import com.diffplug.spotless.maven.FormatterFactory; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.yaml.JacksonYamlStep; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + */ +public class JacksonYaml implements FormatterStepFactory { + + @Parameter + private String version = JacksonYamlStep.defaultVersion(); + + @Parameter + boolean endWithEol = new JacksonConfig().isEndWithEol(); + + @Parameter + boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); + + @Parameter + private Map features = Collections.emptyMap(); + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + JacksonConfig jacksonConfig = new JacksonConfig(); + + if (features != null) { + jacksonConfig.appendFeatureToToggle(features); + } + jacksonConfig.setEndWithEol(endWithEol); + + return JacksonYamlStep + .create(jacksonConfig, version, stepConfig.getProvisioner()); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java index 6cba1b2ebd..a6ceaaa592 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java @@ -34,7 +34,7 @@ public String licenseHeaderDelimiter() { return null; } - public void addJackson(Jackson jackson) { + public void addJackson(JacksonYaml jackson) { addStepFactory(jackson); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index e492109faa..90b3a2f077 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -58,8 +58,6 @@ public void testFormatJson_WithGson_sortByKeys() throws Exception { setFile("json_test.json").toResource("json/sortByKeysBefore.json"); String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); - LOGGER.error(output); - System.err.println(output); assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); } @@ -72,4 +70,25 @@ public void testFormatJson_WithGson_defaultConfig_nestedObject() throws Exceptio assertFile("json_test.json").sameAsResource("json/nestedObjectAfter.json"); } + + @Test + public void testFormatJson_WithJackson_sortByKeys() throws Exception { + writePomWithJsonSteps("true"); + + setFile("json_test.json").toResource("json/sortByKeysBefore.json"); + + String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); + } + + @Test + public void testFormatJson_WithJackson_sortByKeys_noSpaceAfterKeySeparator() throws Exception { + writePomWithJsonSteps("falsetrue"); + + setFile("json_test.json").toResource("json/sortByKeysBefore.json"); + + String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); + } + } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index b5a417c536..15366ab2e6 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -48,6 +48,15 @@ public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exce assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.yaml"); } + @Test + public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_withEol() throws Exception { + writePomWithYamlSteps("true"); + + setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean_with_eol.yaml"); + } + @Test public void testFormatYaml_WithJackson_defaultConfig_multipleDocuments() throws Exception { writePomWithYamlSteps(""); diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json new file mode 100644 index 0000000000..c4a48de2f2 --- /dev/null +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json @@ -0,0 +1,19 @@ +{ + "A": 1, + "X": 2, + "_arraysNotSorted": [ + 3, + 2, + 1 + ], + "a": 3, + "c": 4, + "x": 5, + "z": { + "A": 1, + "X": 2, + "a": 3, + "c": 4, + "x": 5 + } +} diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json new file mode 100644 index 0000000000..c4a48de2f2 --- /dev/null +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json @@ -0,0 +1,19 @@ +{ + "A": 1, + "X": 2, + "_arraysNotSorted": [ + 3, + 2, + 1 + ], + "a": 3, + "c": 4, + "x": 5, + "z": { + "A": 1, + "X": 2, + "a": 3, + "c": 4, + "x": 5 + } +} diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml new file mode 100644 index 0000000000..6080ba1f82 --- /dev/null +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml @@ -0,0 +1,12 @@ +--- +episodes: +- 1 +- 2 +- 3 +- 4 +- 5 +- 6 +- 7 +best-jedi: + name: "Obi-Wan" + side: "light" From 6c20790c626b05045dc8e53afce004cbac9b8d9c Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 15 Jan 2023 16:21:38 -0800 Subject: [PATCH 0283/1120] Format more type annotations as type annotations --- CHANGES.md | 2 ++ .../com/diffplug/spotless/java/FormatAnnotationsStep.java | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c08ca86796..b871fc4be8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. +* Format more type annotations as type annotations [#????](https://github.com/diffplug/spotless/pull/????) + ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java index d05a53ee1b..f37502d145 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java @@ -55,6 +55,13 @@ public final class FormatAnnotationsStep { "Acceleration", "ACCTop", "AinferBottom", + "AinferDefaultType", + "AinferParent", + "AinferSibling1", + "AinferSibling2", + "AinferTop", + "AinferImplicitAnno", + "AinferSiblingWithFields", "AlwaysSafe", "Angle", "AnnoWithStringArg", @@ -102,6 +109,7 @@ public final class FormatAnnotationsStep { "DefaultType", "degrees", "Det", + "DoesNotMatchRegex", "DotSeparatedIdentifiers", "DotSeparatedIdentifiersOrPrimitiveType", "DoubleVal", From b4c0f1b8abf725ad5adc3dcd6f377613b901d0d4 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 15 Jan 2023 16:24:54 -0800 Subject: [PATCH 0284/1120] Update `CHANGES.md` files --- CHANGES.md | 3 +-- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b871fc4be8..2f8ecc46f5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,8 +22,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* Format more type annotations as type annotations [#????](https://github.com/diffplug/spotless/pull/????) - +* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f6210ce8de..ef2b7a74c3 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. +* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6f59030a8e..71d44df464 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -14,6 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. +* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) From 48245dfa47abf5ce4d87189a5eb8883ec7f3d698 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 15 Jan 2023 16:27:02 -0800 Subject: [PATCH 0285/1120] Update copyright date --- .../java/com/diffplug/spotless/java/FormatAnnotationsStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java index f37502d145..5a2d856850 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 70f38248ba47310e58e58970e0885d437e77c775 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 15 Jan 2023 16:34:20 -0800 Subject: [PATCH 0286/1120] Move changelog entry --- CHANGES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2f8ecc46f5..9c0ed23980 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,10 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +### Fixed +* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) +### Changes ## [2.32.0] - 2023-01-13 ### Added @@ -22,7 +26,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) From 65e74655e9191d1c891cafb6e3c5683da35bb041 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Mon, 16 Jan 2023 21:17:46 +0400 Subject: [PATCH 0287/1120] Add doc, Improve tests --- CHANGES.md | 2 + ...unc.java => JacksonJsonFormatterFunc.java} | 53 +++++++++++++-- .../glue/yaml/JacksonYamlFormatterFunc.java | 66 +++++++++++++++++++ .../glue/yaml/YamlJacksonFormatterFunc.java | 34 ---------- .../diffplug/spotless/json/JacksonConfig.java | 27 ++++---- plugin-maven/CHANGES.md | 5 ++ plugin-maven/README.md | 12 ++-- .../spotless/maven/json/JacksonJson.java | 10 ++- .../spotless/maven/yaml/JacksonYaml.java | 14 ++-- .../spotless/maven/json/JsonTest.java | 9 ++- .../spotless/maven/yaml/YamlTest.java | 6 +- ...After_Jackson_spaceAfterKeySeparator.json} | 0 ...h_bracket.clean.spaceBeforeSeparator.yaml} | 2 +- 13 files changed, 156 insertions(+), 84 deletions(-) rename lib/src/jackson/java/com/diffplug/spotless/glue/json/{JsonJacksonFormatterFunc.java => JacksonJsonFormatterFunc.java} (70%) create mode 100644 lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java delete mode 100644 lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java rename testlib/src/main/resources/json/{sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json => sortByKeysAfter_Jackson_spaceAfterKeySeparator.json} (100%) rename testlib/src/main/resources/yaml/{array_with_bracket.clean_with_eol.yaml => array_with_bracket.clean.spaceBeforeSeparator.yaml} (81%) diff --git a/CHANGES.md b/CHANGES.md index c08ca86796..fd10d2c14e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Rename `YamlJacksonStep` into `JacksonYamlStep` while normalizing Jackson usage ([#1492](https://github.com/diffplug/spotless/pull/1492)) ## [2.32.0] - 2023-01-13 ### Added diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java similarity index 70% rename from lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java rename to lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index 0a13ab6626..c19e56b549 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JsonJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -16,9 +16,14 @@ package com.diffplug.spotless.glue.json; import java.io.IOException; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.util.DefaultIndenter; +import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; +import com.fasterxml.jackson.core.util.Separators; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -30,10 +35,10 @@ * A {@link FormatterFunc} based on Jackson library */ // https://github.com/FasterXML/jackson-dataformats-text/issues/372 -public class JsonJacksonFormatterFunc implements FormatterFunc { +public class JacksonJsonFormatterFunc implements FormatterFunc { private JacksonConfig jacksonConfig; - public JsonJacksonFormatterFunc(JacksonConfig jacksonConfig) { + public JacksonJsonFormatterFunc(JacksonConfig jacksonConfig) { this.jacksonConfig = jacksonConfig; } @@ -56,6 +61,8 @@ protected ObjectMapper makeObjectMapper() { JsonFactory jsonFactory = makeJsonFactory(); ObjectMapper objectMapper = new ObjectMapper(jsonFactory); + objectMapper.setDefaultPrettyPrinter(makePrinter()); + // Configure the ObjectMapper // https://github.com/FasterXML/jackson-databind#commonly-used-features jacksonConfig.getFeatureToToggle().forEach((rawFeature, toggle) -> { @@ -68,6 +75,44 @@ protected ObjectMapper makeObjectMapper() { return objectMapper; } + protected DefaultPrettyPrinter makePrinter() { + boolean spaceBeforeSeparator = jacksonConfig.isSpaceBeforeSeparator(); + + DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(getIndentation(), "\n"); + DefaultPrettyPrinter printer = new DefaultPrettyPrinter() { + private static final long serialVersionUID = 1L; + + @Override + public DefaultPrettyPrinter createInstance() { + return new DefaultPrettyPrinter(this); + } + + @Override + public DefaultPrettyPrinter withSeparators(Separators separators) { + this._separators = separators; + if (spaceBeforeSeparator) { + this._objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " "; + } else { + this._objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSeparator() + " "; + } + return this; + } + }; + + printer.indentObjectsWith(indenter); + printer.indentArraysWith(indenter); + return printer; + } + + protected String getIndentation() { + int indentSpaces = jacksonConfig.getIndentSpaces(); + if (indentSpaces < 0) { + return "\t"; + } else { + return IntStream.range(0, indentSpaces).mapToObj(i -> "").collect(Collectors.joining()); + } + } + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { // We may consider adding manually an initial '---' prefix to help management of multiple documents // if (!input.trim().startsWith("---")) { @@ -91,10 +136,6 @@ protected String format(ObjectMapper objectMapper, String input) throws IllegalA ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); String outputFromjackson = objectMapper.writeValueAsString(objectNode); - if (jacksonConfig.isEndWithEol() && !outputFromjackson.endsWith("\n")) { - outputFromjackson += "\n"; - } - return outputFromjackson; } catch (JsonProcessingException e) { throw new AssertionError("Unable to format. input='" + input + "'", e); diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java new file mode 100644 index 0000000000..6a471a884c --- /dev/null +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -0,0 +1,66 @@ +/* + * 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. + * 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.yaml; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; + +import com.diffplug.spotless.glue.json.JacksonJsonFormatterFunc; +import com.diffplug.spotless.json.JacksonConfig; + +public class JacksonYamlFormatterFunc extends JacksonJsonFormatterFunc { + + public JacksonYamlFormatterFunc(JacksonConfig jacksonConfig) { + super(jacksonConfig); + } + + @Override + protected YAMLFactory makeJsonFactory() { + return new YAMLFactory(); + } + + @Override + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + // We may consider adding manually an initial '---' prefix to help management of multiple documents + // if (!input.trim().startsWith("---")) { + // input = "---" + "\n" + input; + // } + + try { + // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson + // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 + // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' + // JsonParser yamlParser = objectMapper.getFactory().createParser(input); + // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); + // return objectMapper.writeValueAsString(docs); + + // A JsonNode may keep the comments from the input node + // JsonNode jsonNode = objectMapper.readTree(input); + //Not 'toPrettyString' as one could require no INDENT_OUTPUT + // return jsonNode.toPrettyString(); + ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); + String outputFromjackson = objectMapper.writeValueAsString(objectNode); + + return outputFromjackson; + } catch (JsonProcessingException e) { + throw new AssertionError("Unable to format. input='" + input + "'", e); + } + } +} diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java deleted file mode 100644 index eda2675985..0000000000 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - * 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.yaml; - -import com.diffplug.spotless.glue.json.JsonJacksonFormatterFunc; - -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; - -import com.diffplug.spotless.json.JacksonConfig; - -public class YamlJacksonFormatterFunc extends JsonJacksonFormatterFunc { - - public YamlJacksonFormatterFunc(JacksonConfig jacksonConfig) { - super(jacksonConfig); - } - - @Override - protected YAMLFactory makeJsonFactory() { - return new YAMLFactory(); - } -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java index 526e235eb7..2fadf31d78 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.json; +import java.io.Serializable; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -22,7 +23,7 @@ /** * A DTO holding the options for Jackson-based formatters */ -public class JacksonConfig { +public class JacksonConfig implements Serializable { private static final Map DEFAULT_FEATURE_TOGGLES; @@ -33,14 +34,14 @@ public class JacksonConfig { DEFAULT_FEATURE_TOGGLES = defaultFeatureToggles; } - protected Map featureToToggle; - - // https://github.com/revelc/formatter-maven-plugin/pull/405 - protected boolean endWithEol = false; + protected Map featureToToggle = new LinkedHashMap<>(); // https://github.com/revelc/formatter-maven-plugin/pull/280 + // By default, Jackson adds a ' ' before separator, which is not standard with most IDE/JSON libraries protected boolean spaceBeforeSeparator = false; + // protected int indentSpaces; + public Map getFeatureToToggle() { return Collections.unmodifiableMap(featureToToggle); } @@ -53,14 +54,6 @@ public void appendFeatureToToggle(Map features) { this.featureToToggle.putAll(features); } - public boolean isEndWithEol() { - return endWithEol; - } - - public void setEndWithEol(boolean endWithEol) { - this.endWithEol = endWithEol; - } - public boolean isSpaceBeforeSeparator() { return spaceBeforeSeparator; } @@ -68,4 +61,12 @@ public boolean isSpaceBeforeSeparator() { public void setSpaceBeforeSeparator(boolean spaceBeforeSeparator) { this.spaceBeforeSeparator = spaceBeforeSeparator; } + + // public int getIndentSpaces() { + // return indentSpaces; + // } + + // public void setIndentSpaces(int indentSpaces) { + // this.indentSpaces = indentSpaces; + // } } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 05cc349e9f..d6326cba12 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Introduce `` ([#1492](https://github.com/diffplug/spotless/pull/1492)) + * **POTENTIALLY BREAKING** `JacksonYaml` is now configured with a `Map` to configure features +* Jackson (JSON and YAML) has new `spaceBeforeSeparator` option + * **POTENTIALLY BREAKING** `spaceBeforeSeparator` is defaulted to false while the formatter was behaving with `true` ## [2.30.0] - 2023-01-13 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2a455dfe07..6dca992591 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -924,12 +924,12 @@ Uses Jackson and YAMLFactory to pretty print objects: ```xml 2.14.1 - - INDENT_OUTPUT - - - DEFAULT_HAS_NO_DISABLED_FEATURE - + + true + false + true|false + + false ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java index cf03ef21ca..31c59a5f81 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java @@ -33,10 +33,10 @@ public class JacksonJson implements FormatterStepFactory { @Parameter - String version = JacksonJsonStep.defaultVersion(); + private String version = JacksonJsonStep.defaultVersion(); @Parameter - boolean endWithEol = new JacksonConfig().isEndWithEol(); + private boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); @Parameter private Map features = Collections.emptyMap(); @@ -45,10 +45,8 @@ public class JacksonJson implements FormatterStepFactory { public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { JacksonConfig jacksonConfig = new JacksonConfig(); - if (features != null) { - jacksonConfig.appendFeatureToToggle(features); - } - jacksonConfig.setEndWithEol(endWithEol); + jacksonConfig.appendFeatureToToggle(features); + jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); return JacksonJsonStep .create(jacksonConfig, version, stepConfig.getProvisioner()); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java index d3d9558cf4..1cd23bc3cc 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java @@ -18,12 +18,11 @@ import java.util.Collections; import java.util.Map; -import com.diffplug.spotless.maven.FormatterFactory; - import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; import com.diffplug.spotless.yaml.JacksonYamlStep; @@ -37,10 +36,7 @@ public class JacksonYaml implements FormatterStepFactory { private String version = JacksonYamlStep.defaultVersion(); @Parameter - boolean endWithEol = new JacksonConfig().isEndWithEol(); - - @Parameter - boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); + private boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); @Parameter private Map features = Collections.emptyMap(); @@ -49,10 +45,8 @@ public class JacksonYaml implements FormatterStepFactory { public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { JacksonConfig jacksonConfig = new JacksonConfig(); - if (features != null) { - jacksonConfig.appendFeatureToToggle(features); - } - jacksonConfig.setEndWithEol(endWithEol); + jacksonConfig.appendFeatureToToggle(features); + jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); return JacksonYamlStep .create(jacksonConfig, version, stepConfig.getProvisioner()); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index 90b3a2f077..b263be8173 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -70,7 +70,6 @@ public void testFormatJson_WithGson_defaultConfig_nestedObject() throws Exceptio assertFile("json_test.json").sameAsResource("json/nestedObjectAfter.json"); } - @Test public void testFormatJson_WithJackson_sortByKeys() throws Exception { writePomWithJsonSteps("true"); @@ -78,17 +77,17 @@ public void testFormatJson_WithJackson_sortByKeys() throws Exception { setFile("json_test.json").toResource("json/sortByKeysBefore.json"); String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); - assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfter_Jackson.json"); } @Test - public void testFormatJson_WithJackson_sortByKeys_noSpaceAfterKeySeparator() throws Exception { - writePomWithJsonSteps("falsetrue"); + public void testFormatJson_WithJackson_sortByKeys_spaceAfterKeySeparator() throws Exception { + writePomWithJsonSteps("truetrue"); setFile("json_test.json").toResource("json/sortByKeysBefore.json"); String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); - assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); + assertFile("json_test.json").sameAsResource("json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 15366ab2e6..51f8da99f4 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -49,12 +49,12 @@ public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exce } @Test - public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_withEol() throws Exception { - writePomWithYamlSteps("true"); + public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_spaceBeforeSeparator() throws Exception { + writePomWithYamlSteps("true"); setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml"); mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean_with_eol.yaml"); + assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml"); } @Test diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json similarity index 100% rename from testlib/src/main/resources/json/sortByKeysAfter_Jackson_noSpaceAfterKeySeparator.json rename to testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml similarity index 81% rename from testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml rename to testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml index 6080ba1f82..c6f891b9de 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean_with_eol.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml @@ -9,4 +9,4 @@ episodes: - 7 best-jedi: name: "Obi-Wan" - side: "light" + side: "light" \ No newline at end of file From f05126de68661f584b1b5865b406f35f700ae2e5 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Mon, 16 Jan 2023 23:02:39 +0400 Subject: [PATCH 0288/1120] Fix Spotbugs --- .../glue/json/JacksonJsonFormatterFunc.java | 79 ++++++++----------- .../diffplug/spotless/json/JacksonConfig.java | 1 + 2 files changed, 35 insertions(+), 45 deletions(-) diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index c19e56b549..c44ff0d0d1 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -16,8 +16,6 @@ package com.diffplug.spotless.glue.json; import java.io.IOException; -import java.util.stream.Collectors; -import java.util.stream.IntStream; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonProcessingException; @@ -79,25 +77,7 @@ protected DefaultPrettyPrinter makePrinter() { boolean spaceBeforeSeparator = jacksonConfig.isSpaceBeforeSeparator(); DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(getIndentation(), "\n"); - DefaultPrettyPrinter printer = new DefaultPrettyPrinter() { - private static final long serialVersionUID = 1L; - - @Override - public DefaultPrettyPrinter createInstance() { - return new DefaultPrettyPrinter(this); - } - - @Override - public DefaultPrettyPrinter withSeparators(Separators separators) { - this._separators = separators; - if (spaceBeforeSeparator) { - this._objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " "; - } else { - this._objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSeparator() + " "; - } - return this; - } - }; + DefaultPrettyPrinter printer = new SpotlessDefaultPrettyPrinter(spaceBeforeSeparator); printer.indentObjectsWith(indenter); printer.indentArraysWith(indenter); @@ -105,34 +85,18 @@ public DefaultPrettyPrinter withSeparators(Separators separators) { } protected String getIndentation() { - int indentSpaces = jacksonConfig.getIndentSpaces(); - if (indentSpaces < 0) { - return "\t"; - } else { - return IntStream.range(0, indentSpaces).mapToObj(i -> "").collect(Collectors.joining()); - } + // DefaultIndenter default constructor relies on this + return " "; + // int indentSpaces = jacksonConfig.getIndentSpaces(); + // if (indentSpaces < 0) { + // return "\t"; + // } else { + // return IntStream.range(0, indentSpaces).mapToObj(i -> "").collect(Collectors.joining()); + // } } protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - // We may consider adding manually an initial '---' prefix to help management of multiple documents - // if (!input.trim().startsWith("---")) { - // input = "---" + "\n" + input; - // } - try { - // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson - // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 - // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' - // JsonParser yamlParser = objectMapper.getFactory().createParser(input); - // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); - // return objectMapper.writeValueAsString(docs); - - // 2023-01: This returns JSON instead of YAML - // This will transit with a JsonNode - // A JsonNode may keep the comments from the input node - // JsonNode jsonNode = objectMapper.readTree(input); - //Not 'toPrettyString' as one could require no INDENT_OUTPUT - // return jsonNode.toPrettyString(); ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); String outputFromjackson = objectMapper.writeValueAsString(objectNode); @@ -141,4 +105,29 @@ protected String format(ObjectMapper objectMapper, String input) throws IllegalA throw new AssertionError("Unable to format. input='" + input + "'", e); } } + + protected static class SpotlessDefaultPrettyPrinter extends DefaultPrettyPrinter { + private static final long serialVersionUID = 1L; + private final boolean spaceBeforeSeparator; + + public SpotlessDefaultPrettyPrinter(boolean spaceBeforeSeparator) { + this.spaceBeforeSeparator = spaceBeforeSeparator; + } + + @Override + public DefaultPrettyPrinter createInstance() { + return new DefaultPrettyPrinter(this); + } + + @Override + public DefaultPrettyPrinter withSeparators(Separators separators) { + this._separators = separators; + if (spaceBeforeSeparator) { + this._objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " "; + } else { + this._objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSeparator() + " "; + } + return this; + } + } } diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java index 2fadf31d78..7690913f34 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -24,6 +24,7 @@ * A DTO holding the options for Jackson-based formatters */ public class JacksonConfig implements Serializable { + private static final long serialVersionUID = 1L; private static final Map DEFAULT_FEATURE_TOGGLES; From beb99af54563b473cd8f209afa78aca35f813d7b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:06:43 -0800 Subject: [PATCH 0289/1120] Adopt `de.benediktritter.maven-plugin-development` --- plugin-maven/build.gradle | 169 +++--------------- .../src/test/resources/pom-build.xml.mustache | 96 ---------- 2 files changed, 21 insertions(+), 244 deletions(-) delete mode 100644 plugin-maven/src/test/resources/pom-build.xml.mustache diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 3ea73e6101..6cf17dd986 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -1,42 +1,15 @@ -buildscript { - repositories { mavenCentral() } - dependencies { classpath "com.github.spullara.mustache.java:compiler:${VER_MUSTACHE}" } -} plugins { - id 'cz.malohlava.visteg' version '1.0.5' // https://github.com/mmalohlava/gradle-visteg + // https://www.benediktritter.de/maven-plugin-development/#release-history + id 'de.benediktritter.maven-plugin-development' version '0.4.0' } + repositories { mavenCentral() } apply from: rootProject.file('gradle/changelog.gradle') -apply from: rootProject.file('gradle/spotless-freshmark.gradle') - -// to generate taskGraph.pdf -// - set enabled (below) to true -// - run: ./gradlew :plugin-maven:test -// - run: rm plugin-maven/output.pdf -// - run: dot -Tpdf plugin-maven/build/reports/visteg.dot > plugin-maven/taskGraph.pdf -visteg { - enabled = false - nodeShape = 'box' - startNodeShape = 'box' - endNodeShape = 'box' - colorscheme = 'pastel24' // https://www.graphviz.org/doc/info/colors.html -} - -import com.github.mustachejava.DefaultMustacheFactory - -import java.nio.file.Files - -import static java.nio.charset.StandardCharsets.UTF_8 -import static java.nio.file.StandardOpenOption.CREATE -import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING - ext.artifactId = project.artifactIdMaven version = spotlessChangelog.versionNext -apply from: rootProject.file("gradle/java-setup.gradle") -apply from: rootProject.file("gradle/java-publish.gradle") -final MAVEN_PROJECT_DIR = project.layout.buildDirectory.dir("mavenProject").get() -final LOCAL_MAVEN_REPO_DIR = project.layout.buildDirectory.dir("localMavenRepository").get() +apply from: rootProject.file("gradle/java-setup.gradle") +apply from: rootProject.file('gradle/spotless-freshmark.gradle') def mvnw(String args) { boolean isWin = System.getProperty('os.name').toLowerCase().contains('win') @@ -55,17 +28,15 @@ def mvnw(String args) { } } -String libVersion = version.endsWith('-SNAPSHOT') ? - rootProject.spotlessChangelog.versionNext : - rootProject.spotlessChangelog.versionLast +apply plugin: 'de.benediktritter.maven-plugin-development' +mavenPlugin { + name = 'Spotless Maven Plugin' + artifactId = project.artifactIdMaven + description = project.description +} dependencies { - if (version.endsWith('-SNAPSHOT') || (rootProject.spotlessChangelog.versionNext == rootProject.spotlessChangelog.versionLast)) { - implementation project(':lib') - implementation project(':lib-extra') - } else { - implementation "com.diffplug.spotless:spotless-lib:${libVersion}" - implementation "com.diffplug.spotless:spotless-lib-extra:${libVersion}" - } + implementation project(':lib') + implementation project(':lib-extra') compileOnly "org.apache.maven:maven-plugin-api:${VER_MAVEN_API}" compileOnly "org.apache.maven.plugin-tools:maven-plugin-annotations:${VER_MAVEN_API}" @@ -90,112 +61,14 @@ dependencies { testImplementation "org.apache.maven:maven-core:${VER_MAVEN_API}" } -task copySourceFiles(type: Sync) { - from "src/main/java" - into MAVEN_PROJECT_DIR.dir("src/main/java") -} - -task copyMvnw(type: Copy, dependsOn: copySourceFiles) { - from 'src/test/resources' - include 'mvnw' - include 'mvnw.cmd' - include '.mvn/**' - into MAVEN_PROJECT_DIR -} - -task installLocalDependencies -def libs = [ - 'lib', - 'lib-extra', - 'testlib' -] -libs.each { - def groupId = 'com.diffplug.spotless' - def artifactId = "spotless-${it}" - def jarTask = tasks.getByPath(":${it}:jar") - def file = jarTask.archivePath - - def installDependency = task "install_${artifactId}"(type: Exec) { - workingDir MAVEN_PROJECT_DIR - - inputs.file(file) - outputs.dir(LOCAL_MAVEN_REPO_DIR.file(groupId.replace('.', '/') + "/" + artifactId + "/" + version)) - commandLine mvnw("org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file " + - "-Dfile=${file} " + - "-DgroupId=${groupId} " + - "-DartifactId=${artifactId} " + - "-Dversion=${libVersion} " + - "-Dpackaging=jar " + - "-DlocalRepositoryPath=${LOCAL_MAVEN_REPO_DIR}") - } - installDependency.dependsOn(jarTask) - - installLocalDependencies.dependsOn installDependency -} - -task createPomXml(dependsOn: installLocalDependencies) { - def newPomXml = MAVEN_PROJECT_DIR.file("pom.xml").asFile.toPath() - - outputs.file(newPomXml) - doLast { - def additionalDependencies = project.configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts.findAll { - return !libs.contains(it.moduleVersion.id.name) - }.collect { - return " \n" + - " ${it.moduleVersion.id.group}\n" + - " ${it.moduleVersion.id.name}\n" + - " ${it.moduleVersion.id.version}\n" + - " \n" - }.join() - - def versions = [ - spotlessMavenPluginVersion: version, - mavenApiVersion : VER_MAVEN_API, - eclipseAetherVersion : VER_ECLIPSE_AETHER, - spotlessLibVersion : libVersion, - jsr305Version : VER_JSR_305, - additionalDependencies : additionalDependencies - ] - - def pomXmlTemplate = project.layout.projectDirectory.file("src/test/resources/pom-build.xml.mustache").asFile.toPath() - - Files.newBufferedReader(pomXmlTemplate).withCloseable { reader -> - Files.newBufferedWriter(newPomXml, UTF_8, CREATE, TRUNCATE_EXISTING).withCloseable { writer -> - def mustache = new DefaultMustacheFactory().compile(reader, "pom") - mustache.execute(writer, versions) - } - } - } -} - -task runMavenBuild(type: Exec, dependsOn: [ - copySourceFiles, - copyMvnw, - createPomXml -]) { - outputs.dir(LOCAL_MAVEN_REPO_DIR) - - workingDir MAVEN_PROJECT_DIR - // -B batch mode to make dependency download logging less verbose - commandLine mvnw("clean install -B -Dmaven.repo.local=${LOCAL_MAVEN_REPO_DIR}") -} - -jar.setActions Arrays.asList() -jar.dependsOn(runMavenBuild) -File jarIn = MAVEN_PROJECT_DIR.file("target/spotless-maven-plugin-${version}.jar").asFile -File jarOut = jar.archivePath -jar.inputs.file(jarIn) -jar.outputs.file(jarOut) -jar.doLast { - Files.copy(jarIn.toPath(), jarOut.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) -} - -test { useJUnitPlatform() } - apply from: rootProject.file('gradle/special-tests.gradle') -tasks.withType(Test) { - systemProperty "localMavenRepositoryDir", LOCAL_MAVEN_REPO_DIR.asFile - systemProperty "spotlessMavenPluginVersion", project.version - dependsOn(jar) +tasks.withType(Test).configureEach { + useJUnitPlatform() + systemProperty 'spotlessMavenPluginVersion', project.version + dependsOn 'publishToMavenLocal' + dependsOn ':lib:publishToMavenLocal' + dependsOn ':lib-extra:publishToMavenLocal' } + +apply from: rootProject.file("gradle/java-publish.gradle") diff --git a/plugin-maven/src/test/resources/pom-build.xml.mustache b/plugin-maven/src/test/resources/pom-build.xml.mustache deleted file mode 100644 index 3c1d1a7d5b..0000000000 --- a/plugin-maven/src/test/resources/pom-build.xml.mustache +++ /dev/null @@ -1,96 +0,0 @@ - - 4.0.0 - - com.diffplug.spotless - spotless-maven-plugin - {{spotlessMavenPluginVersion}} - maven-plugin - - Spotless Maven Plugin - - - - 3.1.0 - - - - UTF-8 - 1.8 - 1.8 - - - {{mavenApiVersion}} - {{eclipseAetherVersion}} - {{spotlessLibVersion}} - {{jsr305Version}} - - - - - org.apache.maven - maven-core - ${maven.api.version} - provided - - - org.apache.maven - maven-plugin-api - ${maven.api.version} - provided - - - org.apache.maven.plugin-tools - maven-plugin-annotations - ${maven.api.version} - provided - - - org.eclipse.aether - aether-api - ${eclipse.aether.version} - provided - - - org.eclipse.aether - aether-util - ${eclipse.aether.version} - provided - - - com.google.code.findbugs - jsr305 - ${jsr305.version} - provided - - - - com.diffplug.spotless - spotless-lib - ${spotless.lib.version} - - - com.diffplug.spotless - spotless-lib-extra - ${spotless.lib.version} - - -{{{additionalDependencies}}} - - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - 3.5 - - - - - From 48ded12b4812b562065f54db20b4214ddae1f019 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:07:18 -0800 Subject: [PATCH 0290/1120] We now use the default local maven repository. --- .../spotless/maven/MavenIntegrationHarness.java | 6 +----- .../java/com/diffplug/spotless/maven/MavenRunner.java | 10 ++-------- 2 files changed, 3 insertions(+), 13 deletions(-) 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 e37bb0f13d..ad19f44624 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 @@ -53,7 +53,6 @@ public class MavenIntegrationHarness extends ResourceHarness { */ private static final String SPOTLESS_MAVEN_VERSION_IDE = null; - private static final String LOCAL_MAVEN_REPOSITORY_DIR = "localMavenRepositoryDir"; private static final String SPOTLESS_MAVEN_PLUGIN_VERSION = "spotlessMavenPluginVersion"; private static final String CONFIGURATION = "configuration"; private static final String EXECUTIONS = "executions"; @@ -179,8 +178,7 @@ protected void writePom(String[] executions, String[] configuration, String[] de protected MavenRunner mavenRunner() throws IOException { return MavenRunner.create() - .withProjectDir(rootFolder()) - .withLocalRepository(new File(getSystemProperty(LOCAL_MAVEN_REPOSITORY_DIR))); + .withProjectDir(rootFolder()); } /** @@ -247,8 +245,6 @@ private static String getSystemProperty(String name) { if (SPOTLESS_MAVEN_VERSION_IDE != null) { if (name.equals("spotlessMavenPluginVersion")) { return SPOTLESS_MAVEN_VERSION_IDE; - } else if (name.equals("localMavenRepositoryDir")) { - return new File("build/localMavenRepository").getAbsolutePath(); } else { throw Unhandled.stringException(name); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java index a86e000187..b5e2392a24 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.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. @@ -46,7 +46,6 @@ private MavenRunner() {} private File projectDir; private String[] args; - private File localRepositoryDir; private Map environment = new HashMap<>(); public MavenRunner withProjectDir(File projectDir) { @@ -59,11 +58,6 @@ public MavenRunner withArguments(String... args) { return this; } - public MavenRunner withLocalRepository(File localRepositoryDir) { - this.localRepositoryDir = localRepositoryDir; - return this; - } - public MavenRunner withRemoteDebug(int port) { String address = (Jvm.version() < 9 ? "" : "*:") + port; environment.put("MAVEN_OPTS", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=" + address); @@ -75,7 +69,7 @@ private Result run() throws IOException, InterruptedException { Objects.requireNonNull(args, "Need to call withArguments() first"); // run maven with the given args in the given directory String argsString = String.join(" ", Arrays.asList(args)); - List cmds = getPlatformCmds("-e -Dmaven.repo.local=" + localRepositoryDir + ' ' + argsString); + List cmds = getPlatformCmds("-e " + argsString); ProcessBuilder builder = new ProcessBuilder(cmds); builder.directory(projectDir); builder.environment().putAll(environment); From 491da2e1fc0968080c6ad4860873c30d142ed1b3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:07:41 -0800 Subject: [PATCH 0291/1120] We don't need to exclude maven from the initial assemble anymore. --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e302e6637..1f08c201f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,8 +30,7 @@ jobs: - name: spotlessCheck run: ./gradlew spotlessCheck --build-cache - name: assemble testClasses - run: ./gradlew assemble testClasses --build-cache -PSPOTLESS_EXCLUDE_MAVEN=true - # If this gets resolved, remove the EXCLUDE_MAVEN https://github.com/diffplug/spotless/issues/554 + run: ./gradlew assemble testClasses --build-cache build: needs: sanityCheck strategy: From 0f18e245981ad1909aad7bf91cf634446a6d1aab Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:18:01 -0800 Subject: [PATCH 0292/1120] Update changelog. --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 05cc349e9f..6b22962cba 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) ## [2.30.0] - 2023-01-13 ### Added From 8b73372dd286fe43efeb23dcdc8dfa03d85f5fda Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:20:33 -0800 Subject: [PATCH 0293/1120] Move maven version constants to the maven buildfile. --- gradle.properties | 8 +------- plugin-maven/build.gradle | 5 +++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 71f755522f..c3b71fd92e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,10 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.1 -VER_MOCKITO=4.11.0 - -# Used for Maven Plugin -VER_MAVEN_API=3.0 -VER_ECLIPSE_AETHER=1.1.0 -VER_MUSTACHE=0.9.10 -VER_PLEXUS_RESOURCES=1.2.0 +VER_MOCKITO=4.11.0 \ No newline at end of file diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 6cf17dd986..e06fce9ace 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -34,6 +34,11 @@ mavenPlugin { artifactId = project.artifactIdMaven description = project.description } + +String VER_MAVEN_API = '3.0' +String VER_ECLIPSE_AETHER = '1.1.0' +String VER_MUSTACHE = '0.9.10' +String VER_PLEXUS_RESOURCES = '1.2.0' dependencies { implementation project(':lib') implementation project(':lib-extra') From 5d7c3b741a4518097bffaacf7e6c30342302c1de Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 16:38:18 -0800 Subject: [PATCH 0294/1120] Move the multimodule harnessing to the only place where it is used. --- .../maven/MavenIntegrationHarness.java | 93 +---------------- .../maven/MultiModuleProjectTest.java | 99 ++++++++++++++++++- 2 files changed, 99 insertions(+), 93 deletions(-) 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 ad19f44624..15c504fc72 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 @@ -16,9 +16,7 @@ package com.diffplug.spotless.maven; import static com.diffplug.common.base.Strings.isNullOrEmpty; -import static java.util.Arrays.asList; import static java.util.Arrays.stream; -import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; import static java.util.stream.Collectors.toList; import static org.junit.jupiter.api.Assertions.fail; @@ -59,7 +57,6 @@ public class MavenIntegrationHarness extends ResourceHarness { private static final String MODULES = "modules"; private static final String DEPENDENCIES = "dependencies"; private static final String MODULE_NAME = "name"; - private static final String CHILD_ID = "childId"; private static final int REMOTE_DEBUG_PORT = 5005; private final MustacheFactory mustacheFactory = new DefaultMustacheFactory(); @@ -190,10 +187,6 @@ protected MavenRunner mavenRunnerWithRemoteDebug() throws IOException { return mavenRunner().withRemoteDebug(REMOTE_DEBUG_PORT); } - protected MultiModuleProjectCreator multiModuleProject() { - return new MultiModuleProjectCreator(); - } - protected String createPomXmlContent(String pluginVersion, String[] executions, String[] configuration, String[] dependencies) throws IOException { return createPomXmlContent("/pom-test.xml.mustache", pluginVersion, executions, configuration, dependencies); } @@ -207,7 +200,7 @@ protected String createPomXmlContent(String pluginVersion, String[] executions, return createPomXmlContent(pluginVersion, executions, configuration, null); } - private String createPomXmlContent(String pomTemplate, Map params) throws IOException { + protected String createPomXmlContent(String pomTemplate, Map params) throws IOException { URL url = MavenIntegrationHarness.class.getResource(pomTemplate); try (BufferedReader reader = Resources.asCharSource(url, StandardCharsets.UTF_8).openBufferedStream()) { Mustache mustache = mustacheFactory.compile(reader, "pom"); @@ -217,7 +210,7 @@ private String createPomXmlContent(String pomTemplate, Map param } } - private static Map buildPomXmlParams(String pluginVersion, String[] executions, String[] configuration, String[] modules, String[] dependencies) { + protected static Map buildPomXmlParams(String pluginVersion, String[] executions, String[] configuration, String[] modules, String[] dependencies) { Map params = new HashMap<>(); params.put(SPOTLESS_MAVEN_PLUGIN_VERSION, pluginVersion == null ? getSystemProperty(SPOTLESS_MAVEN_PLUGIN_VERSION) : pluginVersion); @@ -276,86 +269,4 @@ private static String[] including(String... includes) { private static String[] formats(String... formats) { return groupWithSteps("formats", formats); } - - protected class MultiModuleProjectCreator { - - private String configSubProject; - private SubProjectFile[] configSubProjectFiles; - private String[] configuration; - private final Map> subProjects = new LinkedHashMap<>(); - - protected MultiModuleProjectCreator withConfigSubProject(String name, SubProjectFile... files) { - configSubProject = name; - configSubProjectFiles = files; - return this; - } - - protected MultiModuleProjectCreator withConfiguration(String... lines) { - configuration = lines; - return this; - } - - protected MultiModuleProjectCreator addSubProject(String name, SubProjectFile... files) { - subProjects.put(name, asList(files)); - return this; - } - - protected void create() throws IOException { - createRootPom(); - createConfigSubProject(); - createSubProjects(); - } - - private void createRootPom() throws IOException { - List modulesList = new ArrayList<>(); - modulesList.add(configSubProject); - modulesList.addAll(subProjects.keySet()); - String[] modules = modulesList.toArray(new String[0]); - - Map rootPomParams = buildPomXmlParams(null, null, configuration, modules, null); - setFile("pom.xml").toContent(createPomXmlContent("/multi-module/pom-parent.xml.mustache", rootPomParams)); - } - - private void createConfigSubProject() throws IOException { - if (configSubProject != null) { - String content = createPomXmlContent("/multi-module/pom-config.xml.mustache", emptyMap()); - setFile(configSubProject + "/pom.xml").toContent(content); - - createSubProjectFiles(configSubProject, asList(configSubProjectFiles)); - } - } - - private void createSubProjects() throws IOException { - for (Map.Entry> entry : subProjects.entrySet()) { - String subProjectName = entry.getKey(); - List subProjectFiles = entry.getValue(); - - String content = createPomXmlContent("/multi-module/pom-child.xml.mustache", singletonMap(CHILD_ID, subProjectName)); - setFile(subProjectName + "/pom.xml").toContent(content); - - createSubProjectFiles(subProjectName, subProjectFiles); - } - } - - private void createSubProjectFiles(String subProjectName, List subProjectFiles) throws IOException { - for (SubProjectFile file : subProjectFiles) { - setFile(subProjectName + '/' + file.to).toResource(file.from); - } - } - } - - protected static class SubProjectFile { - - private final String from; - private final String to; - - private SubProjectFile(String from, String to) { - this.from = from; - this.to = to; - } - - protected static SubProjectFile file(String from, String to) { - return new SubProjectFile(from, to); - } - } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java index e67b1bcad3..ae8378c566 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.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. @@ -15,7 +15,15 @@ */ package com.diffplug.spotless.maven; -import static com.diffplug.spotless.maven.MavenIntegrationHarness.SubProjectFile.file; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import org.junit.jupiter.api.Test; @@ -96,4 +104,91 @@ void testConfigurationDependency() throws Exception { assertFile("three/src/main/scala/test1.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); assertFile("three/src/test/scala/test2.scala").sameAsResource("scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); } + + private static final String CHILD_ID = "childId"; + + protected MultiModuleProjectCreator multiModuleProject() { + return new MultiModuleProjectCreator(); + } + + class MultiModuleProjectCreator { + private String configSubProject; + private SubProjectFile[] configSubProjectFiles; + private String[] configuration; + private final Map> subProjects = new LinkedHashMap<>(); + + protected MultiModuleProjectCreator withConfigSubProject(String name, SubProjectFile... files) { + configSubProject = name; + configSubProjectFiles = files; + return this; + } + + protected MultiModuleProjectCreator withConfiguration(String... lines) { + configuration = lines; + return this; + } + + protected MultiModuleProjectCreator addSubProject(String name, SubProjectFile... files) { + subProjects.put(name, asList(files)); + return this; + } + + protected void create() throws IOException { + createRootPom(); + createConfigSubProject(); + createSubProjects(); + } + + private void createRootPom() throws IOException { + List modulesList = new ArrayList<>(); + modulesList.add(configSubProject); + modulesList.addAll(subProjects.keySet()); + String[] modules = modulesList.toArray(new String[0]); + + Map rootPomParams = buildPomXmlParams(null, null, configuration, modules, null); + setFile("pom.xml").toContent(createPomXmlContent("/multi-module/pom-parent.xml.mustache", rootPomParams)); + } + + private void createConfigSubProject() throws IOException { + if (configSubProject != null) { + String content = createPomXmlContent("/multi-module/pom-config.xml.mustache", emptyMap()); + setFile(configSubProject + "/pom.xml").toContent(content); + + createSubProjectFiles(configSubProject, asList(configSubProjectFiles)); + } + } + + private void createSubProjects() throws IOException { + for (Map.Entry> entry : subProjects.entrySet()) { + String subProjectName = entry.getKey(); + List subProjectFiles = entry.getValue(); + + String content = createPomXmlContent("/multi-module/pom-child.xml.mustache", singletonMap(CHILD_ID, subProjectName)); + setFile(subProjectName + "/pom.xml").toContent(content); + + createSubProjectFiles(subProjectName, subProjectFiles); + } + } + + private void createSubProjectFiles(String subProjectName, List subProjectFiles) { + for (SubProjectFile file : subProjectFiles) { + setFile(subProjectName + '/' + file.to).toResource(file.from); + } + } + } + + static class SubProjectFile { + + private final String from; + private final String to; + + private SubProjectFile(String from, String to) { + this.from = from; + this.to = to; + } + } + + static SubProjectFile file(String from, String to) { + return new SubProjectFile(from, to); + } } From 7294dbcfa94778d2f2c25e2e7d34237faac33685 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:38:08 -0800 Subject: [PATCH 0295/1120] MavenRunner now uses a single ProcessRunner across an entire test class. --- .../com/diffplug/spotless/ProcessRunner.java | 34 +++++- .../maven/MavenIntegrationHarness.java | 16 +++ .../diffplug/spotless/maven/MavenRunner.java | 111 +++--------------- 3 files changed, 63 insertions(+), 98 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index c798ed6c07..7a1d0ac774 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,12 @@ package com.diffplug.spotless; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutionException; @@ -55,13 +57,18 @@ public Result shell(String cmd) throws IOException, InterruptedException { /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ public Result shellWinUnix(String cmdWin, String cmdUnix) throws IOException, InterruptedException { + return shellWinUnix(null, cmdWin, cmdUnix); + } + + /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ + public Result shellWinUnix(File cwd, String cmdWin, String cmdUnix) throws IOException, InterruptedException { List args; if (FileSignature.machineIsWin()) { args = Arrays.asList("cmd", "/c", cmdWin); } else { args = Arrays.asList("sh", "-c", cmdUnix); } - return exec(args); + return exec(cwd, args); } /** Creates a process with the given arguments. */ @@ -76,12 +83,25 @@ public Result exec(byte[] stdin, String... args) throws IOException, Interrupted /** Creates a process with the given arguments. */ public Result exec(List args) throws IOException, InterruptedException { - return exec(new byte[0], args); + return exec((File) null, args); + } + + /** Creates a process with the given arguments. */ + public Result exec(File cwd, List args) throws IOException, InterruptedException { + return exec(cwd, new byte[0], args); } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ public Result exec(byte[] stdin, List args) throws IOException, InterruptedException { + return exec(null, stdin, args); + } + + /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ + public Result exec(File cwd, byte[] stdin, List args) throws IOException, InterruptedException { ProcessBuilder builder = new ProcessBuilder(args); + if (cwd != null) { + builder.directory(cwd); + } Process process = builder.start(); Future outputFut = threadStdOut.submit(() -> drainToBytes(process.getInputStream(), bufStdOut)); Future errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr)); @@ -147,6 +167,14 @@ public byte[] stdErr() { return stdErr; } + public String stdOutUtf8() { + return new String(stdOut, StandardCharsets.UTF_8); + } + + public String stdErrUtf8() { + return new String(stdErr, StandardCharsets.UTF_8); + } + /** Returns true if the exit code was not zero. */ public boolean exitNotZero() { return exitCode != 0; 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 15c504fc72..1c44eef55e 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 @@ -31,6 +31,8 @@ import java.nio.file.Path; import java.util.*; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import com.github.mustachejava.DefaultMustacheFactory; @@ -40,6 +42,7 @@ import com.diffplug.common.base.Unhandled; import com.diffplug.common.io.Resources; import com.diffplug.spotless.Jvm; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.ResourceHarness; public class MavenIntegrationHarness extends ResourceHarness { @@ -175,9 +178,22 @@ protected void writePom(String[] executions, String[] configuration, String[] de protected MavenRunner mavenRunner() throws IOException { return MavenRunner.create() + .withRunner(runner) .withProjectDir(rootFolder()); } + private static ProcessRunner runner; + + @BeforeAll + static void setupRunner() throws IOException { + runner = new ProcessRunner(); + } + + @AfterAll + static void closeRunner() throws IOException { + runner.close(); + } + /** * Useful for local development. Allows debugging the Spotless Maven Plugin remotely. * Effectively translates into running {@code mvnDebug} on port 5005. The forked JVM will be diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java index b5e2392a24..4fe454ceba 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java @@ -17,21 +17,15 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.Charset; import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; -import com.diffplug.common.base.Throwables; -import com.diffplug.common.io.ByteStreams; -import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.Jvm; +import com.diffplug.spotless.ProcessRunner; /** * Harness for running a maven build, same idea as the @@ -47,6 +41,7 @@ private MavenRunner() {} private File projectDir; private String[] args; private Map environment = new HashMap<>(); + private ProcessRunner runner; public MavenRunner withProjectDir(File projectDir) { this.projectDir = Objects.requireNonNull(projectDir); @@ -58,110 +53,36 @@ public MavenRunner withArguments(String... args) { return this; } + public MavenRunner withRunner(ProcessRunner runner) { + this.runner = runner; + return this; + } + public MavenRunner withRemoteDebug(int port) { String address = (Jvm.version() < 9 ? "" : "*:") + port; environment.put("MAVEN_OPTS", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=" + address); return this; } - private Result run() throws IOException, InterruptedException { + private ProcessRunner.Result run() throws IOException, InterruptedException { Objects.requireNonNull(projectDir, "Need to call withProjectDir() first"); Objects.requireNonNull(args, "Need to call withArguments() first"); // run maven with the given args in the given directory - String argsString = String.join(" ", Arrays.asList(args)); - List cmds = getPlatformCmds("-e " + argsString); - ProcessBuilder builder = new ProcessBuilder(cmds); - builder.directory(projectDir); - builder.environment().putAll(environment); - Process process = builder.start(); - // slurp and return the stdout, stderr, and exitValue - Slurper output = new Slurper(process.getInputStream()); - Slurper error = new Slurper(process.getErrorStream()); - int exitValue = process.waitFor(); - output.join(); - error.join(); - return new Result(exitValue, output.result(), error.result()); + String argsString = "-e " + String.join(" ", Arrays.asList(args)); + return runner.shellWinUnix(projectDir, "mvnw " + argsString, "./mvnw " + argsString); } /** Runs the command and asserts that exit code is 0. */ - public Result runNoError() throws IOException, InterruptedException { - Result result = run(); - assertThat(result.exitValue()).as("Run without error %s", result).isEqualTo(0); + public ProcessRunner.Result runNoError() throws IOException, InterruptedException { + ProcessRunner.Result result = run(); + assertThat(result.exitCode()).as("Run without error %s", result).isEqualTo(0); return result; } /** Runs the command and asserts that exit code is not 0. */ - public Result runHasError() throws IOException, InterruptedException { - Result result = run(); - assertThat(result.exitValue()).as("Run with error %s", result).isNotEqualTo(0); + public ProcessRunner.Result runHasError() throws IOException, InterruptedException { + ProcessRunner.Result result = run(); + assertThat(result.exitCode()).as("Run with error %s", result).isNotEqualTo(0); return result; } - - public static class Result { - private final int exitValue; - private final String output; - private final String error; - - public Result(int exitValue, String output, String error) { - super(); - this.exitValue = exitValue; - this.output = Objects.requireNonNull(output); - this.error = Objects.requireNonNull(error); - } - - public int exitValue() { - return exitValue; - } - - public String output() { - return output; - } - - public String error() { - return error; - } - - @Override - public String toString() { - return "Result{" + - "exitValue=" + exitValue + - ", output='" + output + '\'' + - ", error='" + error + '\'' + - '}'; - } - } - - /** Prepends any arguments necessary to run a console command. */ - private static List getPlatformCmds(String cmd) { - if (FileSignature.machineIsWin()) { - return Arrays.asList("cmd", "/c", "mvnw " + cmd); - } else { - return Arrays.asList("/bin/sh", "-c", "./mvnw " + cmd); - } - } - - private static class Slurper extends Thread { - private final InputStream input; - private volatile String result; - - Slurper(InputStream input) { - this.input = Objects.requireNonNull(input); - start(); - } - - @Override - public void run() { - try { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - ByteStreams.copy(input, output); - result = output.toString(Charset.defaultCharset().name()); - } catch (Exception e) { - result = Throwables.getStackTraceAsString(e); - } - } - - public String result() { - return result; - } - } } From b314a0126abd90098e1c4d79dacd9ccd551cb35b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:38:26 -0800 Subject: [PATCH 0296/1120] Adapt maven tests to use ProcessRunner. --- .../spotless/maven/SpotlessCheckMojoTest.java | 8 +++++--- .../maven/incremental/UpToDateCheckingTest.java | 8 ++++---- .../javascript/JavascriptFormatStepTest.java | 5 ++--- .../diffplug/spotless/maven/json/JsonTest.java | 2 +- .../maven/markdown/FlexmarkMavenTest.java | 5 ++--- .../spotless/maven/pom/SortPomMavenTest.java | 4 ++-- .../maven/prettier/PrettierFormatStepTest.java | 16 ++++++++-------- .../typescript/TypescriptFormatStepTest.java | 16 ++++++++-------- .../diffplug/spotless/maven/yaml/YamlTest.java | 6 +++--- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java index cb37e4a4c5..566851c26c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -21,6 +21,8 @@ import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ProcessRunner; + class SpotlessCheckMojoTest extends MavenIntegrationHarness { private static final String UNFORMATTED_FILE = "license/MissingLicense.test"; @@ -72,8 +74,8 @@ private void testSpotlessCheck(String fileName, String command, boolean expectEr MavenRunner mavenRunner = mavenRunner().withArguments(command); if (expectError) { - MavenRunner.Result result = mavenRunner.runHasError(); - assertThat(result.output()).contains("The following files had format violations"); + ProcessRunner.Result result = mavenRunner.runHasError(); + assertThat(result.stdOutUtf8()).contains("The following files had format violations"); } else { mavenRunner.runNoError(); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java index f315c7eefe..6afcba7430 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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. @@ -254,15 +254,15 @@ private List writeFiles(String resource, String suffix, int count) throws } private String runSpotlessApply() throws Exception { - return mavenRunnerForGoal("apply").runNoError().output(); + return mavenRunnerForGoal("apply").runNoError().stdOutUtf8(); } private String runSpotlessCheck() throws Exception { - return mavenRunnerForGoal("check").runNoError().output(); + return mavenRunnerForGoal("check").runNoError().stdOutUtf8(); } private String runSpotlessCheckOnUnformattedFiles() throws Exception { - return mavenRunnerForGoal("check").runHasError().output(); + return mavenRunnerForGoal("check").runHasError().stdOutUtf8(); } private MavenRunner mavenRunnerForGoal(String goal) throws IOException { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java index 5c8a5f04b3..d738e17dac 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/javascript/JavascriptFormatStepTest.java @@ -20,9 +20,9 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; -import com.diffplug.spotless.maven.MavenRunner.Result; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @@ -50,8 +50,7 @@ void eslintConfigFile() throws Exception { setFile(".eslintrc.js").toResource("npm/eslint/javascript/custom_rules/.eslintrc.js"); setFile(TEST_FILE_PATH).toResource("npm/eslint/javascript/custom_rules/javascript-es6.dirty"); - Result result = mavenRunner().withArguments("spotless:apply").runNoError(); - System.out.println(result.output()); + ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runNoError(); assertFile(TEST_FILE_PATH).sameAsResource("npm/eslint/javascript/custom_rules/javascript-es6.clean"); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index e492109faa..884aba79c7 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -57,7 +57,7 @@ public void testFormatJson_WithGson_sortByKeys() throws Exception { setFile("json_test.json").toResource("json/sortByKeysBefore.json"); - String output = mavenRunner().withArguments("spotless:apply").runNoError().output(); + String output = mavenRunner().withArguments("spotless:apply").runNoError().stdOutUtf8(); LOGGER.error(output); System.err.println(output); assertFile("json_test.json").sameAsResource("json/sortByKeysAfter.json"); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java index a623ca7f3c..eb1c6cc95f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.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. @@ -26,8 +26,7 @@ public void testFlexmarkWithDefaultConfig() throws Exception { writePomWithMarkdownSteps(""); setFile("markdown_test.md").toResource("markdown/flexmark/FlexmarkUnformatted.md"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("markdown_test.md").sameAsResource("markdown/flexmark/FlexmarkFormatted.md"); } - } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/pom/SortPomMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/pom/SortPomMavenTest.java index ca9d77a6e3..93eb8a9633 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/pom/SortPomMavenTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/pom/SortPomMavenTest.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. @@ -25,7 +25,7 @@ public void testSortPomWithDefaultConfig() throws Exception { writePomWithPomSteps(""); setFile("pom_test.xml").toResource("pom/pom_dirty.xml"); - mavenRunner().withArguments("spotless:apply").runNoError().error(); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("pom_test.xml").sameAsResource("pom/pom_clean_default.xml"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index c0a9267b93..47dab5d152 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java @@ -21,8 +21,8 @@ import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.maven.MavenIntegrationHarness; -import com.diffplug.spotless.maven.MavenRunner.Result; import com.diffplug.spotless.maven.generic.Prettier; import com.diffplug.spotless.tag.NpmTest; @@ -43,7 +43,7 @@ private String prepareRun(String kind, String suffix) throws IOException { return path; } - private Result runExpectingError(String kind, String suffix) throws IOException, InterruptedException { + private ProcessRunner.Result runExpectingError(String kind, String suffix) throws IOException, InterruptedException { String path = prepareRun(kind, suffix); return mavenRunner().withArguments("spotless:apply").runHasError(); } @@ -102,8 +102,8 @@ void unique_dependency_config() throws Exception { " 1.16.4", ""); - Result result = mavenRunner().withArguments("spotless:apply").runHasError(); - assertThat(result.output()).contains(Prettier.ERROR_MESSAGE_ONLY_ONE_CONFIG); + ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runHasError(); + assertThat(result.stdOutUtf8()).contains(Prettier.ERROR_MESSAGE_ONLY_ONE_CONFIG); } @Test @@ -156,8 +156,8 @@ void autodetect_npmrc_file() throws Exception { " 1.16.4", " .prettierrc.yml", ""); - Result result = runExpectingError("typescript", suffix); - assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); + ProcessRunner.Result result = runExpectingError("typescript", suffix); + assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } @Test @@ -174,7 +174,7 @@ void select_configured_npmrc_file() throws Exception { " .prettierrc.yml", " ${basedir}/.custom_npmrc", ""); - Result result = runExpectingError("typescript", suffix); - assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); + ProcessRunner.Result result = runExpectingError("typescript", suffix); + assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index 95097fe467..a09111d30d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -21,9 +21,9 @@ import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.maven.MavenIntegrationHarness; -import com.diffplug.spotless.maven.MavenRunner.Result; import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.EslintStyleGuide; import com.diffplug.spotless.tag.NpmTest; @@ -48,7 +48,7 @@ private String prepareRunTsfmt(String kind) throws IOException { return TEST_FILE_PATH; } - private Result runExpectingErrorTsfmt(String kind) throws IOException, InterruptedException { + private ProcessRunner.Result runExpectingErrorTsfmt(String kind) throws IOException, InterruptedException { prepareRunTsfmt(kind); return mavenRunner().withArguments("spotless:apply").runHasError(); } @@ -124,8 +124,8 @@ void testTypescript_2_Configs() throws Exception { setFile("tsfmt.json").toResource("npm/tsfmt/tsfmt/tsfmt.json"); setFile(path).toResource("npm/tsfmt/tsfmt/tsfmt.dirty"); - Result result = mavenRunner().withArguments("spotless:apply").runHasError(); - assertThat(result.output()).contains("must specify exactly one configFile or config"); + ProcessRunner.Result result = mavenRunner().withArguments("spotless:apply").runHasError(); + assertThat(result.stdOutUtf8()).contains("must specify exactly one configFile or config"); } @Test @@ -141,8 +141,8 @@ void testNpmrcIsAutoPickedUp() throws Exception { " ${basedir}/tslint.json", ""); setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json"); - Result result = runExpectingErrorTsfmt("tslint"); - assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); + ProcessRunner.Result result = runExpectingErrorTsfmt("tslint"); + assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } @Test @@ -159,8 +159,8 @@ void testNpmrcIsConfigurativelyPickedUp() throws Exception { " ${basedir}/.custom_npmrc", ""); setFile("tslint.json").toResource("npm/tsfmt/tslint/tslint.json"); - Result result = runExpectingErrorTsfmt("tslint"); - assertThat(result.output()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); + ProcessRunner.Result result = runExpectingErrorTsfmt("tslint"); + assertThat(result.stdOutUtf8()).containsPattern("Running npm command.*npm install.* failed with exit code: 1"); } @Test diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index b5a417c536..f17feeb10a 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -21,8 +21,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.maven.MavenIntegrationHarness; -import com.diffplug.spotless.maven.MavenRunner.Result; public class YamlTest extends MavenIntegrationHarness { private static final Logger LOGGER = LoggerFactory.getLogger(YamlTest.class); @@ -32,9 +32,9 @@ public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws writePomWithYamlSteps(""); setFile("yaml_test.yaml").toResource("yaml/separator_comments.yaml"); - Result runNoError = mavenRunner().withArguments("spotless:apply").runNoError(); + ProcessRunner.Result runNoError = mavenRunner().withArguments("spotless:apply").runNoError(); LOGGER.error("result: {}", runNoError); - assertThat(runNoError.exitValue()).as("Run without error %s", runNoError).isEqualTo(0); + assertThat(runNoError.exitCode()).as("Run without error %s", runNoError).isEqualTo(0); LOGGER.error("GOGO"); assertFile("yaml_test.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); } From bc4a2684d118b63818803bc1e99417023a229133 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:46:43 -0800 Subject: [PATCH 0297/1120] Add support for environment variables into ProcessRunner so that MavenRunner's support for remote debug works again. --- .../com/diffplug/spotless/ProcessRunner.java | 21 +++++++++---------- .../diffplug/spotless/maven/MavenRunner.java | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 7a1d0ac774..e2149a03d6 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -57,18 +58,18 @@ public Result shell(String cmd) throws IOException, InterruptedException { /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ public Result shellWinUnix(String cmdWin, String cmdUnix) throws IOException, InterruptedException { - return shellWinUnix(null, cmdWin, cmdUnix); + return shellWinUnix(null, null, cmdWin, cmdUnix); } /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ - public Result shellWinUnix(File cwd, String cmdWin, String cmdUnix) throws IOException, InterruptedException { + public Result shellWinUnix(File cwd, Map environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException { List args; if (FileSignature.machineIsWin()) { args = Arrays.asList("cmd", "/c", cmdWin); } else { args = Arrays.asList("sh", "-c", cmdUnix); } - return exec(cwd, args); + return exec(cwd, environment, new byte[0], args); } /** Creates a process with the given arguments. */ @@ -83,25 +84,23 @@ public Result exec(byte[] stdin, String... args) throws IOException, Interrupted /** Creates a process with the given arguments. */ public Result exec(List args) throws IOException, InterruptedException { - return exec((File) null, args); - } - - /** Creates a process with the given arguments. */ - public Result exec(File cwd, List args) throws IOException, InterruptedException { - return exec(cwd, new byte[0], args); + return exec(null, args); } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ public Result exec(byte[] stdin, List args) throws IOException, InterruptedException { - return exec(null, stdin, args); + return exec(null, null, stdin, args); } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(File cwd, byte[] stdin, List args) throws IOException, InterruptedException { + public Result exec(File cwd, Map environment, byte[] stdin, List args) throws IOException, InterruptedException { ProcessBuilder builder = new ProcessBuilder(args); if (cwd != null) { builder.directory(cwd); } + if (environment != null) { + builder.environment().putAll(environment); + } Process process = builder.start(); Future outputFut = threadStdOut.submit(() -> drainToBytes(process.getInputStream(), bufStdOut)); Future errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr)); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java index 4fe454ceba..d878b18c5f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java @@ -69,7 +69,7 @@ private ProcessRunner.Result run() throws IOException, InterruptedException { Objects.requireNonNull(args, "Need to call withArguments() first"); // run maven with the given args in the given directory String argsString = "-e " + String.join(" ", Arrays.asList(args)); - return runner.shellWinUnix(projectDir, "mvnw " + argsString, "./mvnw " + argsString); + return runner.shellWinUnix(projectDir, environment, "mvnw " + argsString, "./mvnw " + argsString); } /** Runs the command and asserts that exit code is 0. */ From 7b5f01949713ea90dbc6928346545d15c704a1f2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:49:33 -0800 Subject: [PATCH 0298/1120] Fix a bug in how ProcessRunner handled null stdin. --- lib/src/main/java/com/diffplug/spotless/ProcessRunner.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index e2149a03d6..1356c0ac0d 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -69,7 +69,7 @@ public Result shellWinUnix(File cwd, Map environment, String cmd } else { args = Arrays.asList("sh", "-c", cmdUnix); } - return exec(cwd, environment, new byte[0], args); + return exec(cwd, environment, null, args); } /** Creates a process with the given arguments. */ @@ -101,6 +101,9 @@ public Result exec(File cwd, Map environment, byte[] stdin, List if (environment != null) { builder.environment().putAll(environment); } + if (stdin == null) { + stdin = new byte[0]; + } Process process = builder.start(); Future outputFut = threadStdOut.submit(() -> drainToBytes(process.getInputStream(), bufStdOut)); Future errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr)); From 9d894cd364bcb20bc38d1f22a61e1f37b956f870 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:52:02 -0800 Subject: [PATCH 0299/1120] Update the core changelog since ProcessRunner has gotten a few new methods. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c08ca86796..bff243b753 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) ## [2.32.0] - 2023-01-13 ### Added From 86c613b08be06ff9dab3a59e1dcc7e1227e59d91 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:54:36 -0800 Subject: [PATCH 0300/1120] Small tweak to reduce diff. --- .../com/diffplug/spotless/maven/MavenIntegrationHarness.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 1c44eef55e..5a724408c8 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 @@ -178,8 +178,8 @@ protected void writePom(String[] executions, String[] configuration, String[] de protected MavenRunner mavenRunner() throws IOException { return MavenRunner.create() - .withRunner(runner) - .withProjectDir(rootFolder()); + .withProjectDir(rootFolder()) + .withRunner(runner); } private static ProcessRunner runner; From aa0c878c8817ef0afcc192e1e5257a3e3d7e83f7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 17:57:18 -0800 Subject: [PATCH 0301/1120] Fix spotbugs warning. --- .../main/java/com/diffplug/spotless/ProcessRunner.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 1356c0ac0d..41c664cafe 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -31,6 +31,7 @@ import java.util.concurrent.Future; import java.util.function.BiConsumer; +import edu.umd.cs.findbugs.annotations.Nullable; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; /** @@ -62,7 +63,7 @@ public Result shellWinUnix(String cmdWin, String cmdUnix) throws IOException, In } /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ - public Result shellWinUnix(File cwd, Map environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException { + public Result shellWinUnix(@Nullable File cwd, @Nullable Map environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException { List args; if (FileSignature.machineIsWin()) { args = Arrays.asList("cmd", "/c", cmdWin); @@ -78,7 +79,7 @@ public Result exec(String... args) throws IOException, InterruptedException { } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(byte[] stdin, String... args) throws IOException, InterruptedException { + public Result exec(@Nullable byte[] stdin, String... args) throws IOException, InterruptedException { return exec(stdin, Arrays.asList(args)); } @@ -88,12 +89,12 @@ public Result exec(List args) throws IOException, InterruptedException { } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(byte[] stdin, List args) throws IOException, InterruptedException { + public Result exec(@Nullable byte[] stdin, List args) throws IOException, InterruptedException { return exec(null, null, stdin, args); } /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ - public Result exec(File cwd, Map environment, byte[] stdin, List args) throws IOException, InterruptedException { + public Result exec(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, List args) throws IOException, InterruptedException { ProcessBuilder builder = new ProcessBuilder(args); if (cwd != null) { builder.directory(cwd); From e9bea7e369cd2b1bbbda8d5cda958d2f74b1a6a7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 17 Jan 2023 03:02:14 +0000 Subject: [PATCH 0302/1120] fix(deps): update dependency org.assertj:assertj-core to v3.24.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 71f755522f..ecf51ea654 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ VER_SLF4J=[1.6,2.0[ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 -VER_ASSERTJ=3.24.1 +VER_ASSERTJ=3.24.2 VER_MOCKITO=4.11.0 # Used for Maven Plugin From c51331dc79298ba3a2cdf6356ddcb405dfd65ef1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 22:47:38 -0800 Subject: [PATCH 0303/1120] Centralize test configuration into `special-tests` and make sure it doesn't get overwritten. --- lib-extra/build.gradle | 4 ++-- lib/build.gradle | 5 +---- plugin-gradle/build.gradle | 6 ++---- plugin-maven/build.gradle | 2 -- testlib/build.gradle | 16 ---------------- 5 files changed, 5 insertions(+), 28 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index d94992f8d3..08bf286d8d 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -25,8 +25,8 @@ dependencies { // we'll hold the core lib to a high standard spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) -test { - useJUnitPlatform() +apply from: rootProject.file('gradle/special-tests.gradle') +tasks.named('test') { if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // needed for EclipseCdtFormatterStepTest jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' diff --git a/lib/build.gradle b/lib/build.gradle index 3ef2064765..e7b0298132 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -112,10 +112,7 @@ dependencies { // we'll hold the core lib to a high standard spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) -tasks.withType(Test).configureEach { - useJUnitPlatform() -} - +apply from: rootProject.file('gradle/special-tests.gradle') jar { for (glue in NEEDS_GLUE) { from sourceSets.getByName(glue).output.classesDirs diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 8a3260d943..11258db0e6 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -27,13 +27,11 @@ dependencies { testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" } -test { - useJUnitPlatform() +apply from: rootProject.file('gradle/special-tests.gradle') +tasks.named('test') { testLogging.showStandardStreams = true } -apply from: rootProject.file('gradle/special-tests.gradle') - ////////////////////////// // GRADLE PLUGIN PORTAL // ////////////////////////// diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index e06fce9ace..b46cdda708 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -67,9 +67,7 @@ dependencies { } apply from: rootProject.file('gradle/special-tests.gradle') - tasks.withType(Test).configureEach { - useJUnitPlatform() systemProperty 'spotlessMavenPluginVersion', project.version dependsOn 'publishToMavenLocal' dependsOn ':lib:publishToMavenLocal' diff --git a/testlib/build.gradle b/testlib/build.gradle index 30c44ece23..4b16572a8c 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -21,22 +21,6 @@ dependencies { // we'll hold the testlib to a low standard (prize brevity) spotbugs { reportLevel = 'high' } // low|medium|high (low = sensitive to even minor mistakes) -test { - useJUnitPlatform() - if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { - // for GJF https://github.com/diffplug/spotless/issues/834 - def args = [ - '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED', - '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED', - '--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED', - '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED', - '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED', - '--add-opens=java.base/java.lang=ALL-UNNAMED' - ] - jvmArgs args - } -} - apply from: rootProject.file('gradle/special-tests.gradle') javadoc { From 5e1a0e97ed6d53f3694309e161460b459e9cb802 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 17 Jan 2023 12:53:20 +0400 Subject: [PATCH 0304/1120] Jackson - Yaml starts diverging to enable yanml-specific options --- .../glue/json/JacksonJsonFormatterFunc.java | 40 ++++----- .../glue/yaml/JacksonYamlFormatterFunc.java | 28 +++++-- .../diffplug/spotless/json/JacksonConfig.java | 11 +-- .../spotless/yaml/JacksonYamlConfig.java | 50 ++++++++++++ .../spotless/yaml/JacksonYamlStep.java | 2 +- .../gradle/spotless/JacksonGradleConfig.java | 67 +++++++++++++++ .../gradle/spotless/JsonExtension.java | 23 +++++- .../gradle/spotless/SpotlessExtension.java | 6 ++ .../gradle/spotless/YamlExtension.java | 75 +++++++++++++++++ .../gradle/spotless/YamlExtensionTest.java | 81 +++++++++++++++++++ plugin-maven/CHANGES.md | 7 +- plugin-maven/README.md | 28 +++++-- .../spotless/maven/yaml/JacksonYaml.java | 10 ++- .../spotless/maven/yaml/YamlTest.java | 8 +- ...ay_with_bracket.clean.no_start_marker.yaml | 11 +++ ...th_bracket.clean.spaceBeforeSeparator.yaml | 6 +- 16 files changed, 387 insertions(+), 66 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java create mode 100644 testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index c44ff0d0d1..934e60fcd8 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -18,6 +18,7 @@ import java.io.IOException; import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonFactoryBuilder; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.util.DefaultIndenter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; @@ -47,12 +48,22 @@ public String apply(String input) throws Exception { return format(objectMapper, input); } + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + try { + ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); + return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); + } catch (JsonProcessingException e) { + throw new AssertionError("Unable to format. input='" + input + "'", e); + } + } + /** * @return a {@link JsonFactory}. May be overridden to handle alternative formats. * @see jackson-dataformats-text */ protected JsonFactory makeJsonFactory() { - return new JsonFactory(); + // We may later accept JsonFactory.Features + return new JsonFactoryBuilder().build(); } protected ObjectMapper makeObjectMapper() { @@ -76,7 +87,9 @@ protected ObjectMapper makeObjectMapper() { protected DefaultPrettyPrinter makePrinter() { boolean spaceBeforeSeparator = jacksonConfig.isSpaceBeforeSeparator(); - DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(getIndentation(), "\n"); + // DefaultIndenter default constructor relies on 2 whitespaces as default tabulation + // By we want to force '\n' as eol given Spotless provides LF-input (whatever the actual File content/current OS) + DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(" ", "\n"); DefaultPrettyPrinter printer = new SpotlessDefaultPrettyPrinter(spaceBeforeSeparator); printer.indentObjectsWith(indenter); @@ -84,28 +97,6 @@ protected DefaultPrettyPrinter makePrinter() { return printer; } - protected String getIndentation() { - // DefaultIndenter default constructor relies on this - return " "; - // int indentSpaces = jacksonConfig.getIndentSpaces(); - // if (indentSpaces < 0) { - // return "\t"; - // } else { - // return IntStream.range(0, indentSpaces).mapToObj(i -> "").collect(Collectors.joining()); - // } - } - - protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - try { - ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - String outputFromjackson = objectMapper.writeValueAsString(objectNode); - - return outputFromjackson; - } catch (JsonProcessingException e) { - throw new AssertionError("Unable to format. input='" + input + "'", e); - } - } - protected static class SpotlessDefaultPrettyPrinter extends DefaultPrettyPrinter { private static final long serialVersionUID = 1L; private final boolean spaceBeforeSeparator; @@ -123,6 +114,7 @@ public DefaultPrettyPrinter createInstance() { public DefaultPrettyPrinter withSeparators(Separators separators) { this._separators = separators; if (spaceBeforeSeparator) { + // This is Jackson default behavior this._objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " "; } else { this._objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSeparator() + " "; diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index 6a471a884c..f7686ad503 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -17,23 +17,39 @@ import java.io.IOException; +import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; import com.diffplug.spotless.glue.json.JacksonJsonFormatterFunc; -import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.yaml.JacksonYamlConfig; public class JacksonYamlFormatterFunc extends JacksonJsonFormatterFunc { + final JacksonYamlConfig yamlConfig; - public JacksonYamlFormatterFunc(JacksonConfig jacksonConfig) { + public JacksonYamlFormatterFunc(JacksonYamlConfig jacksonConfig) { super(jacksonConfig); + this.yamlConfig = jacksonConfig; } - @Override - protected YAMLFactory makeJsonFactory() { - return new YAMLFactory(); + protected JsonFactory makeJsonFactory() { + YAMLFactoryBuilder yamlFactoryBuilder = new YAMLFactoryBuilder(new YAMLFactory()); + + // Configure the ObjectMapper + // https://github.com/FasterXML/jackson-databind#commonly-used-features + yamlConfig.getYamlFeatureToToggle().forEach((rawFeature, toggle) -> { + // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection + // Refers to 'com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature' + YAMLGenerator.Feature feature = YAMLGenerator.Feature.valueOf(rawFeature); + + yamlFactoryBuilder.configure(feature, toggle); + }); + + return yamlFactoryBuilder.build(); } @Override @@ -56,7 +72,7 @@ protected String format(ObjectMapper objectMapper, String input) throws IllegalA //Not 'toPrettyString' as one could require no INDENT_OUTPUT // return jsonNode.toPrettyString(); ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - String outputFromjackson = objectMapper.writeValueAsString(objectNode); + String outputFromjackson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); return outputFromjackson; } catch (JsonProcessingException e) { diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java index 7690913f34..d5ca990b08 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -31,6 +31,7 @@ public class JacksonConfig implements Serializable { static { Map defaultFeatureToggles = new LinkedHashMap<>(); // We activate by default the PrettyPrinter from Jackson + // @see com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT defaultFeatureToggles.put("INDENT_OUTPUT", true); DEFAULT_FEATURE_TOGGLES = defaultFeatureToggles; } @@ -41,8 +42,6 @@ public class JacksonConfig implements Serializable { // By default, Jackson adds a ' ' before separator, which is not standard with most IDE/JSON libraries protected boolean spaceBeforeSeparator = false; - // protected int indentSpaces; - public Map getFeatureToToggle() { return Collections.unmodifiableMap(featureToToggle); } @@ -62,12 +61,4 @@ public boolean isSpaceBeforeSeparator() { public void setSpaceBeforeSeparator(boolean spaceBeforeSeparator) { this.spaceBeforeSeparator = spaceBeforeSeparator; } - - // public int getIndentSpaces() { - // return indentSpaces; - // } - - // public void setIndentSpaces(int indentSpaces) { - // this.indentSpaces = indentSpaces; - // } } diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java new file mode 100644 index 0000000000..2463b9603f --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java @@ -0,0 +1,50 @@ +/* + * 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.yaml; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +import com.diffplug.spotless.json.JacksonConfig; + +/** + * Specialization of {@link JacksonConfig} for YAML documents + */ +public class JacksonYamlConfig extends JacksonConfig { + private static final long serialVersionUID = 1L; + + protected Map yamlFeatureToToggle = new LinkedHashMap<>(); + + public Map getYamlFeatureToToggle() { + return Collections.unmodifiableMap(yamlFeatureToToggle); + } + + /** + * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + */ + public void setYamlFeatureToToggle(Map yamlFeatureToToggle) { + this.yamlFeatureToToggle = yamlFeatureToToggle; + } + + /** + * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + */ + public void appendYamlFeatureToToggle(Map features) { + this.yamlFeatureToToggle.putAll(features); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java index 944d90e6c9..04d1895fe0 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java @@ -73,7 +73,7 @@ private State(JacksonConfig jacksonConfig, FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.yaml.JacksonYamlFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(JacksonConfig.class); + Constructor constructor = formatterFunc.getConstructor(JacksonYamlConfig.class); return (FormatterFunc) constructor.newInstance(jacksonConfig); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java new file mode 100644 index 0000000000..d388f45d11 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java @@ -0,0 +1,67 @@ +/* + * 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.gradle.spotless; + +import java.util.Collections; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonStep; + +public abstract class JacksonGradleConfig { + protected final FormatExtension formatExtension; + + protected JacksonConfig jacksonConfig; + + protected String version = JacksonJsonStep.defaultVersion(); + + public JacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { + this.formatExtension = formatExtension; + + this.jacksonConfig = jacksonConfig; + formatExtension.addStep(createStep()); + } + + public JacksonGradleConfig(FormatExtension formatExtension) { + this(new JacksonConfig(), formatExtension); + } + + public JacksonGradleConfig config(JacksonConfig jacksonConfig) { + this.jacksonConfig = jacksonConfig; + formatExtension.replaceStep(createStep()); + return this; + } + + public JacksonGradleConfig feature(String feature, boolean toggle) { + this.jacksonConfig.appendFeatureToToggle(Collections.singletonMap(feature, toggle)); + formatExtension.replaceStep(createStep()); + return this; + } + + public JacksonGradleConfig spaceBeforeSeparator(boolean toggle) { + this.jacksonConfig.setSpaceBeforeSeparator(toggle); + formatExtension.replaceStep(createStep()); + return this; + } + + public JacksonGradleConfig version(String version) { + this.version = version; + formatExtension.replaceStep(createStep()); + return this; + } + + protected abstract FormatterStep createStep(); +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 25182fa4bc..542b2d5431 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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,6 +18,8 @@ import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.json.JsonSimpleStep; import com.diffplug.spotless.json.gson.GsonStep; @@ -47,6 +49,10 @@ public GsonConfig gson() { return new GsonConfig(); } + public JacksonJsonGradleConfig jackson() { + return new JacksonJsonGradleConfig(this); + } + public class SimpleConfig { private int indent; @@ -108,4 +114,19 @@ private FormatterStep createStep() { } } + public static class JacksonJsonGradleConfig extends JacksonGradleConfig { + + public JacksonJsonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { + super(jacksonConfig, formatExtension); + } + + public JacksonJsonGradleConfig(FormatExtension formatExtension) { + this(new JacksonConfig(), formatExtension); + } + + @Override + protected FormatterStep createStep() { + return JacksonJsonStep.create(jacksonConfig, version, formatExtension.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 1c65fad310..8c3128e02d 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 @@ -193,6 +193,12 @@ public void json(Action closure) { format(JsonExtension.NAME, JsonExtension.class, closure); } + /** Configures the special YAML-specific extension. */ + public void yaml(Action closure) { + requireNonNull(closure); + format(JsonExtension.NAME, YamlExtension.class, closure); + } + /** Configures a custom extension. */ public void format(String name, Action closure) { requireNonNull(name, "name"); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java new file mode 100644 index 0000000000..5907ea985a --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -0,0 +1,75 @@ +/* + * 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. + * 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.util.Collections; + +import javax.inject.Inject; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.JacksonJsonStep; +import com.diffplug.spotless.yaml.JacksonYamlConfig; +import com.diffplug.spotless.yaml.JacksonYamlStep; + +public class YamlExtension extends FormatExtension { + private static final String DEFAULT_GSON_VERSION = JacksonJsonStep.defaultVersion(); + static final String NAME = "yaml"; + + @Inject + public YamlExtension(SpotlessExtension spotless) { + super(spotless); + } + + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + throw noDefaultTargetException(); + } + super.setupTask(task); + } + + public JacksonGradleConfig jackson() { + return new JacksonYamlGradleConfig(this); + } + + public class JacksonYamlGradleConfig extends JacksonGradleConfig { + protected JacksonYamlConfig jacksonConfig; + + public JacksonYamlGradleConfig(JacksonYamlConfig jacksonConfig, FormatExtension formatExtension) { + super(jacksonConfig, formatExtension); + + this.jacksonConfig = jacksonConfig; + } + + public JacksonYamlGradleConfig(FormatExtension formatExtension) { + this(new JacksonYamlConfig(), formatExtension); + } + + /** + * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + */ + public JacksonGradleConfig yamlFeature(String feature, boolean toggle) { + this.jacksonConfig.appendYamlFeatureToToggle(Collections.singletonMap(feature, toggle)); + formatExtension.replaceStep(createStep()); + return this; + } + + @Override + protected FormatterStep createStep() { + return JacksonYamlStep.create(jacksonConfig, version, provisioner()); + } + } +} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java new file mode 100644 index 0000000000..c16053a661 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -0,0 +1,81 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +class YamlExtensionTest extends GradleIntegrationHarness { + @Test + void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + "}", + "}"); + setFile("src/main/resources/example.yaml").toResource("yaml/separator_comments.yaml"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); + } + + @Test + void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_spaceBeforeSeparator() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson().spaceBeforeSeparator(true)", + "}", + "}"); + setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml"); + } + + // see YAMLGenerator.Feature.WRITE_DOC_START_MARKER + @Test + void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson().yamlFeature('WRITE_DOC_START_MARKER', false)", + "}", + "}"); + setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.yaml"); + } + +} diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d6326cba12..5bcc4b24c6 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,13 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -### Added -* Introduce `` ([#1492](https://github.com/diffplug/spotless/pull/1492)) - * **POTENTIALLY BREAKING** `JacksonYaml` is now configured with a `Map` to configure features -* Jackson (JSON and YAML) has new `spaceBeforeSeparator` option - * **POTENTIALLY BREAKING** `spaceBeforeSeparator` is defaulted to false while the formatter was behaving with `true` -## [2.30.0] - 2023-01-13 +# [2.30.0] - 2023-01-13 ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 6dca992591..e76d424611 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.30.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.30.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.29.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.29.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -864,6 +864,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n + ``` @@ -898,6 +899,22 @@ all HTML characters are written escaped or none. Set `escapeHtml` if you prefer [javadoc of String](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#compareTo(java.lang.String)) for details. +### Jackson + +Uses Jackson for formatting. + +```xml + + 2.14.1 + + true + false + true|false + + false + +``` + @@ -924,10 +941,11 @@ Uses Jackson and YAMLFactory to pretty print objects: ```xml 2.14.1 - - true + + true false - true|false + false + true|false false diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java index 1cd23bc3cc..9741c3f5d0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java @@ -21,10 +21,10 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.json.JacksonConfig; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.yaml.JacksonYamlConfig; import com.diffplug.spotless.yaml.JacksonYamlStep; /** @@ -36,16 +36,20 @@ public class JacksonYaml implements FormatterStepFactory { private String version = JacksonYamlStep.defaultVersion(); @Parameter - private boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); + private boolean spaceBeforeSeparator = new JacksonYamlConfig().isSpaceBeforeSeparator(); @Parameter private Map features = Collections.emptyMap(); + @Parameter + private Map yamlFeatures = Collections.emptyMap(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - JacksonConfig jacksonConfig = new JacksonConfig(); + JacksonYamlConfig jacksonConfig = new JacksonYamlConfig(); jacksonConfig.appendFeatureToToggle(features); + jacksonConfig.appendYamlFeatureToToggle(yamlFeatures); jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); return JacksonYamlStep diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 51f8da99f4..aaea2c65b1 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -15,14 +15,11 @@ */ package com.diffplug.spotless.maven.yaml; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.diffplug.spotless.maven.MavenIntegrationHarness; -import com.diffplug.spotless.maven.MavenRunner.Result; public class YamlTest extends MavenIntegrationHarness { private static final Logger LOGGER = LoggerFactory.getLogger(YamlTest.class); @@ -32,10 +29,7 @@ public void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws writePomWithYamlSteps(""); setFile("yaml_test.yaml").toResource("yaml/separator_comments.yaml"); - Result runNoError = mavenRunner().withArguments("spotless:apply").runNoError(); - LOGGER.error("result: {}", runNoError); - assertThat(runNoError.exitValue()).as("Run without error %s", runNoError).isEqualTo(0); - LOGGER.error("GOGO"); + mavenRunner().withArguments("spotless:apply").runNoError(); assertFile("yaml_test.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); } diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml new file mode 100644 index 0000000000..7f2f5a96cd --- /dev/null +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml @@ -0,0 +1,11 @@ +episodes: +- 1 +- 2 +- 3 +- 4 +- 5 +- 6 +- 7 +best-jedi: + name: "Obi-Wan" + side: "light" diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml index c6f891b9de..7dc9255e06 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml @@ -7,6 +7,6 @@ episodes: - 5 - 6 - 7 -best-jedi: - name: "Obi-Wan" - side: "light" \ No newline at end of file +best-jedi : + name : "Obi-Wan" + side : "light" From 533dc9999c56ca8dbd381f3ea74b79bcd5774e50 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 00:33:53 +0400 Subject: [PATCH 0305/1120] Progress with gradle and tests --- .../glue/json/AJacksonFormatterFunc.java | 87 +++++++++++++++++++ .../glue/json/JacksonJsonFormatterFunc.java | 59 ++++--------- .../glue/yaml/JacksonYamlFormatterFunc.java | 9 +- .../diffplug/spotless/json/JacksonConfig.java | 14 +-- .../spotless/json/JacksonJsonConfig.java | 59 +++++++++++++ .../spotless/json/JacksonJsonStep.java | 6 +- .../spotless/yaml/JacksonYamlStep.java | 13 +-- .../gradle/spotless/JacksonGradleConfig.java | 6 -- .../gradle/spotless/JsonExtension.java | 28 +++++- .../gradle/spotless/YamlExtension.java | 6 +- .../gradle/spotless/JsonExtensionTest.java | 56 ++++++++---- .../gradle/spotless/YamlExtensionTest.java | 33 ++----- .../spotless/maven/json/JacksonJson.java | 6 +- .../spotless/maven/yaml/JacksonYaml.java | 4 - ...ay_with_bracket.clean.no_start_marker.yaml | 4 +- 15 files changed, 259 insertions(+), 131 deletions(-) create mode 100644 lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java new file mode 100644 index 0000000000..a835c85f9a --- /dev/null +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java @@ -0,0 +1,87 @@ +/* + * 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. + * 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.json; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.json.JacksonConfig; + +/** + * A {@link FormatterFunc} based on Jackson library + */ +// https://github.com/FasterXML/jackson-dataformats-text/issues/372 +public abstract class AJacksonFormatterFunc implements FormatterFunc { + private JacksonConfig jacksonConfig; + + public AJacksonFormatterFunc(JacksonConfig jacksonConfig) { + this.jacksonConfig = jacksonConfig; + } + + @Override + public String apply(String input) throws Exception { + ObjectMapper objectMapper = makeObjectMapper(); + + return format(objectMapper, input); + } + + protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + try { + ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); + return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); + } catch (JsonProcessingException e) { + throw new AssertionError("Unable to format. input='" + input + "'", e); + } + } + + /** + * @return a {@link JsonFactory}. May be overridden to handle alternative formats. + * @see jackson-dataformats-text + */ + protected abstract JsonFactory makeJsonFactory(); + + protected ObjectMapper makeObjectMapper() { + JsonFactory jsonFactory = makeJsonFactory(); + ObjectMapper objectMapper = new ObjectMapper(jsonFactory); + + objectMapper.setDefaultPrettyPrinter(makePrinter()); + + // Configure the ObjectMapper + // https://github.com/FasterXML/jackson-databind#commonly-used-features + jacksonConfig.getFeatureToToggle().forEach((rawFeature, toggle) -> { + // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection + SerializationFeature feature = SerializationFeature.valueOf(rawFeature); + + objectMapper.configure(feature, toggle); + }); + + new JsonFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, true); + + return objectMapper; + } + + protected DefaultPrettyPrinter makePrinter() { + return new DefaultPrettyPrinter(); + } +} diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index 934e60fcd8..5aadcc568f 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -15,99 +15,72 @@ */ package com.diffplug.spotless.glue.json; -import java.io.IOException; - import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonFactoryBuilder; -import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.util.DefaultIndenter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.core.util.Separators; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonConfig; /** * A {@link FormatterFunc} based on Jackson library */ // https://github.com/FasterXML/jackson-dataformats-text/issues/372 -public class JacksonJsonFormatterFunc implements FormatterFunc { - private JacksonConfig jacksonConfig; +public class JacksonJsonFormatterFunc extends AJacksonFormatterFunc { + private JacksonJsonConfig jacksonConfig; - public JacksonJsonFormatterFunc(JacksonConfig jacksonConfig) { + public JacksonJsonFormatterFunc(JacksonJsonConfig jacksonConfig) { + super(jacksonConfig); this.jacksonConfig = jacksonConfig; } - @Override - public String apply(String input) throws Exception { - ObjectMapper objectMapper = makeObjectMapper(); - - return format(objectMapper, input); - } - - protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - try { - ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); - } catch (JsonProcessingException e) { - throw new AssertionError("Unable to format. input='" + input + "'", e); - } - } - /** * @return a {@link JsonFactory}. May be overridden to handle alternative formats. * @see jackson-dataformats-text */ protected JsonFactory makeJsonFactory() { - // We may later accept JsonFactory.Features - return new JsonFactoryBuilder().build(); - } - - protected ObjectMapper makeObjectMapper() { - JsonFactory jsonFactory = makeJsonFactory(); - ObjectMapper objectMapper = new ObjectMapper(jsonFactory); - - objectMapper.setDefaultPrettyPrinter(makePrinter()); + JsonFactory jsonFactory = new JsonFactoryBuilder().build(); // Configure the ObjectMapper // https://github.com/FasterXML/jackson-databind#commonly-used-features - jacksonConfig.getFeatureToToggle().forEach((rawFeature, toggle) -> { + jacksonConfig.getJsonFeatureToToggle().forEach((rawFeature, toggle) -> { // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - SerializationFeature feature = SerializationFeature.valueOf(rawFeature); + JsonGenerator.Feature feature = JsonGenerator.Feature.valueOf(rawFeature); - objectMapper.configure(feature, toggle); + jsonFactory.configure(feature, toggle); }); - return objectMapper; + return jsonFactory; } + @Override protected DefaultPrettyPrinter makePrinter() { boolean spaceBeforeSeparator = jacksonConfig.isSpaceBeforeSeparator(); // DefaultIndenter default constructor relies on 2 whitespaces as default tabulation // By we want to force '\n' as eol given Spotless provides LF-input (whatever the actual File content/current OS) DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(" ", "\n"); - DefaultPrettyPrinter printer = new SpotlessDefaultPrettyPrinter(spaceBeforeSeparator); + DefaultPrettyPrinter printer = new SpotlessJsonPrettyPrinter(spaceBeforeSeparator); printer.indentObjectsWith(indenter); printer.indentArraysWith(indenter); return printer; } - protected static class SpotlessDefaultPrettyPrinter extends DefaultPrettyPrinter { + protected static class SpotlessJsonPrettyPrinter extends DefaultPrettyPrinter { private static final long serialVersionUID = 1L; private final boolean spaceBeforeSeparator; - public SpotlessDefaultPrettyPrinter(boolean spaceBeforeSeparator) { + public SpotlessJsonPrettyPrinter(boolean spaceBeforeSeparator) { this.spaceBeforeSeparator = spaceBeforeSeparator; } @Override public DefaultPrettyPrinter createInstance() { - return new DefaultPrettyPrinter(this); + return new SpotlessJsonPrettyPrinter(spaceBeforeSeparator); } @Override diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index f7686ad503..3986374c9e 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -25,15 +25,19 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; -import com.diffplug.spotless.glue.json.JacksonJsonFormatterFunc; +import com.diffplug.spotless.glue.json.AJacksonFormatterFunc; import com.diffplug.spotless.yaml.JacksonYamlConfig; -public class JacksonYamlFormatterFunc extends JacksonJsonFormatterFunc { +public class JacksonYamlFormatterFunc extends AJacksonFormatterFunc { final JacksonYamlConfig yamlConfig; public JacksonYamlFormatterFunc(JacksonYamlConfig jacksonConfig) { super(jacksonConfig); this.yamlConfig = jacksonConfig; + + if (jacksonConfig == null) { + throw new IllegalArgumentException("ARG"); + } } protected JsonFactory makeJsonFactory() { @@ -43,7 +47,6 @@ protected JsonFactory makeJsonFactory() { // https://github.com/FasterXML/jackson-databind#commonly-used-features yamlConfig.getYamlFeatureToToggle().forEach((rawFeature, toggle) -> { // https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection - // Refers to 'com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature' YAMLGenerator.Feature feature = YAMLGenerator.Feature.valueOf(rawFeature); yamlFactoryBuilder.configure(feature, toggle); diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java index d5ca990b08..250b77d1f1 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -21,7 +21,7 @@ import java.util.Map; /** - * A DTO holding the options for Jackson-based formatters + * A DTO holding the basic for Jackson-based formatters */ public class JacksonConfig implements Serializable { private static final long serialVersionUID = 1L; @@ -38,10 +38,6 @@ public class JacksonConfig implements Serializable { protected Map featureToToggle = new LinkedHashMap<>(); - // https://github.com/revelc/formatter-maven-plugin/pull/280 - // By default, Jackson adds a ' ' before separator, which is not standard with most IDE/JSON libraries - protected boolean spaceBeforeSeparator = false; - public Map getFeatureToToggle() { return Collections.unmodifiableMap(featureToToggle); } @@ -53,12 +49,4 @@ public void setFeatureToToggle(Map featureToToggle) { public void appendFeatureToToggle(Map features) { this.featureToToggle.putAll(features); } - - public boolean isSpaceBeforeSeparator() { - return spaceBeforeSeparator; - } - - public void setSpaceBeforeSeparator(boolean spaceBeforeSeparator) { - this.spaceBeforeSeparator = spaceBeforeSeparator; - } } diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java new file mode 100644 index 0000000000..50b28605d1 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java @@ -0,0 +1,59 @@ +/* + * 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.json; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Specialization of {@link JacksonConfig} for JSON documents + */ +public class JacksonJsonConfig extends JacksonConfig { + private static final long serialVersionUID = 1L; + + protected Map jsonFeatureToToggle = new LinkedHashMap<>(); + + // https://github.com/revelc/formatter-maven-plugin/pull/280 + // By default, Jackson adds a ' ' before separator, which is not standard with most IDE/JSON libraries + protected boolean spaceBeforeSeparator = false; + + public Map getJsonFeatureToToggle() { + return Collections.unmodifiableMap(jsonFeatureToToggle); + } + + /** + * @see com.fasterxml.jackson.core.JsonGenerator.Feature + */ + public void setJsonFeatureToToggle(Map jsonFeatureToToggle) { + this.jsonFeatureToToggle = jsonFeatureToToggle; + } + + /** + * @see com.fasterxml.jackson.core.JsonGenerator.Feature + */ + public void appendJsonFeatureToToggle(Map features) { + this.jsonFeatureToToggle.putAll(features); + } + + public boolean isSpaceBeforeSeparator() { + return spaceBeforeSeparator; + } + + public void setSpaceBeforeSeparator(boolean spaceBeforeSeparator) { + this.spaceBeforeSeparator = spaceBeforeSeparator; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java index 0fe1ab057b..f15edbbd42 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java @@ -41,7 +41,7 @@ public static String defaultVersion() { return DEFAULT_VERSION; } - public static FormatterStep create(JacksonConfig jacksonConfig, + public static FormatterStep create(JacksonJsonConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); @@ -51,7 +51,7 @@ public static FormatterStep create(JacksonConfig jacksonConfig, } public static FormatterStep create(Provisioner provisioner) { - return create(new JacksonConfig(), defaultVersion(), provisioner); + return create(new JacksonJsonConfig(), defaultVersion(), provisioner); } private static final class State implements Serializable { @@ -72,7 +72,7 @@ private State(JacksonConfig jacksonConfig, FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.json.JacksonJsonFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(JacksonConfig.class); + Constructor constructor = formatterFunc.getConstructor(JacksonJsonConfig.class); return (FormatterFunc) constructor.newInstance(jacksonConfig); } } diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java index 04d1895fe0..201199fe8b 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java @@ -25,7 +25,6 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.JarState; import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.json.JacksonConfig; /** * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. @@ -42,7 +41,7 @@ public static String defaultVersion() { return DEFAULT_VERSION; } - public static FormatterStep create(JacksonConfig jacksonConfig, + public static FormatterStep create(JacksonYamlConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); @@ -52,21 +51,25 @@ public static FormatterStep create(JacksonConfig jacksonConfig, } public static FormatterStep create(Provisioner provisioner) { - return create(new JacksonConfig(), defaultVersion(), provisioner); + return create(new JacksonYamlConfig(), defaultVersion(), provisioner); } private static final class State implements Serializable { private static final long serialVersionUID = 1L; - private final JacksonConfig jacksonConfig; + private final JacksonYamlConfig jacksonConfig; private final JarState jarState; - private State(JacksonConfig jacksonConfig, + private State(JacksonYamlConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) throws IOException { this.jacksonConfig = jacksonConfig; + if (jacksonConfig == null) { + throw new IllegalArgumentException("ARG"); + } + this.jarState = JarState.from(JacksonYamlStep.MAVEN_COORDINATE + jacksonVersion, provisioner); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java index d388f45d11..afc0c36371 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java @@ -51,12 +51,6 @@ public JacksonGradleConfig feature(String feature, boolean toggle) { return this; } - public JacksonGradleConfig spaceBeforeSeparator(boolean toggle) { - this.jacksonConfig.setSpaceBeforeSeparator(toggle); - formatExtension.replaceStep(createStep()); - return this; - } - public JacksonGradleConfig version(String version) { this.version = version; formatExtension.replaceStep(createStep()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 542b2d5431..31f605809c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -15,10 +15,12 @@ */ package com.diffplug.gradle.spotless; +import java.util.Collections; + import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonConfig; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.json.JsonSimpleStep; import com.diffplug.spotless.json.gson.GsonStep; @@ -49,7 +51,7 @@ public GsonConfig gson() { return new GsonConfig(); } - public JacksonJsonGradleConfig jackson() { + public JacksonJsonGradleConfig jacksonJson() { return new JacksonJsonGradleConfig(this); } @@ -115,17 +117,35 @@ private FormatterStep createStep() { } public static class JacksonJsonGradleConfig extends JacksonGradleConfig { + protected JacksonJsonConfig jacksonConfig; - public JacksonJsonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { + public JacksonJsonGradleConfig(JacksonJsonConfig jacksonConfig, FormatExtension formatExtension) { super(jacksonConfig, formatExtension); + this.jacksonConfig = jacksonConfig; + + if (jacksonConfig == null) { + throw new IllegalArgumentException("ARG2"); + } } public JacksonJsonGradleConfig(FormatExtension formatExtension) { - this(new JacksonConfig(), formatExtension); + this(new JacksonJsonConfig(), formatExtension); + } + + /** + * @see com.fasterxml.jackson.core.JsonGenerator.Feature + */ + public JacksonGradleConfig jsonFeature(String feature, boolean toggle) { + this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle)); + formatExtension.replaceStep(createStep()); + return this; } @Override protected FormatterStep createStep() { + if (jacksonConfig == null) { + throw new IllegalArgumentException("ARG3"); + } return JacksonJsonStep.create(jacksonConfig, version, formatExtension.provisioner()); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index 5907ea985a..3fc12e0495 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -41,7 +41,7 @@ protected void setupTask(SpotlessTask task) { super.setupTask(task); } - public JacksonGradleConfig jackson() { + public JacksonGradleConfig jacksonYaml() { return new JacksonYamlGradleConfig(this); } @@ -52,6 +52,10 @@ public JacksonYamlGradleConfig(JacksonYamlConfig jacksonConfig, FormatExtension super(jacksonConfig, formatExtension); this.jacksonConfig = jacksonConfig; + + if (jacksonConfig == null) { + throw new IllegalArgumentException("ARG"); + } } public JacksonYamlGradleConfig(FormatExtension formatExtension) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java index e2fb9f70aa..945c72cf75 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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. @@ -30,9 +30,9 @@ void simpleDefaultFormatting() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'examples/**/*.json'", - " simple()", - "}", + " target 'examples/**/*.json'", + " simple()", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/nestedObjectBefore.json"); setFile("examples/main/resources/example.json").toResource("json/nestedObjectBefore.json"); @@ -51,9 +51,9 @@ void simpleFormattingWithCustomNumberOfSpaces() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'src/**/*.json'", - " simple().indentWithSpaces(6)", - "}", + " target 'src/**/*.json'", + " simple().indentWithSpaces(6)", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); gradleRunner().withArguments("spotlessApply").build(); @@ -70,9 +70,9 @@ void gsonDefaultFormatting() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'examples/**/*.json'", - " gson()", - "}", + " target 'examples/**/*.json'", + " gson()", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/nestedObjectBefore.json"); setFile("examples/main/resources/example.json").toResource("json/nestedObjectBefore.json"); @@ -91,9 +91,9 @@ void gsonFormattingWithCustomNumberOfSpaces() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'src/**/*.json'", - " gson().indentWithSpaces(6)", - "}", + " target 'src/**/*.json'", + " gson().indentWithSpaces(6)", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/singletonArrayBefore.json"); gradleRunner().withArguments("spotlessApply").build(); @@ -110,9 +110,9 @@ void gsonFormattingWithSortingByKeys() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'src/**/*.json'", - " gson().sortByKeys()", - "}", + " target 'src/**/*.json'", + " gson().sortByKeys()", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/sortByKeysBefore.json"); gradleRunner().withArguments("spotlessApply").build(); @@ -129,13 +129,31 @@ void gsonFormattingWithHtmlEscape() throws IOException { "repositories { mavenCentral() }", "spotless {", " json {", - " target 'src/**/*.json'", - " gson().escapeHtml()", - "}", + " target 'src/**/*.json'", + " gson().escapeHtml()", + " }", "}"); setFile("src/main/resources/example.json").toResource("json/escapeHtmlGsonBefore.json"); gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/resources/example.json").sameAsResource("json/escapeHtmlGsonAfter.json"); } + @Test + void jacksonFormattingWithSortingByKeys() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'src/**/*.json'", + " jacksonJson().feature('ORDER_MAP_ENTRIES_BY_KEYS', true)", + " }", + "}"); + setFile("src/main/resources/example.json").toResource("json/sortByKeysBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/sortByKeysAfter_Jackson.json"); + } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index c16053a661..79e0df0d8d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -30,34 +30,15 @@ void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws IOExcep "repositories { mavenCentral() }", "spotless {", " yaml {", - " target 'src/**/*.yaml'", - " jackson()", - "}", + " target 'src/**/*.yaml'", + " jacksonYaml()", + " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/separator_comments.yaml"); gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/separator_comments.clean.yaml"); } - @Test - void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_spaceBeforeSeparator() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " yaml {", - " target 'src/**/*.yaml'", - " jackson().spaceBeforeSeparator(true)", - "}", - "}"); - setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml"); - } - // see YAMLGenerator.Feature.WRITE_DOC_START_MARKER @Test void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { @@ -69,9 +50,11 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { "repositories { mavenCentral() }", "spotless {", " yaml {", - " target 'src/**/*.yaml'", - " jackson().yamlFeature('WRITE_DOC_START_MARKER', false)", - "}", + " target 'src/**/*.yaml'", + " jacksonYaml()" + + " .yamlFeature('WRITE_DOC_START_MARKER', false)" + + " .yamlFeature('MINIMIZE_QUOTES', true)", + " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); gradleRunner().withArguments("spotlessApply").build(); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java index 31c59a5f81..9bca852754 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java @@ -21,7 +21,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.json.JacksonConfig; +import com.diffplug.spotless.json.JacksonJsonConfig; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.FormatterStepConfig; @@ -36,14 +36,14 @@ public class JacksonJson implements FormatterStepFactory { private String version = JacksonJsonStep.defaultVersion(); @Parameter - private boolean spaceBeforeSeparator = new JacksonConfig().isSpaceBeforeSeparator(); + private boolean spaceBeforeSeparator = new JacksonJsonConfig().isSpaceBeforeSeparator(); @Parameter private Map features = Collections.emptyMap(); @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - JacksonConfig jacksonConfig = new JacksonConfig(); + JacksonJsonConfig jacksonConfig = new JacksonJsonConfig(); jacksonConfig.appendFeatureToToggle(features); jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java index 9741c3f5d0..d97cc41647 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/JacksonYaml.java @@ -35,9 +35,6 @@ public class JacksonYaml implements FormatterStepFactory { @Parameter private String version = JacksonYamlStep.defaultVersion(); - @Parameter - private boolean spaceBeforeSeparator = new JacksonYamlConfig().isSpaceBeforeSeparator(); - @Parameter private Map features = Collections.emptyMap(); @@ -50,7 +47,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { jacksonConfig.appendFeatureToToggle(features); jacksonConfig.appendYamlFeatureToToggle(yamlFeatures); - jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); return JacksonYamlStep .create(jacksonConfig, version, stepConfig.getProvisioner()); diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml index 7f2f5a96cd..0e5571531a 100644 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml +++ b/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml @@ -7,5 +7,5 @@ episodes: - 6 - 7 best-jedi: - name: "Obi-Wan" - side: "light" + name: Obi-Wan + side: light From 4d6f9610e6542dd91029c9031d2a93c5c89319bb Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 00:50:12 +0400 Subject: [PATCH 0306/1120] Small fixes --- ...leConfig.java => AJacksonGradleConfig.java} | 18 ++++-------------- .../gradle/spotless/JsonExtension.java | 4 ++-- .../gradle/spotless/YamlExtension.java | 6 +++--- .../gradle/spotless/YamlExtensionTest.java | 4 ++-- 4 files changed, 11 insertions(+), 21 deletions(-) rename plugin-gradle/src/main/java/com/diffplug/gradle/spotless/{JacksonGradleConfig.java => AJacksonGradleConfig.java} (71%) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java similarity index 71% rename from plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java rename to plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java index afc0c36371..e3d5cee661 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JacksonGradleConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java @@ -21,37 +21,27 @@ import com.diffplug.spotless.json.JacksonConfig; import com.diffplug.spotless.json.JacksonJsonStep; -public abstract class JacksonGradleConfig { +public abstract class AJacksonGradleConfig { protected final FormatExtension formatExtension; protected JacksonConfig jacksonConfig; protected String version = JacksonJsonStep.defaultVersion(); - public JacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { + public AJacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { this.formatExtension = formatExtension; this.jacksonConfig = jacksonConfig; formatExtension.addStep(createStep()); } - public JacksonGradleConfig(FormatExtension formatExtension) { - this(new JacksonConfig(), formatExtension); - } - - public JacksonGradleConfig config(JacksonConfig jacksonConfig) { - this.jacksonConfig = jacksonConfig; - formatExtension.replaceStep(createStep()); - return this; - } - - public JacksonGradleConfig feature(String feature, boolean toggle) { + public AJacksonGradleConfig feature(String feature, boolean toggle) { this.jacksonConfig.appendFeatureToToggle(Collections.singletonMap(feature, toggle)); formatExtension.replaceStep(createStep()); return this; } - public JacksonGradleConfig version(String version) { + public AJacksonGradleConfig version(String version) { this.version = version; formatExtension.replaceStep(createStep()); return this; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 31f605809c..94e94c639e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -116,7 +116,7 @@ private FormatterStep createStep() { } } - public static class JacksonJsonGradleConfig extends JacksonGradleConfig { + public static class JacksonJsonGradleConfig extends AJacksonGradleConfig { protected JacksonJsonConfig jacksonConfig; public JacksonJsonGradleConfig(JacksonJsonConfig jacksonConfig, FormatExtension formatExtension) { @@ -135,7 +135,7 @@ public JacksonJsonGradleConfig(FormatExtension formatExtension) { /** * @see com.fasterxml.jackson.core.JsonGenerator.Feature */ - public JacksonGradleConfig jsonFeature(String feature, boolean toggle) { + public AJacksonGradleConfig jsonFeature(String feature, boolean toggle) { this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle)); formatExtension.replaceStep(createStep()); return this; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index 3fc12e0495..e5dc3d79ac 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -41,11 +41,11 @@ protected void setupTask(SpotlessTask task) { super.setupTask(task); } - public JacksonGradleConfig jacksonYaml() { + public AJacksonGradleConfig jacksonYaml() { return new JacksonYamlGradleConfig(this); } - public class JacksonYamlGradleConfig extends JacksonGradleConfig { + public class JacksonYamlGradleConfig extends AJacksonGradleConfig { protected JacksonYamlConfig jacksonConfig; public JacksonYamlGradleConfig(JacksonYamlConfig jacksonConfig, FormatExtension formatExtension) { @@ -65,7 +65,7 @@ public JacksonYamlGradleConfig(FormatExtension formatExtension) { /** * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature */ - public JacksonGradleConfig yamlFeature(String feature, boolean toggle) { + public AJacksonGradleConfig yamlFeature(String feature, boolean toggle) { this.jacksonConfig.appendYamlFeatureToToggle(Collections.singletonMap(feature, toggle)); formatExtension.replaceStep(createStep()); return this; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 79e0df0d8d..618b8d17ca 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -51,8 +51,8 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { "spotless {", " yaml {", " target 'src/**/*.yaml'", - " jacksonYaml()" + - " .yamlFeature('WRITE_DOC_START_MARKER', false)" + + " jacksonYaml()" , + " .yamlFeature('WRITE_DOC_START_MARKER', false)" , " .yamlFeature('MINIMIZE_QUOTES', true)", " }", "}"); From 38bc206a73283d0ddff1d10bb1fb45b3493edff3 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 00:53:57 +0400 Subject: [PATCH 0307/1120] Fix style --- .../java/com/diffplug/gradle/spotless/YamlExtensionTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 618b8d17ca..ee5ee33366 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -51,8 +51,8 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { "spotless {", " yaml {", " target 'src/**/*.yaml'", - " jacksonYaml()" , - " .yamlFeature('WRITE_DOC_START_MARKER', false)" , + " jacksonYaml()", + " .yamlFeature('WRITE_DOC_START_MARKER', false)", " .yamlFeature('MINIMIZE_QUOTES', true)", " }", "}"); From b42a1453b385b4320072eaf654da1b6cc4d2297d Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 17 Jan 2023 12:54:28 -0800 Subject: [PATCH 0308/1120] Make changelog entries more informative --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9c0ed23980..3e648d9e0c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added ### Fixed -* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes ## [2.32.0] - 2023-01-13 diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d3ee07acad..0ed49a3408 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 ( * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d7d40f65c7..d0942d2ca8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -16,7 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* Format more type annotations as type annotations [#1494](https://github.com/diffplug/spotless/pull/1494) +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) From 4ff0c33c8055fb661680724db0ddba265d0de6eb Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 17 Jan 2023 12:57:39 -0800 Subject: [PATCH 0309/1120] Put changelog entries in "unreleased" section --- plugin-gradle/CHANGES.md | 5 ++++- plugin-maven/CHANGES.md | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 0ed49a3408..63e5b43d74 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +### Fixed +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) +### Changes ## [6.13.0] - 2023-01-14 ### Added @@ -15,7 +19,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d0942d2ca8..e951241a09 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +### Fixed +* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) +### Changes ## [2.30.0] - 2023-01-13 ### Added @@ -16,7 +20,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Fix subgroups leading catch all matcher. -* The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) From 87c4a2a23fc9a3e74fd7e525d31dc8e41c9c852d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 17 Jan 2023 14:42:24 -0800 Subject: [PATCH 0310/1120] Remove mvnw beacuse we don't need it here anymore. --- plugin-maven/build.gradle | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index b46cdda708..1fad11be70 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -11,23 +11,6 @@ version = spotlessChangelog.versionNext apply from: rootProject.file("gradle/java-setup.gradle") apply from: rootProject.file('gradle/spotless-freshmark.gradle') -def mvnw(String args) { - boolean isWin = System.getProperty('os.name').toLowerCase().contains('win') - if (isWin) { - return [ - 'cmd', - '/c', - 'mvnw.cmd -e ' + args - ] - } else { - return [ - '/bin/sh', - '-c', - './mvnw -e ' + args - ] - } -} - apply plugin: 'de.benediktritter.maven-plugin-development' mavenPlugin { name = 'Spotless Maven Plugin' From c3a88cb2df3e1ddae20e388f5fbbdffee48e2e05 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 17 Jan 2023 14:43:08 -0800 Subject: [PATCH 0311/1120] Inline the mustache dependency because it's only used in one place. --- plugin-maven/build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 1fad11be70..ad51318d93 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -20,7 +20,6 @@ mavenPlugin { String VER_MAVEN_API = '3.0' String VER_ECLIPSE_AETHER = '1.1.0' -String VER_MUSTACHE = '0.9.10' String VER_PLEXUS_RESOURCES = '1.2.0' dependencies { implementation project(':lib') @@ -42,7 +41,7 @@ dependencies { testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation "org.mockito:mockito-core:${VER_MOCKITO}" testImplementation "com.diffplug.durian:durian-io:${VER_DURIAN}" - testImplementation "com.github.spullara.mustache.java:compiler:${VER_MUSTACHE}" + testImplementation 'com.github.spullara.mustache.java:compiler:0.9.10' testImplementation "org.apache.maven:maven-plugin-api:${VER_MAVEN_API}" testImplementation "org.eclipse.aether:aether-api:${VER_ECLIPSE_AETHER}" testImplementation "org.codehaus.plexus:plexus-resources:${VER_PLEXUS_RESOURCES}" From b256bd48ef418e0f4c04e8409bcca357964c25b3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 17 Jan 2023 14:48:42 -0800 Subject: [PATCH 0312/1120] Fix testlib test. --- testlib/build.gradle | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testlib/build.gradle b/testlib/build.gradle index 4b16572a8c..64d4681805 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -22,6 +22,15 @@ dependencies { spotbugs { reportLevel = 'high' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') +tasks.named('test') { + if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { + // for Antlr4FormatterStepTest and KtLintStepTest + def args = [ + '--add-opens=java.base/java.lang=ALL-UNNAMED' + ] + jvmArgs args + } +} javadoc { options.addStringOption('Xdoclint:none', '-quiet') From 4b2097c3ed3a1ef7ee9550aa20e7a02948106b07 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 17 Jan 2023 15:25:09 -0800 Subject: [PATCH 0313/1120] Update changelogs. --- CHANGES.md | 6 ++++-- lib/build.gradle | 3 +++ plugin-gradle/CHANGES.md | 6 ++++-- plugin-maven/CHANGES.md | 6 ++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 45627807f3..0bdcf657b2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +#### Removed +* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) + * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. + * From now on, we will support no more than 2 breaking changes at a time. ## [2.32.0] - 2023-01-13 ### Added @@ -39,8 +43,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Switch our publishing infrastructure from CircleCI to GitHub Actions ([#1462](https://github.com/diffplug/spotless/pull/1462)). * Help wanted for moving our tests too ([#1472](https://github.com/diffplug/spotless/issues/1472)) -#### Removed -* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) ## [2.31.1] - 2023-01-02 ### Fixed diff --git a/lib/build.gradle b/lib/build.gradle index 7e2496139c..fc2c1c04a0 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -28,6 +28,9 @@ for (glue in NEEDS_GLUE) { versionCompatibility { adapters { namespaces.register('KtLint') { + // as discussed at https://github.com/diffplug/spotless/pull/1475 + // we will support no more than 2 breaking changes at a time = 3 incompatible versions + // we will try to drop down to only one version if a stable API can be maintained for a full year versions = [ '0.46.0', '0.47.0', diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 84fc0f4d83..bc4f2bd5e5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,6 +7,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +#### Removed +* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) + * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. + * From now on, we will support no more than 2 breaking changes at a time. ## [6.13.0] - 2023-01-14 ### Added @@ -22,8 +26,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) -#### Removed -* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) ## [6.12.1] - 2023-01-02 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 7556875183..ce07394b98 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,6 +8,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) +#### Removed +* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) + * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. + * From now on, we will support no more than 2 breaking changes at a time. ## [2.30.0] - 2023-01-13 ### Added @@ -25,8 +29,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) * Reduce spurious invalidations of the up-to-date index file ([#1461](https://github.com/diffplug/spotless/pull/1461)) * Bump default version for `prettier` from `2.0.5` to `2.8.1` ([#1453](https://github.com/diffplug/spotless/pull/1453)) -#### Removed -* Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) ## [2.29.0] - 2023-01-02 ### Added From 949c0984671a3092219d0e7674d885bbe160f51a Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 09:35:44 +0400 Subject: [PATCH 0314/1120] Fix Yaml referring to Json --- .../com/diffplug/gradle/spotless/SpotlessExtension.java | 2 +- plugin-maven/CHANGES.md | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 8c3128e02d..0a31a15764 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 @@ -196,7 +196,7 @@ public void json(Action closure) { /** Configures the special YAML-specific extension. */ public void yaml(Action closure) { requireNonNull(closure); - format(JsonExtension.NAME, YamlExtension.class, closure); + format(YamlExtension.NAME, YamlExtension.class, closure); } /** Configures a custom extension. */ diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 97eea5d7c0..cba82652cc 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,12 +4,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* Introduce `` ([#1492](https://github.com/diffplug/spotless/pull/1492)) + * **POTENTIALLY BREAKING** `JacksonYaml` is now configured with a `Map` to configure features +* Jackson (`json` and `yaml`) has new `spaceBeforeSeparator` option + * **POTENTIALLY BREAKING** `spaceBeforeSeparator` is defaulted to false while the formatter was behaving with `true` ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) -# [2.30.0] - 2023-01-13 +## [2.30.0] - 2023-01-13 ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) * **POTENTIALLY BREAKING** `ktlint` step now modifies license headers. Make sure to put `licenseHeader` *after* `ktlint`. From 37875ce62ef876c08a6357a191aa2abf80221f38 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 10:28:10 +0400 Subject: [PATCH 0315/1120] Rename to jackson step for both yaml and json --- .../com/diffplug/spotless/yaml/JacksonYamlStep.java | 6 ++---- .../gradle/spotless/AJacksonGradleConfig.java | 2 +- .../com/diffplug/gradle/spotless/JsonExtension.java | 12 ++++-------- .../com/diffplug/gradle/spotless/YamlExtension.java | 10 +++++----- .../diffplug/gradle/spotless/JsonExtensionTest.java | 2 +- .../diffplug/gradle/spotless/YamlExtensionTest.java | 6 +++--- ...ith_bracket.clean.no_start_marker.no_quotes.yaml} | 0 7 files changed, 16 insertions(+), 22 deletions(-) rename testlib/src/main/resources/yaml/{array_with_bracket.clean.no_start_marker.yaml => array_with_bracket.clean.no_start_marker.no_quotes.yaml} (100%) diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java index 201199fe8b..a87e40f420 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java @@ -30,6 +30,7 @@ * Simple YAML formatter which reformats the file according to Jackson YAMLFactory. */ // https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson +// https://stackoverflow.com/questions/60891174/i-want-to-load-a-yaml-file-possibly-edit-the-data-and-then-dump-it-again-how public class JacksonYamlStep { static final String MAVEN_COORDINATE = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:"; // https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml @@ -44,6 +45,7 @@ public static String defaultVersion() { public static FormatterStep create(JacksonYamlConfig jacksonConfig, String jacksonVersion, Provisioner provisioner) { + Objects.requireNonNull(jacksonConfig, "jacksonConfig cannot be null"); Objects.requireNonNull(provisioner, "provisioner cannot be null"); return FormatterStep.createLazy("yaml", () -> new State(jacksonConfig, jacksonVersion, provisioner), @@ -66,10 +68,6 @@ private State(JacksonYamlConfig jacksonConfig, Provisioner provisioner) throws IOException { this.jacksonConfig = jacksonConfig; - if (jacksonConfig == null) { - throw new IllegalArgumentException("ARG"); - } - this.jarState = JarState.from(JacksonYamlStep.MAVEN_COORDINATE + jacksonVersion, provisioner); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java index e3d5cee661..c017d41d04 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java @@ -28,11 +28,11 @@ public abstract class AJacksonGradleConfig { protected String version = JacksonJsonStep.defaultVersion(); + // Make sure to call 'formatExtension.addStep(createStep());' in the extented constructors public AJacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatExtension) { this.formatExtension = formatExtension; this.jacksonConfig = jacksonConfig; - formatExtension.addStep(createStep()); } public AJacksonGradleConfig feature(String feature, boolean toggle) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 94e94c639e..b964fcb54d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -51,7 +51,7 @@ public GsonConfig gson() { return new GsonConfig(); } - public JacksonJsonGradleConfig jacksonJson() { + public JacksonJsonGradleConfig jackson() { return new JacksonJsonGradleConfig(this); } @@ -123,9 +123,7 @@ public JacksonJsonGradleConfig(JacksonJsonConfig jacksonConfig, FormatExtension super(jacksonConfig, formatExtension); this.jacksonConfig = jacksonConfig; - if (jacksonConfig == null) { - throw new IllegalArgumentException("ARG2"); - } + formatExtension.addStep(createStep()); } public JacksonJsonGradleConfig(FormatExtension formatExtension) { @@ -141,11 +139,9 @@ public AJacksonGradleConfig jsonFeature(String feature, boolean toggle) { return this; } + // 'final' as it is called in the constructor @Override - protected FormatterStep createStep() { - if (jacksonConfig == null) { - throw new IllegalArgumentException("ARG3"); - } + protected final FormatterStep createStep() { return JacksonJsonStep.create(jacksonConfig, version, formatExtension.provisioner()); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index e5dc3d79ac..26b742f02a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -19,6 +19,7 @@ import javax.inject.Inject; +import com.diffplug.common.base.Throwables; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.yaml.JacksonYamlConfig; @@ -41,7 +42,7 @@ protected void setupTask(SpotlessTask task) { super.setupTask(task); } - public AJacksonGradleConfig jacksonYaml() { + public AJacksonGradleConfig jackson() { return new JacksonYamlGradleConfig(this); } @@ -53,9 +54,7 @@ public JacksonYamlGradleConfig(JacksonYamlConfig jacksonConfig, FormatExtension this.jacksonConfig = jacksonConfig; - if (jacksonConfig == null) { - throw new IllegalArgumentException("ARG"); - } + formatExtension.addStep(createStep()); } public JacksonYamlGradleConfig(FormatExtension formatExtension) { @@ -71,8 +70,9 @@ public AJacksonGradleConfig yamlFeature(String feature, boolean toggle) { return this; } + // 'final' as it is called in the constructor @Override - protected FormatterStep createStep() { + protected final FormatterStep createStep() { return JacksonYamlStep.create(jacksonConfig, version, provisioner()); } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java index 945c72cf75..a878615eaa 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java @@ -149,7 +149,7 @@ void jacksonFormattingWithSortingByKeys() throws IOException { "spotless {", " json {", " target 'src/**/*.json'", - " jacksonJson().feature('ORDER_MAP_ENTRIES_BY_KEYS', true)", + " jackson().feature('ORDER_MAP_ENTRIES_BY_KEYS', true)", " }", "}"); setFile("src/main/resources/example.json").toResource("json/sortByKeysBefore.json"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index ee5ee33366..455dfc6dcf 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -31,7 +31,7 @@ void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws IOExcep "spotless {", " yaml {", " target 'src/**/*.yaml'", - " jacksonYaml()", + " jackson()", " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/separator_comments.yaml"); @@ -51,14 +51,14 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { "spotless {", " yaml {", " target 'src/**/*.yaml'", - " jacksonYaml()", + " jackson()", " .yamlFeature('WRITE_DOC_START_MARKER', false)", " .yamlFeature('MINIMIZE_QUOTES', true)", " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.yaml"); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml"); } } diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml similarity index 100% rename from testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.yaml rename to testlib/src/main/resources/yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml From a22109e5e4b3e7daf4ae41b308d39bead18a06ef Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 10:41:53 +0400 Subject: [PATCH 0316/1120] spotlessApply --- .../spotless/glue/yaml/JacksonYamlFormatterFunc.java | 5 ----- .../java/com/diffplug/gradle/spotless/YamlExtension.java | 1 - .../java/com/diffplug/gradle/spotless/YamlExtensionTest.java | 2 +- plugin-maven/README.md | 4 ++-- .../test/java/com/diffplug/spotless/maven/yaml/YamlTest.java | 1 - 5 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index 3986374c9e..0cf4591717 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -57,11 +57,6 @@ protected JsonFactory makeJsonFactory() { @Override protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - // We may consider adding manually an initial '---' prefix to help management of multiple documents - // if (!input.trim().startsWith("---")) { - // input = "---" + "\n" + input; - // } - try { // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index 26b742f02a..bf268914fc 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -19,7 +19,6 @@ import javax.inject.Inject; -import com.diffplug.common.base.Throwables; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.yaml.JacksonYamlConfig; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 455dfc6dcf..7baddc4177 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -57,7 +57,7 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); - gradleRunner().withArguments("spotlessApply").build(); + gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml"); } diff --git a/plugin-maven/README.md b/plugin-maven/README.md index e76d424611..7673a440c6 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.29.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.29.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.30.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.30.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index 084f1495eb..aaea2c65b1 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -19,7 +19,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.maven.MavenIntegrationHarness; public class YamlTest extends MavenIntegrationHarness { From 7bc34f48328a42bdc26a58c2b1d22f2b68892256 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 11:46:36 +0400 Subject: [PATCH 0317/1120] Switch from ObjectNode to Map to enable SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS --- .../glue/json/AJacksonFormatterFunc.java | 16 ++++++++------ .../glue/json/JacksonJsonFormatterFunc.java | 2 +- .../diffplug/spotless/json/JacksonConfig.java | 2 +- .../spotless/json/JacksonJsonConfig.java | 4 ++-- .../spotless/yaml/JacksonYamlConfig.java | 4 ++-- .../gradle/spotless/JsonExtension.java | 2 +- .../gradle/spotless/YamlExtension.java | 3 +-- .../spotless/maven/json/JsonTest.java | 2 +- .../spotless/maven/yaml/YamlTest.java | 9 -------- .../json/sortByKeysAfter_Jackson.json | 22 ++++++++----------- ...sAfter_Jackson_spaceAfterKeySeparator.json | 22 ++++++++----------- ...th_bracket.clean.spaceBeforeSeparator.yaml | 12 ---------- 12 files changed, 36 insertions(+), 64 deletions(-) delete mode 100644 testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java index a835c85f9a..a41ecf90d2 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java @@ -16,10 +16,11 @@ package com.diffplug.spotless.glue.json; import java.io.IOException; +import java.util.Map; import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.PrettyPrinter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -48,8 +49,11 @@ public String apply(String input) throws Exception { protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { try { - ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); + // ObjectNode is not compatible with SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS + Map objectNode = objectMapper.readValue(input, Map.class); + String output = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); + + return output; } catch (JsonProcessingException e) { throw new AssertionError("Unable to format. input='" + input + "'", e); } @@ -65,7 +69,7 @@ protected ObjectMapper makeObjectMapper() { JsonFactory jsonFactory = makeJsonFactory(); ObjectMapper objectMapper = new ObjectMapper(jsonFactory); - objectMapper.setDefaultPrettyPrinter(makePrinter()); + objectMapper.setDefaultPrettyPrinter(makePrettyPrinter()); // Configure the ObjectMapper // https://github.com/FasterXML/jackson-databind#commonly-used-features @@ -76,12 +80,10 @@ protected ObjectMapper makeObjectMapper() { objectMapper.configure(feature, toggle); }); - new JsonFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, true); - return objectMapper; } - protected DefaultPrettyPrinter makePrinter() { + protected PrettyPrinter makePrettyPrinter() { return new DefaultPrettyPrinter(); } } diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index 5aadcc568f..ae455fbbb4 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -57,7 +57,7 @@ protected JsonFactory makeJsonFactory() { } @Override - protected DefaultPrettyPrinter makePrinter() { + protected DefaultPrettyPrinter makePrettyPrinter() { boolean spaceBeforeSeparator = jacksonConfig.isSpaceBeforeSeparator(); // DefaultIndenter default constructor relies on 2 whitespaces as default tabulation diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java index 250b77d1f1..f0dba8f072 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonConfig.java @@ -36,7 +36,7 @@ public class JacksonConfig implements Serializable { DEFAULT_FEATURE_TOGGLES = defaultFeatureToggles; } - protected Map featureToToggle = new LinkedHashMap<>(); + protected Map featureToToggle = new LinkedHashMap<>(DEFAULT_FEATURE_TOGGLES); public Map getFeatureToToggle() { return Collections.unmodifiableMap(featureToToggle); diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java index 50b28605d1..efff594663 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonConfig.java @@ -36,14 +36,14 @@ public Map getJsonFeatureToToggle() { } /** - * @see com.fasterxml.jackson.core.JsonGenerator.Feature + * Refers to com.fasterxml.jackson.core.JsonGenerator.Feature */ public void setJsonFeatureToToggle(Map jsonFeatureToToggle) { this.jsonFeatureToToggle = jsonFeatureToToggle; } /** - * @see com.fasterxml.jackson.core.JsonGenerator.Feature + * Refers to com.fasterxml.jackson.core.JsonGenerator.Feature */ public void appendJsonFeatureToToggle(Map features) { this.jsonFeatureToToggle.putAll(features); diff --git a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java index 2463b9603f..166ee5f307 100644 --- a/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlConfig.java @@ -34,14 +34,14 @@ public Map getYamlFeatureToToggle() { } /** - * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + * Refers to com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature */ public void setYamlFeatureToToggle(Map yamlFeatureToToggle) { this.yamlFeatureToToggle = yamlFeatureToToggle; } /** - * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + * Refers to com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature */ public void appendYamlFeatureToToggle(Map features) { this.yamlFeatureToToggle.putAll(features); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index b964fcb54d..ef0e993d37 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -131,7 +131,7 @@ public JacksonJsonGradleConfig(FormatExtension formatExtension) { } /** - * @see com.fasterxml.jackson.core.JsonGenerator.Feature + * @Refers to com.fasterxml.jackson.core.JsonGenerator.Feature */ public AJacksonGradleConfig jsonFeature(String feature, boolean toggle) { this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle)); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index bf268914fc..7be3264102 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -25,7 +25,6 @@ import com.diffplug.spotless.yaml.JacksonYamlStep; public class YamlExtension extends FormatExtension { - private static final String DEFAULT_GSON_VERSION = JacksonJsonStep.defaultVersion(); static final String NAME = "yaml"; @Inject @@ -61,7 +60,7 @@ public JacksonYamlGradleConfig(FormatExtension formatExtension) { } /** - * @see com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature + * Refers to com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature */ public AJacksonGradleConfig yamlFeature(String feature, boolean toggle) { this.jacksonConfig.appendYamlFeatureToToggle(Collections.singletonMap(feature, toggle)); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index 47de001a73..1897cc764a 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -76,7 +76,7 @@ public void testFormatJson_WithJackson_sortByKeys() throws Exception { setFile("json_test.json").toResource("json/sortByKeysBefore.json"); - mavenRunner().withArguments("spotless:apply").runNoError(); + mavenRunner().withArguments("spotless:apply", "-X").runNoError(); assertFile("json_test.json").sameAsResource("json/sortByKeysAfter_Jackson.json"); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java index aaea2c65b1..6af4d09ce9 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/yaml/YamlTest.java @@ -42,15 +42,6 @@ public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets() throws Exce assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.yaml"); } - @Test - public void testFormatYaml_WithJackson_defaultConfig_arrayBrackets_spaceBeforeSeparator() throws Exception { - writePomWithYamlSteps("true"); - - setFile("yaml_test.yaml").toResource("yaml/array_with_bracket.yaml"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("yaml_test.yaml").sameAsResource("yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml"); - } - @Test public void testFormatYaml_WithJackson_defaultConfig_multipleDocuments() throws Exception { writePomWithYamlSteps(""); diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json index c4a48de2f2..3af39fd0fb 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json @@ -1,19 +1,15 @@ { + "A": 1, + "X": 2, + "_arraysNotSorted": [ 3, 2, 1 ], + "a": 3, + "c": 4, + "x": 5, + "z": { "A": 1, "X": 2, - "_arraysNotSorted": [ - 3, - 2, - 1 - ], "a": 3, "c": 4, - "x": 5, - "z": { - "A": 1, - "X": 2, - "a": 3, - "c": 4, - "x": 5 - } + "x": 5 + } } diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json index c4a48de2f2..3af39fd0fb 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json @@ -1,19 +1,15 @@ { + "A": 1, + "X": 2, + "_arraysNotSorted": [ 3, 2, 1 ], + "a": 3, + "c": 4, + "x": 5, + "z": { "A": 1, "X": 2, - "_arraysNotSorted": [ - 3, - 2, - 1 - ], "a": 3, "c": 4, - "x": 5, - "z": { - "A": 1, - "X": 2, - "a": 3, - "c": 4, - "x": 5 - } + "x": 5 + } } diff --git a/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml b/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml deleted file mode 100644 index 7dc9255e06..0000000000 --- a/testlib/src/main/resources/yaml/array_with_bracket.clean.spaceBeforeSeparator.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -episodes: -- 1 -- 2 -- 3 -- 4 -- 5 -- 6 -- 7 -best-jedi : - name : "Obi-Wan" - side : "light" From 8d2cdd3d5c800161fa8149a8c4aa6f9d7d596849 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 12:33:38 +0400 Subject: [PATCH 0318/1120] Fix management of multiple documents YAML --- .../glue/json/AJacksonFormatterFunc.java | 2 +- .../glue/yaml/JacksonYamlFormatterFunc.java | 31 +++++---- .../spotless/json/JsonSimpleStep.java | 6 +- .../gradle/spotless/YamlExtensionTest.java | 67 +++++++++++++++---- .../resources/yaml/array_at_root.clean.yaml | 5 ++ .../main/resources/yaml/array_at_root.yaml | 7 ++ .../yaml/multiple_documents.clean.yaml | 12 ++-- .../resources/yaml/multiple_documents.yaml | 14 ++-- 8 files changed, 99 insertions(+), 45 deletions(-) create mode 100644 testlib/src/main/resources/yaml/array_at_root.clean.yaml create mode 100644 testlib/src/main/resources/yaml/array_at_root.yaml diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java index a41ecf90d2..244ce05a9e 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java @@ -55,7 +55,7 @@ protected String format(ObjectMapper objectMapper, String input) throws IllegalA return output; } catch (JsonProcessingException e) { - throw new AssertionError("Unable to format. input='" + input + "'", e); + throw new IllegalArgumentException("Unable to format. input='" + input + "'", e); } } diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index 0cf4591717..96012e1041 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -15,12 +15,18 @@ */ package com.diffplug.spotless.glue.yaml; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.List; import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.SequenceWriter; +import com.fasterxml.jackson.databind.node.ContainerNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; @@ -57,24 +63,21 @@ protected JsonFactory makeJsonFactory() { @Override protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { + //if (true) + // throw new IllegalArgumentException("input = \r\n" + input); try { // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 - // 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' - // JsonParser yamlParser = objectMapper.getFactory().createParser(input); - // List docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); - // return objectMapper.writeValueAsString(docs); + JsonParser yamlParser = objectMapper.getFactory().createParser(input); + List documents = objectMapper.readValues(yamlParser, ContainerNode.class).readAll(); - // A JsonNode may keep the comments from the input node - // JsonNode jsonNode = objectMapper.readTree(input); - //Not 'toPrettyString' as one could require no INDENT_OUTPUT - // return jsonNode.toPrettyString(); - ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); - String outputFromjackson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode); - - return outputFromjackson; + // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055 + // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055 + StringWriter stringWriter = new StringWriter(); + objectMapper.writer().writeValues(stringWriter).writeAll(documents).close(); + return stringWriter.toString(); } catch (JsonProcessingException e) { - throw new AssertionError("Unable to format. input='" + input + "'", e); + throw new IllegalArgumentException("Unable to format. input='" + input + "'", e); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java b/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java index a970149133..1f4db3e059 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java @@ -81,7 +81,7 @@ FormatterFunc toFormatter() { return format(arrayConstructor, arrayToString, s); } - throw new AssertionError(String.format("Unable to determine JSON type, expected a '{' or '[' but found '%s'", first)); + throw new IllegalArgumentException(String.format("Unable to determine JSON type, expected a '{' or '[' but found '%s'", first)); }; } @@ -89,8 +89,8 @@ private String format(Constructor constructor, Method toString, String input) try { Object parsed = constructor.newInstance(input); return toString.invoke(parsed, indentSpaces) + "\n"; - } catch (InvocationTargetException ex) { - throw new AssertionError("Unable to format JSON", ex.getCause()); + } catch (InvocationTargetException e) { + throw new IllegalArgumentException("Unable to format JSON", e); } } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 7baddc4177..295934dd26 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -43,22 +43,63 @@ void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws IOExcep @Test void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " yaml {", - " target 'src/**/*.yaml'", - " jackson()", - " .yamlFeature('WRITE_DOC_START_MARKER', false)", - " .yamlFeature('MINIMIZE_QUOTES', true)", - " }", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " .yamlFeature('WRITE_DOC_START_MARKER', false)", + " .yamlFeature('MINIMIZE_QUOTES', true)", + " }", + "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml"); } + @Test + void testFormatYaml_WithJackson_multipleDocuments() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " .yamlFeature('MINIMIZE_QUOTES', true)", + " }", + "}"); + setFile("src/main/resources/example.yaml").toResource("yaml/multiple_documents.yaml"); + gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/multiple_documents.clean.jackson.yaml"); + } + + + @Test + void testFormatYaml_WithJackson_arrayAtRoot() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " }", + "}"); + setFile("src/main/resources/example.yaml").toResource("yaml/array_at_root.yaml"); + gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); + assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_at_root.clean.yaml"); + } + + } diff --git a/testlib/src/main/resources/yaml/array_at_root.clean.yaml b/testlib/src/main/resources/yaml/array_at_root.clean.yaml new file mode 100644 index 0000000000..f9bae04114 --- /dev/null +++ b/testlib/src/main/resources/yaml/array_at_root.clean.yaml @@ -0,0 +1,5 @@ +--- +- key1: "value1" + key2: "value2" +- key3: "value3" + key4: "value4" diff --git a/testlib/src/main/resources/yaml/array_at_root.yaml b/testlib/src/main/resources/yaml/array_at_root.yaml new file mode 100644 index 0000000000..b26f6bb246 --- /dev/null +++ b/testlib/src/main/resources/yaml/array_at_root.yaml @@ -0,0 +1,7 @@ +- key1: value1 + key2: value2 + + +- key3: value3 + key4: value4 + diff --git a/testlib/src/main/resources/yaml/multiple_documents.clean.yaml b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml index 45e0b0916b..3651473955 100644 --- a/testlib/src/main/resources/yaml/multiple_documents.clean.yaml +++ b/testlib/src/main/resources/yaml/multiple_documents.clean.yaml @@ -1,8 +1,8 @@ ---- -document: this is document 1 - ---- -document: this is document 2 +# Document 1 +key1: value1 +key2: value2 --- -document: this is document 3 \ No newline at end of file +# Document 2 +key3: value3 +key4: value4 diff --git a/testlib/src/main/resources/yaml/multiple_documents.yaml b/testlib/src/main/resources/yaml/multiple_documents.yaml index 51f14a5862..3651473955 100644 --- a/testlib/src/main/resources/yaml/multiple_documents.yaml +++ b/testlib/src/main/resources/yaml/multiple_documents.yaml @@ -1,10 +1,8 @@ -document: this is document 1 ---- - -document: this is document 2 - +# Document 1 +key1: value1 +key2: value2 --- - - -document: this is document 3 \ No newline at end of file +# Document 2 +key3: value3 +key4: value4 From a3693e78c1326a281dac76de9327515243d3f27e Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 12:36:06 +0400 Subject: [PATCH 0319/1120] spotlessApply --- .../glue/json/AJacksonFormatterFunc.java | 1 - .../glue/yaml/JacksonYamlFormatterFunc.java | 3 - .../spotless/json/JsonSimpleStep.java | 2 +- .../gradle/spotless/YamlExtension.java | 1 - .../gradle/spotless/YamlExtensionTest.java | 74 +++++++++---------- 5 files changed, 37 insertions(+), 44 deletions(-) diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java index 244ce05a9e..6f363ad1b7 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/AJacksonFormatterFunc.java @@ -24,7 +24,6 @@ import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.json.JacksonConfig; diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index 96012e1041..edb350c559 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -15,17 +15,14 @@ */ package com.diffplug.spotless.glue.yaml; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.StringWriter; -import java.nio.charset.StandardCharsets; import java.util.List; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SequenceWriter; import com.fasterxml.jackson.databind.node.ContainerNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder; diff --git a/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java b/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java index 1f4db3e059..85ccbfa6e2 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.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. diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index 7be3264102..abc2dce359 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -20,7 +20,6 @@ import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.yaml.JacksonYamlConfig; import com.diffplug.spotless.yaml.JacksonYamlStep; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 295934dd26..82801eb0fd 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -43,19 +43,19 @@ void testFormatYaml_WithJackson_defaultConfig_separatorComments() throws IOExcep @Test void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " yaml {", - " target 'src/**/*.yaml'", - " jackson()", - " .yamlFeature('WRITE_DOC_START_MARKER', false)", - " .yamlFeature('MINIMIZE_QUOTES', true)", - " }", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " .yamlFeature('WRITE_DOC_START_MARKER', false)", + " .yamlFeature('MINIMIZE_QUOTES', true)", + " }", + "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_with_bracket.yaml"); gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_with_bracket.clean.no_start_marker.no_quotes.yaml"); @@ -64,42 +64,40 @@ void testFormatYaml_WithJackson_skipDocStartMarker() throws IOException { @Test void testFormatYaml_WithJackson_multipleDocuments() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " yaml {", - " target 'src/**/*.yaml'", - " jackson()", - " .yamlFeature('MINIMIZE_QUOTES', true)", - " }", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " .yamlFeature('MINIMIZE_QUOTES', true)", + " }", + "}"); setFile("src/main/resources/example.yaml").toResource("yaml/multiple_documents.yaml"); gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/multiple_documents.clean.jackson.yaml"); } - @Test void testFormatYaml_WithJackson_arrayAtRoot() throws IOException { setFile("build.gradle").toLines( - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " yaml {", - " target 'src/**/*.yaml'", - " jackson()", - " }", - "}"); + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " yaml {", + " target 'src/**/*.yaml'", + " jackson()", + " }", + "}"); setFile("src/main/resources/example.yaml").toResource("yaml/array_at_root.yaml"); gradleRunner().withArguments("spotlessApply", "--stacktrace").build(); assertFile("src/main/resources/example.yaml").sameAsResource("yaml/array_at_root.clean.yaml"); } - } From c613302d0b1d4edece0c1d6a9a408aea716cedf4 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 13:01:25 +0400 Subject: [PATCH 0320/1120] Improve documentation, fix tests --- plugin-gradle/CHANGES.md | 2 + plugin-gradle/README.md | 65 +++++++++++++++++-- plugin-maven/README.md | 20 ++++-- .../spotless/maven/json/JacksonJson.java | 4 ++ .../multiple_documents.clean.jackson.yaml | 6 +- 5 files changed, 83 insertions(+), 14 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 63e5b43d74..94d7a90409 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* Support `jackson()` for YAML files ([#1492](https://github.com/diffplug/spotless/pull/1492)) +* Support `jackson()` for JSON files ([#1492](https://github.com/diffplug/spotless/pull/1492)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f2567a5924..e1bd2fe0dd 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -737,11 +737,12 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ```gradle spotless { json { - target 'src/**/*.json' // you have to set the target manually - simple() // has its own section below + target 'src/**/*.json' // you have to set the target manually + simple() // has its own section below prettier().config(['parser': 'json']) // see Prettier section below - eclipseWtp('json') // see Eclipse web tools platform section - gson() // has its own section below + eclipseWtp('json') // see Eclipse web tools platform section + gson() // has its own section below + jackson() // has its own section below } } ``` @@ -780,10 +781,60 @@ spotless { Notes: * There's no option in Gson to leave HTML as-is (i.e. escaped HTML would remain escaped, raw would remain raw). Either -all HTML characters are written escaped or none. Set `escapeHtml` if you prefer the former. + all HTML characters are written escaped or none. Set `escapeHtml` if you prefer the former. * `sortByKeys` will apply lexicographic order on the keys of the input JSON. See the -[javadoc of String](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#compareTo(java.lang.String)) -for details. + [javadoc of String](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#compareTo(java.lang.String)) + for details. + +### Jackson + +Uses Jackson for json files. + +```gradle +spotless { + json { + target 'src/**/*.json' + jackson() + .spaceBeforeSeparator(false) // optional: add a whitespace before key separator. False by default + .feature('INDENT_OUTPUT', true) // optional: true by default + .feature('ORDER_MAP_ENTRIES_BY_KEYS', true) // optional: false by default + .feature('ANY_OTHER_FEATURE', true|false) // optional: any SerializationFeature can be toggled on or off + .jsonFeature('ANY_OTHER_FEATURE', true|false) // any JsonGenerator.Feature can be toggled on or off + } +} +``` + + +## YAML + +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) + +```gradle +spotless { + yaml { + target 'src/**/*.yaml' // you have to set the target manually + jackson() // has its own section below + } +} +``` + +### Jackson + +Uses Jackson for `yaml` files. + +```gradle +spotless { + yaml { + target 'src/**/*.yaml' + jackson() + .spaceBeforeSeparator(false) // optional: add a whitespace before key separator. False by default + .feature('INDENT_OUTPUT', true) // optional: true by default + .feature('ORDER_MAP_ENTRIES_BY_KEYS', true) // optional: false by default + .feature('ANY_OTHER_FEATURE', true|false) // optional: any SerializationFeature can be toggled on or off + .yamlFeature('ANY_OTHER_FEATURE', true|false) // any YAMLGenerator.Feature can be toggled on or off + } +} +``` diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 7673a440c6..37d1046b1d 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -907,11 +907,15 @@ Uses Jackson for formatting. 2.14.1 - true - false - true|false + true + false + true|false - false + + false + true|false + + false ``` @@ -944,9 +948,13 @@ Uses Jackson and YAMLFactory to pretty print objects: true false - false - true|false + true|false + + true + false + true|false + false ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java index 9bca852754..ecf925ddbe 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JacksonJson.java @@ -41,11 +41,15 @@ public class JacksonJson implements FormatterStepFactory { @Parameter private Map features = Collections.emptyMap(); + @Parameter + private Map jsonFeatures = Collections.emptyMap(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { JacksonJsonConfig jacksonConfig = new JacksonJsonConfig(); jacksonConfig.appendFeatureToToggle(features); + jacksonConfig.appendJsonFeatureToToggle(jsonFeatures); jacksonConfig.setSpaceBeforeSeparator(spaceBeforeSeparator); return JacksonJsonStep diff --git a/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml b/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml index aa731919b4..ff56b4f77a 100644 --- a/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml +++ b/testlib/src/main/resources/yaml/multiple_documents.clean.jackson.yaml @@ -1,2 +1,6 @@ --- -document: "this is document 1" +key1: "value1" +key2: "value2" +--- +key3: "value3" +key4: "value4" From 97ecda34a74bb07e86fa3f4db38e70b9352f49ed Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 13:27:27 +0400 Subject: [PATCH 0321/1120] Fix Javadoc --- .../main/java/com/diffplug/gradle/spotless/JsonExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index ef0e993d37..1e9de2e831 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -131,7 +131,7 @@ public JacksonJsonGradleConfig(FormatExtension formatExtension) { } /** - * @Refers to com.fasterxml.jackson.core.JsonGenerator.Feature + * Refers to com.fasterxml.jackson.core.JsonGenerator.Feature */ public AJacksonGradleConfig jsonFeature(String feature, boolean toggle) { this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle)); From a80ed394092c9cdd76427f60221136db3795649f Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 13:51:01 +0400 Subject: [PATCH 0322/1120] Sync mvn and gradle tests on YAML --- .../java/com/diffplug/gradle/spotless/YamlExtensionTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java index 82801eb0fd..067c809846 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/YamlExtensionTest.java @@ -73,7 +73,6 @@ void testFormatYaml_WithJackson_multipleDocuments() throws IOException { " yaml {", " target 'src/**/*.yaml'", " jackson()", - " .yamlFeature('MINIMIZE_QUOTES', true)", " }", "}"); setFile("src/main/resources/example.yaml").toResource("yaml/multiple_documents.yaml"); From 4b3cb2421996895eef8f871ac47a3089867780ae Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 16 Jan 2023 20:45:45 +0100 Subject: [PATCH 0323/1120] allow supplying node-binary path or look for it as a sibling to npm binary. the path of the npm binary is then prepended to the system PATH before launching the npm process. --- .../spotless/npm/EslintFormatterStep.java | 10 +-- .../spotless/npm/NodeExecutableResolver.java | 45 ++++++++++++++ .../npm/NpmFormatterStepLocations.java | 62 +++++++++++++++++++ .../npm/NpmFormatterStepStateBase.java | 18 ++---- .../spotless/npm/NpmPathResolver.java | 18 ++++-- .../com/diffplug/spotless/npm/NpmProcess.java | 16 +++-- .../spotless/npm/PrettierFormatterStep.java | 8 ++- .../spotless/npm/TsFmtFormatterStep.java | 8 ++- .../gradle/spotless/FormatExtension.java | 17 ++++- .../gradle/spotless/JavascriptExtension.java | 3 +- .../gradle/spotless/TypescriptExtension.java | 5 +- .../NpmTestsWithoutNpmInstallationTest.java | 59 ++++++++++++++++++ .../npm/AbstractNpmFormatterStepFactory.java | 11 +++- .../npm/NpmFormatterStepCommonTests.java | 9 ++- 14 files changed, 252 insertions(+), 37 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 81c5b6ce78..74979d90aa 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -94,9 +94,11 @@ private static class State extends NpmFormatterStepStateBase implements Serializ "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/eslint-serve.js"), npmPathResolver.resolveNpmrcContent()), - projectDir, - buildDir, - npmPathResolver.resolveNpmExecutable()); + new NpmFormatterStepLocations( + projectDir, + buildDir, + npmPathResolver.resolveNpmExecutable(), + npmPathResolver.resolveNodeExecutable())); this.eslintConfig = localCopyFiles(requireNonNull(eslintConfig)); } @@ -119,7 +121,7 @@ public FormatterFunc createFormatterFunc() { FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); ServerProcessInfo eslintRestServer = npmRunServer(); EslintRestService restService = new EslintRestService(eslintRestServer.getBaseUrl()); - return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(projectDir, nodeModulesDir, eslintConfig, restService)); + return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(locations.projectDir(), nodeModulesDir, eslintConfig, restService)); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java new file mode 100644 index 0000000000..c9e04da620 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java @@ -0,0 +1,45 @@ +/* + * 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.npm; + +import java.io.File; +import java.util.Optional; + +class NodeExecutableResolver { + + private NodeExecutableResolver() { + // no instance + } + + static String nodeExecutableName() { + String nodeName = "node"; + if (PlatformInfo.normalizedOS() == PlatformInfo.OS.WINDOWS) { + nodeName += ".exe"; + } + return nodeName; + } + + static Optional tryFindNextTo(File npmExecutable) { + if (npmExecutable == null) { + return Optional.empty(); + } + File nodeExecutable = new File(npmExecutable.getParentFile(), nodeExecutableName()); + if (nodeExecutable.exists() && nodeExecutable.isFile() && nodeExecutable.canExecute()) { + return Optional.of(nodeExecutable); + } + return Optional.empty(); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java new file mode 100644 index 0000000000..0c417733e8 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java @@ -0,0 +1,62 @@ +/* + * 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.npm; + +import static java.util.Objects.requireNonNull; + +import java.io.File; +import java.io.Serializable; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +class NpmFormatterStepLocations implements Serializable { + + private static final long serialVersionUID = -1055408537924029969L; + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient File projectDir; + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient File buildDir; + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient File npmExecutable; + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient File nodeExecutable; + + public NpmFormatterStepLocations(File projectDir, File buildDir, File npmExecutable, File nodeExecutable) { + this.projectDir = requireNonNull(projectDir); + this.buildDir = requireNonNull(buildDir); + this.npmExecutable = requireNonNull(npmExecutable); + this.nodeExecutable = requireNonNull(nodeExecutable); + } + + public File projectDir() { + return projectDir; + } + + public File buildDir() { + return buildDir; + } + + public File npmExecutable() { + return npmExecutable; + } + + public File nodeExecutable() { + return nodeExecutable; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 49a166e45c..4f555a177e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -48,23 +48,17 @@ abstract class NpmFormatterStepStateBase implements Serializable { @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") public final transient File nodeModulesDir; - @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - private final transient File npmExecutable; - - @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - public final transient File projectDir; + public final NpmFormatterStepLocations locations; private final NpmConfig npmConfig; private final String stepName; - protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, File projectDir, File buildDir, File npm) throws IOException { + protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFormatterStepLocations locations) throws IOException { this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); - this.projectDir = requireNonNull(projectDir); - this.npmExecutable = npm; - - NodeServerLayout layout = prepareNodeServer(buildDir); + this.locations = locations; + NodeServerLayout layout = prepareNodeServer(locations.buildDir()); this.nodeModulesDir = layout.nodeModulesDir(); this.packageJsonSignature = FileSignature.signAsList(layout.packageJsonFile()); } @@ -88,7 +82,7 @@ private NodeServerLayout prepareNodeServer(File buildDir) throws IOException { } private void runNpmInstall(File npmProjectDir) throws IOException { - new NpmProcess(npmProjectDir, this.npmExecutable).install(); + new NpmProcess(npmProjectDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).install(); } protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { @@ -102,7 +96,7 @@ protected ServerProcessInfo npmRunServer() throws ServerStartException, IOExcept final File serverPortFile = new File(this.nodeModulesDir, "server.port"); NpmResourceHelper.deleteFileIfExists(serverPortFile); // start the http server in node - Process server = new NpmProcess(this.nodeModulesDir, this.npmExecutable).start(); + Process server = new NpmProcess(this.nodeModulesDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); // await the readiness of the http server - wait for at most 60 seconds try { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java index a9a15bd49d..d18146188d 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,8 @@ package com.diffplug.spotless.npm; import java.io.File; -import java.util.Arrays; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -24,14 +25,17 @@ public class NpmPathResolver { private final File explicitNpmExecutable; + private final File explicitNodeExecutable; + private final File explicitNpmrcFile; private final List additionalNpmrcLocations; - public NpmPathResolver(File explicitNpmExecutable, File explicitNpmrcFile, File... additionalNpmrcLocations) { + public NpmPathResolver(File explicitNpmExecutable, File explicitNodeExecutable, File explicitNpmrcFile, List additionalNpmrcLocations) { this.explicitNpmExecutable = explicitNpmExecutable; + this.explicitNodeExecutable = explicitNodeExecutable; this.explicitNpmrcFile = explicitNpmrcFile; - this.additionalNpmrcLocations = Arrays.asList(additionalNpmrcLocations); + this.additionalNpmrcLocations = Collections.unmodifiableList(new ArrayList<>(additionalNpmrcLocations)); } public File resolveNpmExecutable() { @@ -40,6 +44,12 @@ public File resolveNpmExecutable() { .orElseThrow(() -> new IllegalStateException("Can't automatically determine npm executable and none was specifically supplied!\n\n" + NpmExecutableResolver.explainMessage()))); } + public File resolveNodeExecutable() { + return Optional.ofNullable(this.explicitNodeExecutable) + .orElseGet(() -> NodeExecutableResolver.tryFindNextTo(resolveNpmExecutable()) + .orElseThrow(() -> new IllegalStateException("Can't automatically determine node executable and none was specifically supplied!\n\n" + NpmExecutableResolver.explainMessage()))); + } + public String resolveNpmrcContent() { File npmrcFile = Optional.ofNullable(this.explicitNpmrcFile) .orElseGet(() -> new NpmrcResolver(additionalNpmrcLocations).tryFind() diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index 8be94a9ea3..1675a4aa4e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -28,9 +28,12 @@ class NpmProcess { private final File npmExecutable; - NpmProcess(File workingDir, File npmExecutable) { + private final File nodeExecutable; + + NpmProcess(File workingDir, File npmExecutable, File nodeExecutable) { this.workingDir = workingDir; this.npmExecutable = npmExecutable; + this.nodeExecutable = nodeExecutable; } void install() { @@ -61,11 +64,12 @@ private void npmAwait(String... args) { private Process npm(String... args) { List processCommand = processCommand(args); try { - return new ProcessBuilder() + ProcessBuilder processBuilder = new ProcessBuilder() .inheritIO() .directory(this.workingDir) - .command(processCommand) - .start(); + .command(processCommand); + addEnvironmentVariables(processBuilder); + return processBuilder.start(); } catch (IOException e) { throw new NpmProcessException("Failed to launch npm command '" + commandLine(args) + "'.", e); } @@ -78,6 +82,10 @@ private List processCommand(String... args) { return command; } + private void addEnvironmentVariables(ProcessBuilder processBuilder) { + processBuilder.environment().put("PATH", this.nodeExecutable.getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); + } + private String commandLine(String... args) { return "npm " + Arrays.stream(args).collect(Collectors.joining(" ")); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 22a162eb0b..20ff71d08e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -74,9 +74,11 @@ private static class State extends NpmFormatterStepStateBase implements Serializ "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/prettier-serve.js"), npmPathResolver.resolveNpmrcContent()), - projectDir, - buildDir, - npmPathResolver.resolveNpmExecutable()); + new NpmFormatterStepLocations( + projectDir, + buildDir, + npmPathResolver.resolveNpmExecutable(), + npmPathResolver.resolveNodeExecutable())); this.prettierConfig = requireNonNull(prettierConfig); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index 98d694ec33..14d6b1bbd0 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -80,9 +80,11 @@ public State(String stepName, Map versions, File projectDir, Fil "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/tsfmt-serve.js"), npmPathResolver.resolveNpmrcContent()), - projectDir, - buildDir, - npmPathResolver.resolveNpmExecutable()); + new NpmFormatterStepLocations( + projectDir, + buildDir, + npmPathResolver.resolveNpmExecutable(), + npmPathResolver.resolveNodeExecutable())); this.buildDir = requireNonNull(buildDir); this.configFile = configFile; this.inlineTsFmtSettings = inlineTsFmtSettings == null ? new TreeMap<>() : new TreeMap<>(inlineTsFmtSettings); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 4e33c45ed0..8012102200 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -23,6 +23,7 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -524,6 +525,9 @@ public abstract static class NpmStepConfig> { @Nullable protected Object npmFile; + @Nullable + protected Object nodeFile; + @Nullable protected Object npmrcFile; @@ -543,6 +547,13 @@ public T npmExecutable(final Object npmFile) { return (T) this; } + @SuppressWarnings("unchecked") + public T nodeExecutable(final Object nodeFile) { + this.nodeFile = nodeFile; + replaceStep(); + return (T) this; + } + public T npmrc(final Object npmrcFile) { this.npmrcFile = npmrcFile; replaceStep(); @@ -553,6 +564,10 @@ File npmFileOrNull() { return fileOrNull(npmFile); } + File nodeFileOrNull() { + return fileOrNull(nodeFile); + } + File npmrcFileOrNull() { return fileOrNull(npmrcFile); } @@ -604,7 +619,7 @@ protected FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), - new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), new com.diffplug.spotless.npm.PrettierConfig( this.prettierConfigFile != null ? project.file(this.prettierConfigFile) : null, this.prettierConfig)); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index dd476b6a69..e829c2b53a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -17,6 +17,7 @@ import static java.util.Objects.requireNonNull; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -107,7 +108,7 @@ public FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), - new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 0824caa769..2283afccff 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -17,6 +17,7 @@ import static java.util.Objects.requireNonNull; +import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.Objects; @@ -116,7 +117,7 @@ public FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), - new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), typedConfigFile(), config); } @@ -212,7 +213,7 @@ public FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), - new NpmPathResolver(npmFileOrNull(), npmrcFileOrNull(), project.getProjectDir(), project.getRootDir()), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java new file mode 100644 index 0000000000..93bc4b699b --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -0,0 +1,59 @@ +/* + * 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. + * 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 org.assertj.core.api.Assertions; +import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.Test; + +class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness { + + @Test + void useNodeFromNodeGradlePlugin() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " npmVersion = '8.19.2'", + " workDir = file(\"${buildDir}/nodejs\")", + " npmWorkDir = file(\"${buildDir}/npm\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm\")", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java index 5467f4c3bc..e4a052106a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java @@ -18,6 +18,7 @@ import java.io.File; import java.util.AbstractMap; import java.util.Arrays; +import java.util.Collections; import java.util.Map; import java.util.Objects; import java.util.Properties; @@ -34,6 +35,9 @@ public abstract class AbstractNpmFormatterStepFactory implements FormatterStepFa @Parameter private String npmExecutable; + @Parameter + private String nodeExecutable; + @Parameter private String npmrc; @@ -42,6 +46,11 @@ protected File npm(FormatterStepConfig stepConfig) { return npm; } + protected File node(FormatterStepConfig stepConfig) { + File node = nodeExecutable != null ? stepConfig.getFileLocator().locateFile(nodeExecutable) : null; + return node; + } + protected File npmrc(FormatterStepConfig stepConfig) { File npmrc = this.npmrc != null ? stepConfig.getFileLocator().locateFile(this.npmrc) : null; return npmrc; @@ -56,7 +65,7 @@ protected File baseDir(FormatterStepConfig stepConfig) { } protected NpmPathResolver npmPathResolver(FormatterStepConfig stepConfig) { - return new NpmPathResolver(npm(stepConfig), npmrc(stepConfig), baseDir(stepConfig)); + return new NpmPathResolver(npm(stepConfig), node(stepConfig), npmrc(stepConfig), Collections.singletonList(baseDir(stepConfig))); } protected boolean moreThanOneNonNull(Object... objects) { diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java index dff105108a..60dd42801a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java @@ -17,17 +17,22 @@ import java.io.File; import java.io.IOException; +import java.util.Collections; import com.diffplug.spotless.ResourceHarness; public abstract class NpmFormatterStepCommonTests extends ResourceHarness { protected NpmPathResolver npmPathResolver() { - return new NpmPathResolver(npmExecutable(), npmrc()); + return new NpmPathResolver(npmExecutable(), nodeExecutable(), npmrc(), Collections.emptyList()); } private File npmExecutable() { - return NpmExecutableResolver.tryFind().orElseThrow(() -> new IllegalStateException("cannot detect node binary")); + return NpmExecutableResolver.tryFind().orElseThrow(() -> new IllegalStateException("cannot detect npm binary")); + } + + private File nodeExecutable() { + return NodeExecutableResolver.tryFindNextTo(npmExecutable()).orElseThrow(() -> new IllegalStateException("cannot detect node binary")); } private File npmrc() { From f4f8da7a259fbe55fdb66fc97b31f6d55c47a266 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 17 Jan 2023 13:11:59 +0100 Subject: [PATCH 0324/1120] add test for supplying only npm when binary --- .../NpmTestsWithoutNpmInstallationTest.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 93bc4b699b..621d953868 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -22,7 +22,7 @@ class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness { @Test - void useNodeFromNodeGradlePlugin() throws Exception { + void useNodeAndNpmFromNodeGradlePlugin() throws Exception { setFile("build.gradle").toLines( "plugins {", " id 'com.diffplug.spotless'", @@ -39,12 +39,48 @@ void useNodeFromNodeGradlePlugin() throws Exception { "def prettierConfig = [:]", "prettierConfig['printWidth'] = 50", "prettierConfig['parser'] = 'typescript'", + "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", + "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", "spotless {", " format 'mytypescript', {", " target 'test.ts'", " prettier()", - " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm\")", - " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node\")", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } + + @Test + void useNpmFromNodeGradlePlugin() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " workDir = file(\"${buildDir}/nodejs\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", " .config(prettierConfig)", " }", "}"); From 27f9919da7cc5079cfb2823d6c65484c6e542bb9 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 17 Jan 2023 19:51:54 +0100 Subject: [PATCH 0325/1120] also allow to configure node executable only --- .../spotless/npm/NodeExecutableResolver.java | 5 +++ .../spotless/npm/NpmPathResolver.java | 41 ++++++++++++++++--- .../NpmTestsWithoutNpmInstallationTest.java | 34 +++++++++++++++ 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java index c9e04da620..eb30ae78b8 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeExecutableResolver.java @@ -42,4 +42,9 @@ static Optional tryFindNextTo(File npmExecutable) { } return Optional.empty(); } + + public static String explainMessage() { + return "Spotless was unable to find a node executable.\n" + + "Either specify the node executable explicitly or make sure it can be found next to the npm executable."; + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java index d18146188d..4759d2f914 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java @@ -38,16 +38,45 @@ public NpmPathResolver(File explicitNpmExecutable, File explicitNodeExecutable, this.additionalNpmrcLocations = Collections.unmodifiableList(new ArrayList<>(additionalNpmrcLocations)); } + /** + * Finds the npm executable to use. + *
+ * Either the explicit npm executable is returned, or - if an explicit node executable is configured - tries to find + * the npm executable relative to the node executable. + * Falls back to looking for npm on the user's system using {@link NpmExecutableResolver} + * + * @return the npm executable to use + * @throws IllegalStateException if no npm executable could be found + */ public File resolveNpmExecutable() { - return Optional.ofNullable(this.explicitNpmExecutable) - .orElseGet(() -> NpmExecutableResolver.tryFind() - .orElseThrow(() -> new IllegalStateException("Can't automatically determine npm executable and none was specifically supplied!\n\n" + NpmExecutableResolver.explainMessage()))); + if (this.explicitNpmExecutable != null) { + return this.explicitNpmExecutable; + } + if (this.explicitNodeExecutable != null) { + File nodeExecutableCandidate = new File(this.explicitNodeExecutable.getParentFile(), NpmExecutableResolver.npmExecutableName()); + if (nodeExecutableCandidate.canExecute()) { + return nodeExecutableCandidate; + } + } + return NpmExecutableResolver.tryFind() + .orElseThrow(() -> new IllegalStateException("Can't automatically determine npm executable and none was specifically supplied!\n\n" + NpmExecutableResolver.explainMessage())); } + /** + * Finds the node executable to use. + *
+ * Either the explicit node executable is returned, or tries to find the node executable relative to the npm executable + * found by {@link #resolveNpmExecutable()}. + * @return the node executable to use + * @throws IllegalStateException if no node executable could be found + */ public File resolveNodeExecutable() { - return Optional.ofNullable(this.explicitNodeExecutable) - .orElseGet(() -> NodeExecutableResolver.tryFindNextTo(resolveNpmExecutable()) - .orElseThrow(() -> new IllegalStateException("Can't automatically determine node executable and none was specifically supplied!\n\n" + NpmExecutableResolver.explainMessage()))); + if (this.explicitNodeExecutable != null) { + return this.explicitNodeExecutable; + } + File npmExecutable = resolveNpmExecutable(); + return NodeExecutableResolver.tryFindNextTo(npmExecutable) + .orElseThrow(() -> new IllegalStateException("Can't automatically determine node executable and none was specifically supplied!\n\n" + NodeExecutableResolver.explainMessage())); } public String resolveNpmrcContent() { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 621d953868..8147c79228 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -92,4 +92,38 @@ void useNpmFromNodeGradlePlugin() throws Exception { Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); } + + @Test + void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " workDir = file(\"${buildDir}/nodejs\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } } From a96d92c0f524f71fc73476ffed6ab8f6b0425308 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 17 Jan 2023 20:46:32 +0100 Subject: [PATCH 0326/1120] add tests that verifies issue #1499 --- .../NpmTestsWithoutNpmInstallationTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 8147c79228..d5c4e8f092 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -17,6 +17,7 @@ import org.assertj.core.api.Assertions; import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness { @@ -59,6 +60,46 @@ void useNodeAndNpmFromNodeGradlePlugin() throws Exception { assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); } + @Test + @Disabled("This test is disabled because we currently don't support using npm/node installed by the" + + "node-gradle-plugin as the installation takes place in the *execution* phase, but spotless needs it in the *configuration* phase.") + void useNodeAndNpmFromNodeGradlePluginInOneSweep() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " npmVersion = '8.19.2'", + " workDir = file(\"${buildDir}/nodejs\")", + " npmWorkDir = file(\"${buildDir}/npm\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", + "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", + " .config(prettierConfig)", + " }", + "}", + "tasks.named('spotlessMytypescript').configure {", + " it.dependsOn('nodeSetup', 'npmSetup')", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } + @Test void useNpmFromNodeGradlePlugin() throws Exception { setFile("build.gradle").toLines( From b9437cd78b16d4ef2aeee942bc8d7b6f367068ef Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 18 Jan 2023 13:02:15 +0100 Subject: [PATCH 0327/1120] add maven test to verify dynamically installed npm works --- .../maven/MavenIntegrationHarness.java | 27 +++++--- .../maven/MultiModuleProjectTest.java | 2 +- .../spotless/maven/SpotlessCheckMojoTest.java | 1 + .../incremental/UpToDateCheckingTest.java | 3 +- .../maven/npm/NpmFrontendMavenPlugin.java | 66 +++++++++++++++++++ ...namicallyInstalledNpmInstallationTest.java | 48 ++++++++++++++ .../src/test/resources/pom-test.xml.mustache | 1 + 7 files changed, 137 insertions(+), 11 deletions(-) create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java 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 5a724408c8..f4e94e573c 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 @@ -59,6 +59,7 @@ public class MavenIntegrationHarness extends ResourceHarness { private static final String EXECUTIONS = "executions"; private static final String MODULES = "modules"; private static final String DEPENDENCIES = "dependencies"; + private static final String PLUGINS = "plugins"; private static final String MODULE_NAME = "name"; private static final int REMOTE_DEBUG_PORT = 5005; @@ -151,6 +152,10 @@ protected void writePomWithPrettierSteps(String includes, String... steps) throw writePom(formats(groupWithSteps("format", including(includes), steps))); } + protected void writePomWithPrettierSteps(String[] plugins, String includes, String... steps) throws IOException { + writePom(null, formats(groupWithSteps("format", including(includes), steps)), null, plugins); + } + protected void writePomWithPomSteps(String... steps) throws IOException { writePom(groupWithSteps("pom", including("pom_test.xml"), steps)); } @@ -168,11 +173,11 @@ protected void writePomWithYamlSteps(String... steps) throws IOException { } protected void writePom(String... configuration) throws IOException { - writePom(null, configuration, null); + writePom(null, configuration, null, null); } - protected void writePom(String[] executions, String[] configuration, String[] dependencies) throws IOException { - String pomXmlContent = createPomXmlContent(null, executions, configuration, dependencies); + protected void writePom(String[] executions, String[] configuration, String[] dependencies, String[] plugins) throws IOException { + String pomXmlContent = createPomXmlContent(null, executions, configuration, dependencies, plugins); setFile("pom.xml").toContent(pomXmlContent); } @@ -203,17 +208,17 @@ protected MavenRunner mavenRunnerWithRemoteDebug() throws IOException { return mavenRunner().withRemoteDebug(REMOTE_DEBUG_PORT); } - protected String createPomXmlContent(String pluginVersion, String[] executions, String[] configuration, String[] dependencies) throws IOException { - return createPomXmlContent("/pom-test.xml.mustache", pluginVersion, executions, configuration, dependencies); + protected String createPomXmlContent(String pluginVersion, String[] executions, String[] configuration, String[] dependencies, String[] plugins) throws IOException { + return createPomXmlContent("/pom-test.xml.mustache", pluginVersion, executions, configuration, dependencies, plugins); } - protected String createPomXmlContent(String pomTemplate, String pluginVersion, String[] executions, String[] configuration, String[] dependencies) throws IOException { - Map params = buildPomXmlParams(pluginVersion, executions, configuration, null, dependencies); + protected String createPomXmlContent(String pomTemplate, String pluginVersion, String[] executions, String[] configuration, String[] dependencies, String[] plugins) throws IOException { + Map params = buildPomXmlParams(pluginVersion, executions, configuration, null, dependencies, plugins); return createPomXmlContent(pomTemplate, params); } protected String createPomXmlContent(String pluginVersion, String[] executions, String[] configuration) throws IOException { - return createPomXmlContent(pluginVersion, executions, configuration, null); + return createPomXmlContent(pluginVersion, executions, configuration, null, null); } protected String createPomXmlContent(String pomTemplate, Map params) throws IOException { @@ -226,7 +231,7 @@ protected String createPomXmlContent(String pomTemplate, Map par } } - protected static Map buildPomXmlParams(String pluginVersion, String[] executions, String[] configuration, String[] modules, String[] dependencies) { + protected static Map buildPomXmlParams(String pluginVersion, String[] executions, String[] configuration, String[] modules, String[] dependencies, String[] plugins) { Map params = new HashMap<>(); params.put(SPOTLESS_MAVEN_PLUGIN_VERSION, pluginVersion == null ? getSystemProperty(SPOTLESS_MAVEN_PLUGIN_VERSION) : pluginVersion); @@ -247,6 +252,10 @@ protected static Map buildPomXmlParams(String pluginVersion, Str params.put(DEPENDENCIES, String.join("\n", dependencies)); } + if (plugins != null) { + params.put(PLUGINS, String.join("\n", plugins)); + } + return params; } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java index ae8378c566..6206affc04 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java @@ -145,7 +145,7 @@ private void createRootPom() throws IOException { modulesList.addAll(subProjects.keySet()); String[] modules = modulesList.toArray(new String[0]); - Map rootPomParams = buildPomXmlParams(null, null, configuration, modules, null); + Map rootPomParams = buildPomXmlParams(null, null, configuration, modules, null, null); setFile("pom.xml").toContent(createPomXmlContent("/multi-module/pom-parent.xml.mustache", rootPomParams)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java index 566851c26c..92a78e3923 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessCheckMojoTest.java @@ -62,6 +62,7 @@ void testSpotlessCheckBindingToVerifyPhase() throws Exception { " ${basedir}/license.txt", " ", ""}, + null, null); testSpotlessCheck(UNFORMATTED_FILE, "verify", true); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java index 6afcba7430..0a9fe8f2d4 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java @@ -98,7 +98,8 @@ private void writePomWithPluginManagementAndDependency() throws IOException { " javax.inject", " 1", " ", - ""})); + ""}, + null)); } @Test diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java new file mode 100644 index 0000000000..3d20170fab --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java @@ -0,0 +1,66 @@ +/* + * 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.npm; + +/** + * Helper class to configure a maven pom to use frontend-maven-plugin. + * @see frontend-maven-plugin on github + */ +public final class NpmFrontendMavenPlugin { + + public static final String GROUP_ID = "com.github.eirslett"; + public static final String ARTIFACT_ID = "frontend-maven-plugin"; + public static final String VERSION = "1.11.3"; // for now, we stick with this version, as it is the last to support maven 3.1 (see pom-test.xml.mustache) + + public static final String GOAL_INSTALL_NODE_AND_NPM = "install-node-and-npm"; + + public static final String INSTALL_DIRECTORY = "target"; + + private NpmFrontendMavenPlugin() { + // prevent instantiation + } + + public static String[] pomPluginLines(String nodeVersion, String npmVersion) { + return new String[]{ + "", + String.format(" %s", GROUP_ID), + String.format(" %s", ARTIFACT_ID), + String.format(" %s", VERSION), + " ", + " ", + " install node and npm", + " ", + String.format(" %s", GOAL_INSTALL_NODE_AND_NPM), + " ", + " ", + " ", + " ", + (nodeVersion != null ? " " + nodeVersion + "" : ""), + (npmVersion != null ? " " + npmVersion + "" : ""), + String.format(" %s", INSTALL_DIRECTORY), + " ", + "" + }; + } + + public static String installNpmMavenGoal() { + return String.format("%s:%s:%s", GROUP_ID, ARTIFACT_ID, GOAL_INSTALL_NODE_AND_NPM); + } + + public static String installedNpmPath() { + return String.format("%s/node/npm", INSTALL_DIRECTORY); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java new file mode 100644 index 0000000000..78830bf09d --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmTestsWithDynamicallyInstalledNpmInstallationTest.java @@ -0,0 +1,48 @@ +/* + * 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.npm; + +import static com.diffplug.spotless.maven.npm.NpmFrontendMavenPlugin.installNpmMavenGoal; +import static com.diffplug.spotless.maven.npm.NpmFrontendMavenPlugin.installedNpmPath; +import static com.diffplug.spotless.maven.npm.NpmFrontendMavenPlugin.pomPluginLines; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +public class NpmTestsWithDynamicallyInstalledNpmInstallationTest extends MavenIntegrationHarness { + + @Test + void useDownloadedNpmInstallation() throws Exception { + writePomWithPrettierSteps( + pomPluginLines("v18.13.0", null), + "src/main/typescript/test.ts", + "", + " " + installedNpmPath() + "", + ""); + + String kind = "typescript"; + String suffix = "ts"; + String configPath = ".prettierrc.yml"; + setFile(configPath).toResource("npm/prettier/filetypes/" + kind + "/" + ".prettierrc.yml"); + String path = "src/main/" + kind + "/test." + suffix; + setFile(path).toResource("npm/prettier/filetypes/" + kind + "/" + kind + ".dirty"); + + mavenRunner().withArguments(installNpmMavenGoal(), "spotless:apply").runNoError(); + assertFile(path).sameAsResource("npm/prettier/filetypes/" + kind + "/" + kind + ".clean"); + } + +} diff --git a/plugin-maven/src/test/resources/pom-test.xml.mustache b/plugin-maven/src/test/resources/pom-test.xml.mustache index 122f5d9218..6db3cb0c15 100644 --- a/plugin-maven/src/test/resources/pom-test.xml.mustache +++ b/plugin-maven/src/test/resources/pom-test.xml.mustache @@ -21,6 +21,7 @@ + {{{plugins}}} com.diffplug.spotless spotless-maven-plugin From 789b9d210a4b1555f0eee41d7e178798ecdd16f1 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 18 Jan 2023 14:22:13 +0100 Subject: [PATCH 0328/1120] add nodeExecutable configuration to README --- plugin-gradle/README.md | 11 ++++++++--- plugin-maven/README.md | 10 ++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f2567a5924..11f7866644 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -844,18 +844,23 @@ spotless { ### npm detection Prettier is based on NodeJS, so a working NodeJS installation (especially npm) is required on the host running spotless. -Spotless will try to auto-discover an npm installation. If that is not working for you, it is possible to directly configure the npm binary to use. +Spotless will try to auto-discover an npm installation. If that is not working for you, it is possible to directly configure the npm +and/or node binary to use. ```gradle spotless { format 'javascript', { - prettier().npmExecutable('/usr/bin/npm').config(...) + prettier().npmExecutable('/usr/bin/npm').nodeExecutable('/usr/bin/node').config(...) ``` +If you provide both `npmExecutable` and `nodeExecutable`, spotless will use these paths. If you specify only one of the +two, spotless will assume the other one is in the same directory. + ### `.npmrc` detection Spotless picks up npm configuration stored in a `.npmrc` file either in the project directory or in your user home. -Alternatively you can supply spotless with a location of the `.npmrc` file to use. (This can be combined with `npmExecutable`, of course.) +Alternatively you can supply spotless with a location of the `.npmrc` file to use. (This can be combined with +`npmExecutable` and `nodeExecutable`, of course.) ```gradle spotless { diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2a455dfe07..dc3795927a 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1050,17 +1050,23 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos ### npm detection Prettier is based on NodeJS, so to use it, a working NodeJS installation (especially npm) is required on the host running spotless. -Spotless will try to auto-discover an npm installation. If that is not working for you, it is possible to directly configure the npm binary to use. +Spotless will try to auto-discover an npm installation. If that is not working for you, it is possible to directly configure the npm +and/or node binary to use. ```xml /usr/bin/npm + /usr/bin/node ``` +If you provide both `npmExecutable` and `nodeExecutable`, spotless will use these paths. If you specify only one of the +two, spotless will assume the other one is in the same directory. + ### `.npmrc` detection Spotless picks up npm configuration stored in a `.npmrc` file either in the project directory or in your user home. -Alternatively you can supply spotless with a location of the `.npmrc` file to use. (This can be combined with `npmExecutable`, of course.) +Alternatively you can supply spotless with a location of the `.npmrc` file to use. (This can be combined with +`npmExecutable` and `nodeExecutable`, of course.) ```xml From a9c79aee0929dc15ac1683cf64831d85f589e7d9 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 18 Jan 2023 14:31:57 +0100 Subject: [PATCH 0329/1120] add `nodeExecutable` to changes.md --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 60c723f62d..dee5bb6175 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 * `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) +* Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 63e5b43d74..58142c6755 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1bb49898f1..d93893f35b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes From 6b9b870c8754c4af9967ea094b1049f4dc941d25 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 23:08:33 +0400 Subject: [PATCH 0330/1120] Rely on generic JsonNode --- .../spotless/glue/yaml/JacksonYamlFormatterFunc.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index edb350c559..ae6b85530b 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ContainerNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; @@ -60,13 +61,11 @@ protected JsonFactory makeJsonFactory() { @Override protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { - //if (true) - // throw new IllegalArgumentException("input = \r\n" + input); try { // https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 JsonParser yamlParser = objectMapper.getFactory().createParser(input); - List documents = objectMapper.readValues(yamlParser, ContainerNode.class).readAll(); + List documents = objectMapper.readValues(yamlParser, JsonNode.class).readAll(); // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055 // https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-554265055 From 6b6e854e19b0969d23918ae9bd9ec705f25fc46d Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 18 Jan 2023 23:20:27 +0400 Subject: [PATCH 0331/1120] Fix style --- .../diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java index ae6b85530b..89304d8d0a 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/yaml/JacksonYamlFormatterFunc.java @@ -24,7 +24,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ContainerNode; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactoryBuilder; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; From e8f0d2d27bb542987b8cc97b7a4c2b5a04880306 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 18 Jan 2023 19:59:56 +0100 Subject: [PATCH 0332/1120] try fix windows build: set binary name for win --- .../spotless/GradleIntegrationHarness.java | 47 ++- .../NpmTestsWithoutNpmInstallationTest.java | 284 ++++++++++-------- .../maven/npm/NpmFrontendMavenPlugin.java | 2 +- 3 files changed, 193 insertions(+), 140 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java index 9e2f490429..1763fd088f 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.util.List; import java.util.ListIterator; +import java.util.function.BiConsumer; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -117,11 +118,34 @@ protected GradleRunner gradleRunner() throws IOException { } /** Dumps the complete file contents of the folder to the console. */ - protected String getContents() throws IOException { + protected String getContents() { return getContents(subPath -> !subPath.startsWith(".gradle")); } - protected String getContents(Predicate subpathsToInclude) throws IOException { + protected String getContents(Predicate subpathsToInclude) { + return StringPrinter.buildString(printer -> Errors.rethrow().run(() -> iterateFiles(subpathsToInclude, (subpath, file) -> { + printer.println("### " + subpath + " ###"); + try { + printer.println(read(subpath)); + } catch (IOException e) { + throw new RuntimeException(e); + } + }))); + } + + /** Dumps the filtered file listing of the folder to the console. */ + protected String listFiles(Predicate subpathsToInclude) { + return StringPrinter.buildString(printer -> iterateFiles(subpathsToInclude, (subPath, file) -> { + printer.println(subPath + " [" + getFileAttributes(file) + "]"); + })); + } + + /** Dumps the file listing of the folder to the console. */ + protected String listFiles() { + return listFiles(subPath -> !subPath.startsWith(".gradle")); + } + + protected void iterateFiles(Predicate subpathsToInclude, BiConsumer consumer) { TreeDef treeDef = TreeDef.forFile(Errors.rethrow()); List files = TreeStream.depthFirst(treeDef, rootFolder()) .filter(File::isFile) @@ -129,16 +153,17 @@ protected String getContents(Predicate subpathsToInclude) throws IOExcep ListIterator iterator = files.listIterator(files.size()); int rootLength = rootFolder().getAbsolutePath().length() + 1; - return StringPrinter.buildString(printer -> Errors.rethrow().run(() -> { - while (iterator.hasPrevious()) { - File file = iterator.previous(); - String subPath = file.getAbsolutePath().substring(rootLength); - if (subpathsToInclude.test(subPath)) { - printer.println("### " + subPath + " ###"); - printer.println(read(subPath)); - } + while (iterator.hasPrevious()) { + File file = iterator.previous(); + String subPath = file.getAbsolutePath().substring(rootLength); + if (subpathsToInclude.test(subPath)) { + consumer.accept(subPath, file); } - })); + } + } + + protected String getFileAttributes(File file) { + return (file.canRead() ? "r" : "-") + (file.canWrite() ? "w" : "-") + (file.canExecute() ? "x" : "-"); } protected void checkRunsThenUpToDate() throws IOException { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index d5c4e8f092..916d853920 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -20,151 +20,179 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import com.diffplug.common.base.Predicates; + class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness { @Test void useNodeAndNpmFromNodeGradlePlugin() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - " id 'com.github.node-gradle.node' version '3.5.1'", - "}", - "repositories { mavenCentral() }", - "node {", - " download = true", - " version = '18.13.0'", - " npmVersion = '8.19.2'", - " workDir = file(\"${buildDir}/nodejs\")", - " npmWorkDir = file(\"${buildDir}/npm\")", - "}", - "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", - "prettierConfig['parser'] = 'typescript'", - "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", - "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", - "spotless {", - " format 'mytypescript', {", - " target 'test.ts'", - " prettier()", - " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", - " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", - " .config(prettierConfig)", - " }", - "}"); - setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - // make sure node binary is there - gradleRunner().withArguments("nodeSetup", "npmSetup").build(); - // then run spotless using that node installation - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + try { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " npmVersion = '8.19.2'", + " workDir = file(\"${buildDir}/nodejs\")", + " npmWorkDir = file(\"${buildDir}/npm\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'", + "def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}${npmExec}\")", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } catch (Exception e) { + printContents(); + throw e; + } + } + + private void printContents() { + System.out.println("************* Folder contents **************************"); + System.out.println(listFiles(Predicates.and(path -> !path.startsWith(".gradle"), path -> !path.contains("/node_modules/"), path -> !path.contains("/include/")))); + System.out.println("********************************************************"); } @Test @Disabled("This test is disabled because we currently don't support using npm/node installed by the" + "node-gradle-plugin as the installation takes place in the *execution* phase, but spotless needs it in the *configuration* phase.") void useNodeAndNpmFromNodeGradlePluginInOneSweep() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - " id 'com.github.node-gradle.node' version '3.5.1'", - "}", - "repositories { mavenCentral() }", - "node {", - " download = true", - " version = '18.13.0'", - " npmVersion = '8.19.2'", - " workDir = file(\"${buildDir}/nodejs\")", - " npmWorkDir = file(\"${buildDir}/npm\")", - "}", - "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", - "prettierConfig['parser'] = 'typescript'", - "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", - "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", - "spotless {", - " format 'mytypescript', {", - " target 'test.ts'", - " prettier()", - " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", - " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", - " .config(prettierConfig)", - " }", - "}", - "tasks.named('spotlessMytypescript').configure {", - " it.dependsOn('nodeSetup', 'npmSetup')", - "}"); - setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + try { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " npmVersion = '8.19.2'", + " workDir = file(\"${buildDir}/nodejs\")", + " npmWorkDir = file(\"${buildDir}/npm\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'", + "def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}${npmExec}\")", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}\")", + " .config(prettierConfig)", + " }", + "}", + "tasks.named('spotlessMytypescript').configure {", + " it.dependsOn('nodeSetup', 'npmSetup')", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } catch (Exception e) { + printContents(); + throw e; + } } @Test void useNpmFromNodeGradlePlugin() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - " id 'com.github.node-gradle.node' version '3.5.1'", - "}", - "repositories { mavenCentral() }", - "node {", - " download = true", - " version = '18.13.0'", - " workDir = file(\"${buildDir}/nodejs\")", - "}", - "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", - "prettierConfig['parser'] = 'typescript'", - "def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''", - "spotless {", - " format 'mytypescript', {", - " target 'test.ts'", - " prettier()", - " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")", - " .config(prettierConfig)", - " }", - "}"); - setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - // make sure node binary is there - gradleRunner().withArguments("nodeSetup", "npmSetup").build(); - // then run spotless using that node installation - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + try { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " workDir = file(\"${buildDir}/nodejs\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}${npmExec}\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } catch (Exception e) { + printContents(); + throw e; + } } @Test void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - " id 'com.github.node-gradle.node' version '3.5.1'", - "}", - "repositories { mavenCentral() }", - "node {", - " download = true", - " version = '18.13.0'", - " workDir = file(\"${buildDir}/nodejs\")", - "}", - "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", - "prettierConfig['parser'] = 'typescript'", - "def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''", - "spotless {", - " format 'mytypescript', {", - " target 'test.ts'", - " prettier()", - " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")", - " .config(prettierConfig)", - " }", - "}"); - setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); - // make sure node binary is there - gradleRunner().withArguments("nodeSetup", "npmSetup").build(); - // then run spotless using that node installation - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); - Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); - assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + try { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + " id 'com.github.node-gradle.node' version '3.5.1'", + "}", + "repositories { mavenCentral() }", + "node {", + " download = true", + " version = '18.13.0'", + " workDir = file(\"${buildDir}/nodejs\")", + "}", + "def prettierConfig = [:]", + "prettierConfig['printWidth'] = 50", + "prettierConfig['parser'] = 'typescript'", + "def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'", + "spotless {", + " format 'mytypescript', {", + " target 'test.ts'", + " prettier()", + " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}\")", + " .config(prettierConfig)", + " }", + "}"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + // make sure node binary is there + gradleRunner().withArguments("nodeSetup", "npmSetup").build(); + // then run spotless using that node installation + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } catch (Exception e) { + printContents(); + throw e; + } } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java index 3d20170fab..de030ab81c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmFrontendMavenPlugin.java @@ -61,6 +61,6 @@ public static String installNpmMavenGoal() { } public static String installedNpmPath() { - return String.format("%s/node/npm", INSTALL_DIRECTORY); + return String.format("%s/node/npm%s", INSTALL_DIRECTORY, System.getProperty("os.name").toLowerCase().contains("win") ? ".cmd" : ""); } } From 5315110b4b42dbc4c105ce06d0cf153965877cc3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 19 Jan 2023 14:20:10 +0000 Subject: [PATCH 0333/1120] chore(deps): update plugin org.gradle.test-retry to v1.5.1 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 57498bf23f..fb9e7dcf0b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ pluginManagement { // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 // https://github.com/gradle/test-retry-gradle-plugin/releases - id 'org.gradle.test-retry' version '1.5.0' + id 'org.gradle.test-retry' version '1.5.1' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags From fed3ffc811da37a30921aa9835627e8ca377c2e2 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 19 Jan 2023 19:42:01 +0400 Subject: [PATCH 0334/1120] First commit to discuss the idea --- .../spotless/maven/ImpactedFilesTracker.java | 24 +++++++++++++++++++ .../spotless/maven/SpotlessApplyMojo.java | 8 +++++++ 2 files changed, 32 insertions(+) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java new file mode 100644 index 0000000000..6019591e09 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -0,0 +1,24 @@ +package com.diffplug.spotless.maven; + +import java.util.concurrent.atomic.AtomicInteger; + +public class ImpactedFilesTracker { + protected final AtomicInteger nbChecked = new AtomicInteger(); + protected final AtomicInteger nbCleaned = new AtomicInteger(); + + public void checked() { + nbChecked.incrementAndGet(); + } + + public int getChecked() { + return nbChecked.get(); + } + + public void cleaned() { + nbCleaned.incrementAndGet(); + } + + public int getCleaned() { + return nbCleaned.get(); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 7a15d01b17..b617505826 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -33,6 +33,8 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo { @Override protected void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException { + ImpactedFilesTracker impactedFilesTracker = new ImpactedFilesTracker(); + for (File file : files) { if (upToDateChecker.isUpToDate(file.toPath())) { if (getLog().isDebugEnabled()) { @@ -42,10 +44,13 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } try { + impactedFilesTracker.checked(); PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file); if (!dirtyState.isClean() && !dirtyState.didNotConverge()) { + getLog().info(String.format("Writing clean file: %s", file)); dirtyState.writeCanonicalTo(file); buildContext.refresh(file); + impactedFilesTracker.cleaned(); } } catch (IOException e) { throw new MojoExecutionException("Unable to format file " + file, e); @@ -53,5 +58,8 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke upToDateChecker.setUpToDate(file.toPath()); } + + // We print the number of considered files which is useful when ratchetFrom is setup + getLog().info(String.format("A formatter with %s steps cleaned: %s files (for %s considered)", formatter.getSteps().size(), impactedFilesTracker.getCleaned(), impactedFilesTracker.getChecked())); } } From 00e6282d2cab0c067614e3b2cd5138c47ee54bb1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 19 Jan 2023 10:19:25 -0800 Subject: [PATCH 0335/1120] Add the Jackson steps to the root README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 637781d894..0743b69427 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('java.FormatAnnotationsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.gson.GsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', +lib('json.JacksonJsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.JsonSimpleStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', @@ -77,7 +78,7 @@ lib('python.BlackStep') +'{{yes}} | {{no}} lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', -lib('yaml.YamlJacksonStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', '| [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | {{no}} | {{no}} | {{no}} | {{no}} |', ].join('\n'); --> @@ -109,6 +110,7 @@ lib('yaml.YamlJacksonStep') +'{{no}} | {{yes}} | [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.FormatAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | +| [`json.JacksonJsonStep`](lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | @@ -123,7 +125,7 @@ lib('yaml.YamlJacksonStep') +'{{no}} | {{yes}} | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | -| [`yaml.YamlJacksonStep`](lib/src/main/java/com/diffplug/spotless/yaml/YamlJacksonStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`yaml.JacksonYamlStep`](lib/src/main/java/com/diffplug/spotless/yaml/JacksonYamlStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [(Your FormatterStep here)](CONTRIBUTING.md#how-to-add-a-new-formatterstep) | :white_large_square: | :white_large_square: | :white_large_square: | :white_large_square: | From 10f04deb64ca671d8cc448665243dd74337e2ff3 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Thu, 19 Jan 2023 22:06:16 +0100 Subject: [PATCH 0336/1120] move gson formatter to custom compile sourceset --- lib/build.gradle | 5 +- .../spotless/glue/gson/GsonFormatterFunc.java | 77 ++++++++++++++++++ .../json/gson/GsonBuilderWrapper.java | 54 ------------- .../spotless/json/gson/GsonConfig.java | 51 ++++++++++++ .../diffplug/spotless/json/gson/GsonStep.java | 78 ++++--------------- .../spotless/json/gson/GsonWrapper.java | 41 ---------- .../spotless/json/gson/GsonWrapperBase.java | 71 ----------------- .../json/gson/JsonElementWrapper.java | 40 ---------- .../spotless/json/gson/JsonObjectWrapper.java | 56 ------------- .../spotless/json/gson/JsonWriterWrapper.java | 48 ------------ .../gradle/spotless/JsonExtension.java | 21 ++--- .../diffplug/spotless/maven/json/Gson.java | 6 +- 12 files changed, 161 insertions(+), 387 deletions(-) create mode 100644 lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java create mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java diff --git a/lib/build.gradle b/lib/build.gradle index 30c8fe8b15..bb1a389993 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -15,7 +15,8 @@ def NEEDS_GLUE = [ 'flexmark', 'diktat', 'scalafmt', - 'jackson' + 'jackson', + 'gson' ] for (glue in NEEDS_GLUE) { sourceSets.register(glue) { @@ -108,6 +109,8 @@ dependencies { // used for markdown formatting flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' + + gsonCompileOnly 'com.google.code.gson:gson:2.10.1' } // we'll hold the core lib to a high standard diff --git a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java new file mode 100644 index 0000000000..33db1faaa6 --- /dev/null +++ b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java @@ -0,0 +1,77 @@ +package com.diffplug.spotless.glue.gson; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collections; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.ThrowingEx; +import com.diffplug.spotless.json.gson.GsonConfig; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; + +public class GsonFormatterFunc implements FormatterFunc { + + private static final String FAILED_TO_PARSE_ERROR_MESSAGE = "Unable to format JSON"; + + private final Gson gson; + private final GsonConfig gsonConfig; + private final String generatedIndent; + + public GsonFormatterFunc(GsonConfig gsonConfig) { + GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls(); + if (!gsonConfig.isEscapeHtml()) { + gsonBuilder = gsonBuilder.disableHtmlEscaping(); + } + this.gson = gsonBuilder.create(); + this.gsonConfig = gsonConfig; + this.generatedIndent = generateIndent(gsonConfig.getIndentSpaces()); + } + + @Override + public String apply(String inputString) { + String result; + if (inputString.isEmpty()) { + result = ""; + } else { + JsonElement jsonElement = gson.fromJson(inputString, JsonElement.class); + if (jsonElement == null) { + throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE); + } + if (gsonConfig.isSortByKeys() && jsonElement.isJsonObject()) { + jsonElement = sortByKeys(jsonElement.getAsJsonObject()); + } + try (StringWriter stringWriter = new StringWriter()) { + JsonWriter jsonWriter = new JsonWriter(stringWriter); + jsonWriter.setIndent(this.generatedIndent); + gson.toJson(jsonElement, jsonWriter); + result = stringWriter + "\n"; + } catch (IOException ioException) { + throw ThrowingEx.asRuntime(ioException); + } + } + return result; + } + + private JsonElement sortByKeys(JsonObject jsonObject) { + JsonObject result = new JsonObject(); + result.keySet().stream().sorted() + .forEach(key -> { + JsonElement element = jsonObject.get(key); + if (element.isJsonObject()) { + element = sortByKeys(element.getAsJsonObject()); + } + result.add(key, element); + }); + return result; + } + + private String generateIndent(int indentSpaces) { + return String.join("", Collections.nCopies(indentSpaces, " ")); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java deleted file mode 100644 index c2e56f39b8..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonBuilderWrapper.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -import com.diffplug.spotless.JarState; - -class GsonBuilderWrapper extends GsonWrapperBase { - - private final Constructor constructor; - private final Method serializeNullsMethod; - private final Method disableHtmlEscapingMethod; - private final Method createMethod; - - GsonBuilderWrapper(JarState jarState) { - Class clazz = loadClass(jarState.getClassLoader(), "com.google.gson.GsonBuilder"); - this.constructor = getConstructor(clazz); - this.serializeNullsMethod = getMethod(clazz, "serializeNulls"); - this.disableHtmlEscapingMethod = getMethod(clazz, "disableHtmlEscaping"); - this.createMethod = getMethod(clazz, "create"); - } - - Object createGsonBuilder() { - return newInstance(constructor); - } - - Object serializeNulls(Object gsonBuilder) { - return invoke(serializeNullsMethod, gsonBuilder); - } - - Object disableHtmlEscaping(Object gsonBuilder) { - return invoke(disableHtmlEscapingMethod, gsonBuilder); - } - - Object create(Object gsonBuilder) { - return invoke(createMethod, gsonBuilder); - } - -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java new file mode 100644 index 0000000000..c63ad0aaba --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java @@ -0,0 +1,51 @@ +package com.diffplug.spotless.json.gson; + +import java.io.Serializable; + +public class GsonConfig implements Serializable { + private static final long serialVersionUID = 6039715618937332633L; + + private boolean sortByKeys; + private boolean escapeHtml; + private int indentSpaces; + private String version; + + public GsonConfig(boolean sortByKeys, boolean escapeHtml, int indentSpaces, String version) { + this.sortByKeys = sortByKeys; + this.escapeHtml = escapeHtml; + this.indentSpaces = indentSpaces; + this.version = version; + } + + public boolean isSortByKeys() { + return sortByKeys; + } + + public void setSortByKeys(boolean sortByKeys) { + this.sortByKeys = sortByKeys; + } + + public boolean isEscapeHtml() { + return escapeHtml; + } + + public void setEscapeHtml(boolean escapeHtml) { + this.escapeHtml = escapeHtml; + } + + public int getIndentSpaces() { + return indentSpaces; + } + + public void setIndentSpaces(int indentSpaces) { + this.indentSpaces = indentSpaces; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 06519ae39d..624c4f2533 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -17,8 +17,8 @@ import java.io.IOException; import java.io.Serializable; -import java.io.StringWriter; -import java.util.Collections; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.Objects; import com.diffplug.spotless.FormatterFunc; @@ -29,77 +29,27 @@ public class GsonStep { private static final String MAVEN_COORDINATES = "com.google.code.gson:gson"; - public static FormatterStep create(int indentSpaces, boolean sortByKeys, boolean escapeHtml, String version, Provisioner provisioner) { + public static FormatterStep create(GsonConfig gsonConfig, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); - return FormatterStep.createLazy("gson", () -> new State(indentSpaces, sortByKeys, escapeHtml, version, provisioner), State::toFormatter); + return FormatterStep.createLazy("gson", () -> new State(gsonConfig, provisioner), State::toFormatter); } private static final class State implements Serializable { - private static final long serialVersionUID = -1493479043249379485L; + private static final long serialVersionUID = -3240568265160440420L; - private final int indentSpaces; - private final boolean sortByKeys; - private final boolean escapeHtml; private final JarState jarState; + private final GsonConfig gsonConfig; - private State(int indentSpaces, boolean sortByKeys, boolean escapeHtml, String version, Provisioner provisioner) throws IOException { - this.indentSpaces = indentSpaces; - this.sortByKeys = sortByKeys; - this.escapeHtml = escapeHtml; - this.jarState = JarState.from(MAVEN_COORDINATES + ":" + version, provisioner); + private State(GsonConfig gsonConfig, Provisioner provisioner) throws IOException { + this.gsonConfig = gsonConfig; + this.jarState = JarState.from(MAVEN_COORDINATES + ":" + gsonConfig.getVersion(), provisioner); } - FormatterFunc toFormatter() { - JsonWriterWrapper jsonWriterWrapper = new JsonWriterWrapper(jarState); - JsonElementWrapper jsonElementWrapper = new JsonElementWrapper(jarState); - JsonObjectWrapper jsonObjectWrapper = new JsonObjectWrapper(jarState, jsonElementWrapper); - GsonBuilderWrapper gsonBuilderWrapper = new GsonBuilderWrapper(jarState); - GsonWrapper gsonWrapper = new GsonWrapper(jarState, jsonElementWrapper, jsonWriterWrapper); - - Object gsonBuilder = gsonBuilderWrapper.serializeNulls(gsonBuilderWrapper.createGsonBuilder()); - if (!escapeHtml) { - gsonBuilder = gsonBuilderWrapper.disableHtmlEscaping(gsonBuilder); - } - Object gson = gsonBuilderWrapper.create(gsonBuilder); - - return inputString -> { - String result; - if (inputString.isEmpty()) { - result = ""; - } else { - Object jsonElement = gsonWrapper.fromJson(gson, inputString, jsonElementWrapper.getWrappedClass()); - if (jsonElement == null) { - throw new AssertionError(GsonWrapperBase.FAILED_TO_PARSE_ERROR_MESSAGE); - } - if (sortByKeys && jsonElementWrapper.isJsonObject(jsonElement)) { - jsonElement = sortByKeys(jsonObjectWrapper, jsonElementWrapper, jsonElement); - } - try (StringWriter stringWriter = new StringWriter()) { - Object jsonWriter = jsonWriterWrapper.createJsonWriter(stringWriter); - jsonWriterWrapper.setIndent(jsonWriter, generateIndent(indentSpaces)); - gsonWrapper.toJson(gson, jsonElement, jsonWriter); - result = stringWriter + "\n"; - } - } - return result; - }; - } - - private Object sortByKeys(JsonObjectWrapper jsonObjectWrapper, JsonElementWrapper jsonElementWrapper, Object jsonObject) { - Object result = jsonObjectWrapper.createJsonObject(); - jsonObjectWrapper.keySet(jsonObject).stream().sorted() - .forEach(key -> { - Object element = jsonObjectWrapper.get(jsonObject, key); - if (jsonElementWrapper.isJsonObject(element)) { - element = sortByKeys(jsonObjectWrapper, jsonElementWrapper, element); - } - jsonObjectWrapper.add(result, key, element); - }); - return result; - } - - private String generateIndent(int indentSpaces) { - return String.join("", Collections.nCopies(indentSpaces, " ")); + FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + InstantiationException, IllegalAccessException { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gson.GsonFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(GsonConfig.class); + return (FormatterFunc) constructor.newInstance(gsonConfig); } } diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java deleted file mode 100644 index eaca499eed..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapper.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.lang.reflect.Method; - -import com.diffplug.spotless.JarState; - -class GsonWrapper extends GsonWrapperBase { - - private final Method fromJsonMethod; - private final Method toJsonMethod; - - GsonWrapper(JarState jarState, JsonElementWrapper jsonElementWrapper, JsonWriterWrapper jsonWriterWrapper) { - Class clazz = loadClass(jarState.getClassLoader(), "com.google.gson.Gson"); - this.fromJsonMethod = getMethod(clazz, "fromJson", String.class, Class.class); - this.toJsonMethod = getMethod(clazz, "toJson", jsonElementWrapper.getWrappedClass(), jsonWriterWrapper.getWrappedClass()); - } - - Object fromJson(Object gson, String json, Class type) { - return invoke(fromJsonMethod, gson, json, type); - } - - void toJson(Object gson, Object jsonElement, Object jsonWriter) { - invoke(toJsonMethod, gson, jsonElement, jsonWriter); - } - -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java deleted file mode 100644 index 24d12a5722..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonWrapperBase.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -abstract class GsonWrapperBase { - - static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Gson; maybe you set an incompatible version?"; - static final String FAILED_TO_PARSE_ERROR_MESSAGE = "Unable to format JSON"; - - protected final Class loadClass(ClassLoader classLoader, String className) { - try { - return classLoader.loadClass(className); - } catch (ClassNotFoundException cause) { - throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); - } - } - - protected final Constructor getConstructor(Class clazz, Class... argumentTypes) { - try { - return clazz.getConstructor(argumentTypes); - } catch (NoSuchMethodException cause) { - throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); - } - } - - protected final Method getMethod(Class clazz, String name, Class... argumentTypes) { - try { - return clazz.getMethod(name, argumentTypes); - } catch (NoSuchMethodException cause) { - throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); - } - } - - protected final T newInstance(Constructor constructor, Object... args) { - try { - return constructor.newInstance(args); - } catch (InstantiationException | IllegalAccessException cause) { - throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); - } catch (InvocationTargetException cause) { - throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE, cause.getCause()); - } - } - - protected Object invoke(Method method, Object targetObject, Object... args) { - try { - return method.invoke(targetObject, args); - } catch (IllegalAccessException cause) { - throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); - } catch (InvocationTargetException cause) { - throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE, cause.getCause()); - } - } - -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java deleted file mode 100644 index ffdfa649ce..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonElementWrapper.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.lang.reflect.Method; - -import com.diffplug.spotless.JarState; - -class JsonElementWrapper extends GsonWrapperBase { - - private final Class clazz; - private final Method isJsonObjectMethod; - - JsonElementWrapper(JarState jarState) { - this.clazz = loadClass(jarState.getClassLoader(), "com.google.gson.JsonElement"); - this.isJsonObjectMethod = getMethod(clazz, "isJsonObject"); - } - - boolean isJsonObject(Object jsonElement) { - return (boolean) invoke(isJsonObjectMethod, jsonElement); - } - - Class getWrappedClass() { - return clazz; - } - -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java deleted file mode 100644 index 35ec0d876b..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonObjectWrapper.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.Set; - -import com.diffplug.spotless.JarState; - -class JsonObjectWrapper extends GsonWrapperBase { - - private final Constructor constructor; - private final Method keySetMethod; - private final Method getMethod; - private final Method addMethod; - - JsonObjectWrapper(JarState jarState, JsonElementWrapper jsonElementWrapper) { - Class clazz = loadClass(jarState.getClassLoader(), "com.google.gson.JsonObject"); - this.constructor = getConstructor(clazz); - this.keySetMethod = getMethod(clazz, "keySet"); - this.getMethod = getMethod(clazz, "get", String.class); - this.addMethod = getMethod(clazz, "add", String.class, jsonElementWrapper.getWrappedClass()); - } - - Object createJsonObject() { - return newInstance(constructor); - } - - @SuppressWarnings("unchecked") - Set keySet(Object jsonObject) { - return (Set) invoke(keySetMethod, jsonObject); - } - - Object get(Object jsonObject, String key) { - return invoke(getMethod, jsonObject, key); - } - - void add(Object jsonObject, String key, Object element) { - invoke(addMethod, jsonObject, key, element); - } - -} diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java b/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java deleted file mode 100644 index c9d682e2c2..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/JsonWriterWrapper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2022 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.json.gson; - -import java.io.Writer; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -import com.diffplug.spotless.JarState; - -class JsonWriterWrapper extends GsonWrapperBase { - - private final Class clazz; - private final Constructor constructor; - private final Method setIndentMethod; - - JsonWriterWrapper(JarState jarState) { - this.clazz = loadClass(jarState.getClassLoader(), "com.google.gson.stream.JsonWriter"); - this.constructor = getConstructor(clazz, Writer.class); - this.setIndentMethod = getMethod(clazz, "setIndent", String.class); - } - - Object createJsonWriter(Writer writer) { - return newInstance(constructor, writer); - } - - void setIndent(Object jsonWriter, String indent) { - invoke(setIndentMethod, jsonWriter, indent); - } - - Class getWrappedClass() { - return clazz; - } - -} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 1e9de2e831..c684dab291 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -23,11 +23,12 @@ import com.diffplug.spotless.json.JacksonJsonConfig; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.json.JsonSimpleStep; +import com.diffplug.spotless.json.gson.GsonConfig; import com.diffplug.spotless.json.gson.GsonStep; public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; - private static final String DEFAULT_GSON_VERSION = "2.8.9"; + private static final String DEFAULT_GSON_VERSION = "2.10.1"; static final String NAME = "json"; @Inject @@ -47,8 +48,8 @@ public SimpleConfig simple() { return new SimpleConfig(DEFAULT_INDENTATION); } - public GsonConfig gson() { - return new GsonConfig(); + public GsonGradleConfig gson() { + return new GsonGradleConfig(); } public JacksonJsonGradleConfig jackson() { @@ -73,13 +74,13 @@ private FormatterStep createStep() { } } - public class GsonConfig { + public class GsonGradleConfig { private int indentSpaces; private boolean sortByKeys; private boolean escapeHtml; private String version; - public GsonConfig() { + public GsonGradleConfig() { this.indentSpaces = DEFAULT_INDENTATION; this.sortByKeys = false; this.escapeHtml = false; @@ -87,32 +88,32 @@ public GsonConfig() { addStep(createStep()); } - public GsonConfig indentWithSpaces(int indentSpaces) { + public GsonGradleConfig indentWithSpaces(int indentSpaces) { this.indentSpaces = indentSpaces; replaceStep(createStep()); return this; } - public GsonConfig sortByKeys() { + public GsonGradleConfig sortByKeys() { this.sortByKeys = true; replaceStep(createStep()); return this; } - public GsonConfig escapeHtml() { + public GsonGradleConfig escapeHtml() { this.escapeHtml = true; replaceStep(createStep()); return this; } - public GsonConfig version(String version) { + public GsonGradleConfig version(String version) { this.version = version; replaceStep(createStep()); return this; } private FormatterStep createStep() { - return GsonStep.create(indentSpaces, sortByKeys, escapeHtml, version, provisioner()); + return GsonStep.create(new GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), provisioner()); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java index 7962ecb1f7..7dda88dcd9 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java @@ -15,6 +15,8 @@ */ package com.diffplug.spotless.maven.json; +import com.diffplug.spotless.json.gson.GsonConfig; + import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; @@ -23,7 +25,7 @@ import com.diffplug.spotless.maven.FormatterStepFactory; public class Gson implements FormatterStepFactory { - private static final String DEFAULT_GSON_VERSION = "2.8.9"; + private static final String DEFAULT_GSON_VERSION = "2.10.1"; @Parameter int indentSpaces = Json.DEFAULT_INDENTATION; @@ -40,6 +42,6 @@ public class Gson implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { int indentSpaces = this.indentSpaces; - return GsonStep.create(indentSpaces, sortByKeys, escapeHtml, version, stepConfig.getProvisioner()); + return GsonStep.create(new GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), stepConfig.getProvisioner()); } } From 0a86bad22192c5453cc08f8eebe3f28b44abd3d5 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Thu, 19 Jan 2023 22:07:36 +0100 Subject: [PATCH 0337/1120] apply format --- .../spotless/glue/gson/GsonFormatterFunc.java | 37 +++++++++++++------ .../spotless/json/gson/GsonConfig.java | 15 ++++++++ .../diffplug/spotless/json/gson/GsonStep.java | 4 +- .../diffplug/spotless/maven/json/Gson.java | 3 +- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java index 33db1faaa6..c1426a06d1 100644 --- a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java +++ b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java @@ -1,19 +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.glue.gson; import java.io.IOException; import java.io.StringWriter; import java.util.Collections; -import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.ThrowingEx; -import com.diffplug.spotless.json.gson.GsonConfig; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.stream.JsonWriter; +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.ThrowingEx; +import com.diffplug.spotless.json.gson.GsonConfig; + public class GsonFormatterFunc implements FormatterFunc { private static final String FAILED_TO_PARSE_ERROR_MESSAGE = "Unable to format JSON"; @@ -60,13 +75,13 @@ public String apply(String inputString) { private JsonElement sortByKeys(JsonObject jsonObject) { JsonObject result = new JsonObject(); result.keySet().stream().sorted() - .forEach(key -> { - JsonElement element = jsonObject.get(key); - if (element.isJsonObject()) { - element = sortByKeys(element.getAsJsonObject()); - } - result.add(key, element); - }); + .forEach(key -> { + JsonElement element = jsonObject.get(key); + if (element.isJsonObject()) { + element = sortByKeys(element.getAsJsonObject()); + } + result.add(key, element); + }); return result; } diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java index c63ad0aaba..a11c1ee296 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonConfig.java @@ -1,3 +1,18 @@ +/* + * 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.json.gson; import java.io.Serializable; diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 624c4f2533..1fb0f11d62 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ private State(GsonConfig gsonConfig, Provisioner provisioner) throws IOException } FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, - InstantiationException, IllegalAccessException { + InstantiationException, IllegalAccessException { Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gson.GsonFormatterFunc"); Constructor constructor = formatterFunc.getConstructor(GsonConfig.class); return (FormatterFunc) constructor.newInstance(gsonConfig); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java index 7dda88dcd9..fb5a38e890 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Gson.java @@ -15,11 +15,10 @@ */ package com.diffplug.spotless.maven.json; -import com.diffplug.spotless.json.gson.GsonConfig; - import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.gson.GsonConfig; import com.diffplug.spotless.json.gson.GsonStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; From 290a522e154db4ce10116273b35139e5f64ea8bd Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 20 Jan 2023 21:43:58 +0000 Subject: [PATCH 0338/1120] Update plugin de.benediktritter.maven-plugin-development to v0.4.1 --- plugin-maven/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index ad51318d93..664101a0fd 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -1,6 +1,6 @@ plugins { // https://www.benediktritter.de/maven-plugin-development/#release-history - id 'de.benediktritter.maven-plugin-development' version '0.4.0' + id 'de.benediktritter.maven-plugin-development' version '0.4.1' } repositories { mavenCentral() } From eea5d5c1d07f23c7381222bd5010b4933008dee9 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sun, 22 Jan 2023 14:36:44 +0100 Subject: [PATCH 0339/1120] fix tests --- .../spotless/glue/gson/GsonFormatterFunc.java | 2 +- .../com/diffplug/spotless/json/gson/GsonStep.java | 15 ++++++++++----- .../diffplug/spotless/json/gson/GsonStepTest.java | 14 +++++++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java index c1426a06d1..b19476a1a8 100644 --- a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java +++ b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java @@ -74,7 +74,7 @@ public String apply(String inputString) { private JsonElement sortByKeys(JsonObject jsonObject) { JsonObject result = new JsonObject(); - result.keySet().stream().sorted() + jsonObject.keySet().stream().sorted() .forEach(key -> { JsonElement element = jsonObject.get(key); if (element.isJsonObject()) { diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 1fb0f11d62..58993017fa 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -28,6 +28,7 @@ public class GsonStep { private static final String MAVEN_COORDINATES = "com.google.code.gson:gson"; + private static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Gson; maybe you set an incompatible version?"; public static FormatterStep create(GsonConfig gsonConfig, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); @@ -45,11 +46,15 @@ private State(GsonConfig gsonConfig, Provisioner provisioner) throws IOException this.jarState = JarState.from(MAVEN_COORDINATES + ":" + gsonConfig.getVersion(), provisioner); } - FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, - InstantiationException, IllegalAccessException { - Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gson.GsonFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(GsonConfig.class); - return (FormatterFunc) constructor.newInstance(gsonConfig); + FormatterFunc toFormatter() { + try { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gson.GsonFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(GsonConfig.class); + return (FormatterFunc) constructor.newInstance(gsonConfig); + } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException + | InstantiationException | IllegalAccessException | NoClassDefFoundError cause) { + throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); + } } } diff --git a/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java b/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java index 8f1d758836..3f4d2a84e0 100644 --- a/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/json/gson/GsonStepTest.java @@ -28,7 +28,7 @@ public class GsonStepTest extends JsonFormatterStepCommonTests { - private static final String DEFAULT_VERSION = "2.8.9"; + private static final String DEFAULT_VERSION = "2.10.1"; @Test void handlesComplexNestedObject() { @@ -52,34 +52,34 @@ void handlesNotJson() { @Test void handlesSortingWhenSortByKeyEnabled() { - FormatterStep step = GsonStep.create(INDENT, true, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + FormatterStep step = GsonStep.create(new GsonConfig(true, false, INDENT, DEFAULT_VERSION), TestProvisioner.mavenCentral()); StepHarness.forStep(step).testResource("json/sortByKeysBefore.json", "json/sortByKeysAfter.json"); } @Test void doesNoSortingWhenSortByKeyDisabled() { - FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + FormatterStep step = GsonStep.create(new GsonConfig(false, false, INDENT, DEFAULT_VERSION), TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/sortByKeysBefore.json", "json/sortByKeysAfterDisabled.json"); } @Test void handlesHtmlEscapeWhenEnabled() { - FormatterStep step = GsonStep.create(INDENT, false, true, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + FormatterStep step = GsonStep.create(new GsonConfig(false, true, INDENT, DEFAULT_VERSION), TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfter.json"); } @Test void writesRawHtmlWhenHtmlEscapeDisabled() { - FormatterStep step = GsonStep.create(INDENT, false, false, DEFAULT_VERSION, TestProvisioner.mavenCentral()); + FormatterStep step = GsonStep.create(new GsonConfig(false, false, INDENT, DEFAULT_VERSION), TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("json/escapeHtmlGsonBefore.json", "json/escapeHtmlGsonAfterDisabled.json"); } @Test void handlesVersionIncompatibility() { - FormatterStep step = GsonStep.create(INDENT, false, false, "1.7", TestProvisioner.mavenCentral()); + FormatterStep step = GsonStep.create(new GsonConfig(false, false, INDENT, "1.7"), TestProvisioner.mavenCentral()); Assertions.assertThatThrownBy(() -> step.format("", new File(""))) .isInstanceOf(IllegalStateException.class) .hasMessage("There was a problem interacting with Gson; maybe you set an incompatible version?"); @@ -87,6 +87,6 @@ void handlesVersionIncompatibility() { @Override protected FormatterStep createFormatterStep(int indent, Provisioner provisioner) { - return GsonStep.create(indent, false, false, DEFAULT_VERSION, provisioner); + return GsonStep.create(new GsonConfig(false, false, indent, DEFAULT_VERSION), provisioner); } } From f3481bee7c5f03ad450c2f7a875a204c594ef66f Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sun, 22 Jan 2023 14:37:14 +0100 Subject: [PATCH 0340/1120] apply format --- lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 58993017fa..03baec5104 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -52,7 +52,7 @@ FormatterFunc toFormatter() { Constructor constructor = formatterFunc.getConstructor(GsonConfig.class); return (FormatterFunc) constructor.newInstance(gsonConfig); } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException - | InstantiationException | IllegalAccessException | NoClassDefFoundError cause) { + | InstantiationException | IllegalAccessException | NoClassDefFoundError cause) { throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause); } } From 85d727e19a149fec2144e40fbe3c656ca83df0e2 Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Sun, 22 Jan 2023 14:55:19 +0100 Subject: [PATCH 0341/1120] update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 07b81a8fc5..32c7a7f5a5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Rename `YamlJacksonStep` into `JacksonYamlStep` while normalizing Jackson usage ([#1492](https://github.com/diffplug/spotless/pull/1492)) +* Convert `gson` integration to use a compile-only source set ([#1510](https://github.com/diffplug/spotless/pull/1510)). ## [2.32.0] - 2023-01-13 ### Added From bba246d883a3ad9847d75c4379b7e8b9be1f1907 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 20 Jan 2023 22:00:22 +0100 Subject: [PATCH 0342/1120] 1416: use process runner to catch output --- .../com/diffplug/spotless/ProcessRunner.java | 146 ++++++++++++++++-- .../com/diffplug/spotless/npm/NpmProcess.java | 34 ++-- 2 files changed, 153 insertions(+), 27 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 41c664cafe..4c076e537c 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -15,6 +15,8 @@ */ package com.diffplug.spotless; +import static java.util.Objects.requireNonNull; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -29,9 +31,12 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; -import edu.umd.cs.findbugs.annotations.Nullable; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; /** @@ -95,6 +100,36 @@ public Result exec(@Nullable byte[] stdin, List args) throws IOException /** Creates a process with the given arguments, the given byte array is written to stdin immediately. */ public Result exec(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, List args) throws IOException, InterruptedException { + LongRunningProcess process = start(cwd, environment, stdin, args); + try { + // wait for the process to finish + process.waitFor(); + // collect the output + return process.result(); + } catch (ExecutionException e) { + throw ThrowingEx.asRuntime(e); + } + } + + /** + * Creates a process with the given arguments, the given byte array is written to stdin immediately. + *
+ * Delegates to {@link #start(File, Map, byte[], boolean, List)} with {@code false} for {@code redirectErrorStream}. + */ + public LongRunningProcess start(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, List args) throws IOException { + return start(cwd, environment, stdin, false, args); + } + + /** + * Creates a process with the given arguments, the given byte array is written to stdin immediately. + *
+ * The process is not waited for, so the caller is responsible for calling {@link LongRunningProcess#waitFor()} (if needed). + *
+ * To dispose this {@code ProcessRunner} instance, either call {@link #close()} or {@link LongRunningProcess#close()}. After + * {@link #close()} or {@link LongRunningProcess#close()} has been called, this {@code ProcessRunner} instance must not be used anymore. + */ + public LongRunningProcess start(@Nullable File cwd, @Nullable Map environment, @Nullable byte[] stdin, boolean redirectErrorStream, List args) throws IOException { + checkState(); ProcessBuilder builder = new ProcessBuilder(args); if (cwd != null) { builder.directory(cwd); @@ -105,20 +140,20 @@ public Result exec(@Nullable File cwd, @Nullable Map environment if (stdin == null) { stdin = new byte[0]; } + if (redirectErrorStream) { + builder.redirectErrorStream(true); + } + Process process = builder.start(); Future outputFut = threadStdOut.submit(() -> drainToBytes(process.getInputStream(), bufStdOut)); - Future errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr)); + Future errorFut = null; + if (!redirectErrorStream) { + errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr)); + } // write stdin process.getOutputStream().write(stdin); process.getOutputStream().close(); - // wait for the process to finish - int exitCode = process.waitFor(); - try { - // collect the output - return new Result(args, exitCode, outputFut.get(), errorFut.get()); - } catch (ExecutionException e) { - throw ThrowingEx.asRuntime(e); - } + return new LongRunningProcess(process, args, outputFut, errorFut); } private static void drain(InputStream input, OutputStream output) throws IOException { @@ -141,17 +176,24 @@ public void close() { threadStdErr.shutdown(); } + /** Checks if this {@code ProcessRunner} instance is still usable. */ + private void checkState() { + if (threadStdOut.isShutdown() || threadStdErr.isShutdown()) { + throw new IllegalStateException("ProcessRunner has been closed and must not be used anymore."); + } + } + @SuppressFBWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"}) public static class Result { private final List args; private final int exitCode; private final byte[] stdOut, stdErr; - public Result(List args, int exitCode, byte[] stdOut, byte[] stdErr) { + public Result(@Nonnull List args, int exitCode, @Nonnull byte[] stdOut, @Nullable byte[] stdErr) { this.args = args; this.exitCode = exitCode; this.stdOut = stdOut; - this.stdErr = stdErr; + this.stdErr = (stdErr == null ? new byte[0] : stdErr); } public List args() { @@ -222,8 +264,86 @@ public String toString() { } }; perStream.accept(" stdout", stdOut); - perStream.accept(" stderr", stdErr); + if (stdErr.length > 0) { + perStream.accept(" stderr", stdErr); + } return builder.toString(); } } + + /** + * A long-running process that can be waited for. + */ + public class LongRunningProcess extends Process implements AutoCloseable { + + private final Process delegate; + private final List args; + private final Future outputFut; + private final Future errorFut; + + public LongRunningProcess(@Nonnull Process delegate, @Nonnull List args, @Nonnull Future outputFut, @Nullable Future errorFut) { + this.delegate = requireNonNull(delegate); + this.args = args; + this.outputFut = outputFut; + this.errorFut = errorFut; + } + + @Override + public OutputStream getOutputStream() { + return delegate.getOutputStream(); + } + + @Override + public InputStream getInputStream() { + return delegate.getInputStream(); + } + + @Override + public InputStream getErrorStream() { + return delegate.getErrorStream(); + } + + @Override + public int waitFor() throws InterruptedException { + return delegate.waitFor(); + } + + @Override + public boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException { + return delegate.waitFor(timeout, unit); + } + + @Override + public int exitValue() { + return delegate.exitValue(); + } + + @Override + public void destroy() { + delegate.destroy(); + } + + @Override + public Process destroyForcibly() { + return delegate.destroyForcibly(); + } + + @Override + public boolean isAlive() { + return delegate.isAlive(); + } + + public Result result() throws ExecutionException, InterruptedException { + int exitCode = waitFor(); + return new Result(args, exitCode, this.outputFut.get(), (this.errorFut != null ? this.errorFut.get() : null)); + } + + @Override + public void close() { + if (isAlive()) { + destroy(); + } + ProcessRunner.this.close(); + } + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index 1675a4aa4e..b622cbd8ba 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -19,9 +19,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; +import com.diffplug.spotless.ProcessRunner; +import com.diffplug.spotless.ProcessRunner.LongRunningProcess; + class NpmProcess { private final File workingDir; @@ -30,10 +36,13 @@ class NpmProcess { private final File nodeExecutable; + private final ProcessRunner processRunner; + NpmProcess(File workingDir, File npmExecutable, File nodeExecutable) { this.workingDir = workingDir; this.npmExecutable = npmExecutable; this.nodeExecutable = nodeExecutable; + processRunner = new ProcessRunner(); } void install() { @@ -44,32 +53,27 @@ void install() { "--prefer-offline"); } - Process start() { + LongRunningProcess start() { // adding --scripts-prepend-node-path=true due to https://github.com/diffplug/spotless/issues/619#issuecomment-648018679 return npm("start", "--scripts-prepend-node-path=true"); } private void npmAwait(String... args) { - final Process npmProcess = npm(args); - - try { + try (LongRunningProcess npmProcess = npm(args)) { if (npmProcess.waitFor() != 0) { - throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed with exit code: " + npmProcess.exitValue()); + throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed with exit code: " + npmProcess.exitValue() + "\n\n" + npmProcess.result()); } } catch (InterruptedException e) { throw new NpmProcessException("Running npm command '" + commandLine(args) + "' was interrupted.", e); + } catch (ExecutionException e) { + throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed.", e); } } - private Process npm(String... args) { + private LongRunningProcess npm(String... args) { List processCommand = processCommand(args); try { - ProcessBuilder processBuilder = new ProcessBuilder() - .inheritIO() - .directory(this.workingDir) - .command(processCommand); - addEnvironmentVariables(processBuilder); - return processBuilder.start(); + return processRunner.start(this.workingDir, environmentVariables(), null, true, processCommand); } catch (IOException e) { throw new NpmProcessException("Failed to launch npm command '" + commandLine(args) + "'.", e); } @@ -82,8 +86,10 @@ private List processCommand(String... args) { return command; } - private void addEnvironmentVariables(ProcessBuilder processBuilder) { - processBuilder.environment().put("PATH", this.nodeExecutable.getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); + private Map environmentVariables() { + Map environmentVariables = new HashMap<>(); + environmentVariables.put("PATH", this.nodeExecutable.getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); + return environmentVariables; } private String commandLine(String... args) { From 1c285ecfcd321c0ba37c2ca5d993566e2ce15398 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 20 Jan 2023 23:04:26 +0100 Subject: [PATCH 0343/1120] 1416: suggest prettier plugins --- .../spotless/npm/PrettierFormatterStep.java | 10 +- .../npm/PrettierMissingParserException.java | 116 ++++++++++++++++++ .../spotless/PrettierIntegrationTest.java | 23 ++++ 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 20ff71d08e..22dd4586ee 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -122,7 +122,14 @@ public String applyWithFile(String unix, File file) throws Exception { FormattedPrinter.SYSOUT.print("formatting String '" + unix.substring(0, Math.min(50, unix.length())) + "[...]' in file '" + file + "'"); final String prettierConfigOptionsWithFilepath = assertFilepathInConfigOptions(file); - return restService.format(unix, prettierConfigOptionsWithFilepath); + try { + return restService.format(unix, prettierConfigOptionsWithFilepath); + } catch (SimpleRestClient.SimpleRestResponseException e) { + if (e.getStatusCode() != 200 && e.getResponseMessage().contains("No parser could be inferred")) { + throw new PrettierMissingParserException(file, e); + } + throw e; + } } private String assertFilepathInConfigOptions(File file) { @@ -141,4 +148,5 @@ private String assertFilepathInConfigOptions(File file) { return "{" + filePathOption + (hasAnyConfigOption ? "," : "") + prettierConfigOptions.substring(startOfConfigOption + 1); } } + } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java new file mode 100644 index 0000000000..73f81a0e07 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java @@ -0,0 +1,116 @@ +/* + * 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.npm; + +import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +import javax.annotation.Nonnull; + +class PrettierMissingParserException extends RuntimeException { + private static final long serialVersionUID = 1L; + + private static final Map EXTENSIONS_TO_PLUGINS; + + static { + Map plugins = new HashMap<>(); + // ---- official plugins + plugins.put(".php", "@prettier/plugin-php"); + plugins.put(".pug", "@prettier/plugin-pug"); + plugins.put(".rb", "@prettier/plugin-ruby"); + plugins.put(".xml", "@prettier/plugin-xml"); + + // ---- community plugins + // default namings: astro, elm, java, jsonata, prisma, properties, sh, sql, svelte, toml + plugins.put(".trigger", "prettier-plugin-apex"); + plugins.put(".cls", "prettier-plugin-apex"); + plugins.put(".html.erb", "prettier-plugin-erb"); + Arrays.asList(".glsl", + ".fp", + ".frag", + ".frg", + ".fs", + ".fsh", + ".fshader", + ".geo", + ".geom", + ".glslf", + ".glslv", + ".gs", + ".gshader", + ".rchit", + ".rmiss", + ".shader", + ".tesc", + ".tese", + ".vert", + ".vrx", + ".vsh", + ".vshader").forEach(ext -> plugins.put(ext, "prettier-plugin-glsl")); + Arrays.asList(".go.html", + ".gohtml", + ".gotmpl", + ".go.tmpl", + ".tmpl", + ".tpl", + ".html.tmpl", + ".html.tpl").forEach(ext -> plugins.put(ext, "prettier-plugin-go-template")); + plugins.put(".kt", "kotlin"); + plugins.put(".mo", "motoko"); + Arrays.asList(".nginx", ".nginxconf").forEach(ext -> plugins.put(ext, "prettier-plugin-nginx")); + plugins.put(".sol", "prettier-plugin-solidity"); + + EXTENSIONS_TO_PLUGINS = Collections.unmodifiableMap(plugins); + } + + private final File file; + + public PrettierMissingParserException(@Nonnull File file, Exception cause) { + super("Prettier could not infer a parser for file '" + file + "'. Maybe you need to include a prettier plugin in devDependencies?\n\n" + recommendPlugin(file), cause); + this.file = Objects.requireNonNull(file); + } + + private static String recommendPlugin(File file) { + String pluginName = guessPlugin(file); + return "A good candidate for file '" + file + "' is '" + pluginName + "\n" + + "See if you can find it on \n" + + "or search on npmjs.com for a plugin matching that name: " + + String.format("\n\n", pluginName) + + "For instructions on how to include plugins for prettier in spotless see our documentation:\n" + + "- for gradle \n" + + "- for maven "; + } + + private static String guessPlugin(File file) { + return EXTENSIONS_TO_PLUGINS.entrySet().stream() + .filter(entry -> file.getName().endsWith(entry.getKey())) + .findFirst() + .map(entry -> entry.getValue()) + .orElse("prettier-plugin-" + extension(file)); + } + + public String fileType() { + return extension(file); + } + + private static String extension(File file) { + return file.getName().substring(file.getName().lastIndexOf('.') + 1); + } +} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index bc8ad1148e..4c458e3ca7 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -135,6 +135,29 @@ void useJavaCommunityPlugin() throws IOException { assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); } + @Test + void suggestsMissingJavaCommunityPlugin() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "def prettierConfig = [:]", + "prettierConfig['tabWidth'] = 4", + "def prettierPackages = [:]", + "prettierPackages['prettier'] = '2.0.5'", + "spotless {", + " format 'java', {", + " target 'JavaTest.java'", + " prettier(prettierPackages).config(prettierConfig)", + " }", + "}"); + setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + Assertions.assertThat(spotlessApply.getOutput()).contains("could not infer a parser"); + Assertions.assertThat(spotlessApply.getOutput()).contains("prettier-plugin-java"); + } + @Test void usePhpCommunityPlugin() throws IOException { setFile("build.gradle").toLines( From 32eee78c9ed3dfc542213f5a72fdfde2503c005c Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 22 Jan 2023 21:15:32 +0100 Subject: [PATCH 0344/1120] 1416: limit output fetched by npm process usually only the last few lines are of interest anyway, so be kind to memory usage. --- ...mitedOverwritingByteArrayOutputStream.java | 132 +++++++++++++ .../com/diffplug/spotless/ProcessRunner.java | 13 +- .../com/diffplug/spotless/npm/NpmProcess.java | 2 +- ...dOverwritingByteArrayOutputStreamTest.java | 179 ++++++++++++++++++ 4 files changed, 322 insertions(+), 4 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java create mode 100644 lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java b/lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java new file mode 100644 index 0000000000..a76039fccd --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java @@ -0,0 +1,132 @@ +/* + * 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; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; + +public class LimitedOverwritingByteArrayOutputStream extends ByteArrayOutputStream { + + private final int limit; + + private int zeroIndexPointer = 0; + + private boolean isOverLimit = false; + + public LimitedOverwritingByteArrayOutputStream(int limit) { + this(limit, 32); + } + + public LimitedOverwritingByteArrayOutputStream(int limit, int initialCapacity) { + super(initialCapacity); + if (limit < initialCapacity) { + throw new IllegalArgumentException("Limit must be greater than initial capacity"); + } + if (limit < 0) { + throw new IllegalArgumentException("Limit must be greater than 0"); + } + if (limit % 2 != 0) { + throw new IllegalArgumentException("Limit must be even"); // to fit 16 bit unicode chars + } + this.limit = limit; + } + + // ---- writing + @Override + public synchronized void write(int b) { + if (count < limit) { + super.write(b); + return; + } + isOverLimit = true; + buf[zeroIndexPointer] = (byte) b; + zeroIndexPointer = (zeroIndexPointer + 1) % limit; + } + + @Override + public synchronized void write(byte[] b, int off, int len) { + int remaining = limit - count; + if (remaining >= len) { + super.write(b, off, len); + return; + } + if (remaining > 0) { + // write what we can "normally" + super.write(b, off, remaining); + // rest delegated + write(b, off + remaining, len - remaining); + return; + } + // we are over the limit + isOverLimit = true; + // write till limit is reached + int writeTillLimit = Math.min(len, limit - zeroIndexPointer); + System.arraycopy(b, off, buf, zeroIndexPointer, writeTillLimit); + zeroIndexPointer = (zeroIndexPointer + writeTillLimit) % limit; + if (writeTillLimit < len) { + // write rest + write(b, off + writeTillLimit, len - writeTillLimit); + } + } + + @Override + public synchronized void reset() { + super.reset(); + zeroIndexPointer = 0; + isOverLimit = false; + } + + // ---- output + @Override + public synchronized void writeTo(OutputStream out) throws IOException { + if (!isOverLimit) { + super.writeTo(out); + return; + } + out.write(buf, zeroIndexPointer, limit - zeroIndexPointer); + out.write(buf, 0, zeroIndexPointer); + } + + @Override + public synchronized byte[] toByteArray() { + if (!isOverLimit) { + return super.toByteArray(); + } + byte[] result = new byte[limit]; + System.arraycopy(buf, zeroIndexPointer, result, 0, limit - zeroIndexPointer); + System.arraycopy(buf, 0, result, limit - zeroIndexPointer, zeroIndexPointer); + return result; + } + + @Override + public synchronized String toString() { + if (!isOverLimit) { + return super.toString(); + } + return new String(buf, zeroIndexPointer, limit - zeroIndexPointer) + new String(buf, 0, zeroIndexPointer); + } + + @Override + public synchronized String toString(String charsetName) throws UnsupportedEncodingException { + if (!isOverLimit) { + return super.toString(charsetName); + } + return new String(buf, zeroIndexPointer, limit - zeroIndexPointer, charsetName) + new String(buf, 0, zeroIndexPointer, charsetName); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 4c076e537c..0979c4cbd4 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -52,10 +52,17 @@ public class ProcessRunner implements AutoCloseable { private final ExecutorService threadStdOut = Executors.newSingleThreadExecutor(); private final ExecutorService threadStdErr = Executors.newSingleThreadExecutor(); - private final ByteArrayOutputStream bufStdOut = new ByteArrayOutputStream(); - private final ByteArrayOutputStream bufStdErr = new ByteArrayOutputStream(); + private final ByteArrayOutputStream bufStdOut; + private final ByteArrayOutputStream bufStdErr; - public ProcessRunner() {} + public ProcessRunner() { + this(-1); + } + + public ProcessRunner(int limitedBuffers) { + this.bufStdOut = limitedBuffers >= 0 ? new LimitedOverwritingByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); + this.bufStdErr = limitedBuffers >= 0 ? new LimitedOverwritingByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); + } /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ public Result shell(String cmd) throws IOException, InterruptedException { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index b622cbd8ba..f97193745d 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -42,7 +42,7 @@ class NpmProcess { this.workingDir = workingDir; this.npmExecutable = npmExecutable; this.nodeExecutable = nodeExecutable; - processRunner = new ProcessRunner(); + processRunner = new ProcessRunner(100 * 1024); // 100kB } void install() { diff --git a/lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java b/lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java new file mode 100644 index 0000000000..63998a4d75 --- /dev/null +++ b/lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java @@ -0,0 +1,179 @@ +/* + * 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; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.stream.Stream; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class LimitedOverwritingByteArrayOutputStreamTest { + + private final byte[] bytes = new byte[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toStringBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toString()).isEqualTo("0123456789"); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toStringBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toString()).hasSize(4); + Assertions.assertThat(stream.toString()).isEqualTo("6789"); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toStringBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toString()).isEqualTo("0123456789"); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toByteArrayBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toByteArray()).isEqualTo(bytes); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toByteArrayBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toByteArray()).hasSize(4); + Assertions.assertThat(stream.toByteArray()).isEqualTo(new byte[]{'6', '7', '8', '9'}); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void toByteArrayBehavesOverwritingAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + writeStrategy.write(stream, bytes); + Assertions.assertThat(stream.toByteArray()).isEqualTo(bytes); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void writeToBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + writeStrategy.write(stream, bytes); + ByteArrayOutputStream target = new ByteArrayOutputStream(); + stream.writeTo(target); + Assertions.assertThat(target.toByteArray()).isEqualTo(bytes); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void writeToBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + writeStrategy.write(stream, bytes); + ByteArrayOutputStream target = new ByteArrayOutputStream(); + stream.writeTo(target); + Assertions.assertThat(target.toByteArray()).hasSize(4); + Assertions.assertThat(target.toByteArray()).isEqualTo(new byte[]{'6', '7', '8', '9'}); + } + + @ParameterizedTest(name = "{index} writeStrategy: {0}") + @MethodSource("writeStrategies") + void writeToBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + writeStrategy.write(stream, bytes); + ByteArrayOutputStream target = new ByteArrayOutputStream(); + stream.writeTo(target); + Assertions.assertThat(target.toByteArray()).isEqualTo(bytes); + } + + @Test + void writeToBehavesCorrectlyWhenOverLimitMultipleCalls() { + // this test explicitly captures a border case where the buffer is not empty but can exactly fit what we are writing + LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(2, 1); + stream.write('0'); + stream.write(new byte[]{'1', '2'}, 0, 2); + Assertions.assertThat(stream.toString()).hasSize(2); + Assertions.assertThat(stream.toString()).isEqualTo("12"); + } + + private static Stream writeStrategies() { + return Stream.of( + Arguments.of("writeAllAtOnce", allAtOnce()), + Arguments.of("writeOneByteAtATime", oneByteAtATime()), + Arguments.of("writeTwoBytesAtATime", twoBytesAtATime()), + Arguments.of("writeOneAndThenTwoBytesAtATime", oneAndThenTwoBytesAtATime()), + Arguments.of("firstFourBytesAndThenTheRest", firstFourBytesAndThenTheRest())); + } + + private static ByteWriteStrategy allAtOnce() { + return (stream, bytes) -> stream.write(bytes, 0, bytes.length); + } + + private static ByteWriteStrategy oneByteAtATime() { + return (stream, bytes) -> { + for (byte b : bytes) { + stream.write(b); + } + }; + } + + private static ByteWriteStrategy twoBytesAtATime() { + return (stream, bytes) -> { + for (int i = 0; i < bytes.length; i += 2) { + stream.write(bytes, i, 2); + } + }; + } + + private static ByteWriteStrategy oneAndThenTwoBytesAtATime() { + return (stream, bytes) -> { + int written = 0; + for (int i = 0; i + 3 < bytes.length; i += 3) { + stream.write(bytes, i, 1); + stream.write(bytes, i + 1, 2); + written += 3; + } + if (written < bytes.length) { + stream.write(bytes, written, bytes.length - written); + } + + }; + } + + private static ByteWriteStrategy firstFourBytesAndThenTheRest() { + return (stream, bytes) -> { + stream.write(bytes, 0, 4); + stream.write(bytes, 4, bytes.length - 4); + }; + } + + @FunctionalInterface + private interface ByteWriteStrategy { + void write(LimitedOverwritingByteArrayOutputStream stream, byte[] bytes); + } + +} From 8b56d5dafa4af82b6c327121df14ad0612e6494d Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 22 Jan 2023 21:24:24 +0100 Subject: [PATCH 0345/1120] 1416: document changes --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 07b81a8fc5..f5882e5d99 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) +* `ProcessRunner` allows to limit captured output to a certain number of bytes. ([#1511](https://github.com/diffplug/spotless/pull/1511)) +* `ProcessRunner` is now capable of handling long-running tasks where waiting for exit is delegated to the caller. ([#1511](https://github.com/diffplug/spotless/pull/1511)) * Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cac247a307..f8a6242adf 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +* Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) + ## [6.13.0] - 2023-01-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ecb67f231f..f1ab739b62 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -13,6 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) +* Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) + ## [2.30.0] - 2023-01-13 ### Added From 2c54ee976245a486572c1b728b5f1dd8db1d06e3 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 23 Jan 2023 08:59:28 +0100 Subject: [PATCH 0346/1120] 1416: Integrate PR Feedback --- .../com/diffplug/spotless/ProcessRunner.java | 10 +++++--- ...a => RingBufferByteArrayOutputStream.java} | 14 +++++------ .../com/diffplug/spotless/npm/NpmProcess.java | 2 +- ... RingBufferByteArrayOutputStreamTest.java} | 24 +++++++++---------- 4 files changed, 27 insertions(+), 23 deletions(-) rename lib/src/main/java/com/diffplug/spotless/{LimitedOverwritingByteArrayOutputStream.java => RingBufferByteArrayOutputStream.java} (88%) rename lib/src/test/java/com/diffplug/spotless/{LimitedOverwritingByteArrayOutputStreamTest.java => RingBufferByteArrayOutputStreamTest.java} (83%) diff --git a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java index 0979c4cbd4..4e48042184 100644 --- a/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java +++ b/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java @@ -59,9 +59,13 @@ public ProcessRunner() { this(-1); } - public ProcessRunner(int limitedBuffers) { - this.bufStdOut = limitedBuffers >= 0 ? new LimitedOverwritingByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); - this.bufStdErr = limitedBuffers >= 0 ? new LimitedOverwritingByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); + public static ProcessRunner usingRingBuffersOfCapacity(int limit) { + return new ProcessRunner(limit); + } + + private ProcessRunner(int limitedBuffers) { + this.bufStdOut = limitedBuffers >= 0 ? new RingBufferByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); + this.bufStdErr = limitedBuffers >= 0 ? new RingBufferByteArrayOutputStream(limitedBuffers) : new ByteArrayOutputStream(); } /** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */ diff --git a/lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java b/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java similarity index 88% rename from lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java rename to lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java index a76039fccd..0353b50846 100644 --- a/lib/src/main/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStream.java +++ b/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java @@ -20,7 +20,7 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; -public class LimitedOverwritingByteArrayOutputStream extends ByteArrayOutputStream { +class RingBufferByteArrayOutputStream extends ByteArrayOutputStream { private final int limit; @@ -28,20 +28,20 @@ public class LimitedOverwritingByteArrayOutputStream extends ByteArrayOutputStre private boolean isOverLimit = false; - public LimitedOverwritingByteArrayOutputStream(int limit) { + public RingBufferByteArrayOutputStream(int limit) { this(limit, 32); } - public LimitedOverwritingByteArrayOutputStream(int limit, int initialCapacity) { + public RingBufferByteArrayOutputStream(int limit, int initialCapacity) { super(initialCapacity); if (limit < initialCapacity) { - throw new IllegalArgumentException("Limit must be greater than initial capacity"); + throw new IllegalArgumentException("Limit must be greater than initial capacity. Limit: " + limit + ", initial capacity: " + initialCapacity); } - if (limit < 0) { - throw new IllegalArgumentException("Limit must be greater than 0"); + if (limit < 2) { + throw new IllegalArgumentException("Limit must be greater than or equal to 2 but is " + limit); } if (limit % 2 != 0) { - throw new IllegalArgumentException("Limit must be even"); // to fit 16 bit unicode chars + throw new IllegalArgumentException("Limit must be an even number but is " + limit); // to fit 16 bit unicode chars } this.limit = limit; } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index f97193745d..6384900d82 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -42,7 +42,7 @@ class NpmProcess { this.workingDir = workingDir; this.npmExecutable = npmExecutable; this.nodeExecutable = nodeExecutable; - processRunner = new ProcessRunner(100 * 1024); // 100kB + processRunner = ProcessRunner.usingRingBuffersOfCapacity(100 * 1024); // 100kB } void install() { diff --git a/lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java b/lib/src/test/java/com/diffplug/spotless/RingBufferByteArrayOutputStreamTest.java similarity index 83% rename from lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java rename to lib/src/test/java/com/diffplug/spotless/RingBufferByteArrayOutputStreamTest.java index 63998a4d75..94fa49dbc1 100644 --- a/lib/src/test/java/com/diffplug/spotless/LimitedOverwritingByteArrayOutputStreamTest.java +++ b/lib/src/test/java/com/diffplug/spotless/RingBufferByteArrayOutputStreamTest.java @@ -25,14 +25,14 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -class LimitedOverwritingByteArrayOutputStreamTest { +class RingBufferByteArrayOutputStreamTest { private final byte[] bytes = new byte[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toStringBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(12, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toString()).isEqualTo("0123456789"); } @@ -40,7 +40,7 @@ void toStringBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStra @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toStringBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(4, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toString()).hasSize(4); Assertions.assertThat(stream.toString()).isEqualTo("6789"); @@ -49,7 +49,7 @@ void toStringBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStr @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toStringBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(bytes.length, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toString()).isEqualTo("0123456789"); } @@ -57,7 +57,7 @@ void toStringBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeS @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toByteArrayBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(12, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toByteArray()).isEqualTo(bytes); } @@ -65,7 +65,7 @@ void toByteArrayBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeS @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toByteArrayBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(4, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toByteArray()).hasSize(4); Assertions.assertThat(stream.toByteArray()).isEqualTo(new byte[]{'6', '7', '8', '9'}); @@ -74,7 +74,7 @@ void toByteArrayBehavesOverwritingOverLimit(String name, ByteWriteStrategy write @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void toByteArrayBehavesOverwritingAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(bytes.length, 1); writeStrategy.write(stream, bytes); Assertions.assertThat(stream.toByteArray()).isEqualTo(bytes); } @@ -82,7 +82,7 @@ void toByteArrayBehavesOverwritingAtExactlyLimit(String name, ByteWriteStrategy @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void writeToBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(12, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(12, 1); writeStrategy.write(stream, bytes); ByteArrayOutputStream target = new ByteArrayOutputStream(); stream.writeTo(target); @@ -92,7 +92,7 @@ void writeToBehavesNormallyWithinLimit(String name, ByteWriteStrategy writeStrat @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void writeToBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(4, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(4, 1); writeStrategy.write(stream, bytes); ByteArrayOutputStream target = new ByteArrayOutputStream(); stream.writeTo(target); @@ -103,7 +103,7 @@ void writeToBehavesOverwritingOverLimit(String name, ByteWriteStrategy writeStra @ParameterizedTest(name = "{index} writeStrategy: {0}") @MethodSource("writeStrategies") void writeToBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeStrategy) throws IOException { - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(bytes.length, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(bytes.length, 1); writeStrategy.write(stream, bytes); ByteArrayOutputStream target = new ByteArrayOutputStream(); stream.writeTo(target); @@ -113,7 +113,7 @@ void writeToBehavesNormallyAtExactlyLimit(String name, ByteWriteStrategy writeSt @Test void writeToBehavesCorrectlyWhenOverLimitMultipleCalls() { // this test explicitly captures a border case where the buffer is not empty but can exactly fit what we are writing - LimitedOverwritingByteArrayOutputStream stream = new LimitedOverwritingByteArrayOutputStream(2, 1); + RingBufferByteArrayOutputStream stream = new RingBufferByteArrayOutputStream(2, 1); stream.write('0'); stream.write(new byte[]{'1', '2'}, 0, 2); Assertions.assertThat(stream.toString()).hasSize(2); @@ -173,7 +173,7 @@ private static ByteWriteStrategy firstFourBytesAndThenTheRest() { @FunctionalInterface private interface ByteWriteStrategy { - void write(LimitedOverwritingByteArrayOutputStream stream, byte[] bytes); + void write(RingBufferByteArrayOutputStream stream, byte[] bytes); } } From c0cd99ddc2cdf630423cc4c38b7a0b97dec225ea Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 23 Jan 2023 09:10:30 +0100 Subject: [PATCH 0347/1120] 1416: spotbugs adaptions --- .../com/diffplug/spotless/RingBufferByteArrayOutputStream.java | 3 +++ .../diffplug/spotless/npm/PrettierMissingParserException.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java b/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java index 0353b50846..da4fc6aa04 100644 --- a/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java +++ b/lib/src/main/java/com/diffplug/spotless/RingBufferByteArrayOutputStream.java @@ -20,6 +20,8 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + class RingBufferByteArrayOutputStream extends ByteArrayOutputStream { private final int limit; @@ -113,6 +115,7 @@ public synchronized byte[] toByteArray() { return result; } + @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "We want to use the default encoding here since this is contract on ByteArrayOutputStream") @Override public synchronized String toString() { if (!isOverLimit) { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java index 73f81a0e07..6956545135 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java @@ -92,7 +92,8 @@ private static String recommendPlugin(File file) { return "A good candidate for file '" + file + "' is '" + pluginName + "\n" + "See if you can find it on \n" + "or search on npmjs.com for a plugin matching that name: " - + String.format("\n\n", pluginName) + + String.format("", pluginName) + + "\n\n" + "For instructions on how to include plugins for prettier in spotless see our documentation:\n" + "- for gradle \n" + "- for maven "; From 4aa3b7e0f460eaa7a7c329a7868e71060151c95b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 12:13:01 -0800 Subject: [PATCH 0348/1120] Run spotbugs in all configurations because it's not that slow (17 seconds on my M1) and it's confusing to PR authors to not run. --- gradle/java-setup.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 9c9f394405..f8f2dedf39 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -34,8 +34,6 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { } tasks.named('spotbugsMain') { - // only run on Java 8 (no benefit to running twice) - enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11 reports { html.enabled = true } From c849de8a376989005235263e5172fb7141218499 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 15:59:14 -0800 Subject: [PATCH 0349/1120] Revert previous commit b/c spotbugs gives errant warnings on Java 8. --- gradle/java-setup.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index f8f2dedf39..9c9f394405 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -34,6 +34,8 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { } tasks.named('spotbugsMain') { + // only run on Java 8 (no benefit to running twice) + enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11 reports { html.enabled = true } From 0b2a3295487b43d13f2cc6ab5e058c751588cc9b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 16:58:29 -0800 Subject: [PATCH 0350/1120] Stop running CI on java 8. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f08c201f5..e78061fc4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,19 +37,19 @@ jobs: fail-fast: false matrix: kind: [maven, gradle] - jre: [8, 11, 17] + jre: [11, 17] os: [ubuntu-latest] include: # test windows at the diagonals of the above matrix - kind: maven - jre: 8 + jre: 11 os: windows-latest - kind: gradle jre: 17 os: windows-latest # npm on linux only (crazy slow on windows) - kind: npm - jre: 8 + jre: 11 os: ubuntu-latest runs-on: ${{ matrix.os }} steps: From 826760dbad1912590068c5b6ea0c3c7bb9c4250b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 16:58:53 -0800 Subject: [PATCH 0351/1120] Run spotbugs on all supported JRE because it's not that slow (17 seconds on my M1) and it's confusing to PR authors to not run. --- gradle/java-setup.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 9c9f394405..f8f2dedf39 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -34,8 +34,6 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { } tasks.named('spotbugsMain') { - // only run on Java 8 (no benefit to running twice) - enabled = org.gradle.api.JavaVersion.current() == org.gradle.api.JavaVersion.VERSION_11 reports { html.enabled = true } From 1c5a3ef960f1e55f72be0c39c5803e69e23c2291 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 16:59:40 -0800 Subject: [PATCH 0352/1120] Remove `@EnabledForJreRange(min = JAVA_11)` since we don't support < Java 11 anymore anyway. --- .../extra/java/EclipseJdtFormatterStepTest.java | 7 ++----- .../gradle/spotless/KotlinExtensionTest.java | 13 ------------- .../gradle/spotless/KotlinGradleExtensionTest.java | 6 +----- .../spotless/maven/java/GoogleJavaFormatTest.java | 6 +----- .../spotless/maven/java/PalantirJavaFormatTest.java | 6 +----- .../diffplug/spotless/maven/kotlin/KtfmtTest.java | 6 +----- .../spotless/java/GoogleJavaFormatStepTest.java | 6 ++---- .../spotless/java/PalantirJavaFormatStepTest.java | 4 +--- .../com/diffplug/spotless/kotlin/KtfmtStepTest.java | 8 +------- 9 files changed, 10 insertions(+), 52 deletions(-) diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java index 3e5e1853c7..2ade78f742 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.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. @@ -15,14 +15,11 @@ */ package com.diffplug.spotless.extra.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import java.io.File; import java.util.stream.Stream; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -57,7 +54,7 @@ private static Stream formatWithVersion() { /** New format interface requires source file information to distinguish module-info from compilation unit */ @Nested - @EnabledForJreRange(min = JAVA_11) + class NewFormatInterface extends EclipseResourceHarness { public NewFormatInterface() throws Exception { super(createBuilder(), "module-info.java", getTestResource("java/eclipse/ModuleInfoUnformatted.test"), getTestResource("java/eclipse/ModuleInfoFormatted.test")); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index d77b22d0d3..a15a51412e 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -15,12 +15,9 @@ */ package com.diffplug.gradle.spotless; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import java.io.IOException; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; class KotlinExtensionTest extends GradleIntegrationHarness { private static final String HEADER = "// License Header"; @@ -63,7 +60,6 @@ void integrationDiktat() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integrationKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -82,7 +78,6 @@ void integrationKtfmt() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integrationKtfmt_dropboxStyle_0_18() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -101,7 +96,6 @@ void integrationKtfmt_dropboxStyle_0_18() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integrationKtfmt_dropboxStyle_0_19() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -197,7 +191,6 @@ void testWithHeader() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithHeaderKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -236,7 +229,6 @@ void testWithCustomHeaderSeparator() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomHeaderSeparatorKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -282,7 +274,6 @@ void testWithNonStandardYearSeparator() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithNonStandardYearSeparatorKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -309,7 +300,6 @@ void testWithNonStandardYearSeparatorKtfmt() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -331,7 +321,6 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomMaxWidthDefaultStyleKtfmtGradleKts() throws IOException { setFile("build.gradle.kts").toLines( "plugins {", @@ -353,7 +342,6 @@ void testWithCustomMaxWidthDefaultStyleKtfmtGradleKts() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomMaxWidthDropboxStyleKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -375,7 +363,6 @@ void testWithCustomMaxWidthDropboxStyleKtfmt() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void testWithCustomMaxWidthDropboxStyleKtfmtGradleKts() throws IOException { setFile("build.gradle.kts").toLines( "plugins {", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 0f3438ffff..015414c331 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -16,13 +16,11 @@ package com.diffplug.gradle.spotless; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; import java.io.IOException; import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; class KotlinGradleExtensionTest extends GradleIntegrationHarness { @Test @@ -151,7 +149,6 @@ void withExperimentalEditorConfigOverride() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integration_ktfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -170,7 +167,6 @@ void integration_ktfmt() throws IOException { } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void integration_ktfmt_with_dropbox_style() throws IOException { setFile("build.gradle").toLines( "plugins {", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java index 6fbff78cc7..98a83d612c 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.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. @@ -15,10 +15,7 @@ */ package com.diffplug.spotless.maven.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.maven.MavenIntegrationHarness; @@ -45,7 +42,6 @@ void specificVersionSpecificStyle() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11) void specificVersionReflowLongStrings() throws Exception { writePomWithJavaSteps( "", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java index 33ec8ea84f..d8d66fa46d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,7 @@ */ package com.diffplug.spotless.maven.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.maven.MavenIntegrationHarness; @@ -34,7 +31,6 @@ void specificVersionDefaultStyle() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11) void specificJava11Version2() throws Exception { writePomWithJavaSteps( "", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 88dcd172e0..4ae266cc23 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -15,14 +15,10 @@ */ package com.diffplug.spotless.maven.kotlin; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.maven.MavenIntegrationHarness; -@EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. class KtfmtTest extends MavenIntegrationHarness { @Test void testKtfmt() throws Exception { diff --git a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java index cf2a90ad79..ff64b574e1 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; import static org.junit.jupiter.api.condition.JRE.JAVA_13; import static org.junit.jupiter.api.condition.JRE.JAVA_15; @@ -42,7 +41,7 @@ void jvm13Features() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11, max = JAVA_15) // google-java-format requires JRE 11+ + @EnabledForJreRange(max = JAVA_15) // google-java-format requires JRE 11+ void behavior18() throws Exception { FormatterStep step = GoogleJavaFormatStep.create("1.8", TestProvisioner.mavenCentral()); StepHarness.forStep(step) @@ -125,7 +124,6 @@ protected FormatterStep create() { } @Test - @EnabledForJreRange(min = JAVA_11) // google-java-format requires JRE 11+ void equalityGroupArtifact() throws Exception { new SerializableEqualityTester() { String groupArtifact = GoogleJavaFormatStep.defaultGroupArtifact(); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java index ad358cafc6..dfd59c2655 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.java; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; import static org.junit.jupiter.api.condition.JRE.JAVA_13; import org.junit.jupiter.api.Test; @@ -38,7 +37,6 @@ void jvm13Features() throws Exception { } @Test - @EnabledForJreRange(min = JAVA_11) void behavior2() throws Exception { FormatterStep step = PalantirJavaFormatStep.create("2.28.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java index ddaf1b324b..bfa971fc40 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -15,32 +15,26 @@ */ package com.diffplug.spotless.kotlin; -import static org.junit.jupiter.api.condition.JRE.JAVA_11; - import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; import com.diffplug.spotless.*; @Disabled class KtfmtStepTest extends ResourceHarness { @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void behavior() throws Exception { FormatterStep step = KtfmtStep.create(TestProvisioner.mavenCentral()); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic.clean"); } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void dropboxStyle_0_18() throws Exception { FormatterStep step = KtfmtStep.create("0.18", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX, null); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic-dropboxstyle.clean"); } @Test - @EnabledForJreRange(min = JAVA_11) // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. void dropboxStyle_0_19() throws Exception { FormatterStep step = KtfmtStep.create("0.19", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX, null); StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic-dropboxstyle.clean"); From 14e71fb57d313726b0b11f9ece946001540d55cc Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 17:02:39 -0800 Subject: [PATCH 0353/1120] The maven and gradle plugins yell at their users to update to Java 11, and how to update without affecting their users. --- .../com/diffplug/gradle/spotless/SpotlessPlugin.java | 10 +++++++++- .../diffplug/spotless/maven/AbstractSpotlessMojo.java | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java index 868502d216..91847af0cf 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -16,21 +16,29 @@ package com.diffplug.gradle.spotless; import org.gradle.api.GradleException; +import org.gradle.api.JavaVersion; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.plugins.BasePlugin; +import com.diffplug.spotless.Jvm; import com.diffplug.spotless.SpotlessCache; public class SpotlessPlugin implements Plugin { static final String SPOTLESS_MODERN = "spotlessModern"; static final String MINIMUM_GRADLE = "6.1.1"; + private static final int MINIMUM_JRE = 11; @Override public void apply(Project project) { if (SpotlessPluginRedirect.gradleIsTooOld(project)) { throw new GradleException("Spotless requires Gradle " + MINIMUM_GRADLE + " or newer, this was " + project.getGradle().getGradleVersion()); } + if (Jvm.version() < MINIMUM_JRE) { + throw new GradleException("Spotless requires JRE " + MINIMUM_JRE + " or newer, this was " + JavaVersion.current() + ".\n" + + "You can upgrade your build JRE and still compile for older targets, see below\n" + + "https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation"); + } // if -PspotlessModern=true, then use the modern stuff instead of the legacy stuff if (project.hasProperty(SPOTLESS_MODERN)) { project.getLogger().warn("'spotlessModern' has no effect as of Spotless 5.0, recommend removing it."); 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 e594c724ef..c4082f52e0 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 @@ -53,6 +53,7 @@ import org.sonatype.plexus.build.incremental.BuildContext; import com.diffplug.spotless.Formatter; +import com.diffplug.spotless.Jvm; import com.diffplug.spotless.LineEnding; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.generic.LicenseHeaderStep; @@ -190,6 +191,16 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { protected abstract void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException; + private static final int MINIMUM_JRE = 11; + + protected AbstractSpotlessMojo() { + if (Jvm.version() < MINIMUM_JRE) { + throw new RuntimeException("Spotless requires JRE " + MINIMUM_JRE + " or newer, this was " + Jvm.version() + ".\n" + + "You can upgrade your build JRE and still compile for older targets, see below\n" + + "https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation"); + } + } + @Override public final void execute() throws MojoExecutionException { if (shouldSkip()) { From b0975be27dab83fb62012650a273662e193f648a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 23 Jan 2023 17:02:48 -0800 Subject: [PATCH 0354/1120] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f5882e5d99..4c6a1aa0c4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +* **POTENTIALLY BREAKING** Bump minimum JRE from 8 to 11, next release likely to bump bytecode to Java 11 ([#1514](https://github.com/diffplug/spotless/pull/1514) part 1 of [#1337](https://github.com/diffplug/spotless/issues/1337)) * Rename `YamlJacksonStep` into `JacksonYamlStep` while normalizing Jackson usage ([#1492](https://github.com/diffplug/spotless/pull/1492)) ## [2.32.0] - 2023-01-13 diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f8a6242adf..fa2119f8c5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,9 +10,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +* **POTENTIALLY BREAKING** Bump minimum JRE from 8 to 11 ([#1514](https://github.com/diffplug/spotless/pull/1514) part 1 of [#1337](https://github.com/diffplug/spotless/issues/1337)) + * You can bump your build JRE without bumping your requirements ([docs](https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation)). * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) - ## [6.13.0] - 2023-01-14 ### Added * **POTENTIALLY BREAKING** `ktlint` step now supports `.editorconfig` ([#1442](https://github.com/diffplug/spotless/pull/1442) implements [#142](https://github.com/diffplug/spotless/issues/142)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f1ab739b62..66ef83fb6f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -12,10 +12,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes +* **POTENTIALLY BREAKING** Bump minimum JRE from 8 to 11 ([#1514](https://github.com/diffplug/spotless/pull/1514) part 1 of [#1337](https://github.com/diffplug/spotless/issues/1337)) + * You can bump your build JRE without bumping your requirements ([docs](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html)). * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) - ## [2.30.0] - 2023-01-13 ### Added * Add option `editorConfigFile` for `ktLint` [#142](https://github.com/diffplug/spotless/issues/142) From 5955883bf5fb7bb77f8a970725040a74e8b56205 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 16:12:13 +0800 Subject: [PATCH 0355/1120] Defer more test configurations --- _ext/eclipse-wtp/build.gradle | 2 +- _ext/gradle/java-setup.gradle | 4 +++- gradle/special-tests.gradle | 2 +- lib-extra/build.gradle | 2 +- plugin-gradle/build.gradle | 2 +- testlib/build.gradle | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/_ext/eclipse-wtp/build.gradle b/_ext/eclipse-wtp/build.gradle index 92a78578f6..feacfbf4c1 100644 --- a/_ext/eclipse-wtp/build.gradle +++ b/_ext/eclipse-wtp/build.gradle @@ -100,7 +100,7 @@ sourceSets { * All test classes need to run separately since they all instatiate different setups of the * Eclipse framework. */ -test { +tasks.withType(Test).configureEach { //Skip default tests, which would run every test case. exclude '**' } diff --git a/_ext/gradle/java-setup.gradle b/_ext/gradle/java-setup.gradle index 598077d73c..9572fc2955 100644 --- a/_ext/gradle/java-setup.gradle +++ b/_ext/gradle/java-setup.gradle @@ -22,4 +22,6 @@ dependencies { testImplementation project(':testlib') } -test { useJUnitPlatform() } +tasks.withType(Test).configureEach { + useJUnitPlatform() +} diff --git a/gradle/special-tests.gradle b/gradle/special-tests.gradle index c435bc7e81..fd5f602243 100644 --- a/gradle/special-tests.gradle +++ b/gradle/special-tests.gradle @@ -7,7 +7,7 @@ def special = [ ] boolean isCiServer = System.getenv().containsKey("CI") -tasks.named('test') { +tasks.withType(Test).configureEach { // See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations useJUnitPlatform { excludeTags special as String[] diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 08bf286d8d..8381d14041 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -26,7 +26,7 @@ dependencies { spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') -tasks.named('test') { +tasks.withType(Test).configureEach { if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // needed for EclipseCdtFormatterStepTest jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED' diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 11258db0e6..3e44335276 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -28,7 +28,7 @@ dependencies { } apply from: rootProject.file('gradle/special-tests.gradle') -tasks.named('test') { +tasks.withType(Test).configureEach { testLogging.showStandardStreams = true } diff --git a/testlib/build.gradle b/testlib/build.gradle index 64d4681805..639df8a2ab 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -22,7 +22,7 @@ dependencies { spotbugs { reportLevel = 'high' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') -tasks.named('test') { +tasks.withType(Test).configureEach { if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // for Antlr4FormatterStepTest and KtLintStepTest def args = [ From c4df046be318e7a780a7e3b9ba100ceb62d1be3a Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 16:43:18 +0800 Subject: [PATCH 0356/1120] Let check depend on version compatibility tasks https://github.com/davidburstrom/version-compatibility-gradle-plugin#lifecycle-tasks --- lib/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/build.gradle b/lib/build.gradle index 30c8fe8b15..0b42c7bcc1 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -42,6 +42,11 @@ versionCompatibility { } } +tasks.named("check").configure { + dependsOn(tasks.named("testCompatibilityAdapters")) + dependsOn(tasks.named("testCompatibility")) +} + dependencies { compileOnly 'org.slf4j:slf4j-api:2.0.0' // zero runtime reqs is a hard requirements for spotless-lib From 057f6c42a0dbbe61f7a77ec14828a7f233e6b250 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 17:09:22 +0800 Subject: [PATCH 0357/1120] Make KtLintCompat0Dot48Dot0AdapterTest workable https://github.com/pinterest/ktlint/blob/2642124cfec306050dd0258870a16dc95aaa106c/build-logic/src/main/kotlin/ToolchainForTests.kt#L16-L35 --- lib/build.gradle | 17 +++++++++++++++++ .../KtLintCompat0Dot48Dot0AdapterTest.java | 7 +++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 0b42c7bcc1..1a112c78cc 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -119,6 +119,23 @@ dependencies { spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) apply from: rootProject.file('gradle/special-tests.gradle') +tasks.withType(Test).configureEach { + def jdkVersion = JavaVersion.current().majorVersion.toInteger() + def args = [] + if (jdkVersion >= 16) { + // https://docs.gradle.org/7.5/userguide/upgrading_version_7.html#removes_implicit_add_opens_for_test_workers + args += [ + "--add-opens=java.base/java.lang=ALL-UNNAMED", + "--add-opens=java.base/java.util=ALL-UNNAMED", + ] + } + if (jdkVersion >= 18) { + // https://openjdk.org/jeps/411 + args += "-Djava.security.manager=allow" + } + jvmArgs(args) +} + jar { for (glue in NEEDS_GLUE) { from sourceSets.getByName(glue).output.classesDirs diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index 6825b3d818..8804f86b08 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -22,6 +22,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -33,12 +34,13 @@ public class KtLintCompat0Dot48Dot0AdapterTest { public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); String text = loadAndWriteText(path, "empty_class_body.kt"); + final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); Map userData = new HashMap<>(); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, path, false, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @@ -46,6 +48,7 @@ public void testDefaults(@TempDir Path path) throws IOException { public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); String text = loadAndWriteText(path, "fails_no_semicolons.kt"); + final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); Map userData = new HashMap<>(); @@ -53,7 +56,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, path, false, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } From e6b290084e7b1e40a031ae4c1cf954aeef7b5cc9 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 23:13:36 +0800 Subject: [PATCH 0358/1120] Cleanup usages of gradle/gradle-build-action - Remove cache from actions/setup-java. - Enable gradle-home-cache-cleanup flag, see https://github.com/gradle/gradle-build-action/blob/main/README.md#removing-unused-files-from-gradle-user-home-before-saving-to-cache. --- .github/workflows/changelog-print.yml | 3 ++- .github/workflows/ci.yml | 10 ++++++++-- .github/workflows/deploy.yml | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/changelog-print.yml b/.github/workflows/changelog-print.yml index 330f78cda0..a3009e3a39 100644 --- a/.github/workflows/changelog-print.yml +++ b/.github/workflows/changelog-print.yml @@ -15,7 +15,8 @@ jobs: with: java-version: 11 distribution: 'temurin' - cache: 'gradle' - name: gradle caching uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true - run: ./gradlew changelogPrint diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f08c201f5..86cf955059 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,10 @@ jobs: with: distribution: "temurin" java-version: 11 - cache: gradle + - name: gradle caching + uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true - name: spotlessCheck run: ./gradlew spotlessCheck --build-cache - name: assemble testClasses @@ -60,7 +63,10 @@ jobs: with: distribution: "temurin" java-version: ${{ matrix.jre }} - cache: gradle + - name: gradle caching + uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true - name: build (maven-only) if: matrix.kind == 'maven' run: ./gradlew :plugin-maven:build -x spotlessCheck --build-cache diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9a1dcdf609..d41dc8fc30 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -42,9 +42,10 @@ jobs: with: java-version: 11 distribution: 'temurin' - cache: 'gradle' - name: gradle caching uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true - name: publish all if: "${{ github.event.inputs.to_publish == 'all' }}" run: | From 8be92ffc42d6beb9a62397b9d0d9cccb075e9b90 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jan 2023 23:17:01 +0800 Subject: [PATCH 0359/1120] Mark bat files end with CRLF --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index e6141d8894..dc4cb6b0bd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ * text eol=lf +*.bat eol=crlf *.png binary *.jar binary From 92b3cf85596384115ea04d41a039b5e3c47bfb7f Mon Sep 17 00:00:00 2001 From: Abel Keszei Date: Tue, 24 Jan 2023 21:17:32 +0100 Subject: [PATCH 0360/1120] keep old signature of GsonStep.create() and restore GsonConfig classname --- .../diffplug/spotless/json/gson/GsonStep.java | 5 +++++ .../gradle/spotless/JsonExtension.java | 19 +++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java index 03baec5104..ec90255b77 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java @@ -30,6 +30,11 @@ public class GsonStep { private static final String MAVEN_COORDINATES = "com.google.code.gson:gson"; private static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Gson; maybe you set an incompatible version?"; + @Deprecated + public static FormatterStep create(int indentSpaces, boolean sortByKeys, boolean escapeHtml, String version, Provisioner provisioner) { + return create(new GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), provisioner); + } + public static FormatterStep create(GsonConfig gsonConfig, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); return FormatterStep.createLazy("gson", () -> new State(gsonConfig, provisioner), State::toFormatter); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index c684dab291..39b158ce1e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -23,7 +23,6 @@ import com.diffplug.spotless.json.JacksonJsonConfig; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.json.JsonSimpleStep; -import com.diffplug.spotless.json.gson.GsonConfig; import com.diffplug.spotless.json.gson.GsonStep; public class JsonExtension extends FormatExtension { @@ -48,8 +47,8 @@ public SimpleConfig simple() { return new SimpleConfig(DEFAULT_INDENTATION); } - public GsonGradleConfig gson() { - return new GsonGradleConfig(); + public GsonConfig gson() { + return new GsonConfig(); } public JacksonJsonGradleConfig jackson() { @@ -74,13 +73,13 @@ private FormatterStep createStep() { } } - public class GsonGradleConfig { + public class GsonConfig { private int indentSpaces; private boolean sortByKeys; private boolean escapeHtml; private String version; - public GsonGradleConfig() { + public GsonConfig() { this.indentSpaces = DEFAULT_INDENTATION; this.sortByKeys = false; this.escapeHtml = false; @@ -88,32 +87,32 @@ public GsonGradleConfig() { addStep(createStep()); } - public GsonGradleConfig indentWithSpaces(int indentSpaces) { + public GsonConfig indentWithSpaces(int indentSpaces) { this.indentSpaces = indentSpaces; replaceStep(createStep()); return this; } - public GsonGradleConfig sortByKeys() { + public GsonConfig sortByKeys() { this.sortByKeys = true; replaceStep(createStep()); return this; } - public GsonGradleConfig escapeHtml() { + public GsonConfig escapeHtml() { this.escapeHtml = true; replaceStep(createStep()); return this; } - public GsonGradleConfig version(String version) { + public GsonConfig version(String version) { this.version = version; replaceStep(createStep()); return this; } private FormatterStep createStep() { - return GsonStep.create(new GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), provisioner()); + return GsonStep.create(new com.diffplug.spotless.json.gson.GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), provisioner()); } } From 9982c3a7f30cd3a12467f9fb7f18fde6b155a815 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Wed, 25 Jan 2023 02:08:01 +0100 Subject: [PATCH 0361/1120] Drop some old tests --- .../spotless/kotlin/KtLintStepTest.java | 62 ------------------- 1 file changed, 62 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 1be0c7b72f..f69d038b6a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -37,68 +37,6 @@ void behavior() { "Wildcard import"); } - @Test - void worksShyiko() { - FormatterStep step = KtLintStep.create("0.31.0", TestProvisioner.mavenCentral()); - StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo( - "Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - } - - // Regression test to ensure it works on the version it switched to Pinterest (version 0.32.0) - // but before 0.34. - // https://github.com/diffplug/spotless/issues/419 - @Test - void worksPinterestAndPre034() { - FormatterStep step = KtLintStep.create("0.32.0", TestProvisioner.mavenCentral()); - StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - } - - // Regression test to handle alpha and 1.x version numbers - // https://github.com/diffplug/spotless/issues/668 - @Test - void worksAlpha1() { - FormatterStep step = KtLintStep.create("0.38.0-alpha01", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - - @Test - void works0_44_0() { - FormatterStep step = KtLintStep.create("0.44.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - - @Disabled("https://github.com/pinterest/ktlint/issues/1421") - @Test - void works0_45_0() { - FormatterStep step = KtLintStep.create("0.45.0", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - - @Test - void works0_45_1() { - FormatterStep step = KtLintStep.create("0.45.1", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - - @Test - void works0_45_2() { - FormatterStep step = KtLintStep.create("0.45.2", TestProvisioner.mavenCentral()); - StepHarness.forStep(step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean"); - } - @Test void works0_46_0() { FormatterStep step = KtLintStep.create("0.46.0", TestProvisioner.mavenCentral()); From aab121d345486bbc4a9eaf8ac9d4ef3bd1417622 Mon Sep 17 00:00:00 2001 From: Eir Nym <485399+eirnym@users.noreply.github.com> Date: Wed, 25 Jan 2023 02:14:48 +0100 Subject: [PATCH 0362/1120] Remove stale imports --- .../test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index f69d038b6a..3047245298 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -15,13 +15,11 @@ */ package com.diffplug.spotless.kotlin; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; -import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.TestProvisioner; From a35e23b400ac05d187b4c144a1d2ff0b2f83c88a Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 09:44:15 +0800 Subject: [PATCH 0363/1120] Enable Gradle's build scan --- settings.gradle | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/settings.gradle b/settings.gradle index fb9e7dcf0b..ca48729297 100644 --- a/settings.gradle +++ b/settings.gradle @@ -29,6 +29,7 @@ plugins { id 'org.gradle.test-retry' apply false id 'com.adarshr.test-logger' apply false id 'io.github.davidburstrom.version-compatibility' apply false + id "com.gradle.enterprise" version "3.12.2" } if (System.env['CI'] != null) { // use the remote buildcache on all CI builds @@ -58,6 +59,14 @@ if (System.env['CI'] != null) { } } +gradleEnterprise { + buildScan { + termsOfServiceUrl = "https://gradle.com/terms-of-service" + termsOfServiceAgree = "yes" + publishAlways() + } +} + rootProject.name = 'spotless' include 'lib' // reusable library with no dependencies From 27629933ab7dcd9d95c008735e789f5a46620b65 Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 19 Jan 2023 00:12:18 +0800 Subject: [PATCH 0364/1120] Generate the correct qualifiedRuleId for Ktlint 0.48.x --- .../glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java | 2 +- .../glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java | 2 ++ plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 5d24603f70..1e54a80859 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -140,7 +140,7 @@ private static EditorConfigOverride createEditorConfigOverride(final List String[] parts = entry.getKey().substring(7).split("_", 2); if (parts.length == 1) { // convert ktlint_{ruleset} to {ruleset} - String qualifiedRuleId = parts[0]; + String qualifiedRuleId = parts[0] + ":"; property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(qualifiedRuleId); } else { // convert ktlint_{ruleset}_{rulename} to {ruleset}:{rulename} diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index 8804f86b08..c811b51233 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -55,6 +55,8 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + // ktlint_filename is an invalid rule in ktlint 0.48.0 + editorConfigOverrideMap.put("ktlint_filename", "disabled"); String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 17bf123b41..37d08f9b75 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) +* **POTENTIALLY BREAKING** Generate the correct qualifiedRuleId for Ktlint 0.48.x [#1495](https://github.com/diffplug/spotless/pull/1495) ### Changes * **POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 448011be3c..2a23405d35 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) +* **POTENTIALLY BREAKING** Generate the correct qualifiedRuleId for Ktlint 0.48.x [#1495](https://github.com/diffplug/spotless/pull/1495) ### Changes * Spotless' custom build was replaced by [`maven-plugin-development`](https://github.com/britter/maven-plugin-development). ([#1496](https://github.com/diffplug/spotless/pull/1496) fixes [#554](https://github.com/diffplug/spotless/issues/554)) * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) From 70ad96cd566396097e53520f3ebf8b2aa32011b9 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 24 Jan 2023 16:48:14 +0100 Subject: [PATCH 0365/1120] 1499: delay npmInstall and npmExec resolution to enable interoperability with `node-gradle-plugin` --- .../spotless/npm/EslintFormatterStep.java | 32 +++++++------ .../npm/NpmFormatterStepLocations.java | 11 +++-- .../npm/NpmFormatterStepStateBase.java | 47 ++++++++++--------- .../spotless/npm/PrettierFormatterStep.java | 4 +- .../spotless/npm/TsFmtFormatterStep.java | 4 +- .../NpmTestsWithoutNpmInstallationTest.java | 3 -- 6 files changed, 53 insertions(+), 48 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 74979d90aa..2a095e9ad7 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -81,7 +81,9 @@ public static FormatterStep create(Map devDependencies, Provisio private static class State extends NpmFormatterStepStateBase implements Serializable { private static final long serialVersionUID = -539537027004745812L; - private final EslintConfig eslintConfig; + private final EslintConfig origEslintConfig; + + private transient EslintConfig eslintConfigInUse; State(String stepName, Map devDependencies, File projectDir, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { super(stepName, @@ -97,21 +99,23 @@ private static class State extends NpmFormatterStepStateBase implements Serializ new NpmFormatterStepLocations( projectDir, buildDir, - npmPathResolver.resolveNpmExecutable(), - npmPathResolver.resolveNodeExecutable())); - this.eslintConfig = localCopyFiles(requireNonNull(eslintConfig)); + npmPathResolver::resolveNpmExecutable, + npmPathResolver::resolveNodeExecutable)); + this.origEslintConfig = requireNonNull(eslintConfig.verify()); + this.eslintConfigInUse = eslintConfig; } - private EslintConfig localCopyFiles(EslintConfig orig) { - if (orig.getEslintConfigPath() == null) { - return orig.verify(); + @Override + protected void prepareNodeServerLayout() throws IOException { + super.prepareNodeServerLayout(); + if (origEslintConfig.getEslintConfigPath() != null) { + // If any config files are provided, we need to make sure they are at the same location as the node modules + // as eslint will try to resolve plugin/config names relatively to the config file location and some + // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) + FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); + File configFileCopy = NpmResourceHelper.copyFileToDir(origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); + this.eslintConfigInUse = this.origEslintConfig.withEslintConfigPath(configFileCopy).verify(); } - // If any config files are provided, we need to make sure they are at the same location as the node modules - // as eslint will try to resolve plugin/config names relatively to the config file location and some - // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) - FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", orig.getEslintConfigPath(), nodeModulesDir); - File configFileCopy = NpmResourceHelper.copyFileToDir(orig.getEslintConfigPath(), nodeModulesDir); - return orig.withEslintConfigPath(configFileCopy).verify(); } @Override @@ -121,7 +125,7 @@ public FormatterFunc createFormatterFunc() { FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); ServerProcessInfo eslintRestServer = npmRunServer(); EslintRestService restService = new EslintRestService(eslintRestServer.getBaseUrl()); - return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(locations.projectDir(), nodeModulesDir, eslintConfig, restService)); + return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(locations.projectDir(), nodeServerLayout.nodeModulesDir(), eslintConfigInUse, restService)); } catch (IOException e) { throw ThrowingEx.asRuntime(e); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java index 0c417733e8..0e99e1afab 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.Serializable; +import java.util.function.Supplier; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -32,12 +33,12 @@ class NpmFormatterStepLocations implements Serializable { private final transient File buildDir; @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - private final transient File npmExecutable; + private final transient Supplier npmExecutable; @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - private final transient File nodeExecutable; + private final transient Supplier nodeExecutable; - public NpmFormatterStepLocations(File projectDir, File buildDir, File npmExecutable, File nodeExecutable) { + public NpmFormatterStepLocations(File projectDir, File buildDir, Supplier npmExecutable, Supplier nodeExecutable) { this.projectDir = requireNonNull(projectDir); this.buildDir = requireNonNull(buildDir); this.npmExecutable = requireNonNull(npmExecutable); @@ -53,10 +54,10 @@ public File buildDir() { } public File npmExecutable() { - return npmExecutable; + return npmExecutable.get(); } public File nodeExecutable() { - return nodeExecutable; + return nodeExecutable.get(); } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 4f555a177e..996400ce33 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -31,7 +31,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterFunc; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -42,11 +41,8 @@ abstract class NpmFormatterStepStateBase implements Serializable { private static final long serialVersionUID = 1460749955865959948L; - @SuppressWarnings("unused") - private final FileSignature packageJsonSignature; - @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") - public final transient File nodeModulesDir; + protected final transient NodeServerLayout nodeServerLayout; public final NpmFormatterStepLocations locations; @@ -58,45 +54,52 @@ protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFor this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); this.locations = locations; - NodeServerLayout layout = prepareNodeServer(locations.buildDir()); - this.nodeModulesDir = layout.nodeModulesDir(); - this.packageJsonSignature = FileSignature.signAsList(layout.packageJsonFile()); + this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), stepName); } - private NodeServerLayout prepareNodeServer(File buildDir) throws IOException { - NodeServerLayout layout = new NodeServerLayout(buildDir, stepName); - NpmResourceHelper.assertDirectoryExists(layout.nodeModulesDir()); - NpmResourceHelper.writeUtf8StringToFile(layout.packageJsonFile(), + protected void prepareNodeServerLayout() throws IOException { + NpmResourceHelper.assertDirectoryExists(nodeServerLayout.nodeModulesDir()); + NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.packageJsonFile(), this.npmConfig.getPackageJsonContent()); NpmResourceHelper - .writeUtf8StringToFile(layout.serveJsFile(), this.npmConfig.getServeScriptContent()); + .writeUtf8StringToFile(nodeServerLayout.serveJsFile(), this.npmConfig.getServeScriptContent()); if (this.npmConfig.getNpmrcContent() != null) { - NpmResourceHelper.writeUtf8StringToFile(layout.npmrcFile(), this.npmConfig.getNpmrcContent()); + NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.npmrcFile(), this.npmConfig.getNpmrcContent()); } else { - NpmResourceHelper.deleteFileIfExists(layout.npmrcFile()); + NpmResourceHelper.deleteFileIfExists(nodeServerLayout.npmrcFile()); } + } + + protected void prepareNodeServer() throws IOException { FormattedPrinter.SYSOUT.print("running npm install"); - runNpmInstall(layout.nodeModulesDir()); + runNpmInstall(nodeServerLayout.nodeModulesDir()); FormattedPrinter.SYSOUT.print("npm install finished"); - return layout; } private void runNpmInstall(File npmProjectDir) throws IOException { new NpmProcess(npmProjectDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).install(); } - protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { - if (!this.nodeModulesDir.exists()) { - prepareNodeServer(NodeServerLayout.getBuildDirFromNodeModulesDir(this.nodeModulesDir)); + protected void assertNodeServerDirReady() throws IOException { + if (!this.nodeServerLayout.nodeModulesDir().exists() || !this.nodeServerLayout.packageJsonFile().isFile()) { + // reinstall if missing + prepareNodeServerLayout(); } + if (!new File(this.nodeServerLayout.nodeModulesDir(), "node_modules").isDirectory()) { + // run npm install if node_modules is missing + prepareNodeServer(); + } + } + protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { + assertNodeServerDirReady(); try { // The npm process will output the randomly selected port of the http server process to 'server.port' file // so in order to be safe, remove such a file if it exists before starting. - final File serverPortFile = new File(this.nodeModulesDir, "server.port"); + final File serverPortFile = new File(this.nodeServerLayout.nodeModulesDir(), "server.port"); NpmResourceHelper.deleteFileIfExists(serverPortFile); // start the http server in node - Process server = new NpmProcess(this.nodeModulesDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); + Process server = new NpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); // await the readiness of the http server - wait for at most 60 seconds try { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 22dd4586ee..22f1a69e7c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -77,8 +77,8 @@ private static class State extends NpmFormatterStepStateBase implements Serializ new NpmFormatterStepLocations( projectDir, buildDir, - npmPathResolver.resolveNpmExecutable(), - npmPathResolver.resolveNodeExecutable())); + npmPathResolver::resolveNpmExecutable, + npmPathResolver::resolveNodeExecutable)); this.prettierConfig = requireNonNull(prettierConfig); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index 14d6b1bbd0..4bd665c764 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -83,8 +83,8 @@ public State(String stepName, Map versions, File projectDir, Fil new NpmFormatterStepLocations( projectDir, buildDir, - npmPathResolver.resolveNpmExecutable(), - npmPathResolver.resolveNodeExecutable())); + npmPathResolver::resolveNpmExecutable, + npmPathResolver::resolveNodeExecutable)); this.buildDir = requireNonNull(buildDir); this.configFile = configFile; this.inlineTsFmtSettings = inlineTsFmtSettings == null ? new TreeMap<>() : new TreeMap<>(inlineTsFmtSettings); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 916d853920..986e2726cb 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -17,7 +17,6 @@ import org.assertj.core.api.Assertions; import org.gradle.testkit.runner.BuildResult; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.common.base.Predicates; @@ -74,8 +73,6 @@ private void printContents() { } @Test - @Disabled("This test is disabled because we currently don't support using npm/node installed by the" + - "node-gradle-plugin as the installation takes place in the *execution* phase, but spotless needs it in the *configuration* phase.") void useNodeAndNpmFromNodeGradlePluginInOneSweep() throws Exception { try { setFile("build.gradle").toLines( From fac7fd1ece0887111e06a2b24def6b24d1cee77c Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 24 Jan 2023 19:51:51 +0100 Subject: [PATCH 0366/1120] 1499: document changes for delaying npm install --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 1 + 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index e8af5aec03..d41f40aaa6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * ** POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. +* NpmFormatterStepStateBase delays `npm install` call until the formatter is first used. This enables better integration + with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522)) ## [2.32.0] - 2023-01-13 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 37d08f9b75..cbcd3bd953 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -15,6 +15,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * **POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. +* `npm`-based formatters `ESLint`, `prettier` and `tsfmt` delay their `npm install` call until the formatters are first + used. For gradle this effectively moves the `npm install` call out of the configuration phase and as such enables + better integration with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522)) ## [6.13.0] - 2023-01-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 2a23405d35..93dd005ab6 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * **POTENTIALLY BREAKING** Removed support for KtLint 0.3x and 0.45.2 ([#1475](https://github.com/diffplug/spotless/pull/1475)) * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. +* `npm`-based formatters `ESLint`, `prettier` and `tsfmt` delay their `npm install` call until the formatters are first used. ([#1522](https://github.com/diffplug/spotless/pull/1522) ## [2.30.0] - 2023-01-13 ### Added From 7caf4c08c0daea72d15439bd8cd364e77638158f Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 24 Jan 2023 20:52:34 +0100 Subject: [PATCH 0367/1120] 1499: add documentation and examples showcasing the integration --- plugin-gradle/README.md | 7 +++ .../NpmTestsWithoutNpmInstallationTest.java | 47 +++++++------------ ...onTest_gradle_node_plugin_example_1.gradle | 38 +++++++++++++++ ...onTest_gradle_node_plugin_example_2.gradle | 35 ++++++++++++++ 4 files changed, 96 insertions(+), 31 deletions(-) create mode 100644 plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle create mode 100644 plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index b6e95807d9..7e486719e7 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -907,6 +907,13 @@ spotless { If you provide both `npmExecutable` and `nodeExecutable`, spotless will use these paths. If you specify only one of the two, spotless will assume the other one is in the same directory. +If you use the `gradle-node-plugin` ([github](https://github.com/node-gradle/gradle-node-plugin)), it is possible to use the +node- and npm-binaries dynamically installed by this plugin. See +[this](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle) +or [this](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle) example. + +```gradle + ### `.npmrc` detection Spotless picks up npm configuration stored in a `.npmrc` file either in the project directory or in your user home. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java index 986e2726cb..03d14292e9 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java @@ -73,38 +73,23 @@ private void printContents() { } @Test - void useNodeAndNpmFromNodeGradlePluginInOneSweep() throws Exception { + void useNodeAndNpmFromNodeGradlePlugin_example1() throws Exception { try { - setFile("build.gradle").toLines( - "plugins {", - " id 'com.diffplug.spotless'", - " id 'com.github.node-gradle.node' version '3.5.1'", - "}", - "repositories { mavenCentral() }", - "node {", - " download = true", - " version = '18.13.0'", - " npmVersion = '8.19.2'", - " workDir = file(\"${buildDir}/nodejs\")", - " npmWorkDir = file(\"${buildDir}/npm\")", - "}", - "def prettierConfig = [:]", - "prettierConfig['printWidth'] = 50", - "prettierConfig['parser'] = 'typescript'", - "def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'", - "def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'", - "spotless {", - " format 'mytypescript', {", - " target 'test.ts'", - " prettier()", - " .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}${npmExec}\")", - " .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}\")", - " .config(prettierConfig)", - " }", - "}", - "tasks.named('spotlessMytypescript').configure {", - " it.dependsOn('nodeSetup', 'npmSetup')", - "}"); + setFile("build.gradle").toResource("com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle"); + setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean"); + } catch (Exception e) { + printContents(); + throw e; + } + } + + @Test + void useNpmFromNodeGradlePlugin_example2() throws Exception { + try { + setFile("build.gradle").toResource("com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle"); setFile("test.ts").toResource("npm/prettier/config/typescript.dirty"); final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle new file mode 100644 index 0000000000..7ec7a2c592 --- /dev/null +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle @@ -0,0 +1,38 @@ +/** + * This example shows how to use the gradle-node-plugin to install node and npm in separate directories + * and use these binaries with the prettier formatter. + */ +plugins { + id 'com.diffplug.spotless' + id 'com.github.node-gradle.node' version '3.5.1' +} +repositories { mavenCentral() } +node { + download = true + version = '18.13.0' + npmVersion = '8.19.2' + // when setting both these directories, npm and node will be in separate directories + workDir = file("${buildDir}/nodejs") + npmWorkDir = file("${buildDir}/npm") +} +def prettierConfig = [:] +prettierConfig['printWidth'] = 50 +prettierConfig['parser'] = 'typescript' + +// the executable names +def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm' +def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node' + +spotless { + format 'mytypescript', { + target 'test.ts' + prettier() + .npmExecutable("${tasks.named('npmSetup').get().npmDir.get()}${npmExec}") // get the npm executable path from gradle-node-plugin + .nodeExecutable("${tasks.named('nodeSetup').get().nodeDir.get()}${nodeExec}") // get the node executable path from gradle-node-plugin + .config(prettierConfig) + } +} + +tasks.named('spotlessMytypescript').configure { + it.dependsOn('nodeSetup', 'npmSetup') +} diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle new file mode 100644 index 0000000000..eb59b85cf0 --- /dev/null +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle @@ -0,0 +1,35 @@ +/** + * This example shows how to use the gradle-node-plugin to install node and npm together and + * use these binaries with the prettier formatter. + */ +plugins { + id 'com.diffplug.spotless' + id 'com.github.node-gradle.node' version '3.5.1' +} +repositories { mavenCentral() } +node { + download = true + version = '18.13.0' + // when not setting an explicit `npmWorkDir`, the npm binary will be installed next to the node binary + workDir = file("${buildDir}/nodejs") +} +def prettierConfig = [:] +prettierConfig['printWidth'] = 50 +prettierConfig['parser'] = 'typescript' + +// the executable name +def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm' + +spotless { + typescript { + target 'test.ts' + prettier() + .npmExecutable("${tasks.named('npmSetup').get().npmDir.get()}${npmExec}") // get the npm executable path from gradle-node-plugin + // setting the nodeExecutable is not necessary, since it will be found in the same directory as the npm executable (see above) + .config(prettierConfig) + } +} + +tasks.named('spotlessTypescript').configure { + it.dependsOn('nodeSetup', 'npmSetup') +} From 28ba93b8f3098b5ec104c87ab97d1eecb67b18ff Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 24 Jan 2023 20:54:09 +0100 Subject: [PATCH 0368/1120] 1499: drive-by-bugfix when using singleton map directly, it could occur that we tried to manipulate that map later (combination of using `prettier()` inside `typescript` block while supplying a prettier config via `config([...])` --- .../java/com/diffplug/gradle/spotless/TypescriptExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 2283afccff..a11f1b0c39 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -166,7 +166,7 @@ protected FormatterStep createStep() { private void fixParserToTypescript() { if (this.prettierConfig == null) { - this.prettierConfig = Collections.singletonMap("parser", "typescript"); + this.prettierConfig = new TreeMap<>(Collections.singletonMap("parser", "typescript")); } else { final Object replaced = this.prettierConfig.put("parser", "typescript"); if (replaced != null) { From 292d7e2bd4fb86f10c05207fc4ff918f3a9dd5df Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 25 Jan 2023 11:18:36 +0100 Subject: [PATCH 0369/1120] 1499: refactor re-install needed detection --- .../spotless/npm/NodeServerLayout.java | 34 ++++++++++++++++++- .../npm/NpmFormatterStepStateBase.java | 12 +++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java index a175080517..63a6a923da 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,11 @@ package com.diffplug.spotless.npm; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.stream.Stream; + +import com.diffplug.spotless.ThrowingEx; class NodeServerLayout { @@ -50,4 +55,31 @@ public File npmrcFile() { static File getBuildDirFromNodeModulesDir(File nodeModulesDir) { return nodeModulesDir.getParentFile(); } + + public boolean isLayoutPrepared() { + if (!nodeModulesDir().isDirectory()) { + return false; + } + if (!packageJsonFile().isFile()) { + return false; + } + if (!serveJsFile().isFile()) { + return false; + } + // npmrc is optional, so must not be checked here + return true; + } + + public boolean isNodeModulesPrepared() { + Path nodeModulesInstallDirPath = new File(nodeModulesDir(), "node_modules").toPath(); + if (!Files.isDirectory(nodeModulesInstallDirPath)) { + return false; + } + // check if it is NOT empty + return ThrowingEx.get(() -> { + try (Stream entries = Files.list(nodeModulesInstallDirPath)) { + return entries.findFirst().isPresent(); + } + }); + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 996400ce33..9cff41e604 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -81,16 +81,24 @@ private void runNpmInstall(File npmProjectDir) throws IOException { } protected void assertNodeServerDirReady() throws IOException { - if (!this.nodeServerLayout.nodeModulesDir().exists() || !this.nodeServerLayout.packageJsonFile().isFile()) { + if (needsPrepareNodeServerLayout()) { // reinstall if missing prepareNodeServerLayout(); } - if (!new File(this.nodeServerLayout.nodeModulesDir(), "node_modules").isDirectory()) { + if (needsPrepareNodeServer()) { // run npm install if node_modules is missing prepareNodeServer(); } } + protected boolean needsPrepareNodeServer() { + return this.nodeServerLayout.isNodeModulesPrepared(); + } + + protected boolean needsPrepareNodeServerLayout() { + return !this.nodeServerLayout.isLayoutPrepared(); + } + protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { assertNodeServerDirReady(); try { From 7326772bad72c2855fecc62421b4e43031609af6 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 25 Jan 2023 11:27:58 +0100 Subject: [PATCH 0370/1120] 1499: spotbugs --- .../java/com/diffplug/spotless/npm/EslintFormatterStep.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 2a095e9ad7..221a745ad7 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -39,6 +39,8 @@ import com.diffplug.spotless.ThrowingEx; import com.diffplug.spotless.npm.EslintRestService.FormatOption; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + public class EslintFormatterStep { private static final Logger logger = LoggerFactory.getLogger(EslintFormatterStep.class); @@ -83,6 +85,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ private static final long serialVersionUID = -539537027004745812L; private final EslintConfig origEslintConfig; + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") private transient EslintConfig eslintConfigInUse; State(String stepName, Map devDependencies, File projectDir, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { From e9f73f02e37cd8c2e1ea6d70e6da7235ce9dd18a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 25 Jan 2023 04:47:26 -0800 Subject: [PATCH 0371/1120] Run `equoIde` and get an IDE with the Spotless project imported and ready to go. --- CONTRIBUTING.md | 2 +- build.gradle | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 782e377d58..af2e690784 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing to Spotless -Pull requests are welcome, preferably against `main`. Feel free to develop spotless any way you like. +Pull requests are welcome, preferably against `main`. Feel free to develop spotless any way you like, but if you like Eclipse and Gradle Buildship then [`gradlew equoIde` will install an IDE and set it up for you](https://github.com/equodev/equo-ide). ## How Spotless works diff --git a/build.gradle b/build.gradle index f9e3d0de21..450ee61583 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,26 @@ +plugins { + // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md + id 'dev.equo.ide' version '0.12.1' +} +equoIde { + branding.title('Spotless').icon(file('_images/spotless_logo.png')) + + // waiting on https://github.com/equodev/equo-ide/pull/65 + //welcome().openUrlOnStartup('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') + + // everything below becomes the default after https://github.com/equodev/equo-ide/pull/66 + p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' + install 'org.eclipse.releng.java.languages.categoryIU' + install 'org.eclipse.platform.ide.categoryIU' + + p2repo 'https://download.eclipse.org/buildship/updates/e423/releases/3.x/3.1.6.v20220511-1359/' + install 'org.eclipse.buildship.feature.group' +} + repositories { mavenCentral() } + apply from: rootProject.file('gradle/java-publish.gradle') apply from: rootProject.file('gradle/changelog.gradle') allprojects { @@ -18,4 +38,4 @@ spotless { trimTrailingWhitespace() endWithNewline() } -} \ No newline at end of file +} From 2a8f9890919ef6a73d0112f79415f22addedc897 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 20:49:27 +0800 Subject: [PATCH 0372/1120] Remove retry plugin https://docs.gradle.com/enterprise/gradle-plugin/#test_retry_migration --- gradle/special-tests.gradle | 1 - settings.gradle | 3 --- 2 files changed, 4 deletions(-) diff --git a/gradle/special-tests.gradle b/gradle/special-tests.gradle index fd5f602243..52f82e4e1b 100644 --- a/gradle/special-tests.gradle +++ b/gradle/special-tests.gradle @@ -1,4 +1,3 @@ -apply plugin: 'org.gradle.test-retry' apply plugin: 'com.adarshr.test-logger' def special = [ 'Npm', diff --git a/settings.gradle b/settings.gradle index ca48729297..8ab9430f00 100644 --- a/settings.gradle +++ b/settings.gradle @@ -11,8 +11,6 @@ pluginManagement { id 'com.diffplug.spotless-changelog' version '2.4.1' // https://github.com/diffplug/goomph/blob/main/CHANGES.md id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 - // https://github.com/gradle/test-retry-gradle-plugin/releases - id 'org.gradle.test-retry' version '1.5.1' // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags @@ -26,7 +24,6 @@ plugins { id 'com.github.spotbugs' apply false id 'com.diffplug.spotless-changelog' apply false id 'com.diffplug.p2.asmaven' apply false - id 'org.gradle.test-retry' apply false id 'com.adarshr.test-logger' apply false id 'io.github.davidburstrom.version-compatibility' apply false id "com.gradle.enterprise" version "3.12.2" From b722ec38fe1c63f57dc36aacf285075ea6c1f002 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 25 Jan 2023 04:24:02 -0800 Subject: [PATCH 0373/1120] We'll need to bump our minimum Java to 11, which is already happening in our next release. --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5702d21bdd..f06bdef37e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ artifactIdMaven=spotless-maven-plugin artifactIdGradle=spotless-plugin-gradle # Build requirements -VER_JAVA=1.8 +VER_JAVA=11 VER_SPOTBUGS=4.7.3 VER_JSR_305=3.0.2 @@ -28,4 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=4.11.0 \ No newline at end of file +VER_MOCKITO=4.11.0 From 20c5e75d3b65e3b0dde4dbab0eca0779126d4d9c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 25 Jan 2023 05:11:05 -0800 Subject: [PATCH 0374/1120] Setup the p2deps plugin and add solstice to lib-extra. --- lib-extra/build.gradle | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 8381d14041..5a225ee272 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java-library' + id 'dev.equo.p2deps' version '0.12.1' } ext.artifactId = project.artifactIdLibExtra version = rootProject.spotlessChangelog.versionNext @@ -14,6 +15,8 @@ dependencies { // needed by GitAttributesLineEndings implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" implementation "com.googlecode.concurrent-trees:concurrent-trees:2.6.1" + // for eclipse + implementation "dev.equo.ide:solstice:0.11.0" // testing testImplementation project(':testlib') @@ -22,6 +25,24 @@ dependencies { testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" } +def NEEDS_P2_DEPS = [] +for (needsP2 in NEEDS_P2_DEPS) { + sourceSets.register(needsP2) { + compileClasspath += sourceSets.main.output + runtimeClasspath += sourceSets.main.output + java {} + } +} +jar { + for (needsP2 in NEEDS_P2_DEPS) { + from sourceSets.getByName(needsP2).output.classesDirs + } +} + +apply plugin: 'dev.equo.p2deps' +p2deps { +} + // we'll hold the core lib to a high standard spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) From 5be0c69beb7bce66993c3ffbe9c965a48b8005f0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 25 Jan 2023 05:14:31 -0800 Subject: [PATCH 0375/1120] Move the build deps out of _ext and into lib-extra. --- _ext/eclipse-jdt/build.gradle | 8 +------- lib-extra/build.gradle | 13 ++++++++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/_ext/eclipse-jdt/build.gradle b/_ext/eclipse-jdt/build.gradle index 283e52f86d..8b71deba18 100644 --- a/_ext/eclipse-jdt/build.gradle +++ b/_ext/eclipse-jdt/build.gradle @@ -10,10 +10,4 @@ ext { } dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" - implementation("org.eclipse.jdt:org.eclipse.jdt.core:${VER_ECLIPSE_JDT_CORE}") { - exclude group: 'org.eclipse.platform', module: 'org.eclipse.ant.core' - exclude group: 'org.eclipse.platform', module: 'org.eclipse.core.expressions' - exclude group: 'org.eclipse.platform', module: 'org.eclipse.core.filesystem' - } -} \ No newline at end of file +} diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 5a225ee272..b24f3ed5cc 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -25,7 +25,9 @@ dependencies { testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" } -def NEEDS_P2_DEPS = [] +def NEEDS_P2_DEPS = [ + 'jdt' +] for (needsP2 in NEEDS_P2_DEPS) { sourceSets.register(needsP2) { compileClasspath += sourceSets.main.output @@ -41,6 +43,15 @@ jar { apply plugin: 'dev.equo.p2deps' p2deps { + into 'jdtCompileOnly', { + p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' + install 'org.eclipse.jdt.core' + addFilter 'minimize', { filter -> + filter.exclude 'org.eclipse.ant.core' + filter.exclude 'org.eclipse.core.expressions' + filter.exclude 'org.eclipse.core.filesystem' + } + } } // we'll hold the core lib to a high standard From f564cc8a679bb516841e4ba2532fcd148d51f56c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 25 Jan 2023 05:15:16 -0800 Subject: [PATCH 0376/1120] Move the JDT shim code out of _ext and into lib-extra, compiling against p2deps. --- .../extra/eclipse/java/package-info.java | 20 ------------ .../jdt}/EclipseJdtFormatterStepImpl.java | 31 ++++--------------- 2 files changed, 6 insertions(+), 45 deletions(-) delete mode 100644 _ext/eclipse-jdt/src/main/java/com/diffplug/spotless/extra/eclipse/java/package-info.java rename {_ext/eclipse-jdt/src/main/java/com/diffplug/spotless/extra/eclipse/java => lib-extra/src/jdt/java/com/diffplug/spotless/extra/jdt}/EclipseJdtFormatterStepImpl.java (65%) diff --git a/_ext/eclipse-jdt/src/main/java/com/diffplug/spotless/extra/eclipse/java/package-info.java b/_ext/eclipse-jdt/src/main/java/com/diffplug/spotless/extra/eclipse/java/package-info.java deleted file mode 100644 index 190557cc74..0000000000 --- a/_ext/eclipse-jdt/src/main/java/com/diffplug/spotless/extra/eclipse/java/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2016 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. - */ -/** Eclipse JDT based Spotless formatter */ -@ParametersAreNonnullByDefault -package com.diffplug.spotless.extra.eclipse.java; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/_ext/eclipse-jdt/src/main/java/com/diffplug/spotless/extra/eclipse/java/EclipseJdtFormatterStepImpl.java b/lib-extra/src/jdt/java/com/diffplug/spotless/extra/jdt/EclipseJdtFormatterStepImpl.java similarity index 65% rename from _ext/eclipse-jdt/src/main/java/com/diffplug/spotless/extra/eclipse/java/EclipseJdtFormatterStepImpl.java rename to lib-extra/src/jdt/java/com/diffplug/spotless/extra/jdt/EclipseJdtFormatterStepImpl.java index b3fb7acaf3..7e59744149 100644 --- a/_ext/eclipse-jdt/src/main/java/com/diffplug/spotless/extra/eclipse/java/EclipseJdtFormatterStepImpl.java +++ b/lib-extra/src/jdt/java/com/diffplug/spotless/extra/jdt/EclipseJdtFormatterStepImpl.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. @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.java; +package com.diffplug.spotless.extra.jdt; import java.io.File; import java.util.Properties; -import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.ToolFactory; import org.eclipse.jdt.core.formatter.CodeFormatter; import org.eclipse.jdt.internal.compiler.env.IModule; @@ -26,35 +25,17 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.text.edits.TextEdit; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; - /** Formatter step which calls out to the Eclipse JDT formatter. */ public class EclipseJdtFormatterStepImpl { + /** Spotless demands for internal formatter chains Unix (LF) line endings. */ + public static final String LINE_DELIMITER = "\n"; private final CodeFormatter codeFormatter; - public EclipseJdtFormatterStepImpl(Properties settings) throws Exception { - SpotlessEclipseFramework.setup(new FrameworkConfig()); + public EclipseJdtFormatterStepImpl(Properties settings) { this.codeFormatter = ToolFactory.createCodeFormatter(settings, ToolFactory.M_FORMAT_EXISTING); } - private static class FrameworkConfig implements SpotlessEclipseConfig { - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - config.useSlf4J(EclipseJdtFormatterStepImpl.class.getPackage().getName()); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - config.add(new JavaCore()); - } - } - /** @deprecated Use {@link #format(String, File)} instead. */ @Deprecated public String format(String raw) throws Exception { @@ -66,7 +47,7 @@ public String format(String raw, File file) throws Exception { int kind = (file.getName().equals(IModule.MODULE_INFO_JAVA) ? CodeFormatter.K_MODULE_INFO : CodeFormatter.K_COMPILATION_UNIT) | CodeFormatter.F_INCLUDE_COMMENTS; - TextEdit edit = codeFormatter.format(kind, raw, 0, raw.length(), 0, SpotlessEclipseFramework.LINE_DELIMITER); + TextEdit edit = codeFormatter.format(kind, raw, 0, raw.length(), 0, LINE_DELIMITER); if (edit == null) { throw new IllegalArgumentException("Invalid java syntax for formatting."); } else { From c61ddbdf9d548182893b007511c8de56b49fd960 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 25 Jan 2023 05:34:13 -0800 Subject: [PATCH 0377/1120] Use host (maven/gradle) to get maven deps and solstice to get p2 deps. --- .../extra/eclipse/EquoBasedStepBuilder.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 lib-extra/src/main/java/com/diffplug/spotless/extra/eclipse/EquoBasedStepBuilder.java diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/eclipse/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/eclipse/EquoBasedStepBuilder.java new file mode 100644 index 0000000000..c9a9bc4cf3 --- /dev/null +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/eclipse/EquoBasedStepBuilder.java @@ -0,0 +1,83 @@ +/* + * 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. + * 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.extra.eclipse; + +import java.io.File; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.ThrowingEx; + +import dev.equo.solstice.p2.P2Client; +import dev.equo.solstice.p2.P2Model; +import dev.equo.solstice.p2.P2Unit; + +/** + * Generic Eclipse based formatter step {@link State} builder. + */ +public class EquoBasedStepBuilder { + private final String formatterName; + private final Provisioner mavenProvisioner; + private final P2Model p2; + private final ThrowingEx.Function stateToFormatter; + private String formatterVersion; + + /** Initialize valid default configuration, taking latest version */ + public EquoBasedStepBuilder(String formatterName, Provisioner mavenProvisioner, P2Model p2, ThrowingEx.Function stateToFormatter) { + this.formatterName = formatterName; + this.mavenProvisioner = mavenProvisioner; + this.p2 = p2; + this.stateToFormatter = stateToFormatter; + } + + /** Returns the FormatterStep (whose state will be calculated lazily). */ + public FormatterStep build() throws Exception { + return FormatterStep.createLazy(formatterName, this::get, stateToFormatter); + } + + /** Creates the state of the configuration. */ + EquoBasedStepBuilder.State get() throws Exception { + var caching = P2Client.Caching.PREFER_OFFLINE; + var p2query = p2.query(caching); + + List p2units = p2query.getJarsNotOnMavenCentral(); + List mavenCoords = p2query.getJarsOnMavenCentral(); + + List p2Jars = new ArrayList<>(); + if (!p2units.isEmpty()) { + try (P2Client client = new P2Client(caching)) { + for (var p2unit : p2units) { + p2Jars.add(client.download(p2unit)); + } + } + } + boolean withTransitives = false; + Set mavenJars = mavenProvisioner.provisionWithTransitives(withTransitives, mavenCoords); + + throw new UnsupportedOperationException("TODO"); + } + + /** + * State of Eclipse configuration items, providing functionality to derived information + * based on the state. + */ + public static class State implements Serializable {} +} From 01adf6f4484a40ea87ea6030128a14766e8fa2ad Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 25 Jan 2023 00:27:34 -0800 Subject: [PATCH 0378/1120] Now we don't need any JDT lockfiles, because we can easily compute them at runtime. --- .../eclipse_jdt_formatter/v4.10.0.lockfile | 18 ----------------- .../eclipse_jdt_formatter/v4.11.0.lockfile | 19 ------------------ .../eclipse_jdt_formatter/v4.12.0.lockfile | 18 ----------------- .../eclipse_jdt_formatter/v4.13.0.lockfile | 18 ----------------- .../eclipse_jdt_formatter/v4.14.0.lockfile | 19 ------------------ .../eclipse_jdt_formatter/v4.15.0.lockfile | 19 ------------------ .../eclipse_jdt_formatter/v4.16.0.lockfile | 19 ------------------ .../eclipse_jdt_formatter/v4.17.0.lockfile | 19 ------------------ .../eclipse_jdt_formatter/v4.18.0.lockfile | 19 ------------------ .../eclipse_jdt_formatter/v4.19.0.lockfile | 19 ------------------ .../eclipse_jdt_formatter/v4.20.0.lockfile | 20 ------------------- .../eclipse_jdt_formatter/v4.21.0.lockfile | 20 ------------------- .../eclipse_jdt_formatter/v4.6.1.lockfile | 2 -- .../eclipse_jdt_formatter/v4.6.2.lockfile | 18 ----------------- .../eclipse_jdt_formatter/v4.6.3.lockfile | 2 -- .../eclipse_jdt_formatter/v4.7.0.lockfile | 2 -- .../eclipse_jdt_formatter/v4.7.1.lockfile | 2 -- .../eclipse_jdt_formatter/v4.7.2.lockfile | 2 -- .../eclipse_jdt_formatter/v4.7.3a.lockfile | 18 ----------------- .../eclipse_jdt_formatter/v4.8.0.lockfile | 18 ----------------- .../eclipse_jdt_formatter/v4.9.0.lockfile | 18 ----------------- 21 files changed, 309 deletions(-) delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.10.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.11.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.12.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.13.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.14.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.15.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.16.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.17.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.18.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.19.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.20.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.21.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.1.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.2.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.3.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.1.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.2.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.3a.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.8.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.9.0.lockfile diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.10.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.10.0.lockfile deleted file mode 100644 index 42d81d7324..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.10.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on JDT version 4.10.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tag/?h=R4_10 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.16.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.0 -org.eclipse.platform:org.eclipse.core.jobs:3.10.0 -org.eclipse.platform:org.eclipse.core.resources:3.13.0 -org.eclipse.platform:org.eclipse.core.runtime:3.14.0 -org.eclipse.platform:org.eclipse.equinox.app:1.3.500 -org.eclipse.platform:org.eclipse.equinox.common:3.10.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.0 -org.eclipse.platform:org.eclipse.osgi:3.13.0 -org.eclipse.platform:org.eclipse.text:3.6.300 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.11.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.11.0.lockfile deleted file mode 100644 index 3bbf59db23..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.11.0.lockfile +++ /dev/null @@ -1,19 +0,0 @@ -# Spotless formatter based on JDT version 4.11.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tag/?h=R4_11 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.17.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.0 -org.eclipse.platform:org.eclipse.core.jobs:3.10.0 -org.eclipse.platform:org.eclipse.core.resources:3.13.0 -org.eclipse.platform:org.eclipse.core.runtime:3.14.0 -org.eclipse.platform:org.eclipse.equinox.app:1.3.500 -org.eclipse.platform:org.eclipse.equinox.common:3.10.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.0 -org.eclipse.platform:org.eclipse.osgi:3.13.0 -org.eclipse.platform:org.eclipse.text:3.6.300 - diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.12.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.12.0.lockfile deleted file mode 100644 index c9bfc9a57d..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.12.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on JDT version 4.12.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tag/?h=R4_12 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.2.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.18.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.400 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.300 -org.eclipse.platform:org.eclipse.core.jobs:3.10.400 -org.eclipse.platform:org.eclipse.core.resources:3.13.400 -org.eclipse.platform:org.eclipse.core.runtime:3.15.300 -org.eclipse.platform:org.eclipse.equinox.app:1.4.200 -org.eclipse.platform:org.eclipse.equinox.common:3.10.400 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.400 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.400 -org.eclipse.platform:org.eclipse.osgi:3.14.0 -org.eclipse.platform:org.eclipse.text:3.8.200 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.13.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.13.0.lockfile deleted file mode 100644 index 4ee0adb3cf..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.13.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on JDT version 4.13.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tag/?h=R4_13 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.2.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.19.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.500 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.400 -org.eclipse.platform:org.eclipse.core.jobs:3.10.500 -org.eclipse.platform:org.eclipse.core.resources:3.13.500 -org.eclipse.platform:org.eclipse.core.runtime:3.16.0 -org.eclipse.platform:org.eclipse.equinox.app:1.4.300 -org.eclipse.platform:org.eclipse.equinox.common:3.10.500 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.500 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.500 -org.eclipse.platform:org.eclipse.osgi:3.15.0 -org.eclipse.platform:org.eclipse.text:3.9.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.14.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.14.0.lockfile deleted file mode 100644 index b42352633a..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.14.0.lockfile +++ /dev/null @@ -1,19 +0,0 @@ -# Spotless formatter based on JDT version 4.14.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/?h=R4_14 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.3.0 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.20.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.600 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.500 -org.eclipse.platform:org.eclipse.core.jobs:3.10.600 -org.eclipse.platform:org.eclipse.core.resources:3.13.600 -org.eclipse.platform:org.eclipse.core.runtime:3.17.0 -org.eclipse.platform:org.eclipse.equinox.app:1.4.300 -org.eclipse.platform:org.eclipse.equinox.common:3.10.600 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.600 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.600 -org.eclipse.platform:org.eclipse.osgi:3.15.100 -org.eclipse.platform:org.eclipse.text:3.10.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.15.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.15.0.lockfile deleted file mode 100644 index ee21631962..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.15.0.lockfile +++ /dev/null @@ -1,19 +0,0 @@ -# Spotless formatter based on JDT version 4.15.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/?h=R4_15 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.3.0 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.21.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.700 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.600 -org.eclipse.platform:org.eclipse.core.jobs:3.10.700 -org.eclipse.platform:org.eclipse.core.resources:3.13.600 -org.eclipse.platform:org.eclipse.core.runtime:3.17.100 -org.eclipse.platform:org.eclipse.equinox.app:1.4.400 -org.eclipse.platform:org.eclipse.equinox.common:3.11.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.700 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.700 -org.eclipse.platform:org.eclipse.osgi:3.15.200 -org.eclipse.platform:org.eclipse.text:3.10.100 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.16.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.16.0.lockfile deleted file mode 100644 index 7ff27b440a..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.16.0.lockfile +++ /dev/null @@ -1,19 +0,0 @@ -# Spotless formatter based on JDT version 4.16.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/?h=R4_16 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.3.0 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.22.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.700 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.700 -org.eclipse.platform:org.eclipse.core.jobs:3.10.800 -org.eclipse.platform:org.eclipse.core.resources:3.13.700 -org.eclipse.platform:org.eclipse.core.runtime:3.18.0 -org.eclipse.platform:org.eclipse.equinox.app:1.4.500 -org.eclipse.platform:org.eclipse.equinox.common:3.12.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.0 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.800 -org.eclipse.platform:org.eclipse.osgi:3.15.300 -org.eclipse.platform:org.eclipse.text:3.10.200 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.17.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.17.0.lockfile deleted file mode 100644 index 47cb5f10dd..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.17.0.lockfile +++ /dev/null @@ -1,19 +0,0 @@ -# Spotless formatter based on JDT version 4.17.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/?h=R4_17 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.4.1 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.23.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.700 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.800 -org.eclipse.platform:org.eclipse.core.jobs:3.10.800 -org.eclipse.platform:org.eclipse.core.resources:3.13.800 -org.eclipse.platform:org.eclipse.core.runtime:3.19.0 -org.eclipse.platform:org.eclipse.equinox.app:1.5.0 -org.eclipse.platform:org.eclipse.equinox.common:3.13.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.0 -org.eclipse.platform:org.eclipse.equinox.registry:3.9.0 -org.eclipse.platform:org.eclipse.osgi:3.16.0 -org.eclipse.platform:org.eclipse.text:3.10.300 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.18.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.18.0.lockfile deleted file mode 100644 index c5b2799c11..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.18.0.lockfile +++ /dev/null @@ -1,19 +0,0 @@ -# Spotless formatter based on JDT version 4.18.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/?h=R4_18 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.4.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.24.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.800 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.800 -org.eclipse.platform:org.eclipse.core.jobs:3.10.1000 -org.eclipse.platform:org.eclipse.core.resources:3.13.900 -org.eclipse.platform:org.eclipse.core.runtime:3.20.0 -org.eclipse.platform:org.eclipse.equinox.app:1.5.0 -org.eclipse.platform:org.eclipse.equinox.common:3.14.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.10.0 -org.eclipse.platform:org.eclipse.osgi:3.16.100 -org.eclipse.platform:org.eclipse.text:3.10.400 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.19.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.19.0.lockfile deleted file mode 100644 index fcc96b8520..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.19.0.lockfile +++ /dev/null @@ -1,19 +0,0 @@ -# Spotless formatter based on JDT version 4.19.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/?h=R4_19 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.4.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.25.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.800 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.900 -org.eclipse.platform:org.eclipse.core.jobs:3.10.1100 -org.eclipse.platform:org.eclipse.core.resources:3.14.0 -org.eclipse.platform:org.eclipse.core.runtime:3.20.100 -org.eclipse.platform:org.eclipse.equinox.app:1.5.100 -org.eclipse.platform:org.eclipse.equinox.common:3.14.100 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.200 -org.eclipse.platform:org.eclipse.equinox.registry:3.10.100 -org.eclipse.platform:org.eclipse.osgi:3.16.200 -org.eclipse.platform:org.eclipse.text:3.11.0 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.20.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.20.0.lockfile deleted file mode 100644 index b06a9bc617..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.20.0.lockfile +++ /dev/null @@ -1,20 +0,0 @@ -# Spotless formatter based on JDT version 4.20.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/?h=R4_20 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.1 -com.diffplug.spotless:spotless-eclipse-base:3.5.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.26.0 -org.eclipse.platform:org.eclipse.core.commands:3.10.0 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.1000 -org.eclipse.platform:org.eclipse.core.filesystem:1.9.0 -org.eclipse.platform:org.eclipse.core.jobs:3.11.0 -org.eclipse.platform:org.eclipse.core.resources:3.15.0 -org.eclipse.platform:org.eclipse.core.runtime:3.22.0 -org.eclipse.platform:org.eclipse.equinox.app:1.5.100 -org.eclipse.platform:org.eclipse.equinox.common:3.15.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.200 -org.eclipse.platform:org.eclipse.equinox.registry:3.10.200 -org.eclipse.platform:org.eclipse.osgi:3.16.300 -org.eclipse.platform:org.eclipse.text:3.12.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.21.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.21.0.lockfile deleted file mode 100644 index 84a90489c9..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.21.0.lockfile +++ /dev/null @@ -1,20 +0,0 @@ -# Spotless formatter based on JDT version 4.21.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/?h=R4_21 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.1 -com.diffplug.spotless:spotless-eclipse-base:3.5.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.27.0 -org.eclipse.platform:org.eclipse.core.commands:3.10.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.8.0 -org.eclipse.platform:org.eclipse.core.filesystem:1.9.100 -org.eclipse.platform:org.eclipse.core.jobs:3.12.0 -org.eclipse.platform:org.eclipse.core.resources:3.15.100 -org.eclipse.platform:org.eclipse.core.runtime:3.23.0 -org.eclipse.platform:org.eclipse.equinox.app:1.6.0 -org.eclipse.platform:org.eclipse.equinox.common:3.15.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.9.0 -org.eclipse.platform:org.eclipse.equinox.registry:3.11.0 -org.eclipse.platform:org.eclipse.osgi:3.17.0 -org.eclipse.platform:org.eclipse.text:3.12.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.1.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.1.lockfile deleted file mode 100644 index fd408e7ecc..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.1.lockfile +++ /dev/null @@ -1,2 +0,0 @@ -# Spotless formatter based on JDT version 4.6.1 (see https://projects.eclipse.org/projects/eclipse.jdt) -com.diffplug.spotless:spotless-ext-eclipse-jdt:4.6.1 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.2.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.2.lockfile deleted file mode 100644 index a042b7e734..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.2.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on JDT version 4.6.2 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/?h=R4_6_maintenance to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.12.2 -org.eclipse.platform:org.eclipse.core.commands:3.9.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.0 -org.eclipse.platform:org.eclipse.core.jobs:3.10.0 -org.eclipse.platform:org.eclipse.core.resources:3.13.0 -org.eclipse.platform:org.eclipse.core.runtime:3.14.0 -org.eclipse.platform:org.eclipse.equinox.app:1.3.500 -org.eclipse.platform:org.eclipse.equinox.common:3.10.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.0 -org.eclipse.platform:org.eclipse.osgi:3.13.0 -org.eclipse.platform:org.eclipse.text:3.6.300 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.3.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.3.lockfile deleted file mode 100644 index 714ff708c8..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.6.3.lockfile +++ /dev/null @@ -1,2 +0,0 @@ -# Spotless formatter based on JDT version 4.6.3 (see https://projects.eclipse.org/projects/eclipse.jdt) -com.diffplug.spotless:spotless-ext-eclipse-jdt:4.6.3 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.0.lockfile deleted file mode 100644 index 9e3eefbcb1..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.0.lockfile +++ /dev/null @@ -1,2 +0,0 @@ -# Spotless formatter based on JDT version 4.7 (see https://projects.eclipse.org/projects/eclipse.jdt) -com.diffplug.spotless:spotless-ext-eclipse-jdt:4.7.0 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.1.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.1.lockfile deleted file mode 100644 index 650c67e13b..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.1.lockfile +++ /dev/null @@ -1,2 +0,0 @@ -# Spotless formatter based on JDT version 4.7.1 (see https://projects.eclipse.org/projects/eclipse.jdt) -com.diffplug.spotless:spotless-ext-eclipse-jdt:4.7.1 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.2.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.2.lockfile deleted file mode 100644 index 35abd036aa..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.2.lockfile +++ /dev/null @@ -1,2 +0,0 @@ -# Spotless formatter based on JDT version 4.7.2 (see https://projects.eclipse.org/projects/eclipse.jdt) -com.diffplug.spotless:spotless-ext-eclipse-jdt:4.7.2 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.3a.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.3a.lockfile deleted file mode 100644 index a5e7aaa57b..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.7.3a.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on JDT version 4.7.3a (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/log/?h=R4_7_maintenance to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.13.101 -org.eclipse.platform:org.eclipse.core.commands:3.9.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.0 -org.eclipse.platform:org.eclipse.core.jobs:3.10.0 -org.eclipse.platform:org.eclipse.core.resources:3.13.0 -org.eclipse.platform:org.eclipse.core.runtime:3.14.0 -org.eclipse.platform:org.eclipse.equinox.app:1.3.500 -org.eclipse.platform:org.eclipse.equinox.common:3.10.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.0 -org.eclipse.platform:org.eclipse.osgi:3.13.0 -org.eclipse.platform:org.eclipse.text:3.6.300 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.8.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.8.0.lockfile deleted file mode 100644 index a9204f5a45..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.8.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on JDT version 4.8.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tag/?h=R4_8 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.14.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.0 -org.eclipse.platform:org.eclipse.core.jobs:3.10.0 -org.eclipse.platform:org.eclipse.core.resources:3.13.0 -org.eclipse.platform:org.eclipse.core.runtime:3.14.0 -org.eclipse.platform:org.eclipse.equinox.app:1.3.500 -org.eclipse.platform:org.eclipse.equinox.common:3.10.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.0 -org.eclipse.platform:org.eclipse.osgi:3.13.0 -org.eclipse.platform:org.eclipse.text:3.6.300 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.9.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.9.0.lockfile deleted file mode 100644 index 5a19c69254..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_jdt_formatter/v4.9.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on JDT version 4.9.0 (see https://projects.eclipse.org/projects/eclipse.jdt) -# Compare tag in M2 pom with https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/tag/?h=R4_9 to determine core version. -com.diffplug.spotless:spotless-eclipse-jdt:4.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.jdt:org.eclipse.jdt.core:3.15.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.0 -org.eclipse.platform:org.eclipse.core.jobs:3.10.0 -org.eclipse.platform:org.eclipse.core.resources:3.13.0 -org.eclipse.platform:org.eclipse.core.runtime:3.14.0 -org.eclipse.platform:org.eclipse.equinox.app:1.3.500 -org.eclipse.platform:org.eclipse.equinox.common:3.10.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.0 -org.eclipse.platform:org.eclipse.osgi:3.13.0 -org.eclipse.platform:org.eclipse.text:3.6.300 \ No newline at end of file From 46d370dd5e5e0ebaadcd4ebca2eef1927d2806f3 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 25 Jan 2023 19:20:05 +0100 Subject: [PATCH 0379/1120] 1499: provide npm output if server starting fails --- .../diffplug/spotless/npm/NpmFormatterStepStateBase.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 9cff41e604..3e5fa1ff18 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -32,6 +32,8 @@ import org.slf4j.LoggerFactory; import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.ProcessRunner.LongRunningProcess; +import com.diffplug.spotless.ThrowingEx; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -101,13 +103,14 @@ protected boolean needsPrepareNodeServerLayout() { protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { assertNodeServerDirReady(); + LongRunningProcess server = null; try { // The npm process will output the randomly selected port of the http server process to 'server.port' file // so in order to be safe, remove such a file if it exists before starting. final File serverPortFile = new File(this.nodeServerLayout.nodeModulesDir(), "server.port"); NpmResourceHelper.deleteFileIfExists(serverPortFile); // start the http server in node - Process server = new NpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); + server = new NpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); // await the readiness of the http server - wait for at most 60 seconds try { @@ -128,7 +131,7 @@ protected ServerProcessInfo npmRunServer() throws ServerStartException, IOExcept String serverPort = NpmResourceHelper.readUtf8StringFromFile(serverPortFile).trim(); return new ServerProcessInfo(server, serverPort, serverPortFile); } catch (IOException | TimeoutException e) { - throw new ServerStartException(e); + throw new ServerStartException("Starting server failed." + (server != null ? "\n\nProcess result:\n" + ThrowingEx.get(server::result) : ""), e); } } @@ -197,7 +200,7 @@ public void close() throws Exception { protected static class ServerStartException extends RuntimeException { private static final long serialVersionUID = -8803977379866483002L; - public ServerStartException(Throwable cause) { + public ServerStartException(String message, Throwable cause) { super(cause); } } From 012e4ae55cd0c9c3783ed6130e6edf6e10700277 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 25 Jan 2023 19:21:35 +0100 Subject: [PATCH 0380/1120] 1499: fix condition --- .../com/diffplug/spotless/npm/NpmFormatterStepStateBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 3e5fa1ff18..92ac7df6f2 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -94,7 +94,7 @@ protected void assertNodeServerDirReady() throws IOException { } protected boolean needsPrepareNodeServer() { - return this.nodeServerLayout.isNodeModulesPrepared(); + return !this.nodeServerLayout.isNodeModulesPrepared(); } protected boolean needsPrepareNodeServerLayout() { From 76b626cc73ef469c499a3b5fc33f807c0645766f Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 25 Jan 2023 22:29:12 +0400 Subject: [PATCH 0381/1120] Handle specifically empty filePath, and not default FS rootDir --- gradle.properties | 2 +- .../java/com/diffplug/spotless/Formatter.java | 12 +++- testlib/build.gradle | 1 + .../com/diffplug/spotless/FormatterTest.java | 66 ++++++++++++++++++- 4 files changed, 76 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5702d21bdd..523440be25 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,4 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=4.11.0 \ No newline at end of file +VER_MOCKITO=5.0.0 diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index 038e77fa64..3a38893cd6 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 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. @@ -237,8 +237,14 @@ public String compute(String unix, File file) { unix = LineEnding.toUnix(formatted); } } catch (Throwable e) { - String relativePath = rootDir.relativize(file.toPath()).toString(); - exceptionPolicy.handleError(e, step, relativePath); + if (file.getPath().isEmpty()) { + // Path.relativize would fail if rootDir is an absolute path + exceptionPolicy.handleError(e, step, ""); + } else { + // Path may be forged from a different FileSystem than Filesystem.default + String relativePath = rootDir.relativize(rootDir.getFileSystem().getPath(file.getPath())).toString(); + exceptionPolicy.handleError(e, step, relativePath); + } } } return unix; diff --git a/testlib/build.gradle b/testlib/build.gradle index 64d4681805..97b17d0dc6 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -12,6 +12,7 @@ dependencies { api "com.diffplug.durian:durian-testlib:${VER_DURIAN}" api "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" api "org.assertj:assertj-core:${VER_ASSERTJ}" + api "org.mockito:mockito-core:$VER_MOCKITO" implementation "com.diffplug.durian:durian-io:${VER_DURIAN}" implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}" diff --git a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java index 06b8e64d31..0faf40bb95 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -15,15 +15,19 @@ */ package com.diffplug.spotless; +import java.io.File; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import com.diffplug.common.base.StandardSystemProperty; import com.diffplug.spotless.generic.EndWithNewlineStep; @@ -89,4 +93,64 @@ protected Formatter create() { } }.testEquals(); } + + // new File("") can be used if there is no File representing this content. It should not conflict with rootDir.relativize(...) + @Test + public void testExceptionWithEmptyPath() throws Exception { + LineEnding.Policy lineEndingsPolicy = LineEnding.UNIX.createPolicy(); + Charset encoding = StandardCharsets.UTF_8; + FormatExceptionPolicy exceptionPolicy = FormatExceptionPolicy.failOnlyOnError(); + + Path rootDir = Paths.get(StandardSystemProperty.USER_DIR.value()); + + FormatterStep step = Mockito.mock(FormatterStep.class); + Mockito.when(step.getName()).thenReturn("someFailingStep"); + Mockito.when(step.format(Mockito.anyString(), Mockito.any(File.class))).thenThrow(new IllegalArgumentException("someReason")); + List steps = Collections.singletonList(step); + + Formatter formatter = Formatter.builder() + .lineEndingsPolicy(lineEndingsPolicy) + .encoding(encoding) + .rootDir(rootDir) + .steps(steps) + .exceptionPolicy(exceptionPolicy) + .build(); + + formatter.compute("someFileContent", new File("")); + } + + // rootDir may be a path not from the default FileSystem + @Test + public void testExceptionWithRootDirIsNotFileSystem() throws Exception { + LineEnding.Policy lineEndingsPolicy = LineEnding.UNIX.createPolicy(); + Charset encoding = StandardCharsets.UTF_8; + FormatExceptionPolicy exceptionPolicy = FormatExceptionPolicy.failOnlyOnError(); + + Path rootDir = Mockito.mock(Path.class); + Path relativized = Mockito.mock(Path.class); + Mockito.when(rootDir.relativize(Mockito.any(Path.class))).then(invok -> { + Path filePath = invok.getArgument(0); + if (filePath.getFileSystem() == FileSystems.getDefault()) { + throw new IllegalArgumentException("Can not relativize through different FileSystems"); + } + + return relativized; + }); + + FormatterStep step = Mockito.mock(FormatterStep.class); + Mockito.when(step.getName()).thenReturn("someFailingStep"); + Mockito.when(step.format(Mockito.anyString(), Mockito.any(File.class))).thenThrow(new IllegalArgumentException("someReason")); + List steps = Collections.singletonList(step); + + Formatter formatter = Formatter.builder() + .lineEndingsPolicy(lineEndingsPolicy) + .encoding(encoding) + .rootDir(rootDir) + .steps(steps) + .exceptionPolicy(exceptionPolicy) + .build(); + + formatter.compute("someFileContent", new File("")); + } + } From a8c0bb818de07242feeb08f5731af6ce6fd7a0cb Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 25 Jan 2023 22:53:07 +0400 Subject: [PATCH 0382/1120] Rollback Mockito to 4.X (as 5.X requires JDK11) --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 523440be25..d99bdac6ce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,4 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=5.13.1.202206130422-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.0.0 +VER_MOCKITO=4.11.0 From 469351773f1a6577a8fea6b328a4986581d385bd Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 21:18:49 +0800 Subject: [PATCH 0383/1120] Compare current Java version via isCompatibleWith --- lib/build.gradle | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 82595da399..f2ca13ccb1 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -107,16 +107,15 @@ spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even min apply from: rootProject.file('gradle/special-tests.gradle') tasks.withType(Test).configureEach { - def jdkVersion = JavaVersion.current().majorVersion.toInteger() def args = [] - if (jdkVersion >= 16) { + if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // https://docs.gradle.org/7.5/userguide/upgrading_version_7.html#removes_implicit_add_opens_for_test_workers args += [ "--add-opens=java.base/java.lang=ALL-UNNAMED", "--add-opens=java.base/java.util=ALL-UNNAMED", ] } - if (jdkVersion >= 18) { + if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_18)) { // https://openjdk.org/jeps/411 args += "-Djava.security.manager=allow" } From bdf09a4071708af3fd4e10ecc68975c8df89cc56 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 21:23:25 +0800 Subject: [PATCH 0384/1120] Apply mavenCentral in dependencyResolutionManagement --- build.gradle | 5 +---- gradle/java-setup.gradle | 1 - plugin-maven/build.gradle | 1 - settings.gradle | 8 ++++++++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index f9e3d0de21..9d43f50135 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,3 @@ -repositories { - mavenCentral() -} apply from: rootProject.file('gradle/java-publish.gradle') apply from: rootProject.file('gradle/changelog.gradle') allprojects { @@ -18,4 +15,4 @@ spotless { trimTrailingWhitespace() endWithNewline() } -} \ No newline at end of file +} diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 9c9f394405..0f80c89d81 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -1,7 +1,6 @@ ////////// // JAVA // ////////// -repositories { mavenCentral() } // setup java apply plugin: 'java' diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 664101a0fd..8ab478d6ba 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -3,7 +3,6 @@ plugins { id 'de.benediktritter.maven-plugin-development' version '0.4.1' } -repositories { mavenCentral() } apply from: rootProject.file('gradle/changelog.gradle') ext.artifactId = project.artifactIdMaven version = spotlessChangelog.versionNext diff --git a/settings.gradle b/settings.gradle index 8ab9430f00..996d5e6b74 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,6 +17,7 @@ pluginManagement { id 'io.github.davidburstrom.version-compatibility' version '0.4.0' } } + plugins { id 'com.diffplug.spotless' apply false id 'com.gradle.plugin-publish' apply false @@ -28,6 +29,13 @@ plugins { id 'io.github.davidburstrom.version-compatibility' apply false id "com.gradle.enterprise" version "3.12.2" } + +dependencyResolutionManagement { + repositories { + mavenCentral() + } +} + if (System.env['CI'] != null) { // use the remote buildcache on all CI builds buildCache { From 57edefb327936a8149d730cbc5863707d139db70 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 21:29:54 +0800 Subject: [PATCH 0385/1120] Apply plugin versions in root plugins block --- settings.gradle | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/settings.gradle b/settings.gradle index 996d5e6b74..d925058035 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,32 +1,27 @@ pluginManagement { - plugins { - id 'com.diffplug.spotless' version '6.13.0' - // https://plugins.gradle.org/plugin/com.gradle.plugin-publish - id 'com.gradle.plugin-publish' version '1.1.0' - // https://github.com/gradle-nexus/publish-plugin/releases - id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' - // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.13' - // https://github.com/diffplug/spotless-changelog - id 'com.diffplug.spotless-changelog' version '2.4.1' - // https://github.com/diffplug/goomph/blob/main/CHANGES.md - id 'com.diffplug.p2.asmaven' version '3.27.0' // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 - // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md - id 'com.adarshr.test-logger' version '3.2.0' - // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags - id 'io.github.davidburstrom.version-compatibility' version '0.4.0' + repositories { + mavenCentral() + gradlePluginPortal() } } plugins { - id 'com.diffplug.spotless' apply false - id 'com.gradle.plugin-publish' apply false - id 'io.github.gradle-nexus.publish-plugin' apply false - id 'com.github.spotbugs' apply false - id 'com.diffplug.spotless-changelog' apply false - id 'com.diffplug.p2.asmaven' apply false - id 'com.adarshr.test-logger' apply false - id 'io.github.davidburstrom.version-compatibility' apply false + id 'com.diffplug.spotless' version '6.13.0' apply false + // https://plugins.gradle.org/plugin/com.gradle.plugin-publish + id 'com.gradle.plugin-publish' version '1.1.0' apply false + // https://github.com/gradle-nexus/publish-plugin/releases + id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' apply false + // https://github.com/spotbugs/spotbugs-gradle-plugin/releases + id 'com.github.spotbugs' version '5.0.13' apply false + // https://github.com/diffplug/spotless-changelog + id 'com.diffplug.spotless-changelog' version '2.4.1' apply false + // https://github.com/diffplug/goomph/blob/main/CHANGES.md + // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 + id 'com.diffplug.p2.asmaven' version '3.27.0' apply false + // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md + id 'com.adarshr.test-logger' version '3.2.0' apply false + // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags + id 'io.github.davidburstrom.version-compatibility' version '0.4.0' apply false id "com.gradle.enterprise" version "3.12.2" } From fff6fdf98af32af8ef089c87477177648bb3bd5b Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 25 Jan 2023 21:38:07 +0800 Subject: [PATCH 0386/1120] Defer more task configurations --- _ext/gradle/java-setup.gradle | 2 +- _ext/gradle/update-lockfile.gradle | 4 ++-- gradle/java-setup.gradle | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/_ext/gradle/java-setup.gradle b/_ext/gradle/java-setup.gradle index 9572fc2955..0d620a6519 100644 --- a/_ext/gradle/java-setup.gradle +++ b/_ext/gradle/java-setup.gradle @@ -9,7 +9,7 @@ apply from: rootProject.file('gradle/java-setup.gradle') apply plugin: 'java-library' // Show warning locations, fail on warnings -tasks.withType(JavaCompile) { +tasks.withType(JavaCompile).configureEach { options.compilerArgs << "-Xlint:unchecked" options.compilerArgs << "-Xlint:deprecation" options.compilerArgs << "-Werror" diff --git a/_ext/gradle/update-lockfile.gradle b/_ext/gradle/update-lockfile.gradle index 098d960eff..3c23bb860b 100644 --- a/_ext/gradle/update-lockfile.gradle +++ b/_ext/gradle/update-lockfile.gradle @@ -1,6 +1,6 @@ // Use file locking -configurations.all { +configurations.configureEach { resolutionStrategy { activateDependencyLocking() } -} \ No newline at end of file +} diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 0f80c89d81..b048229b75 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -7,7 +7,7 @@ apply plugin: 'java' sourceCompatibility = VER_JAVA targetCompatibility = VER_JAVA -tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } +tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' } ////////////// // SPOTBUGS // From 05950364f603bc45648660813cc6e7ab692de11d Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 26 Jan 2023 13:04:10 +0800 Subject: [PATCH 0387/1120] Trigger gradle/wrapper-validation-action after related files changed --- .github/workflows/gradle-wrapper-validation.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index c80a7e5278..2c02ce0fc4 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -1,5 +1,15 @@ name: "Validate Gradle Wrapper" -on: [push, pull_request] +on: + push: + paths: + - 'gradlew' + - 'gradlew.bat' + - 'gradle/wrapper/' + pull_request: + paths: + - 'gradlew' + - 'gradlew.bat' + - 'gradle/wrapper/' permissions: contents: read From f634ef00ec2fc70288601e439f8e1f86440171e4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 25 Jan 2023 22:45:17 -0800 Subject: [PATCH 0388/1120] https://github.com/equodev/equo-ide/pull/65 has merged --- build.gradle | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 450ee61583..d1ae14750e 100644 --- a/build.gradle +++ b/build.gradle @@ -4,9 +4,7 @@ plugins { } equoIde { branding.title('Spotless').icon(file('_images/spotless_logo.png')) - - // waiting on https://github.com/equodev/equo-ide/pull/65 - //welcome().openUrlOnStartup('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') + welcome().openUrlOnStartup('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') // everything below becomes the default after https://github.com/equodev/equo-ide/pull/66 p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' From 56a6f7e3d1ccfcdb2fd385a5d06cc3e831c49b22 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 25 Jan 2023 23:03:33 -0800 Subject: [PATCH 0389/1120] Improved KtLintStepTest.equality to not download so much. --- .../java/com/diffplug/spotless/kotlin/KtLintStepTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 3047245298..6700be168d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -88,14 +88,14 @@ void works0_48_1() { @Test void equality() { new SerializableEqualityTester() { - String version = "0.32.0"; + String version = "0.48.0"; @Override protected void setupTest(API api) { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "0.38.0-alpha01"; + version = "0.48.1"; api.areDifferentThan(); } From fb03922888f9a1e3c3e987249c121df191fe3abd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 10:15:08 -0800 Subject: [PATCH 0390/1120] The Kotlin gradle integration tests had tested every possible combination. A job for the unit tests, not the integration tests. --- .../gradle/spotless/KotlinExtensionTest.java | 262 ------------------ .../spotless/KotlinGradleExtensionTest.java | 121 -------- 2 files changed, 383 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index a15a51412e..947b5bd728 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -23,24 +23,6 @@ class KotlinExtensionTest extends GradleIntegrationHarness { private static final String HEADER = "// License Header"; private static final String HEADER_WITH_YEAR = "// License Header $YEAR"; - @Test - void integration() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint()", - " }", - "}"); - setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/basic.clean"); - } - @Test void integrationDiktat() throws IOException { setFile("build.gradle").toLines( @@ -59,42 +41,6 @@ void integrationDiktat() throws IOException { assertFile("src/main/kotlin/com/example/Main.kt").sameAsResource("kotlin/diktat/main.clean"); } - @Test - void integrationKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt()", - " }", - "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktfmt/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic.clean"); - } - - @Test - void integrationKtfmt_dropboxStyle_0_18() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt('0.18').dropboxStyle()", - " }", - "}"); - setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktfmt/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean"); - } - @Test void integrationKtfmt_dropboxStyle_0_19() throws IOException { setFile("build.gradle").toLines( @@ -113,42 +59,6 @@ void integrationKtfmt_dropboxStyle_0_19() throws IOException { assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean"); } - @Test - void testWithIndentation() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint().editorConfigOverride(['indent_size': '6'])", - " }", - "}"); - setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/basic.clean-indent6"); - } - - @Test - void withExperimental() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint().setUseExperimental(true)", - " }", - "}"); - setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimental.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimental.clean"); - } - @Test void withExperimentalEditorConfigOverride() throws IOException { setFile("build.gradle").toLines( @@ -190,115 +100,6 @@ void testWithHeader() throws IOException { assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test")); } - @Test - void testWithHeaderKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " licenseHeader('" + HEADER + "')", - " ktfmt()", - " }", - "}"); - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeaderKtfmt.test")); - } - - @Test - void testWithCustomHeaderSeparator() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint()", - " licenseHeader ('" + HEADER + "', '@file')", - " }", - "}"); - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test")); - } - - @Test - void testWithCustomHeaderSeparatorKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " licenseHeader ('" + HEADER + "', '@file')", - " ktfmt()", - " }", - "}"); - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithoutHeader.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").hasContent(HEADER + "\n" + getTestResource("kotlin/licenseheader/KotlinCodeWithoutHeaderKtfmt.test")); - } - - @Test - void testWithNonStandardYearSeparator() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktlint()", - " licenseHeader('" + HEADER_WITH_YEAR + "').yearSeparator(', ')", - " }", - "}"); - - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test"); - setFile("src/main/kotlin/AnObject2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - assertFile("src/main/kotlin/AnObject2.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - } - - @Test - void testWithNonStandardYearSeparatorKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " licenseHeader('" + HEADER_WITH_YEAR + "').yearSeparator(', ')", - " ktfmt()", - " }", - "}"); - - setFile("src/main/kotlin/AnObject.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader.test"); - setFile("src/main/kotlin/AnObject2.kt").toResource("kotlin/licenseheader/KotlinCodeWithMultiYearHeader2.test"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/AnObject.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - assertFile("src/main/kotlin/AnObject2.kt").matches(matcher -> { - matcher.startsWith("// License Header 2012, 2014"); - }); - } - @Test void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { setFile("build.gradle").toLines( @@ -319,67 +120,4 @@ void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); } - - @Test - void testWithCustomMaxWidthDefaultStyleKtfmtGradleKts() throws IOException { - setFile("build.gradle.kts").toLines( - "plugins {", - " id(\"org.jetbrains.kotlin.jvm\") version \"1.5.31\"", - " id(\"com.diffplug.spotless\")", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt().configure { options ->", - " options.setMaxWidth(120)", - " }", - " }", - "}"); - - setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width.clean"); - } - - @Test - void testWithCustomMaxWidthDropboxStyleKtfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt().dropboxStyle().configure { options ->", - " options.maxWidth = 120", - " }", - " }", - "}"); - - setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width-dropbox.clean"); - } - - @Test - void testWithCustomMaxWidthDropboxStyleKtfmtGradleKts() throws IOException { - setFile("build.gradle.kts").toLines( - "plugins {", - " id(\"org.jetbrains.kotlin.jvm\") version \"1.5.31\"", - " id(\"com.diffplug.spotless\")", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlin {", - " ktfmt().dropboxStyle().configure { options ->", - " options.setMaxWidth(120)", - " }", - " }", - "}"); - - setFile("src/main/kotlin/max-width.kt").toResource("kotlin/ktfmt/max-width.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/max-width.kt").sameAsResource("kotlin/ktfmt/max-width-dropbox.clean"); - } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 015414c331..13a7cd8472 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -23,56 +23,6 @@ import org.junit.jupiter.api.Test; class KotlinGradleExtensionTest extends GradleIntegrationHarness { - @Test - void integration() throws IOException { - testInDirectory(null); - } - - @Test - void integration_script_in_subdir() throws IOException { - testInDirectory("companionScripts"); - } - - private void testInDirectory(final String directory) throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint()", - " target '**/*.gradle.kts'", - " }", - "}"); - String filePath = "configuration.gradle.kts"; - if (directory != null) { - filePath = directory + "/" + filePath; - } - setFile(filePath).toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile(filePath).sameAsResource("kotlin/ktlint/basic.clean"); - } - - @Test - void integration_default() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/basic.clean"); - } - @Test void integration_default_diktat() throws IOException { setFile("build.gradle").toLines( @@ -91,41 +41,6 @@ void integration_default_diktat() throws IOException { assertThat(result.getOutput()).contains("[AVOID_NESTED_FUNCTIONS] try to avoid using nested functions"); } - @Test - void indentStep() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint().userData(['indent_size': '6'])", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/basic.dirty"); - gradleRunner().withArguments("spotlessCheck").buildAndFail(); - } - - @Test - void withExperimental() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint().setUseExperimental(true)", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimental.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimental.clean"); - } - @Test void withExperimentalEditorConfigOverride() throws IOException { setFile("build.gradle").toLines( @@ -148,24 +63,6 @@ void withExperimentalEditorConfigOverride() throws IOException { assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); } - @Test - void integration_ktfmt() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktfmt()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktfmt/basic.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktfmt/basic.clean"); - } - @Test void integration_ktfmt_with_dropbox_style() throws IOException { setFile("build.gradle").toLines( @@ -183,22 +80,4 @@ void integration_ktfmt_with_dropbox_style() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktfmt/dropboxstyle.clean"); } - - @Test - void integration_lint_script_files_without_top_level_declaration() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktlint()", - " }", - "}"); - setFile("configuration.gradle.kts").toContent("buildscript {}"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").hasContent("buildscript {}"); - } } From 87a168b877a216dd0c397e58aa37e5c319dd8c7c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 10:36:35 -0800 Subject: [PATCH 0391/1120] Bump default KtLint `0.48.1` -> `0.48.2` --- .../diffplug/spotless/kotlin/KtLintStep.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 7bcae36fb0..0d75460902 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -36,11 +36,9 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.48.1"; + private static final String DEFAULT_VERSION = "0.48.2"; static final String NAME = "ktlint"; - static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; - static final String MAVEN_COORDINATE_PRE_0_32 = PACKAGE_PRE_0_32 + ":ktlint:"; static final String MAVEN_COORDINATE = PACKAGE + ":ktlint:"; public static FormatterStep create(Provisioner provisioner) { @@ -114,21 +112,14 @@ static final class State implements Serializable { @Nullable FileSignature editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { - this.version = version; - - String coordinate; - if (BadSemver.version(version) < BadSemver.version(0, 32)) { - coordinate = MAVEN_COORDINATE_PRE_0_32; - } else { - coordinate = MAVEN_COORDINATE; - } - if (BadSemver.version(version) < BadSemver.version(0, 31, 0)) { - throw new IllegalStateException("KtLint versions < 0.31.0 not supported!"); + if (BadSemver.version(version) < BadSemver.version(0, 46, 0)) { + throw new IllegalStateException("KtLint versions < 0.46.0 not supported!"); } + this.version = version; this.useExperimental = useExperimental; this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); - this.jarState = JarState.from(coordinate + version, provisioner); + this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); this.editorConfigPath = editorConfigPath; this.isScript = isScript; } From 87b6dd8b8bd8a3848d02f612f38b1d547a95bcbe Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 10:36:58 -0800 Subject: [PATCH 0392/1120] Bump default scalafmt `3.6.1` -> `3.7.1` --- .../main/java/com/diffplug/spotless/scala/ScalaFmtStep.java | 4 ++-- testlib/src/main/resources/scala/scalafmt/scalafmt.conf | 2 +- .../java/com/diffplug/spotless/scala/ScalaFmtStepTest.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java index bff0d9b215..264ca679db 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -34,7 +34,7 @@ public class ScalaFmtStep { // prevent direct instantiation private ScalaFmtStep() {} - private static final String DEFAULT_VERSION = "3.6.1"; + static final String DEFAULT_VERSION = "3.7.1"; private static final String DEFAULT_SCALA_MAJOR_VERSION = "2.13"; static final String NAME = "scalafmt"; diff --git a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf index e15d7318fa..f3cfb3a031 100644 --- a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf +++ b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.6.1 +version = 3.7.1 runner.dialect = scala213 style = defaultWithAlign # For pretty alignment. maxColumn = 20 # For my teensy narrow display diff --git a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java index 1714dd9e29..c28046e148 100644 --- a/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/scala/ScalaFmtStepTest.java @@ -30,13 +30,13 @@ class ScalaFmtStepTest extends ResourceHarness { @Test void behaviorDefaultConfig() { - StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), null)) + StepHarness.forStep(ScalaFmtStep.create(TestProvisioner.mavenCentral())) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.clean_3.0.0"); } @Test void behaviorCustomConfig() { - StepHarness.forStep(ScalaFmtStep.create("3.0.0", TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) + StepHarness.forStep(ScalaFmtStep.create(ScalaFmtStep.DEFAULT_VERSION, TestProvisioner.mavenCentral(), createTestFile("scala/scalafmt/scalafmt.conf"))) .testResource("scala/scalafmt/basic.dirty", "scala/scalafmt/basic.cleanWithCustomConf_3.0.0"); } From 5d6714d5666194e3b418a23d3d2379b797fb31fc Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 10:41:32 -0800 Subject: [PATCH 0393/1120] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index efbf1e5ae0..363dac1758 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * From now on, we will support no more than 2 breaking changes at a time. * NpmFormatterStepStateBase delays `npm install` call until the formatter is first used. This enables better integration with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522)) +* Bump default `ktlint` version to latest `0.48.1` -> `0.48.2` ([#1529](https://github.com/diffplug/spotless/pull/1529)) +* Bump default `scalafmt` version to latest `3.6.1` -> `3.7.1` ([#1529](https://github.com/diffplug/spotless/pull/1529)) ## [2.32.0] - 2023-01-13 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 693712cbff..8d01068383 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -20,6 +20,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `npm`-based formatters `ESLint`, `prettier` and `tsfmt` delay their `npm install` call until the formatters are first used. For gradle this effectively moves the `npm install` call out of the configuration phase and as such enables better integration with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522)) +* Bump default `ktlint` version to latest `0.48.1` -> `0.48.2` ([#1529](https://github.com/diffplug/spotless/pull/1529)) +* Bump default `scalafmt` version to latest `3.6.1` -> `3.7.1` ([#1529](https://github.com/diffplug/spotless/pull/1529)) ## [6.13.0] - 2023-01-14 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9cda0d2785..3967f468fd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -21,6 +21,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. * `npm`-based formatters `ESLint`, `prettier` and `tsfmt` delay their `npm install` call until the formatters are first used. ([#1522](https://github.com/diffplug/spotless/pull/1522) +* Bump default `ktlint` version to latest `0.48.1` -> `0.48.2` ([#1529](https://github.com/diffplug/spotless/pull/1529)) +* Bump default `scalafmt` version to latest `3.6.1` -> `3.7.1` ([#1529](https://github.com/diffplug/spotless/pull/1529)) ## [2.30.0] - 2023-01-13 ### Added From 5c3411d00a120c59f301c6ea57f4e2aff2fb4164 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 11:07:05 -0800 Subject: [PATCH 0394/1120] Add missing changelog links to root `settings.gradle` --- settings.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/settings.gradle b/settings.gradle index d925058035..a5bb6c0062 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,7 +13,7 @@ plugins { id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases id 'com.github.spotbugs' version '5.0.13' apply false - // https://github.com/diffplug/spotless-changelog + // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md id 'com.diffplug.spotless-changelog' version '2.4.1' apply false // https://github.com/diffplug/goomph/blob/main/CHANGES.md // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 @@ -22,7 +22,8 @@ plugins { id 'com.adarshr.test-logger' version '3.2.0' apply false // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.4.0' apply false - id "com.gradle.enterprise" version "3.12.2" + // https://plugins.gradle.org/plugin/com.gradle.enterprise + id 'com.gradle.enterprise' version '3.12.2' } dependencyResolutionManagement { From f71b28658bf015b20d7b3a4dc084c8b4fa4f0c19 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 11:07:37 -0800 Subject: [PATCH 0395/1120] Fix bug in changelog publish setup. --- gradle/java-publish.gradle | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 3d1ddd1c4f..7d2055d78d 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -186,14 +186,12 @@ if (!version.endsWith('-SNAPSHOT')) { } // ensures that changelog bump and push only happens if the publish was successful def thisProj = project - afterEvaluate { - changelogTasks.named('changelogBump').configure { - dependsOn thisProj.tasks.named('publishPluginMavenPublicationToSonatypeRepository') - dependsOn rootProject.tasks.named('closeAndReleaseSonatypeStagingRepository') - // if we have a gradle plugin, we need to push it up to the plugin portal too - if (thisProj.tasks.names.contains('publishPlugins')) { - dependsOn thisProj.tasks.named('publishPlugins') - } + changelogTasks.named('changelogBump').configure { + dependsOn ":${thisProj.path}:publishPluginMavenPublicationToSonatypeRepository" + dependsOn ":closeAndReleaseSonatypeStagingRepository" + // if we have a gradle plugin, we need to push it up to the plugin portal too + if (thisProj.tasks.names.contains('publishPlugins')) { + dependsOn thisProj.tasks.named('publishPlugins') } } } From 0d34fa703536b7f83b35d45f7eea153d724e2cc3 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 26 Jan 2023 23:20:30 +0400 Subject: [PATCH 0396/1120] Switch from new File() to a Sentinel reference --- .../java/com/diffplug/spotless/Formatter.java | 6 ++- .../com/diffplug/spotless/FormatterStep.java | 6 +-- .../diffplug/spotless/FormatterStepImpl.java | 9 ++--- .../com/diffplug/spotless/FormatterTest.java | 38 +++++++++++++++++-- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index 3a38893cd6..be045e7fe1 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -39,6 +39,9 @@ public final class Formatter implements Serializable, AutoCloseable { private static final long serialVersionUID = 1L; + // This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format + public static final File SENTINEL_NO_FILE_ON_DISK = new File("NO_FILE_ON_DISK.sentinel"); + private LineEnding.Policy lineEndingsPolicy; private Charset encoding; private Path rootDir; @@ -237,8 +240,7 @@ public String compute(String unix, File file) { unix = LineEnding.toUnix(formatted); } } catch (Throwable e) { - if (file.getPath().isEmpty()) { - // Path.relativize would fail if rootDir is an absolute path + if (file == SENTINEL_NO_FILE_ON_DISK) { exceptionPolicy.handleError(e, step, ""); } else { // Path may be forged from a different FileSystem than Filesystem.default diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index 5729f676b2..79793a403e 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.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. @@ -37,8 +37,8 @@ public interface FormatterStep extends Serializable { * @param rawUnix * the content to format, guaranteed to have unix-style newlines ('\n'); never null * @param file - * the file which {@code rawUnix} was obtained from; never null. Pass an empty file using - * {@code new File("")} if and only if no file is actually associated with {@code rawUnix} + * the file which {@code rawUnix} was obtained from; never null. Pass the reference + * {@code Formatter#SENTINEL_NO_FILE_ON_DISK} if and only if no file is actually associated with {@code rawUnix} * @return the formatted content, guaranteed to only have unix-style newlines; may return null * if the formatter step doesn't have any changes to make * @throws Exception if the formatter step experiences a problem diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java index 7663145f51..fe7cabca49 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -109,18 +109,15 @@ protected String format(Integer state, String rawUnix, File file) throws Excepti if (formatter == null) { formatter = formatterSupplier.get(); if (formatter instanceof FormatterFunc.Closeable) { - throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284"); + throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284"); } } return formatter.apply(rawUnix, file); } } - /** A dummy SENTINEL file. */ - static final File SENTINEL = new File(""); - static void checkNotSentinel(File file) { - if (file == SENTINEL) { + if (file == Formatter.SENTINEL_NO_FILE_ON_DISK) { throw new IllegalArgumentException("This step requires the underlying file. If this is a test, use StepHarnessWithFile"); } } diff --git a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java index 0faf40bb95..de96cd2ae3 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java @@ -18,6 +18,7 @@ import java.io.File; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.Paths; @@ -94,7 +95,7 @@ protected Formatter create() { }.testEquals(); } - // new File("") can be used if there is no File representing this content. It should not conflict with rootDir.relativize(...) + // new File("") as filePath is known to fail @Test public void testExceptionWithEmptyPath() throws Exception { LineEnding.Policy lineEndingsPolicy = LineEnding.UNIX.createPolicy(); @@ -116,7 +117,32 @@ public void testExceptionWithEmptyPath() throws Exception { .exceptionPolicy(exceptionPolicy) .build(); - formatter.compute("someFileContent", new File("")); + Assertions.assertThrows(IllegalArgumentException.class, () -> formatter.compute("someFileContent", new File(""))); + } + + // If there is no File actually holding the content, one may rely on Formatter.NO_FILE_ON_DISK + @Test + public void testExceptionWithSentinelNoFileOnDisk() throws Exception { + LineEnding.Policy lineEndingsPolicy = LineEnding.UNIX.createPolicy(); + Charset encoding = StandardCharsets.UTF_8; + FormatExceptionPolicy exceptionPolicy = FormatExceptionPolicy.failOnlyOnError(); + + Path rootDir = Paths.get(StandardSystemProperty.USER_DIR.value()); + + FormatterStep step = Mockito.mock(FormatterStep.class); + Mockito.when(step.getName()).thenReturn("someFailingStep"); + Mockito.when(step.format(Mockito.anyString(), Mockito.any(File.class))).thenThrow(new IllegalArgumentException("someReason")); + List steps = Collections.singletonList(step); + + Formatter formatter = Formatter.builder() + .lineEndingsPolicy(lineEndingsPolicy) + .encoding(encoding) + .rootDir(rootDir) + .steps(steps) + .exceptionPolicy(exceptionPolicy) + .build(); + + formatter.compute("someFileContent", Formatter.SENTINEL_NO_FILE_ON_DISK); } // rootDir may be a path not from the default FileSystem @@ -127,6 +153,12 @@ public void testExceptionWithRootDirIsNotFileSystem() throws Exception { FormatExceptionPolicy exceptionPolicy = FormatExceptionPolicy.failOnlyOnError(); Path rootDir = Mockito.mock(Path.class); + FileSystem customFileSystem = Mockito.mock(FileSystem.class); + Mockito.when(rootDir.getFileSystem()).thenReturn(customFileSystem); + + Path pathFromFile = Mockito.mock(Path.class); + Mockito.when(customFileSystem.getPath(Mockito.anyString())).thenReturn(pathFromFile); + Path relativized = Mockito.mock(Path.class); Mockito.when(rootDir.relativize(Mockito.any(Path.class))).then(invok -> { Path filePath = invok.getArgument(0); @@ -150,7 +182,7 @@ public void testExceptionWithRootDirIsNotFileSystem() throws Exception { .exceptionPolicy(exceptionPolicy) .build(); - formatter.compute("someFileContent", new File("")); + formatter.compute("someFileContent", new File("/some/folder/some.file")); } } From c55e736b620456bfae55e1cac26619bb20c827a4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 11:29:08 -0800 Subject: [PATCH 0397/1120] Published lib/2.33.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 363dac1758..22e568f566 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.33.0] - 2023-01-26 ### Added * `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) * `ProcessRunner` allows to limit captured output to a certain number of bytes. ([#1511](https://github.com/diffplug/spotless/pull/1511)) From dbea734458f3323cf121f84744838fa865c1a1a6 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 26 Jan 2023 23:33:27 +0400 Subject: [PATCH 0398/1120] Refactor mire usages --- lib/src/main/java/com/diffplug/spotless/FormatterFunc.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java index 48a8e810ee..8a8a15076e 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java @@ -127,7 +127,7 @@ public String apply(String unix, File file) throws Exception { @Override public String apply(String unix) throws Exception { - return apply(unix, FormatterStepImpl.SENTINEL); + return apply(unix, Formatter.SENTINEL_NO_FILE_ON_DISK); } }; } @@ -156,7 +156,7 @@ default String apply(String unix, File file) throws Exception { @Override default String apply(String unix) throws Exception { - return apply(unix, FormatterStepImpl.SENTINEL); + return apply(unix, Formatter.SENTINEL_NO_FILE_ON_DISK); } } } From 378a4e8e7f022320b4f0d26844ff390025ee0992 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 26 Jan 2023 23:39:00 +0400 Subject: [PATCH 0399/1120] Fix style --- lib/src/main/java/com/diffplug/spotless/FormatterFunc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java index 8a8a15076e..90d576e8a0 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.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. From 4439934095209a332a8b1cfe1037756cbe878108 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 26 Jan 2023 23:48:21 +0400 Subject: [PATCH 0400/1120] Rely on existing Sentinel --- lib/src/main/java/com/diffplug/spotless/Formatter.java | 5 +---- lib/src/main/java/com/diffplug/spotless/FormatterFunc.java | 6 +++--- lib/src/main/java/com/diffplug/spotless/FormatterStep.java | 2 +- .../main/java/com/diffplug/spotless/FormatterStepImpl.java | 7 +++++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index be045e7fe1..035452e29c 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -39,9 +39,6 @@ public final class Formatter implements Serializable, AutoCloseable { private static final long serialVersionUID = 1L; - // This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format - public static final File SENTINEL_NO_FILE_ON_DISK = new File("NO_FILE_ON_DISK.sentinel"); - private LineEnding.Policy lineEndingsPolicy; private Charset encoding; private Path rootDir; @@ -240,7 +237,7 @@ public String compute(String unix, File file) { unix = LineEnding.toUnix(formatted); } } catch (Throwable e) { - if (file == SENTINEL_NO_FILE_ON_DISK) { + if (file == FormatterStepImpl.SENTINEL) { exceptionPolicy.handleError(e, step, ""); } else { // Path may be forged from a different FileSystem than Filesystem.default diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java index 90d576e8a0..48a8e810ee 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * 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. @@ -127,7 +127,7 @@ public String apply(String unix, File file) throws Exception { @Override public String apply(String unix) throws Exception { - return apply(unix, Formatter.SENTINEL_NO_FILE_ON_DISK); + return apply(unix, FormatterStepImpl.SENTINEL); } }; } @@ -156,7 +156,7 @@ default String apply(String unix, File file) throws Exception { @Override default String apply(String unix) throws Exception { - return apply(unix, Formatter.SENTINEL_NO_FILE_ON_DISK); + return apply(unix, FormatterStepImpl.SENTINEL); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index 79793a403e..11a4d5f99e 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -38,7 +38,7 @@ public interface FormatterStep extends Serializable { * the content to format, guaranteed to have unix-style newlines ('\n'); never null * @param file * the file which {@code rawUnix} was obtained from; never null. Pass the reference - * {@code Formatter#SENTINEL_NO_FILE_ON_DISK} if and only if no file is actually associated with {@code rawUnix} + * {@code FormatterStepImpl#SENTINEL} if and only if no file is actually associated with {@code rawUnix} * @return the formatted content, guaranteed to only have unix-style newlines; may return null * if the formatter step doesn't have any changes to make * @throws Exception if the formatter step experiences a problem diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java index fe7cabca49..3b1b5cf278 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java @@ -109,15 +109,18 @@ protected String format(Integer state, String rawUnix, File file) throws Excepti if (formatter == null) { formatter = formatterSupplier.get(); if (formatter instanceof FormatterFunc.Closeable) { - throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284"); + throw new AssertionError("NeverUpToDate does not support FormatterFunc.Closeable. See https://github.com/diffplug/spotless/pull/284"); } } return formatter.apply(rawUnix, file); } } + /**This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format */ + public static final File SENTINEL = new File(""); + static void checkNotSentinel(File file) { - if (file == Formatter.SENTINEL_NO_FILE_ON_DISK) { + if (file == SENTINEL) { throw new IllegalArgumentException("This step requires the underlying file. If this is a test, use StepHarnessWithFile"); } } From 7f7cc49fed67ea9b8fc5706427dfc16c830570e0 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 26 Jan 2023 23:54:13 +0400 Subject: [PATCH 0401/1120] Fix compilation --- testlib/src/test/java/com/diffplug/spotless/FormatterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java index de96cd2ae3..76f11b3d15 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java @@ -142,7 +142,7 @@ public void testExceptionWithSentinelNoFileOnDisk() throws Exception { .exceptionPolicy(exceptionPolicy) .build(); - formatter.compute("someFileContent", Formatter.SENTINEL_NO_FILE_ON_DISK); + formatter.compute("someFileContent", FormatterStepImpl.SENTINEL); } // rootDir may be a path not from the default FileSystem From 27522dc85e2a368cb8e0d60b3f162fc186ea25e0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:00:39 -0800 Subject: [PATCH 0402/1120] Start publishing against the `release` branch to fix a new issue with GitHub branch protection. It will be a manual process to move `main` towards `release` after a release is complete. --- gradle/changelog.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle/changelog.gradle b/gradle/changelog.gradle index 316e98a2d7..83c16f474e 100644 --- a/gradle/changelog.gradle +++ b/gradle/changelog.gradle @@ -17,6 +17,7 @@ spotlessChangelog { // need -Prelease=true in order to do a publish appendDashSnapshotUnless_dashPrelease=true + branch 'release' tagPrefix "${kind}/" commitMessage "Published ${kind}/{{version}}" // {{version}} will be replaced } From 2aa7f51bc665e23b685c2a6df9fa930584ad8b3c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:06:53 -0800 Subject: [PATCH 0403/1120] Another shot at fixing our publish workflow. --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d41dc8fc30..b2a8f58cf0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,6 +46,8 @@ jobs: uses: gradle/gradle-build-action@v2 with: gradle-home-cache-cleanup: true + - name: git fetch origin release + run: git fetch origin release - name: publish all if: "${{ github.event.inputs.to_publish == 'all' }}" run: | From 2995371d0baf3707886cc387c91c58b9f7ebbe95 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:12:38 -0800 Subject: [PATCH 0404/1120] So we have to run the workflow on the `release` branch, *and* we need to pull `main` so that git ratchet is happy. --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b2a8f58cf0..e692fe8735 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,8 +46,8 @@ jobs: uses: gradle/gradle-build-action@v2 with: gradle-home-cache-cleanup: true - - name: git fetch origin release - run: git fetch origin release + - name: git fetch origin main + run: git fetch origin main - name: publish all if: "${{ github.event.inputs.to_publish == 'all' }}" run: | From f1cfc6189fb0d52d6239348594c6daecb0ce7997 Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 26 Jan 2023 20:16:06 +0000 Subject: [PATCH 0405/1120] Published gradle/6.14.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 50 ++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 8d01068383..49ef0adbbe 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.14.0] - 2023-01-26 ### Added * Support `jackson()` for YAML and JSON files ([#1492](https://github.com/diffplug/spotless/pull/1492)) * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 7e486719e7..67f3cdd69f 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -18,9 +18,9 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/index.html) [![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) -[![Changelog](https://img.shields.io/badge/changelog-6.13.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.14.0-blue.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) @@ -129,10 +129,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -144,7 +144,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -268,8 +268,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -320,8 +320,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -392,7 +392,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -424,7 +424,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -456,7 +456,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -490,7 +490,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -511,7 +511,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -536,7 +536,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -576,7 +576,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -668,7 +668,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -732,7 +732,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -807,7 +807,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -1020,7 +1020,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1093,9 +1093,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1128,11 +1128,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.13.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 07a57ff66f3fa0ffd8abea94e7c0f6ac4f025b5f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:18:26 -0800 Subject: [PATCH 0406/1120] Rename the sentinel and move it to `Formatter`. --- lib/src/main/java/com/diffplug/spotless/Formatter.java | 5 ++++- lib/src/main/java/com/diffplug/spotless/FormatterFunc.java | 6 +++--- .../main/java/com/diffplug/spotless/FormatterStepImpl.java | 5 +---- .../src/main/java/com/diffplug/spotless/StepHarness.java | 2 +- .../src/test/java/com/diffplug/spotless/FormatterTest.java | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index 035452e29c..a55e8e6504 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -237,7 +237,7 @@ public String compute(String unix, File file) { unix = LineEnding.toUnix(formatted); } } catch (Throwable e) { - if (file == FormatterStepImpl.SENTINEL) { + if (file == NO_FILE_SENTINEL) { exceptionPolicy.handleError(e, step, ""); } else { // Path may be forged from a different FileSystem than Filesystem.default @@ -289,4 +289,7 @@ public void close() { } } } + + /** This Sentinel reference may be used to Formatter requires a File, while there is no actual File to format */ + public static final File NO_FILE_SENTINEL = new File("NO_FILE_SENTINEL"); } diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java index 48a8e810ee..14b407a2eb 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterFunc.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterFunc.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. @@ -127,7 +127,7 @@ public String apply(String unix, File file) throws Exception { @Override public String apply(String unix) throws Exception { - return apply(unix, FormatterStepImpl.SENTINEL); + return apply(unix, Formatter.NO_FILE_SENTINEL); } }; } @@ -156,7 +156,7 @@ default String apply(String unix, File file) throws Exception { @Override default String apply(String unix) throws Exception { - return apply(unix, FormatterStepImpl.SENTINEL); + return apply(unix, Formatter.NO_FILE_SENTINEL); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java index 3b1b5cf278..17b62e75c6 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStepImpl.java @@ -116,11 +116,8 @@ protected String format(Integer state, String rawUnix, File file) throws Excepti } } - /**This Sentinel reference may be used where Formatter requires a File, while there is no actual File to format */ - public static final File SENTINEL = new File(""); - static void checkNotSentinel(File file) { - if (file == SENTINEL) { + if (file == Formatter.NO_FILE_SENTINEL) { throw new IllegalArgumentException("This step requires the underlying file. If this is a test, use StepHarnessWithFile"); } } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java index 71e2a663b5..c611cc738a 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java @@ -88,7 +88,7 @@ public AbstractStringAssert testResourceExceptionMsg(String resourceBefore) { public AbstractStringAssert testExceptionMsg(String before) { try { - formatter.compute(LineEnding.toUnix(before), FormatterStepImpl.SENTINEL); + formatter.compute(LineEnding.toUnix(before), Formatter.NO_FILE_SENTINEL); throw new SecurityException("Expected exception"); } catch (Throwable e) { if (e instanceof SecurityException) { diff --git a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java index 76f11b3d15..314507bd8d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FormatterTest.java @@ -142,7 +142,7 @@ public void testExceptionWithSentinelNoFileOnDisk() throws Exception { .exceptionPolicy(exceptionPolicy) .build(); - formatter.compute("someFileContent", FormatterStepImpl.SENTINEL); + formatter.compute("someFileContent", Formatter.NO_FILE_SENTINEL); } // rootDir may be a path not from the default FileSystem From 5bef415be2d600d4b796301ca694de59b77b1171 Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 26 Jan 2023 20:23:34 +0000 Subject: [PATCH 0407/1120] Published maven/2.31.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 3967f468fd..ad79193ad8 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.31.0] - 2023-01-26 ### Added * Prettier will now suggest to install plugins if a parser cannot be inferred from the file extension ([#1511](https://github.com/diffplug/spotless/pull/1511)) * Jackson (`json` and `yaml`) has new `spaceBeforeSeparator` option diff --git a/plugin-maven/README.md b/plugin-maven/README.md index f0fc2bb818..2ade34b67b 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -12,8 +12,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.30.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.30.0-brightgreen.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.31.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.31.0-brightgreen.svg)](CHANGES.md) [![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) [![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) From 9adce647c6dd3e605ddc555c5a972f32d9b192d4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:25:17 -0800 Subject: [PATCH 0408/1120] Fix javadoc. --- lib/src/main/java/com/diffplug/spotless/Formatter.java | 2 +- lib/src/main/java/com/diffplug/spotless/FormatterStep.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index a55e8e6504..3470a3dc69 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -290,6 +290,6 @@ public void close() { } } - /** This Sentinel reference may be used to Formatter requires a File, while there is no actual File to format */ + /** This Sentinel reference may be used to pass string content to a Formatter or FormatterStep when there is no actual File to format */ public static final File NO_FILE_SENTINEL = new File("NO_FILE_SENTINEL"); } diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index 11a4d5f99e..ce09f68450 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -38,7 +38,7 @@ public interface FormatterStep extends Serializable { * the content to format, guaranteed to have unix-style newlines ('\n'); never null * @param file * the file which {@code rawUnix} was obtained from; never null. Pass the reference - * {@code FormatterStepImpl#SENTINEL} if and only if no file is actually associated with {@code rawUnix} + * {@link Formatter#NO_FILE_SENTINEL} if and only if no file is actually associated with {@code rawUnix} * @return the formatted content, guaranteed to only have unix-style newlines; may return null * if the formatter step doesn't have any changes to make * @throws Exception if the formatter step experiences a problem From 1f78affc868f275b92ad3db7aa9eb7ab3416c16d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:28:40 -0800 Subject: [PATCH 0409/1120] Update changelog. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 22e568f566..2af0ab7090 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `Formatter` now has a field `public static final File NO_FILE_SENTINEL` which can be used to pass string content to a Formatter or FormatterStep when there is no actual File to format. ([#1525](https://github.com/diffplug/spotless/pull/1525)) ## [2.33.0] - 2023-01-26 ### Added From 599e1e450183b8492a79b3dd14d37485820f3ce8 Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 26 Jan 2023 20:49:15 +0000 Subject: [PATCH 0410/1120] Published lib/2.34.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2af0ab7090..1f27bbb299 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.34.0] - 2023-01-26 ### Added * `Formatter` now has a field `public static final File NO_FILE_SENTINEL` which can be used to pass string content to a Formatter or FormatterStep when there is no actual File to format. ([#1525](https://github.com/diffplug/spotless/pull/1525)) From 5c4fe0a02935cbdbb3f2bcacbea1948494c87190 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 11:12:46 -0800 Subject: [PATCH 0411/1120] Start compiling as Java 11 bytecode. --- gradle.properties | 2 +- gradle/java-setup.gradle | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index d99bdac6ce..f06bdef37e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ artifactIdMaven=spotless-maven-plugin artifactIdGradle=spotless-plugin-gradle # Build requirements -VER_JAVA=1.8 +VER_JAVA=11 VER_SPOTBUGS=4.7.3 VER_JSR_305=3.0.2 diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 5de128bda7..10eca7a2d4 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -4,10 +4,10 @@ // setup java apply plugin: 'java' - -sourceCompatibility = VER_JAVA -targetCompatibility = VER_JAVA -tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' } +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' + options.release = Integer.parseInt(VER_JAVA) +} ////////////// // SPOTBUGS // From 63eb5589fd6e8d20d710124ea559cfee618a2024 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 19:49:23 -0800 Subject: [PATCH 0412/1120] Remove Java 8 workaround in EncodingErrorMsg. --- .../com/diffplug/spotless/EncodingErrorMsg.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java b/lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java index 168bf9acff..3e4bb3423b 100644 --- a/lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java +++ b/lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -15,7 +15,6 @@ */ package com.diffplug.spotless; -import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -116,8 +115,8 @@ private static void addIfAvailable(Collection charsets, String name) { } private void appendExample(Charset charset, boolean must) { - java8fix(byteBuf).clear(); - java8fix(charBuf).clear(); + byteBuf.clear(); + charBuf.clear(); CharsetDecoder decoder = charset.newDecoder(); if (!must) { @@ -135,7 +134,7 @@ private void appendExample(Charset charset, boolean must) { .onUnmappableCharacter(CodingErrorAction.REPLACE) .decode(byteBuf, charBuf, true); } - java8fix(charBuf).flip(); + charBuf.flip(); int start = Math.max(unrepresentable - CONTEXT, 0); int end = Math.min(charBuf.limit(), unrepresentable + CONTEXT + 1); @@ -147,9 +146,4 @@ private void appendExample(Charset charset, boolean must) { message.append(" <- "); message.append(charset.name()); } - - /** Fixes https://jira.mongodb.org/browse/JAVA-2559, as reported in https://github.com/diffplug/spotless/issues/1081 */ - private static Buffer java8fix(Buffer b) { - return b; - } } From 2fe1bb2030d0690b6c60b26a95bbd9babca77383 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 16 Jan 2023 19:53:45 -0800 Subject: [PATCH 0413/1120] Remove Java 8 workarounds from FeatureClassLoader. --- .../diffplug/spotless/FeatureClassLoader.java | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java index b4a69bef11..998c2082df 100644 --- a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java +++ b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -24,8 +24,6 @@ import java.security.ProtectionDomain; import java.util.Objects; -import javax.annotation.Nullable; - /** * This class loader is used to load classes of Spotless features from a search * path of URLs.
@@ -113,25 +111,7 @@ private static ByteBuffer urlToByteBuffer(URL url) throws IOException { return ByteBuffer.wrap(buffer.toByteArray()); } - /** - * Making spotless Java 9+ compatible. In Java 8 (and minor) the bootstrap - * class loader saw every platform class. In Java 9+ it was changed so the - * bootstrap class loader does not see all classes anymore. This might lead - * to ClassNotFoundException in formatters (e.g. freshmark). - * - * @return null on Java 8 (and minor), otherwise PlatformClassLoader - */ - @Nullable private static ClassLoader getParentClassLoader() { - double version = Double.parseDouble(System.getProperty("java.specification.version")); - if (version > 1.8) { - try { - return (ClassLoader) ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null); - } catch (Exception e) { - throw ThrowingEx.asRuntime(e); - } - } else { - return null; - } + return ThrowingEx.get(() -> (ClassLoader) ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null)); } } From 1f1a53a25990870e2d40d5f953af3c0cf73e87f0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:48:42 -0800 Subject: [PATCH 0414/1120] Use Java 11 methods to simplify FeatureClassLoader. --- .../java/com/diffplug/spotless/FeatureClassLoader.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java index 998c2082df..0703a91318 100644 --- a/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java +++ b/lib/src/main/java/com/diffplug/spotless/FeatureClassLoader.java @@ -101,11 +101,8 @@ public URL findResource(String name) { private static ByteBuffer urlToByteBuffer(URL url) throws IOException { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - int nRead; - byte[] data = new byte[1024]; - InputStream inputStream = url.openStream(); - while ((nRead = inputStream.read(data, 0, data.length)) != -1) { - buffer.write(data, 0, nRead); + try (InputStream inputStream = url.openStream()) { + inputStream.transferTo(buffer); } buffer.flush(); return ByteBuffer.wrap(buffer.toByteArray()); From 77b24bdd325782e23334ab7ee350e7afb68587b4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:52:20 -0800 Subject: [PATCH 0415/1120] Bump JGit and Mockito to latest (which required Java 11). --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index f06bdef37e..dc4f24a36b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 -VER_JGIT=5.13.1.202206130422-r +VER_JGIT=6.4.0.202211300538-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=4.11.0 +VER_MOCKITO=5.0.0 From a4db1d344b871b81c0b07bf0604a1037f9dbbe7d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 12:52:39 -0800 Subject: [PATCH 0416/1120] Update a stray old dep. --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index f2ca13ccb1..9d95007bc1 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -90,7 +90,7 @@ dependencies { compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' - String VER_SCALAFMT="3.6.1" + String VER_SCALAFMT="3.7.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" String VER_DIKTAT = "1.2.4.2" From 0ba186ee1a1d99802ab2e0467d838837ef8b64c0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 13:00:18 -0800 Subject: [PATCH 0417/1120] Update changelog. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 1f27bbb299..401998b233 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337)) ## [2.34.0] - 2023-01-26 ### Added From 4222e95f5726f13cb2d3268d149f372f1af12c66 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 26 Jan 2023 21:08:47 +0000 Subject: [PATCH 0418/1120] Update plugin com.diffplug.spotless to v6.14.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index a5bb6c0062..0ee51448dd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,7 @@ pluginManagement { } plugins { - id 'com.diffplug.spotless' version '6.13.0' apply false + id 'com.diffplug.spotless' version '6.14.0' apply false // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.1.0' apply false // https://github.com/gradle-nexus/publish-plugin/releases From 2046daf067bdbb350d078267a2b26a93deca58af Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 13:16:49 -0800 Subject: [PATCH 0419/1120] Looks like spotbugs is stricter now that we're on Java 11. --- .../integration/DiffMessageFormatter.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java index 15c43c815b..55336e8c04 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.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. @@ -143,7 +143,7 @@ public String getMessage() { Objects.requireNonNull(runToFix, "runToFix"); Objects.requireNonNull(formatter, "formatter"); Objects.requireNonNull(problemFiles, "problemFiles"); - DiffMessageFormatter diffFormater = new DiffMessageFormatter(this); + DiffMessageFormatter diffFormater = new DiffMessageFormatter(formatter, problemFiles); return "The following files had format violations:\n" + diffFormater.buffer + runToFix; @@ -151,10 +151,6 @@ public String getMessage() { throw Errors.asRuntime(e); } } - - String relativePath(File file) { - return formatter.getRootDir().relativize(file.toPath()).toString(); - } } private static final int MAX_CHECK_MESSAGE_LINES = 50; @@ -163,25 +159,32 @@ String relativePath(File file) { private final StringBuilder buffer = new StringBuilder(MAX_CHECK_MESSAGE_LINES * 64); private int numLines = 0; - private DiffMessageFormatter(Builder builder) throws IOException { - ListIterator problemIter = builder.problemFiles.listIterator(); + private final CleanProvider formatter; + + private DiffMessageFormatter(CleanProvider formatter, List problemFiles) throws IOException { + this.formatter = Objects.requireNonNull(formatter, "formatter"); + ListIterator problemIter = problemFiles.listIterator(); while (problemIter.hasNext() && numLines < MAX_CHECK_MESSAGE_LINES) { File file = problemIter.next(); - addFile(builder.relativePath(file) + "\n" + DiffMessageFormatter.diff(builder, file)); + addFile(relativePath(file) + "\n" + diff(file)); } if (problemIter.hasNext()) { - int remainingFiles = builder.problemFiles.size() - problemIter.nextIndex(); + int remainingFiles = problemFiles.size() - problemIter.nextIndex(); if (remainingFiles >= MAX_FILES_TO_LIST) { buffer.append("Violations also present in ").append(remainingFiles).append(" other files.\n"); } else { buffer.append("Violations also present in:\n"); while (problemIter.hasNext()) { - addIntendedLine(NORMAL_INDENT, builder.relativePath(problemIter.next())); + addIntendedLine(NORMAL_INDENT, relativePath(problemIter.next())); } } } } + private String relativePath(File file) { + return formatter.getRootDir().relativize(file.toPath()).toString(); + } + private static final int MIN_LINES_PER_FILE = 4; private static final Splitter NEWLINE_SPLITTER = Splitter.on('\n'); @@ -230,10 +233,10 @@ private void addIntendedLine(String indent, String line) { * look like if formatted using the given formatter. Does not end with any newline * sequence (\n, \r, \r\n). */ - private static String diff(Builder builder, File file) throws IOException { - String raw = new String(Files.readAllBytes(file.toPath()), builder.formatter.getEncoding()); + private String diff(File file) throws IOException { + String raw = new String(Files.readAllBytes(file.toPath()), formatter.getEncoding()); String rawUnix = LineEnding.toUnix(raw); - String formatted = builder.formatter.getFormatted(file, rawUnix); + String formatted = formatter.getFormatted(file, rawUnix); String formattedUnix = LineEnding.toUnix(formatted); if (rawUnix.equals(formattedUnix)) { From 8e1865052fb0300123a2bed4ca271a945bde0574 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 13:49:53 -0800 Subject: [PATCH 0420/1120] spotlessApply for 2023 --- .../main/java/com/diffplug/spotless/markdown/FreshMarkStep.java | 2 +- .../java/com/diffplug/spotless/markdown/FreshMarkStepTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java index fd03e95046..fca5ac39a4 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java b/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java index a5fede28bc..586212383d 100644 --- a/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/markdown/FreshMarkStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. From a610fbf1ae9d64f39e2f9b7b49904e104166f556 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 14:49:05 -0800 Subject: [PATCH 0421/1120] Minor tweaks to homepage. --- README.md | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0743b69427..d2527034ca 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,45 @@ # Spotless: Keep your code spotless - -[![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) -[![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) -[![License Apache](https://img.shields.io/badge/license-apache-brightgreen.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) - +[![Gradle Plugin](https://img.shields.io/gradle-plugin-portal/v/com.diffplug.spotless?color=blue&label=gradle%20plugin)](plugin-gradle) +[![Maven Plugin](https://img.shields.io/maven-central/v/com.diffplug.spotless/spotless-maven-plugin?color=blue&label=maven%20plugin)](plugin-maven) +[![SBT Plugin](https://img.shields.io/badge/sbt%20plugin-0.1.3-blue)](https://github.com/moznion/sbt-spotless) -Spotless can format <antlr | c | c# | c++ | css | flow | graphql | groovy | html | java | javascript | json | jsx | kotlin | less | license headers | markdown | objective-c | protobuf | python | scala | scss | sql | typeScript | vue | yaml | anything> using <gradle | maven | anything>. +Spotless can format <antlr | c | c# | c++ | css | flow | graphql | groovy | html | java | javascript | json | jsx | kotlin | less | license headers | markdown | objective-c | protobuf | python | scala | scss | sql | typeScript | vue | yaml | anything> using <gradle | maven | sbt | anything>. You probably want one of the links below: ## [❇️ Spotless for Gradle](plugin-gradle) (with integrations for [VS Code](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) and [IntelliJ](https://plugins.jetbrains.com/plugin/18321-spotless-gradle)) + +```console +user@machine repo % ./gradlew build +:spotlessJavaCheck FAILED + The following files had format violations: + src\main\java\com\diffplug\gradle\spotless\FormatExtension.java + -\t\t····if·(targets.length·==·0)·{ + +\t\tif·(targets.length·==·0)·{ + Run './gradlew spotlessApply' to fix these violations. +user@machine repo % ./gradlew spotlessApply +:spotlessApply +BUILD SUCCESSFUL +user@machine repo % ./gradlew build +BUILD SUCCESSFUL +``` + ## [❇️ Spotless for Maven](plugin-maven) + +```console +user@machine repo % mvn spotless:check +[ERROR] > The following files had format violations: +[ERROR] src\main\java\com\diffplug\gradle\spotless\FormatExtension.java +[ERROR] -\t\t····if·(targets.length·==·0)·{ +[ERROR] +\t\tif·(targets.length·==·0)·{ +[ERROR] Run 'mvn spotless:apply' to fix these violations. +user@machine repo % mvn spotless:apply +[INFO] BUILD SUCCESS +user@machine repo % mvn spotless:check +[INFO] BUILD SUCCESS +``` + ## [❇️ Spotless for SBT (external for now)](https://github.com/moznion/sbt-spotless) ## [Other build systems](CONTRIBUTING.md#how-to-add-a-new-plugin-for-a-build-system) From 054ccd12ea39201b39d307d3b1749613f77152a6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 26 Jan 2023 15:06:57 -0800 Subject: [PATCH 0422/1120] Update public user counts and remove extra shields (Gitter and CircleCI in particular). --- plugin-gradle/README.md | 16 +++++----------- plugin-maven/README.md | 18 +++++------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 67f3cdd69f..6a56d26e20 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -4,26 +4,20 @@ [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Maven central](https://img.shields.io/badge/mavencentral-yes-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/index.html) -[![License Apache](https://img.shields.io/badge/license-apache-blue.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) [![Changelog](https://img.shields.io/badge/changelog-6.14.0-blue.svg)](CHANGES.md) +[![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/index.html) -[![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) -[![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) [![Add other IDE](https://img.shields.io/badge/IDE-add_yours-blueviolet.svg)](IDE_HOOK.md) @@ -33,7 +27,7 @@ output = [ output = prefixDelimiterReplace(input, 'https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/', '/', versionLast) --> -Spotless is a general-purpose formatting plugin used by [4,000 projects on GitHub (August 2020)](https://github.com/search?l=gradle&q=spotless&type=Code). It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. +Spotless is a general-purpose formatting plugin used by [15,000 projects on GitHub (Jan 2023)](https://github.com/search?l=gradle&q=spotless&type=Code). It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. To people who use your build, it looks like this ([IDE support also available](IDE_HOOK.md)): diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 2ade34b67b..73402cd929 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -3,28 +3,20 @@ [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Javadoc](https://img.shields.io/badge/javadoc-yes-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.31.0/index.html) -[![Changelog](https://img.shields.io/badge/changelog-2.31.0-brightgreen.svg)](CHANGES.md) - -[![Circle CI](https://circleci.com/gh/diffplug/spotless/tree/main.svg?style=shield)](https://circleci.com/gh/diffplug/spotless/tree/main) -[![Live chat](https://img.shields.io/badge/gitter-chat-brightgreen.svg)](https://gitter.im/diffplug/spotless) -[![License Apache](https://img.shields.io/badge/license-apache-brightgreen.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)) +[![Changelog](https://img.shields.io/badge/changelog-2.31.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.31.0/index.html) -Spotless is a general-purpose formatting plugin used by [4,000 projects on GitHub (August 2020)](https://github.com/search?l=gradle&q=spotless&type=Code). It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. Plugin requires a version of Maven higher or equal to 3.1.0. +Spotless is a general-purpose formatting plugin used by [6,000 projects on GitHub (Jan 2023)](https://github.com/search?l=Maven+POM&q=spotless&type=Code). It is completely à la carte, but also includes powerful "batteries-included" if you opt-in. Plugin requires a version of Maven higher or equal to 3.1.0. To people who use your build, it looks like this: From b0d16195d45c04a06965217b2bc14bd69d3fe2aa Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sat, 28 Jan 2023 18:39:41 +0400 Subject: [PATCH 0423/1120] Introduce Formatter.name, Improve synthesis log --- .../java/com/diffplug/spotless/Formatter.java | 26 +++++++++++++--- .../gradle/spotless/SpotlessTask.java | 3 +- .../spotless/maven/FormatterFactory.java | 4 ++- .../spotless/maven/ImpactedFilesTracker.java | 31 +++++++++++++++++++ .../spotless/maven/SpotlessApplyMojo.java | 10 ++++-- .../spotless/StepHarnessWithFile.java | 1 + 6 files changed, 67 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index 038e77fa64..bdfe008a61 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 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. @@ -39,13 +39,16 @@ public final class Formatter implements Serializable, AutoCloseable { private static final long serialVersionUID = 1L; + // The name is used for logging purpose. It does not convey any applicative purpose + private String name; private LineEnding.Policy lineEndingsPolicy; private Charset encoding; private Path rootDir; private List steps; private FormatExceptionPolicy exceptionPolicy; - private Formatter(LineEnding.Policy lineEndingsPolicy, Charset encoding, Path rootDirectory, List steps, FormatExceptionPolicy exceptionPolicy) { + private Formatter(String name, LineEnding.Policy lineEndingsPolicy, Charset encoding, Path rootDirectory, List steps, FormatExceptionPolicy exceptionPolicy) { + this.name = name; this.lineEndingsPolicy = Objects.requireNonNull(lineEndingsPolicy, "lineEndingsPolicy"); this.encoding = Objects.requireNonNull(encoding, "encoding"); this.rootDir = Objects.requireNonNull(rootDirectory, "rootDir"); @@ -55,6 +58,7 @@ private Formatter(LineEnding.Policy lineEndingsPolicy, Charset encoding, Path ro // override serialize output private void writeObject(ObjectOutputStream out) throws IOException { + out.writeObject(name); out.writeObject(lineEndingsPolicy); out.writeObject(encoding.name()); out.writeObject(rootDir.toString()); @@ -65,6 +69,7 @@ private void writeObject(ObjectOutputStream out) throws IOException { // override serialize input @SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + name = (String) in.readObject(); lineEndingsPolicy = (LineEnding.Policy) in.readObject(); encoding = Charset.forName((String) in.readObject()); rootDir = Paths.get((String) in.readObject()); @@ -78,6 +83,10 @@ private void readObjectNoData() throws ObjectStreamException { throw new UnsupportedOperationException(); } + public String getName() { + return name; + } + public LineEnding.Policy getLineEndingsPolicy() { return lineEndingsPolicy; } @@ -103,6 +112,8 @@ public static Formatter.Builder builder() { } public static class Builder { + // optional parameters + private String name = "misc"; // required parameters private LineEnding.Policy lineEndingsPolicy; private Charset encoding; @@ -112,6 +123,11 @@ public static class Builder { private Builder() {} + public Builder name(String name) { + this.name = name; + return this; + } + public Builder lineEndingsPolicy(LineEnding.Policy lineEndingsPolicy) { this.lineEndingsPolicy = lineEndingsPolicy; return this; @@ -138,7 +154,7 @@ public Builder exceptionPolicy(FormatExceptionPolicy exceptionPolicy) { } public Formatter build() { - return new Formatter(lineEndingsPolicy, encoding, rootDir, steps, + return new Formatter(name, lineEndingsPolicy, encoding, rootDir, steps, exceptionPolicy == null ? FormatExceptionPolicy.failOnlyOnError() : exceptionPolicy); } } @@ -248,6 +264,7 @@ public String compute(String unix, File file) { public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + name.hashCode(); result = prime * result + encoding.hashCode(); result = prime * result + lineEndingsPolicy.hashCode(); result = prime * result + rootDir.hashCode(); @@ -268,7 +285,8 @@ public boolean equals(Object obj) { return false; } Formatter other = (Formatter) obj; - return encoding.equals(other.encoding) && + return name.equals(other.name) && + encoding.equals(other.encoding) && lineEndingsPolicy.equals(other.lineEndingsPolicy) && rootDir.equals(other.rootDir) && steps.equals(other.steps) && diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java index 6f2279b2e0..c23cea0845 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -184,6 +184,7 @@ String formatName() { Formatter buildFormatter() { return Formatter.builder() + .name(formatName()) .lineEndingsPolicy(lineEndingsPolicy.get()) .encoding(Charset.forName(encoding)) .rootDir(getProjectDir().get().getAsFile().toPath()) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java index d5fbe60370..b78e987d34 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -101,7 +101,9 @@ public final Formatter newFormatter(Supplier> filesToFormat, Form formatterSteps.add(pair.out()); } + String formatterName = this.getClass().getSimpleName(); return Formatter.builder() + .name(formatterName) .encoding(formatterEncoding) .lineEndingsPolicy(formatterLineEndingPolicy) .exceptionPolicy(new FormatExceptionPolicyStrict()) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java index 6019591e09..7474c109bc 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -1,11 +1,41 @@ +/* + * 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; import java.util.concurrent.atomic.AtomicInteger; +/** + * Tracks the number of processed files, typically by a single Formatter for a whole repository + */ public class ImpactedFilesTracker { + protected final AtomicInteger nbSkipped = new AtomicInteger(); protected final AtomicInteger nbChecked = new AtomicInteger(); protected final AtomicInteger nbCleaned = new AtomicInteger(); + /** + * Some cache mechanism may indicate some content is clean, without having to execute the cleaning process + */ + public void skippedAsCleanCache() { + nbSkipped.incrementAndGet(); + } + + public int getSkipped() { + return nbSkipped.get(); + } + public void checked() { nbChecked.incrementAndGet(); } @@ -21,4 +51,5 @@ public void cleaned() { public int getCleaned() { return nbCleaned.get(); } + } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index b617505826..0f712ecd12 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -37,6 +37,7 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke for (File file : files) { if (upToDateChecker.isUpToDate(file.toPath())) { + impactedFilesTracker.skippedAsCleanCache(); if (getLog().isDebugEnabled()) { getLog().debug("Spotless will not format an up-to-date file: " + file); } @@ -60,6 +61,11 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } // We print the number of considered files which is useful when ratchetFrom is setup - getLog().info(String.format("A formatter with %s steps cleaned: %s files (for %s considered)", formatter.getSteps().size(), impactedFilesTracker.getCleaned(), impactedFilesTracker.getChecked())); + int nbSkipped = impactedFilesTracker.getSkipped(); + int nbChecked = impactedFilesTracker.getChecked(); + int nbCleaned = impactedFilesTracker.getCleaned(); + int totalProcessed = nbSkipped + nbChecked + nbCleaned; + getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", + formatter.getName(), totalProcessed, nbCleaned, nbChecked, nbSkipped)); } } diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java index 98a709c59f..9a9eb4042b 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarnessWithFile.java @@ -38,6 +38,7 @@ private StepHarnessWithFile(ResourceHarness harness, Formatter formatter) { /** Creates a harness for testing steps which do depend on the file. */ public static StepHarnessWithFile forStep(ResourceHarness harness, FormatterStep step) { return new StepHarnessWithFile(harness, Formatter.builder() + .name(step.getName()) .encoding(StandardCharsets.UTF_8) .lineEndingsPolicy(LineEnding.UNIX.createPolicy()) .steps(Collections.singletonList(step)) From 2da48e6f0c1c6a0ae4e7669d43a3756f7df72eb9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 29 Jan 2023 04:16:38 +0000 Subject: [PATCH 0424/1120] Update dependency com.fasterxml.jackson.core:jackson-databind to v2.14.2 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 9d95007bc1..fa80767047 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -62,7 +62,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm // used jackson-based formatters - jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.1' + jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.2' jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1' String VER_KTFMT = '0.42' From 0bb25119d7f96220f4aa5b4072053849a9b06662 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 29 Jan 2023 13:17:02 +0000 Subject: [PATCH 0425/1120] Update dependency org.mockito:mockito-core to v5.1.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index dc4f24a36b..6256e51203 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,4 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.4.0.202211300538-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.0.0 +VER_MOCKITO=5.1.0 From cc03d541e9e2a8b645e54e535ad0259c959c1ff7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 30 Jan 2023 09:08:11 +0000 Subject: [PATCH 0426/1120] Update plugin com.diffplug.spotless-changelog to v3 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 0ee51448dd..379daca7bb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,7 +14,7 @@ plugins { // https://github.com/spotbugs/spotbugs-gradle-plugin/releases id 'com.github.spotbugs' version '5.0.13' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md - id 'com.diffplug.spotless-changelog' version '2.4.1' apply false + id 'com.diffplug.spotless-changelog' version '3.0.1' apply false // https://github.com/diffplug/goomph/blob/main/CHANGES.md // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 id 'com.diffplug.p2.asmaven' version '3.27.0' apply false From cf2a4eb08d002db8b4c51fa4c43ad022361a6013 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:37:03 +0000 Subject: [PATCH 0427/1120] Update plugin com.gradle.enterprise to v3.12.3 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 0ee51448dd..e476425c96 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,7 +23,7 @@ plugins { // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.4.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise - id 'com.gradle.enterprise' version '3.12.2' + id 'com.gradle.enterprise' version '3.12.3' } dependencyResolutionManagement { From cf434f2eecf9a9369f22c1c95f56adbb792df30f Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Mon, 30 Jan 2023 23:19:53 +0400 Subject: [PATCH 0428/1120] Start with Cleanthat Java refactorer --- .../java/JavaCleanthatRefactorerFunc.java | 56 +++++++ .../spotless/java/CleanthatStepFactory.java | 140 ++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java create mode 100644 lib/src/main/java/com/diffplug/spotless/java/CleanthatStepFactory.java diff --git a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java new file mode 100644 index 0000000000..bc96f0019b --- /dev/null +++ b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java @@ -0,0 +1,56 @@ +/* + * Copyright 2021-2023 Solven + * + * 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.java; + +import com.diffplug.spotless.FormatterFunc; +import eu.solven.cleanthat.config.pojo.CleanthatEngineProperties; +import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; +import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorerProperties; +import eu.solven.cleanthat.formatter.LineEnding; +import eu.solven.cleanthat.formatter.PathAndContent; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class JavaCleanthatRefactorerFunc implements FormatterFunc { + private List included; + private List excluded; + + public JavaCleanthatRefactorerFunc(List included, List excluded) { + this.included = included == null ? Collections.emptyList() : included; + this.excluded = excluded == null ? Collections.emptyList() : excluded; + } + + public JavaCleanthatRefactorerFunc() { + this(Arrays.asList(JavaRefactorerProperties.WILDCARD), Arrays.asList()); + } + + @Override + public String apply(String input) throws Exception { + JavaRefactorerProperties refactorerProperties = new JavaRefactorerProperties(); + + refactorerProperties.setIncluded(included); + refactorerProperties.setExcluded(excluded); + + JavaRefactorer refactorer = + new JavaRefactorer(CleanthatEngineProperties.builder().build(), refactorerProperties); + + // Spotless calls steps always with LF eol. + return refactorer.doFormat(new PathAndContent(Paths.get("fake"), input), LineEnding.LF); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatStepFactory.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatStepFactory.java new file mode 100644 index 0000000000..fa9936fb1e --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatStepFactory.java @@ -0,0 +1,140 @@ +/* + * Copyright 2016-2023 Solven + * + * 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.java; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Jvm; +import com.diffplug.spotless.Provisioner; +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Objects; + +/** + * Enables CleanThat as a SpotLess step. This may be moved to Spotless own repo + * (https://github.com/diffplug/spotless/tree/main/lib) + * + * @author Benoit Lacelle + */ +// https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep +public final class CleanthatStepFactory { + + private static final String NAME = "cleanthat"; + private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java:"; + + private static final Jvm.Support JVM_SUPPORT = Jvm.support(NAME).add(8, "2.0"); + + // prevent direct instantiation + private CleanthatStepFactory() { + } + + /** Creates a step which formats everything - code, import order, and unused imports. */ + public static FormatterStep create(Provisioner provisioner) { + return create(defaultVersion(), provisioner); + } + + /** Creates a step which formats everything - code, import order, and unused imports. */ + public static FormatterStep create(String version, Provisioner provisioner) { + return create(MAVEN_COORDINATE, version, defaultExcluded(), defaultIncluded(), provisioner); + } + + private static List defaultExcluded() { + return List.of(); + } + + private static List defaultIncluded() { + return List.of("*"); + } + + /** Creates a step which formats everything - groupArtifact, code, import order, and unused imports. */ + public static FormatterStep create(String groupArtifact, + String version, + List excluded, + List included, + Provisioner provisioner) { + Objects.requireNonNull(groupArtifact, "groupArtifact"); + if (groupArtifact.chars().filter(ch -> ch == ':').count() != 1) { + throw new IllegalArgumentException("groupArtifact must be in the form 'groupId:artifactId'"); + } + Objects.requireNonNull(version, "version"); + Objects.requireNonNull(provisioner, "provisioner"); + return FormatterStep.createLazy(NAME, + () -> new JavaRulesState(NAME, groupArtifact, version, excluded, included, provisioner), + JavaRulesState::createFormat); + } + + /** Get default formatter version */ + public static String defaultVersion() { + return JVM_SUPPORT.getRecommendedFormatterVersion(); + } + + static final class JavaRulesState implements Serializable { + private static final long serialVersionUID = 1L; + + final JarState jarState; + final String stepName; + final String version; + + final List included; + final List excluded; + + JavaRulesState(String stepName, String version, Provisioner provisioner) throws IOException { + this(stepName, MAVEN_COORDINATE, version, defaultExcluded(), defaultIncluded(), provisioner); + } + + JavaRulesState(String stepName, + String groupArtifact, + String version, + List included, + List excluded, + Provisioner provisioner) throws IOException { + JVM_SUPPORT.assertFormatterSupported(version); + // ModuleHelper.doOpenInternalPackagesIfRequired(); + this.jarState = JarState.from(groupArtifact + ":" + version, provisioner); + this.stepName = stepName; + this.version = version; + + this.included = included; + this.excluded = excluded; + } + + @SuppressWarnings("PMD.UseProperClassLoader") + FormatterFunc createFormat() { + ClassLoader classLoader = jarState.getClassLoader(); + + Object formatter; + Method formatterMethod; + try { + Class formatterClazz = + classLoader.loadClass("com.diffplug.spotless.glue.java.JavaCleanthatRefactoringFunc"); + Constructor formatterConstructor = formatterClazz.getConstructor(List.class, List.class); + + formatter = formatterConstructor.newInstance(included, excluded); + formatterMethod = formatterClazz.getMethod("apply", String.class); + } catch (ReflectiveOperationException e) { + throw new IllegalStateException("Issue executing the formatter", e); + } + return JVM_SUPPORT.suggestLaterVersionOnError(version, input -> { + return (String) formatterMethod.invoke(formatter, input); + }); + } + + } +} From 8fcce07eee63e064ad1c8e3583dd6c89c32899fa Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 31 Jan 2023 00:10:27 +0400 Subject: [PATCH 0429/1120] Apply suggestions --- .../java/com/diffplug/spotless/Formatter.java | 2 +- .../spotless/maven/ImpactedFilesTracker.java | 28 +++++++++---------- .../spotless/maven/SpotlessApplyMojo.java | 13 +++++---- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/Formatter.java b/lib/src/main/java/com/diffplug/spotless/Formatter.java index bdfe008a61..dede79c1b3 100644 --- a/lib/src/main/java/com/diffplug/spotless/Formatter.java +++ b/lib/src/main/java/com/diffplug/spotless/Formatter.java @@ -113,7 +113,7 @@ public static Formatter.Builder builder() { public static class Builder { // optional parameters - private String name = "misc"; + private String name = "unnamed"; // required parameters private LineEnding.Policy lineEndingsPolicy; private Charset encoding; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java index 7474c109bc..f66802475e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -15,41 +15,39 @@ */ package com.diffplug.spotless.maven; -import java.util.concurrent.atomic.AtomicInteger; - /** * Tracks the number of processed files, typically by a single Formatter for a whole repository */ -public class ImpactedFilesTracker { - protected final AtomicInteger nbSkipped = new AtomicInteger(); - protected final AtomicInteger nbChecked = new AtomicInteger(); - protected final AtomicInteger nbCleaned = new AtomicInteger(); +class ImpactedFilesTracker { + protected int nbskippedAsCleanCache = 0; + protected int nbCheckedButAlreadyClean = 0; + protected int nbCleaned = 0; /** * Some cache mechanism may indicate some content is clean, without having to execute the cleaning process */ public void skippedAsCleanCache() { - nbSkipped.incrementAndGet(); + nbskippedAsCleanCache++; } - public int getSkipped() { - return nbSkipped.get(); + public int getSkippedAsCleanCache() { + return nbskippedAsCleanCache; } - public void checked() { - nbChecked.incrementAndGet(); + public void checkedButAlreadyClean() { + nbCheckedButAlreadyClean++; } - public int getChecked() { - return nbChecked.get(); + public int getCheckedButAlreadyClean() { + return nbCheckedButAlreadyClean; } public void cleaned() { - nbCleaned.incrementAndGet(); + nbCleaned++; } public int getCleaned() { - return nbCleaned.get(); + return nbCleaned; } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 0f712ecd12..0c1cbf8785 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -45,13 +45,14 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } try { - impactedFilesTracker.checked(); PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file); if (!dirtyState.isClean() && !dirtyState.didNotConverge()) { getLog().info(String.format("Writing clean file: %s", file)); dirtyState.writeCanonicalTo(file); buildContext.refresh(file); impactedFilesTracker.cleaned(); + } else { + impactedFilesTracker.checkedButAlreadyClean(); } } catch (IOException e) { throw new MojoExecutionException("Unable to format file " + file, e); @@ -61,11 +62,11 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } // We print the number of considered files which is useful when ratchetFrom is setup - int nbSkipped = impactedFilesTracker.getSkipped(); - int nbChecked = impactedFilesTracker.getChecked(); - int nbCleaned = impactedFilesTracker.getCleaned(); - int totalProcessed = nbSkipped + nbChecked + nbCleaned; + int skippedAsCleanCache = impactedFilesTracker.getSkippedAsCleanCache(); + int checkedButAlreadyClean = impactedFilesTracker.getCheckedButAlreadyClean(); + int cleaned = impactedFilesTracker.getCleaned(); + int totalProcessed = skippedAsCleanCache + checkedButAlreadyClean + cleaned; getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", - formatter.getName(), totalProcessed, nbCleaned, nbChecked, nbSkipped)); + formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); } } From ed45e5b57bdd4b62874d8d55aa7f5d93a0d7e138 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 30 Jan 2023 23:12:28 +0000 Subject: [PATCH 0430/1120] Update dependency org.mockito:mockito-core to v5.1.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6256e51203..c72fa0429d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,4 +28,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.4.0.202211300538-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.1.0 +VER_MOCKITO=5.1.1 From c890b89c7fb4430858bac8277bc5cfffad87ebac Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 31 Jan 2023 08:39:13 +0400 Subject: [PATCH 0431/1120] Add a CHANGES entry. Log only if totalProcessed>0 --- plugin-maven/CHANGES.md | 1 + .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1bb49898f1..2ecb7735ff 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* A synthesis log with the number of considered files is added after each formatter execution [#1507](https://github.com/diffplug/spotless/pull/1507) ### Fixed * The default list of type annotations used by `formatAnnotations` has had 8 more annotations from the Checker Framework added [#1494](https://github.com/diffplug/spotless/pull/1494) ### Changes diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 0c1cbf8785..8dd758e84b 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -66,7 +66,9 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke int checkedButAlreadyClean = impactedFilesTracker.getCheckedButAlreadyClean(); int cleaned = impactedFilesTracker.getCleaned(); int totalProcessed = skippedAsCleanCache + checkedButAlreadyClean + cleaned; - getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", - formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); + if (totalProcessed > 0) { + getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", + formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); + } } } From 6f6b34fe35753064fdd35e5fcce8b42ec62660fb Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 31 Jan 2023 08:45:30 +0400 Subject: [PATCH 0432/1120] Add debug log if no concerned filers --- .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 8dd758e84b..5f99f6a126 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -69,6 +69,9 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke if (totalProcessed > 0) { getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); + } else { + getLog().debug(String.format("Spotless.%s is not considering a single file", + formatter.getName())); } } } From b48f511c652282ff04738b84214dbc8944ba5412 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 30 Jan 2023 22:41:18 -0800 Subject: [PATCH 0433/1120] Move towards API changes. --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index d1ae14750e..7cfca1fb56 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,8 @@ plugins { id 'dev.equo.ide' version '0.12.1' } equoIde { - branding.title('Spotless').icon(file('_images/spotless_logo.png')) - welcome().openUrlOnStartup('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') + branding().title('Spotless').icon(file('_images/spotless_logo.png')) + welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') // everything below becomes the default after https://github.com/equodev/equo-ide/pull/66 p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' From d7ff074095b4bbcbe1acb6a7e4ad1edf6fccb78f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 30 Jan 2023 22:46:21 -0800 Subject: [PATCH 0434/1120] Treat empty target as a warning (likely a mistake, e.g. #437). --- .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 5f99f6a126..440b72c21e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -70,8 +70,7 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); } else { - getLog().debug(String.format("Spotless.%s is not considering a single file", - formatter.getName())); + getLog().warn(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); } } } From eeee68aaa9e605d23b0622af7ff2650237c96fa5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 30 Jan 2023 22:48:52 -0800 Subject: [PATCH 0435/1120] Minor renaming to condense SpotlessApplyMojo. --- .../spotless/maven/ImpactedFilesTracker.java | 3 +++ .../spotless/maven/SpotlessApplyMojo.java | 16 ++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java index f66802475e..60eb8af762 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ImpactedFilesTracker.java @@ -50,4 +50,7 @@ public int getCleaned() { return nbCleaned; } + public int getTotal() { + return nbskippedAsCleanCache + nbCheckedButAlreadyClean + nbCleaned; + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 440b72c21e..f7f23d6d75 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -33,11 +33,11 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo { @Override protected void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException { - ImpactedFilesTracker impactedFilesTracker = new ImpactedFilesTracker(); + ImpactedFilesTracker counter = new ImpactedFilesTracker(); for (File file : files) { if (upToDateChecker.isUpToDate(file.toPath())) { - impactedFilesTracker.skippedAsCleanCache(); + counter.skippedAsCleanCache(); if (getLog().isDebugEnabled()) { getLog().debug("Spotless will not format an up-to-date file: " + file); } @@ -50,9 +50,9 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke getLog().info(String.format("Writing clean file: %s", file)); dirtyState.writeCanonicalTo(file); buildContext.refresh(file); - impactedFilesTracker.cleaned(); + counter.cleaned(); } else { - impactedFilesTracker.checkedButAlreadyClean(); + counter.checkedButAlreadyClean(); } } catch (IOException e) { throw new MojoExecutionException("Unable to format file " + file, e); @@ -62,13 +62,9 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } // We print the number of considered files which is useful when ratchetFrom is setup - int skippedAsCleanCache = impactedFilesTracker.getSkippedAsCleanCache(); - int checkedButAlreadyClean = impactedFilesTracker.getCheckedButAlreadyClean(); - int cleaned = impactedFilesTracker.getCleaned(); - int totalProcessed = skippedAsCleanCache + checkedButAlreadyClean + cleaned; - if (totalProcessed > 0) { + if (counter.getTotal() > 0) { getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", - formatter.getName(), totalProcessed, cleaned, checkedButAlreadyClean, skippedAsCleanCache)); + formatter.getName(), counter.getTotal(), counter.getCleaned(), counter.getCheckedButAlreadyClean(), counter.getSkippedAsCleanCache())); } else { getLog().warn(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); } From 1981d4b2c8f521264e1d3ece408daf4bebf97e49 Mon Sep 17 00:00:00 2001 From: Aleksey Genus Date: Tue, 31 Jan 2023 16:31:50 +0600 Subject: [PATCH 0436/1120] Sort by keys inside json arrays --- .../spotless/glue/gson/GsonFormatterFunc.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java index b19476a1a8..0ff5037cba 100644 --- a/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java +++ b/lib/src/gson/java/com/diffplug/spotless/glue/gson/GsonFormatterFunc.java @@ -21,6 +21,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.stream.JsonWriter; @@ -57,8 +58,8 @@ public String apply(String inputString) { if (jsonElement == null) { throw new AssertionError(FAILED_TO_PARSE_ERROR_MESSAGE); } - if (gsonConfig.isSortByKeys() && jsonElement.isJsonObject()) { - jsonElement = sortByKeys(jsonElement.getAsJsonObject()); + if (gsonConfig.isSortByKeys()) { + jsonElement = sortByKeys(jsonElement); } try (StringWriter stringWriter = new StringWriter()) { JsonWriter jsonWriter = new JsonWriter(stringWriter); @@ -72,19 +73,36 @@ public String apply(String inputString) { return result; } + private JsonElement sortByKeys(JsonElement jsonElement) { + if (jsonElement.isJsonArray()) { + return sortByKeys(jsonElement.getAsJsonArray()); + } else if (jsonElement.isJsonObject()) { + return sortByKeys(jsonElement.getAsJsonObject()); + } else { + return jsonElement; + } + } + private JsonElement sortByKeys(JsonObject jsonObject) { JsonObject result = new JsonObject(); jsonObject.keySet().stream().sorted() .forEach(key -> { - JsonElement element = jsonObject.get(key); - if (element.isJsonObject()) { - element = sortByKeys(element.getAsJsonObject()); - } - result.add(key, element); + JsonElement sorted = sortByKeys(jsonObject.get(key)); + result.add(key, sorted); }); return result; } + private JsonElement sortByKeys(JsonArray jsonArray) { + var result = new JsonArray(); + for (JsonElement element : jsonArray) { + JsonElement sorted = sortByKeys(element); + result.add(sorted); + } + + return result; + } + private String generateIndent(int indentSpaces) { return String.join("", Collections.nCopies(indentSpaces, " ")); } From d77a3390fd4a378467f2c5b5a790aed2febaa48f Mon Sep 17 00:00:00 2001 From: Aleksey Genus Date: Tue, 31 Jan 2023 17:24:14 +0600 Subject: [PATCH 0437/1120] Add changes --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 401998b233..72a4b99e93 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] ### Changes * **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337)) +* **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) ## [2.34.0] - 2023-01-26 ### Added From 6a9dcfd99ccdf5bec5f7330bd4bae9b404d78fc5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 09:31:49 -0800 Subject: [PATCH 0438/1120] Stop disabling plugin-maven on JITPACK. --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index ac0e81a61b..9573775884 100644 --- a/settings.gradle +++ b/settings.gradle @@ -91,7 +91,7 @@ def getStartProperty(java.lang.String name) { } -if (System.getenv('SPOTLESS_EXCLUDE_MAVEN') != 'true' && getStartProperty('SPOTLESS_EXCLUDE_MAVEN') != 'true' && System.getenv('JITPACK') != 'true') { +if (System.getenv('SPOTLESS_EXCLUDE_MAVEN') != 'true' && getStartProperty('SPOTLESS_EXCLUDE_MAVEN') != 'true') { include 'plugin-maven' // maven-specific glue code } From 4c7b616e510bd83167ff329361ad819fac28ae6e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 09:36:09 -0800 Subject: [PATCH 0439/1120] Set JitPack build JDK to 11. --- jitpack.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 jitpack.yml diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000000..adb3fe10c8 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk11 From c77a4a609afa04b4f5969b7eabecd468cf88664e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 09:49:13 -0800 Subject: [PATCH 0440/1120] Disable signing on JitPack. --- gradle/java-publish.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 7d2055d78d..4f77a43ac2 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -170,7 +170,7 @@ model { } } -if (!version.endsWith('-SNAPSHOT')) { +if (!version.endsWith('-SNAPSHOT') && System.getenv('JITPACK') != 'true') { signing { String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64') useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase']) From 1c060830640b39f04b2e16b6ac49da52d7d0d276 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 09:58:13 -0800 Subject: [PATCH 0441/1120] Another attempt to disable signing on JitPack. --- gradle/java-publish.gradle | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 4f77a43ac2..3839391d3a 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -170,7 +170,11 @@ model { } } -if (!version.endsWith('-SNAPSHOT') && System.getenv('JITPACK') != 'true') { +if (System.getenv('JITPACK') == 'true') { + signing { + setRequired(false) + } +} else if (!version.endsWith('-SNAPSHOT')) { signing { String gpg_key = decode64('ORG_GRADLE_PROJECT_gpg_key64') useInMemoryPgpKeys(gpg_key, System.env['ORG_GRADLE_PROJECT_gpg_passphrase']) From cc43cf1becc90cf964234fa00bd542c0b873d279 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 13:47:59 -0800 Subject: [PATCH 0442/1120] Another attempt at fixing JitPack. --- gradle/java-publish.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 3839391d3a..7583bbe344 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -170,7 +170,7 @@ model { } } -if (System.getenv('JITPACK') == 'true') { +if (System.env['JITPACK'] == 'true') { signing { setRequired(false) } From e3f1ca4c9cd37356c8940c28814e441e78fe02c5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 13:59:54 -0800 Subject: [PATCH 0443/1120] Update contributing guide and changelog. --- CONTRIBUTING.md | 2 +- plugin-maven/CHANGES.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 782e377d58..783f58b9af 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -207,7 +207,7 @@ If it doesn't work, you can check the JitPack log at `https://jitpack.io/com/git ### Maven -Run `./gradlew publishToMavenLocal` to publish this to your local repository. The maven plugin is not published to JitPack due to [jitpack/jitpack.io#4112](https://github.com/jitpack/jitpack.io/issues/4112). +Run `./gradlew publishToMavenLocal` to publish this to your local repository. You can also use the JitPack artifacts, using the same principles as Gradle above. ## License diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c9e0f420a5..0029814ae9 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * A synthesis log with the number of considered files is added after each formatter execution ([#1507](https://github.com/diffplug/spotless/pull/1507)) +* Any commit of the Spotless maven plugin now available via JitPack ([#1547](https://github.com/diffplug/spotless/pull/1547)) ## [2.31.0] - 2023-01-26 ### Added From a413524f4fc09814c51522897453e6dae453e0d7 Mon Sep 17 00:00:00 2001 From: Aleksey Genus Date: Wed, 1 Feb 2023 11:47:14 +0600 Subject: [PATCH 0444/1120] Add changes to maven and gradle changelogs Add tests --- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ testlib/src/main/resources/json/sortByKeysAfter.json | 6 ++++++ .../src/main/resources/json/sortByKeysAfterDisabled.json | 6 ++++++ testlib/src/main/resources/json/sortByKeysBefore.json | 6 ++++++ 5 files changed, 22 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 49ef0adbbe..a81ee7bd93 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Changes +* **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) ## [6.14.0] - 2023-01-26 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c9e0f420a5..1ffea0faa7 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * A synthesis log with the number of considered files is added after each formatter execution ([#1507](https://github.com/diffplug/spotless/pull/1507)) +### Changes +* **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) ## [2.31.0] - 2023-01-26 ### Added diff --git a/testlib/src/main/resources/json/sortByKeysAfter.json b/testlib/src/main/resources/json/sortByKeysAfter.json index c4a48de2f2..7a83087f1d 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter.json +++ b/testlib/src/main/resources/json/sortByKeysAfter.json @@ -6,6 +6,12 @@ 2, 1 ], + "_objectsInArraysAreSorted": [ + { + "a": "1", + "b": 2 + } + ], "a": 3, "c": 4, "x": 5, diff --git a/testlib/src/main/resources/json/sortByKeysAfterDisabled.json b/testlib/src/main/resources/json/sortByKeysAfterDisabled.json index de7462bb98..81d81e6891 100644 --- a/testlib/src/main/resources/json/sortByKeysAfterDisabled.json +++ b/testlib/src/main/resources/json/sortByKeysAfterDisabled.json @@ -15,5 +15,11 @@ 3, 2, 1 + ], + "_objectsInArraysAreSorted": [ + { + "b": 2, + "a": "1" + } ] } diff --git a/testlib/src/main/resources/json/sortByKeysBefore.json b/testlib/src/main/resources/json/sortByKeysBefore.json index de7462bb98..81d81e6891 100644 --- a/testlib/src/main/resources/json/sortByKeysBefore.json +++ b/testlib/src/main/resources/json/sortByKeysBefore.json @@ -15,5 +15,11 @@ 3, 2, 1 + ], + "_objectsInArraysAreSorted": [ + { + "b": 2, + "a": "1" + } ] } From c060599aa9c8cb2ee9ad8660cf891ec3e4765f31 Mon Sep 17 00:00:00 2001 From: Aleksey Genus Date: Wed, 1 Feb 2023 11:48:14 +0600 Subject: [PATCH 0445/1120] Make values consistent --- testlib/src/main/resources/json/sortByKeysAfter.json | 2 +- testlib/src/main/resources/json/sortByKeysAfterDisabled.json | 2 +- testlib/src/main/resources/json/sortByKeysBefore.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/testlib/src/main/resources/json/sortByKeysAfter.json b/testlib/src/main/resources/json/sortByKeysAfter.json index 7a83087f1d..070904e872 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter.json +++ b/testlib/src/main/resources/json/sortByKeysAfter.json @@ -8,7 +8,7 @@ ], "_objectsInArraysAreSorted": [ { - "a": "1", + "a": 1, "b": 2 } ], diff --git a/testlib/src/main/resources/json/sortByKeysAfterDisabled.json b/testlib/src/main/resources/json/sortByKeysAfterDisabled.json index 81d81e6891..eb9e38241f 100644 --- a/testlib/src/main/resources/json/sortByKeysAfterDisabled.json +++ b/testlib/src/main/resources/json/sortByKeysAfterDisabled.json @@ -19,7 +19,7 @@ "_objectsInArraysAreSorted": [ { "b": 2, - "a": "1" + "a": 1 } ] } diff --git a/testlib/src/main/resources/json/sortByKeysBefore.json b/testlib/src/main/resources/json/sortByKeysBefore.json index 81d81e6891..eb9e38241f 100644 --- a/testlib/src/main/resources/json/sortByKeysBefore.json +++ b/testlib/src/main/resources/json/sortByKeysBefore.json @@ -19,7 +19,7 @@ "_objectsInArraysAreSorted": [ { "b": 2, - "a": "1" + "a": 1 } ] } From a7b4da4934957d051f5da027efcd157d92aed586 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 31 Jan 2023 23:29:02 -0800 Subject: [PATCH 0446/1120] We can rely on the defaults within equoIde now. --- build.gradle | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build.gradle b/build.gradle index 7cfca1fb56..28bc589212 100644 --- a/build.gradle +++ b/build.gradle @@ -5,14 +5,6 @@ plugins { equoIde { branding().title('Spotless').icon(file('_images/spotless_logo.png')) welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') - - // everything below becomes the default after https://github.com/equodev/equo-ide/pull/66 - p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' - install 'org.eclipse.releng.java.languages.categoryIU' - install 'org.eclipse.platform.ide.categoryIU' - - p2repo 'https://download.eclipse.org/buildship/updates/e423/releases/3.x/3.1.6.v20220511-1359/' - install 'org.eclipse.buildship.feature.group' } repositories { From 62ddd9eb084721f963fadd03ef235f0e1f00fa84 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 1 Feb 2023 12:30:32 +0400 Subject: [PATCH 0447/1120] Switch from WARN to DEBUG --- .../java/com/diffplug/spotless/maven/SpotlessApplyMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index f7f23d6d75..028cc3fb9c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -66,7 +66,7 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke getLog().info(String.format("Spotless.%s is keeping %s files clean - %s were changed to be clean, %s were already clean, %s were skipped because caching determined they were already clean", formatter.getName(), counter.getTotal(), counter.getCleaned(), counter.getCheckedButAlreadyClean(), counter.getSkippedAsCleanCache())); } else { - getLog().warn(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); + getLog().debug(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); } } } From df8fbf22848a61dd0fff91c19eaff19ca080630a Mon Sep 17 00:00:00 2001 From: Aleksey Genus Date: Wed, 1 Feb 2023 14:36:20 +0600 Subject: [PATCH 0448/1120] Fix jackson tests --- .../main/resources/json/sortByKeysAfterDisabled_Simple.json | 4 ++++ testlib/src/main/resources/json/sortByKeysAfter_Jackson.json | 4 ++++ .../json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json b/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json index d2d3612fbd..cd7ebc2be1 100644 --- a/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json +++ b/testlib/src/main/resources/json/sortByKeysAfterDisabled_Simple.json @@ -11,6 +11,10 @@ "x": 5, "X": 2 }, + "_objectsInArraysAreSorted": [{ + "a": 1, + "b": 2 + }], "_arraysNotSorted": [ 3, 2, diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json index 3af39fd0fb..003b2ba66f 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson.json @@ -2,6 +2,10 @@ "A": 1, "X": 2, "_arraysNotSorted": [ 3, 2, 1 ], + "_objectsInArraysAreSorted": [ { + "a": 1, + "b": 2 + } ], "a": 3, "c": 4, "x": 5, diff --git a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json index 3af39fd0fb..003b2ba66f 100644 --- a/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json +++ b/testlib/src/main/resources/json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json @@ -2,6 +2,10 @@ "A": 1, "X": 2, "_arraysNotSorted": [ 3, 2, 1 ], + "_objectsInArraysAreSorted": [ { + "a": 1, + "b": 2 + } ], "a": 3, "c": 4, "x": 5, From dc9878b949b7e00058ef69d341e3824135f76640 Mon Sep 17 00:00:00 2001 From: Kostiantyn Liutovych Date: Sat, 4 Feb 2023 14:24:18 +0100 Subject: [PATCH 0449/1120] Respect sourceDirectory/testSourceDirectory configs for Java formatters --- plugin-maven/CHANGES.md | 2 + .../spotless/maven/AbstractSpotlessMojo.java | 2 +- .../spotless/maven/FormatterFactory.java | 3 +- .../spotless/maven/antlr4/Antlr4.java | 6 +- .../com/diffplug/spotless/maven/cpp/Cpp.java | 6 +- .../spotless/maven/generic/Format.java | 6 +- .../spotless/maven/groovy/Groovy.java | 6 +- .../diffplug/spotless/maven/java/Java.java | 31 +++- .../spotless/maven/javascript/Javascript.java | 4 +- .../diffplug/spotless/maven/json/Json.java | 4 +- .../spotless/maven/kotlin/Kotlin.java | 6 +- .../spotless/maven/markdown/Markdown.java | 6 +- .../com/diffplug/spotless/maven/pom/Pom.java | 6 +- .../spotless/maven/python/Python.java | 6 +- .../diffplug/spotless/maven/scala/Scala.java | 6 +- .../com/diffplug/spotless/maven/sql/Sql.java | 6 +- .../spotless/maven/typescript/Typescript.java | 4 +- .../diffplug/spotless/maven/yaml/Yaml.java | 4 +- .../maven/MavenIntegrationHarness.java | 17 +- .../maven/MultiModuleProjectTest.java | 2 +- .../maven/java/JavaDefaultIncludesTest.java | 151 ++++++++++++++++++ .../src/test/resources/pom-test.xml.mustache | 1 + 22 files changed, 250 insertions(+), 35 deletions(-) create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/java/JavaDefaultIncludesTest.java diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9c0b237ea3..b924c07fd6 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * A synthesis log with the number of considered files is added after each formatter execution ([#1507](https://github.com/diffplug/spotless/pull/1507)) +### Fixed +* Respect `sourceDirectory` and `testSourceDirectory` POM configurations for Java formatters ([#1553](https://github.com/diffplug/spotless/pull/1553)) ### Changes * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) * Any commit of the Spotless maven plugin now available via JitPack ([#1547](https://github.com/diffplug/spotless/pull/1547)) 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 c4082f52e0..f6aab0eabb 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 @@ -320,7 +320,7 @@ private static String withTrailingSeparator(String path) { private Set getIncludes(FormatterFactory formatterFactory) { Set configuredIncludes = formatterFactory.includes(); - Set includes = configuredIncludes.isEmpty() ? formatterFactory.defaultIncludes() : configuredIncludes; + Set includes = configuredIncludes.isEmpty() ? formatterFactory.defaultIncludes(project) : configuredIncludes; if (includes.isEmpty()) { throw new PluginException("You must specify some files to include, such as 'src/**/*.blah'"); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java index b78e987d34..c4a6663087 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormatterFactory.java @@ -29,6 +29,7 @@ import java.util.stream.Collectors; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; import com.diffplug.common.collect.Sets; import com.diffplug.spotless.FormatExceptionPolicyStrict; @@ -71,7 +72,7 @@ public abstract class FormatterFactory { private ToggleOffOn toggle; - public abstract Set defaultIncludes(); + public abstract Set defaultIncludes(MavenProject project); public abstract String licenseHeaderDelimiter(); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java index bc24ebcf16..a43416fb4e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/antlr4/Antlr4.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -17,6 +17,8 @@ import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.antlr4.Antlr4Defaults; import com.diffplug.spotless.maven.FormatterFactory; @@ -30,7 +32,7 @@ */ public class Antlr4 extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return ImmutableSet.of(Antlr4Defaults.includes()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java index f1d07d8552..44940ae4d8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.cpp.CppDefaults; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -30,7 +32,7 @@ */ public class Cpp extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java index 465381fb52..a696e13ffb 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 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,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -29,7 +31,7 @@ public class Format extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java index e9b3c6c412..8041b812f9 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-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,6 +17,8 @@ import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -33,7 +35,7 @@ public class Groovy extends FormatterFactory { private static final String LICENSE_HEADER_DELIMITER = "package "; @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return DEFAULT_INCLUDES; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index 4bd018d53c..0921a838b3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -15,9 +15,17 @@ */ package com.diffplug.spotless.maven.java; +import static java.util.stream.Collectors.toSet; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Set; +import java.util.stream.Stream; + +import org.apache.maven.model.Build; +import org.apache.maven.project.MavenProject; -import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -29,12 +37,17 @@ */ public class Java extends FormatterFactory { - private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/java/**/*.java", "src/test/java/**/*.java"); private static final String LICENSE_HEADER_DELIMITER = "package "; @Override - public Set defaultIncludes() { - return DEFAULT_INCLUDES; + public Set defaultIncludes(MavenProject project) { + Path projectDir = project.getBasedir().toPath(); + Build build = project.getBuild(); + return Stream.of(build.getSourceDirectory(), build.getTestSourceDirectory()) + .map(Paths::get) + .map(projectDir::relativize) + .map(Java::fileMask) + .collect(toSet()); } @Override @@ -65,4 +78,12 @@ public void addRemoveUnusedImports(RemoveUnusedImports removeUnusedImports) { public void addFormatAnnotations(FormatAnnotations formatAnnotations) { addStepFactory(formatAnnotations); } + + private static String fileMask(Path path) { + String dir = path.toString(); + if (!dir.endsWith(File.separator)) { + dir += File.separator; + } + return dir + "**" + File.separator + "*.java"; + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java index 7ca35dd258..31a5917e06 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -27,7 +29,7 @@ */ public class Javascript extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index 852088278a..5bb7c17b3a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -27,7 +29,7 @@ public class Json extends FormatterFactory { public static final int DEFAULT_INDENTATION = 4; @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java index cfb0aad39e..18eb13773d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Kotlin.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. @@ -19,6 +19,8 @@ import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; @@ -27,7 +29,7 @@ public class Kotlin extends FormatterFactory { private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/kotlin/**/*.kt", "src/test/kotlin/**/*.kt"); @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return DEFAULT_INCLUDES; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Markdown.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Markdown.java index 2ba9b1f58f..0941beb76a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Markdown.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Markdown.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. @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -29,7 +31,7 @@ */ public class Markdown extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/Pom.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/Pom.java index f083a17c89..9a4d3eea06 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/Pom.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/Pom.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,6 +17,8 @@ import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -29,7 +31,7 @@ */ public class Pom extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return ImmutableSet.of("pom.xml"); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/python/Python.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/python/Python.java index 09443f070b..df7348c16c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/python/Python.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/python/Python.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. @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -30,7 +32,7 @@ public class Python extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java index 423ca71930..7a9e455f5f 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 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. @@ -17,6 +17,8 @@ import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -34,7 +36,7 @@ public class Scala extends FormatterFactory { private static final String LICENSE_HEADER_DELIMITER = "package "; @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return DEFAULT_INCLUDES; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/sql/Sql.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/sql/Sql.java index c49ac074d9..64ebcb55d7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/sql/Sql.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/sql/Sql.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright 2020-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,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -27,7 +29,7 @@ */ public class Sql extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index 6f0d7f91b2..6ba45ab719 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -27,7 +29,7 @@ */ public class Typescript extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java index a6ceaaa592..e22f6d40ce 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/yaml/Yaml.java @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + import com.diffplug.spotless.maven.FormatterFactory; /** @@ -25,7 +27,7 @@ */ public class Yaml extends FormatterFactory { @Override - public Set defaultIncludes() { + public Set defaultIncludes(MavenProject project) { return Collections.emptySet(); } 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 f4e94e573c..fdc4a745a1 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 @@ -54,7 +54,9 @@ public class MavenIntegrationHarness extends ResourceHarness { */ private static final String SPOTLESS_MAVEN_VERSION_IDE = null; + private static final String POM_TEMPLATE = "/pom-test.xml.mustache"; private static final String SPOTLESS_MAVEN_PLUGIN_VERSION = "spotlessMavenPluginVersion"; + private static final String BUILD = "build"; private static final String CONFIGURATION = "configuration"; private static final String EXECUTIONS = "executions"; private static final String MODULES = "modules"; @@ -209,11 +211,11 @@ protected MavenRunner mavenRunnerWithRemoteDebug() throws IOException { } protected String createPomXmlContent(String pluginVersion, String[] executions, String[] configuration, String[] dependencies, String[] plugins) throws IOException { - return createPomXmlContent("/pom-test.xml.mustache", pluginVersion, executions, configuration, dependencies, plugins); + return createPomXmlContent(POM_TEMPLATE, pluginVersion, executions, configuration, dependencies, plugins); } protected String createPomXmlContent(String pomTemplate, String pluginVersion, String[] executions, String[] configuration, String[] dependencies, String[] plugins) throws IOException { - Map params = buildPomXmlParams(pluginVersion, executions, configuration, null, dependencies, plugins); + Map params = buildPomXmlParams(pluginVersion, null, executions, configuration, null, dependencies, plugins); return createPomXmlContent(pomTemplate, params); } @@ -221,6 +223,11 @@ protected String createPomXmlContent(String pluginVersion, String[] executions, return createPomXmlContent(pluginVersion, executions, configuration, null, null); } + protected String createPomXmlContent(String[] build, String[] configuration) throws IOException { + Map params = buildPomXmlParams(null, build, null, configuration, null, null, null); + return createPomXmlContent(POM_TEMPLATE, params); + } + protected String createPomXmlContent(String pomTemplate, Map params) throws IOException { URL url = MavenIntegrationHarness.class.getResource(pomTemplate); try (BufferedReader reader = Resources.asCharSource(url, StandardCharsets.UTF_8).openBufferedStream()) { @@ -231,10 +238,14 @@ protected String createPomXmlContent(String pomTemplate, Map par } } - protected static Map buildPomXmlParams(String pluginVersion, String[] executions, String[] configuration, String[] modules, String[] dependencies, String[] plugins) { + protected static Map buildPomXmlParams(String pluginVersion, String[] build, String[] executions, String[] configuration, String[] modules, String[] dependencies, String[] plugins) { Map params = new HashMap<>(); params.put(SPOTLESS_MAVEN_PLUGIN_VERSION, pluginVersion == null ? getSystemProperty(SPOTLESS_MAVEN_PLUGIN_VERSION) : pluginVersion); + if (build != null) { + params.put(BUILD, String.join("\n", build)); + } + if (configuration != null) { params.put(CONFIGURATION, String.join("\n", configuration)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java index 6206affc04..1c9521c402 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java @@ -145,7 +145,7 @@ private void createRootPom() throws IOException { modulesList.addAll(subProjects.keySet()); String[] modules = modulesList.toArray(new String[0]); - Map rootPomParams = buildPomXmlParams(null, null, configuration, modules, null, null); + Map rootPomParams = buildPomXmlParams(null, null, null, configuration, modules, null, null); setFile("pom.xml").toContent(createPomXmlContent("/multi-module/pom-parent.xml.mustache", rootPomParams)); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/JavaDefaultIncludesTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/JavaDefaultIncludesTest.java new file mode 100644 index 0000000000..57f717ad07 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/JavaDefaultIncludesTest.java @@ -0,0 +1,151 @@ +/* + * 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.java; + +import java.io.IOException; +import java.util.Arrays; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +public class JavaDefaultIncludesTest extends MavenIntegrationHarness { + + private static final String UNFORMATTED = "java/removeunusedimports/JavaCodeWithPackageUnformatted.test"; + private static final String FORMATTED = "java/removeunusedimports/JavaCodeWithPackageFormatted.test"; + + private static final String FILE_1 = "src/main/java/com/diffplug/spotless/One.java"; + private static final String FILE_2 = "src/test/java/com/diffplug/spotless/Two.java"; + private static final String FILE_3 = "src/com/diffplug/spotless/Three.java"; + private static final String FILE_4 = "test/com/diffplug/spotless/Four.java"; + private static final String FILE_5 = "foo/bar/Five.java"; + + @BeforeEach + void beforeEach() { + for (String file : Arrays.asList(FILE_1, FILE_2, FILE_3, FILE_4, FILE_5)) { + setFile(file).toResource(UNFORMATTED); + } + } + + @Test + void noCustomConfiguration() throws Exception { + writePomWithBuildConfiguration(); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // Files 1, 2 are formatted because they live under default Maven source & test source dirs + assertFile(FILE_1).sameAsResource(FORMATTED); + assertFile(FILE_2).sameAsResource(FORMATTED); + + // Files 3, 4, 5 are not formatted because they live outside default Maven source & test source dirs + assertFile(FILE_3).sameAsResource(UNFORMATTED); + assertFile(FILE_4).sameAsResource(UNFORMATTED); + assertFile(FILE_5).sameAsResource(UNFORMATTED); + } + + @Test + void customSourceDirConfiguration() throws Exception { + writePomWithBuildConfiguration("src"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // Files 1, 2, 3 are formatted because they live under the custom-configured source dir + assertFile(FILE_1).sameAsResource(FORMATTED); + assertFile(FILE_2).sameAsResource(FORMATTED); + assertFile(FILE_3).sameAsResource(FORMATTED); + + // File 4, 5 are not formatted because they live outside the custom-configured source dir and default test source dir + assertFile(FILE_4).sameAsResource(UNFORMATTED); + assertFile(FILE_5).sameAsResource(UNFORMATTED); + } + + @Test + void customTestSourceDirConfiguration() throws Exception { + writePomWithBuildConfiguration("test"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // File 1 is formatted because it lives under the default source dir + assertFile(FILE_1).sameAsResource(FORMATTED); + // File 4 is formatted because it lives under the custom-configured test source dir + assertFile(FILE_4).sameAsResource(FORMATTED); + + // Files 2, 3, 5 are not formatted because they live outside the default source dir and custom-configured test source dir + assertFile(FILE_2).sameAsResource(UNFORMATTED); + assertFile(FILE_3).sameAsResource(UNFORMATTED); + assertFile(FILE_5).sameAsResource(UNFORMATTED); + } + + @Test + void customSourceDirAndTestSourceDirConfiguration() throws Exception { + writePomWithBuildConfiguration( + "src", + "test"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // Files 1, 2, 3, 4 are formatted because they live under custom-configured source and test source dirs + assertFile(FILE_1).sameAsResource(FORMATTED); + assertFile(FILE_2).sameAsResource(FORMATTED); + assertFile(FILE_3).sameAsResource(FORMATTED); + assertFile(FILE_4).sameAsResource(FORMATTED); + + // File 5 is not formatted because it lives outside custom-configured source and test source dirs + assertFile(FILE_5).sameAsResource(UNFORMATTED); + } + + @Test + void sameCustomSourceDirAndTestSourceDirConfiguration() throws Exception { + writePomWithBuildConfiguration( + "foo/bar", + "foo/bar"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // Files 1, 2, 3, 4 are not formatted because they live outside custom-configured source and test source dirs + assertFile(FILE_1).sameAsResource(UNFORMATTED); + assertFile(FILE_2).sameAsResource(UNFORMATTED); + assertFile(FILE_3).sameAsResource(UNFORMATTED); + assertFile(FILE_4).sameAsResource(UNFORMATTED); + + // File 5 is formatted because it lives under the custom-configured source/test source dir + assertFile(FILE_5).sameAsResource(FORMATTED); + } + + @Test + void nestedCustomSourceDirAndTestSourceDirConfiguration() throws Exception { + writePomWithBuildConfiguration( + "foo", + "foo/bar"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + + // Files 1, 2, 3, 4 are not formatted because they live outside custom-configured source and test source dirs + assertFile(FILE_1).sameAsResource(UNFORMATTED); + assertFile(FILE_2).sameAsResource(UNFORMATTED); + assertFile(FILE_3).sameAsResource(UNFORMATTED); + assertFile(FILE_4).sameAsResource(UNFORMATTED); + + // File 5 is formatted because it lives under the custom-configured source/test source dir + assertFile(FILE_5).sameAsResource(FORMATTED); + } + + private void writePomWithBuildConfiguration(String... build) throws IOException { + String xml = createPomXmlContent(build, new String[]{"", "", ""}); + setFile("pom.xml").toContent(xml); + } +} diff --git a/plugin-maven/src/test/resources/pom-test.xml.mustache b/plugin-maven/src/test/resources/pom-test.xml.mustache index 6db3cb0c15..f87e8c1a3e 100644 --- a/plugin-maven/src/test/resources/pom-test.xml.mustache +++ b/plugin-maven/src/test/resources/pom-test.xml.mustache @@ -20,6 +20,7 @@ + {{{build}}} {{{plugins}}} From 6d3862c702dd522fbb5f989a670b03720f8a49d9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 5 Feb 2023 01:07:51 -0800 Subject: [PATCH 0450/1120] Use the latest JScriptBox on Java 15+ --- .../main/java/com/diffplug/spotless/markdown/FreshMarkStep.java | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java index fca5ac39a4..4477c640c7 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java @@ -66,6 +66,7 @@ public static FormatterStep create(String version, Supplier> prop List mavenCoordinates = new ArrayList<>(); mavenCoordinates.add(MAVEN_COORDINATE + version); if (Jvm.version() >= 15) { + mavenCoordinates.add("com.diffplug.jscriptbox:jscriptbox:3.0.1"); mavenCoordinates.add(NASHORN_MAVEN_COORDINATE + NASHORN_VERSION); } From e9d72aa093a70a8ed66d71aa8625394fa4d0f147 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 5 Feb 2023 01:13:31 -0800 Subject: [PATCH 0451/1120] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 1 - 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 72a4b99e93..c8add05b6a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes * **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337)) +### Fixed * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) +* `freshmark` fixed on java 15+ ([#1304](https://github.com/diffplug/spotless/pull/1304) fixes [#803](https://github.com/diffplug/spotless/issues/803)) ## [2.34.0] - 2023-01-26 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a81ee7bd93..fef2c71346 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,7 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] -### Changes +### Fixed +* `freshmark` fixed on java 15+ ([#1304](https://github.com/diffplug/spotless/pull/1304) fixes [#803](https://github.com/diffplug/spotless/issues/803)) * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) ## [6.14.0] - 2023-01-26 diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index b924c07fd6..d498b868c7 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,7 +7,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * A synthesis log with the number of considered files is added after each formatter execution ([#1507](https://github.com/diffplug/spotless/pull/1507)) ### Fixed * Respect `sourceDirectory` and `testSourceDirectory` POM configurations for Java formatters ([#1553](https://github.com/diffplug/spotless/pull/1553)) -### Changes * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) * Any commit of the Spotless maven plugin now available via JitPack ([#1547](https://github.com/diffplug/spotless/pull/1547)) From 0252904844cbd3a182f9668c49073b809aee97ab Mon Sep 17 00:00:00 2001 From: runner Date: Sun, 5 Feb 2023 16:46:18 +0000 Subject: [PATCH 0452/1120] Published lib/2.34.1 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index c8add05b6a..5f1a1ffa9f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.34.1] - 2023-02-05 ### Changes * **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337)) ### Fixed From 2fece0442035a72fc3be978d47dca483e8d02b2c Mon Sep 17 00:00:00 2001 From: runner Date: Sun, 5 Feb 2023 16:48:11 +0000 Subject: [PATCH 0453/1120] Published gradle/6.14.1 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 50 ++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index fef2c71346..e3234584b8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.14.1] - 2023-02-05 ### Fixed * `freshmark` fixed on java 15+ ([#1304](https://github.com/diffplug/spotless/pull/1304) fixes [#803](https://github.com/diffplug/spotless/issues/803)) * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 6a56d26e20..f61280bc7e 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.14.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.14.1-blue.svg)](CHANGES.md) [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -123,10 +123,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -138,7 +138,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -262,8 +262,8 @@ You can make a pull request to add new annotations to Spotless's default list. ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -314,8 +314,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -386,7 +386,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -418,7 +418,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -450,7 +450,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -484,7 +484,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -505,7 +505,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -530,7 +530,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -570,7 +570,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -662,7 +662,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -726,7 +726,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -801,7 +801,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -1014,7 +1014,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1087,9 +1087,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1122,11 +1122,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 8d99d7dc44b75fbfbcd25a2550332a11f40219cc Mon Sep 17 00:00:00 2001 From: runner Date: Sun, 5 Feb 2023 16:50:20 +0000 Subject: [PATCH 0454/1120] Published maven/2.32.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d498b868c7..567d880f4f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.32.0] - 2023-02-05 ### Added * A synthesis log with the number of considered files is added after each formatter execution ([#1507](https://github.com/diffplug/spotless/pull/1507)) ### Fixed diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 73402cd929..0787150ee1 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.31.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.31.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.32.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.32.0/index.html) + @@ -274,6 +276,25 @@ list of well-known type annotations. You can make a pull request to add new one In the future there will be mechanisms to add/remove annotations from the list. These mechanisms already exist for the Gradle plugin. +### Cleanthat + +[homepage](https://github.com/solven-eu/cleanthat). CleanThat enables automatic refactoring of Java code + +```xml + + 2.0 + ${maven.compiler.source} + + * + + + LiteralsFirstInComparisons + + + OptionalNotEmpty + + +``` ## Groovy diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java index 76c130bcdd..7460ab67b9 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java @@ -20,7 +20,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.java.CleanthatStepFactory; +import com.diffplug.spotless.java.CleanthatJavaStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -33,19 +33,19 @@ public class CleanthatJava implements FormatterStepFactory { // https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source @Parameter(property = "maven.compiler.source") - private String sourceJdk = CleanthatStepFactory.defaultJdkVersion(); + private String sourceJdk = CleanthatJavaStep.defaultJdkVersion(); @Parameter - private List mutators = CleanthatStepFactory.defaultMutators(); + private List mutators = CleanthatJavaStep.defaultMutators(); @Parameter - private List excludedMutators = CleanthatStepFactory.defaultExcludedMutators(); + private List excludedMutators = CleanthatJavaStep.defaultExcludedMutators(); @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { - String groupArtifact = this.groupArtifact != null ? this.groupArtifact : CleanthatStepFactory.defaultGroupArtifact(); - String version = this.version != null ? this.version : CleanthatStepFactory.defaultVersion(); + String groupArtifact = this.groupArtifact != null ? this.groupArtifact : CleanthatJavaStep.defaultGroupArtifact(); + String version = this.version != null ? this.version : CleanthatJavaStep.defaultVersion(); - return CleanthatStepFactory.create(groupArtifact, version, sourceJdk, mutators, excludedMutators, config.getProvisioner()); + return CleanthatJavaStep.create(groupArtifact, version, sourceJdk, mutators, excludedMutators, config.getProvisioner()); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index 0921a838b3..efdf0827db 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -79,6 +79,10 @@ public void addFormatAnnotations(FormatAnnotations formatAnnotations) { addStepFactory(formatAnnotations); } + public void addCleanthat(CleanthatJava cleanthat) { + addStepFactory(cleanthat); + } + private static String fileMask(Path path) { String dir = path.toString(); if (!dir.endsWith(File.separator)) { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java new file mode 100644 index 0000000000..c72aeb15b2 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -0,0 +1,76 @@ +/* + * Copyright 2022-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.java; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +class CleanthatJavaRefactorerTest extends MavenIntegrationHarness { + private static final Logger LOGGER = LoggerFactory.getLogger(CleanthatJavaRefactorerTest.class); + + @Test + void testLiteralsFirstInComparisons() throws Exception { + writePomWithJavaSteps( + "", + ""); + + runTest("LiteralsFirstInComparisons.dirty.java", "LiteralsFirstInComparisons.clean.java"); + } + + @Test + void testMultipleMutators() throws Exception { + writePomWithJavaSteps( + "", + ""); + + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.java"); + } + + @Test + void testExcludeOptionalNotEmpty() throws Exception { + writePomWithJavaSteps( + "", + " ", + " OptionalNotEmpty", + " ", + ""); + + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + } + + @Test + void testIncludeOnlyLiteralsFirstInComparisons() throws Exception { + writePomWithJavaSteps( + "", + " ", + " LiteralsFirstInComparisons", + " ", + ""); + + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + } + + private void runTest(String dirtyPath, String cleanPath) throws Exception { + String path = "src/main/java/test.java"; + setFile(path).toResource("java/cleanthat/" + dirtyPath); + Assertions.assertThat(mavenRunner().withArguments("spotless:apply -X").runNoError().stdOutUtf8()).isEmpty(); + assertFile(path).sameAsResource("java/cleanthat/" + cleanPath); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java new file mode 100644 index 0000000000..8bacfa58db --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java @@ -0,0 +1,8 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return "hardcoded".equals(input); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java new file mode 100644 index 0000000000..3a1e074c91 --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java @@ -0,0 +1,8 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return input.equals("hardcoded"); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java new file mode 100644 index 0000000000..0829602dc1 --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java @@ -0,0 +1,14 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +import java.util.Optional; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return input.equals("hardcoded"); + } + + public boolean isPresent(Optional optional) { + return optional.isPresent(); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java new file mode 100644 index 0000000000..629d24504b --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java @@ -0,0 +1,14 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +import java.util.Optional; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return "hardcoded".equals(input); + } + + public boolean isPresent(Optional optional) { + return !optional.isEmpty(); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java new file mode 100644 index 0000000000..8ac230cabc --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java @@ -0,0 +1,14 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +import java.util.Optional; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return input.equals("hardcoded"); + } + + public boolean isPresent(Optional optional) { + return !optional.isEmpty(); + } +} From f80b45f149e3de392a025b3ac8842b6231299fac Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 7 Feb 2023 18:04:35 +0000 Subject: [PATCH 0464/1120] Update dependency com.facebook:ktfmt to v0.43 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 9d95007bc1..1fa0e41409 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -65,7 +65,7 @@ dependencies { jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.1' jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1' - String VER_KTFMT = '0.42' + String VER_KTFMT = '0.43' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") { From 4f62769da7ba656ee47e9596d7f5b0f9c531c650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Wed, 8 Feb 2023 14:06:17 +0100 Subject: [PATCH 0465/1120] fixes continuation indent in ktfmt default formatter --- .../spotless/glue/ktfmt/KtfmtFormatterFunc.java | 2 +- .../com/diffplug/spotless/maven/kotlin/KtfmtTest.java | 11 +++++++++++ .../main/resources/kotlin/ktfmt/continuation.clean | 6 ++++++ .../main/resources/kotlin/ktfmt/continuation.dirty | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 testlib/src/main/resources/kotlin/ktfmt/continuation.clean create mode 100644 testlib/src/main/resources/kotlin/ktfmt/continuation.dirty diff --git a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java index 72e0e50e3c..e34f7b4755 100644 --- a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java +++ b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java @@ -78,7 +78,7 @@ private FormattingOptions createFormattingOptions() { formattingOptions.getStyle(), ktfmtFormattingOptions.getMaxWidth().orElse(formattingOptions.getMaxWidth()), ktfmtFormattingOptions.getBlockIndent().orElse(formattingOptions.getBlockIndent()), - ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getBlockIndent()), + ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getContinuationIndent()), ktfmtFormattingOptions.getRemoveUnusedImport().orElse(formattingOptions.getRemoveUnusedImports()), formattingOptions.getDebuggingPrintOpsAfterFormatting()); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 4ae266cc23..25ecbc598d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java @@ -19,6 +19,8 @@ import com.diffplug.spotless.maven.MavenIntegrationHarness; +import java.io.IOException; + class KtfmtTest extends MavenIntegrationHarness { @Test void testKtfmt() throws Exception { @@ -36,6 +38,15 @@ void testKtfmt() throws Exception { assertFile(path2).sameAsResource("kotlin/ktfmt/basic.clean"); } + @Test + void testContinuation() throws Exception { + writePomWithKotlinSteps(""); + + setFile("src/main/kotlin/main.kt").toResource("kotlin/ktfmt/continuation.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("src/main/kotlin/main.kt").sameAsResource("kotlin/ktfmt/continuation.clean"); + } + @Test void testKtfmtStyle() throws Exception { writePomWithKotlinSteps(""); diff --git a/testlib/src/main/resources/kotlin/ktfmt/continuation.clean b/testlib/src/main/resources/kotlin/ktfmt/continuation.clean new file mode 100644 index 0000000000..11677928fc --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktfmt/continuation.clean @@ -0,0 +1,6 @@ +fun myFunction() { + val location = + restTemplate.postForLocation( + "/v1/my-api", mapOf("name" to "some-name", "url" to "https://www.google.com")) + return location +} diff --git a/testlib/src/main/resources/kotlin/ktfmt/continuation.dirty b/testlib/src/main/resources/kotlin/ktfmt/continuation.dirty new file mode 100644 index 0000000000..3652274d12 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktfmt/continuation.dirty @@ -0,0 +1,4 @@ +fun myFunction() { + val location = restTemplate.postForLocation("/v1/my-api", mapOf("name" to "some-name", "url" to "https://www.google.com")) + return location +} From 8c74020fd505ecbc46db645b7fa330cbf5fd9514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Wed, 8 Feb 2023 14:16:52 +0100 Subject: [PATCH 0466/1120] adds a summary of the change to plugin-maven/CHANGES.md --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 567d880f4f..0e656e24ec 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Maven plugin with `ktfmt` default style uses correct continuation indent ([#1562](https://github.com/diffplug/spotless/pull/1562)) ## [2.32.0] - 2023-02-05 ### Added From 69e8524c650a53eaae67df350a56bb389b0a8903 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Feb 2023 22:28:15 +0400 Subject: [PATCH 0467/1120] Move to 2.1 to fix issue with class detection --- lib/build.gradle | 5 +- .../spotless/java/CleanthatJavaStep.java | 2 +- .../java/JavaCleanthatRefactorerFuncTest.java | 28 ++++++++ .../java/JavaCleanthatRefactorerFuncTest.java | 72 +++++++++++++++++++ .../java/CleanthatJavaRefactorerTest.java | 2 +- 5 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java create mode 100644 lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java diff --git a/lib/build.gradle b/lib/build.gradle index 0e1c2086ea..cd6996a979 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -55,6 +55,7 @@ dependencies { testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ" testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" + testCommonImplementation 'io.github.solven-eu.cleanthat:java:2.1' // used for pom sorting sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' @@ -102,7 +103,9 @@ dependencies { gsonCompileOnly 'com.google.code.gson:gson:2.10.1' - cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.0' + // TODO How can one add a test module like 'compatKtLint0Dot48Dot0'? + // cleanthatCompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.1' + cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.1' } // we'll hold the core lib to a high standard diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 79434cba56..fe4966d873 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -39,7 +39,7 @@ public final class CleanthatJavaStep { private static final String NAME = "cleanthat"; private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.0"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.1"); // prevent direct instantiation private CleanthatJavaStep() {} diff --git a/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java b/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java new file mode 100644 index 0000000000..2f3cdc9646 --- /dev/null +++ b/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java @@ -0,0 +1,28 @@ +/* + * 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.java; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; + +public class JavaCleanthatRefactorerFuncTest { + @Test + public void testMutatorsDetection() { + Assertions.assertThat(JavaRefactorer.getAllIncluded()).isNotEmpty(); + } +} diff --git a/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java b/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java new file mode 100644 index 0000000000..c811b51233 --- /dev/null +++ b/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java @@ -0,0 +1,72 @@ +/* + * 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.ktlint.compat; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +public class KtLintCompat0Dot48Dot0AdapterTest { + @Test + public void testDefaults(@TempDir Path path) throws IOException { + KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); + String text = loadAndWriteText(path, "empty_class_body.kt"); + final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + assertEquals("class empty_class_body\n", formatted); + } + + @Test + public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { + KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); + String text = loadAndWriteText(path, "fails_no_semicolons.kt"); + final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("indent_style", "tab"); + editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + // ktlint_filename is an invalid rule in ktlint 0.48.0 + editorConfigOverrideMap.put("ktlint_filename", "disabled"); + + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); + } + + private static String loadAndWriteText(Path path, String name) throws IOException { + try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/" + name)) { + Files.copy(is, path.resolve(name)); + } + return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8); + } + +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java index c72aeb15b2..833b19dda8 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -70,7 +70,7 @@ void testIncludeOnlyLiteralsFirstInComparisons() throws Exception { private void runTest(String dirtyPath, String cleanPath) throws Exception { String path = "src/main/java/test.java"; setFile(path).toResource("java/cleanthat/" + dirtyPath); - Assertions.assertThat(mavenRunner().withArguments("spotless:apply -X").runNoError().stdOutUtf8()).isEmpty(); + Assertions.assertThat(mavenRunner().withArguments("spotless:apply").withRemoteDebug(21654).runNoError().stdOutUtf8()).doesNotContain("[ERROR]"); assertFile(path).sameAsResource("java/cleanthat/" + cleanPath); } } From bcab5b4abb044d6ba9b730b56b99c74cd4408453 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Feb 2023 22:32:23 +0400 Subject: [PATCH 0468/1120] Improve documentation and changelog ref --- .../spotless/glue/java/JavaCleanthatRefactorerFunc.java | 4 ++++ .../java/com/diffplug/spotless/java/CleanthatJavaStep.java | 1 + plugin-maven/README.md | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java index 5ec54e69be..7432ebf3f9 100644 --- a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java +++ b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java @@ -30,6 +30,10 @@ import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorerProperties; import eu.solven.cleanthat.formatter.LineEnding; +/** + * The glue for CleanThat: it is build over the version in build.gradle, but at runtime it will be executed over + * the version loaded in JarState, which is by default defined in com.diffplug.spotless.java.CleanthatJavaStep#JVM_SUPPORT + */ public class JavaCleanthatRefactorerFunc implements FormatterFunc { private static final Logger LOGGER = LoggerFactory.getLogger(JavaCleanthatRefactorerFunc.class); diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index fe4966d873..1cd032a304 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -39,6 +39,7 @@ public final class CleanthatJavaStep { private static final String NAME = "cleanthat"; private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java"; + // CleanThat changelog is available at https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.1"); // prevent direct instantiation diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 36d46b2386..b1b9098bfe 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -278,7 +278,7 @@ These mechanisms already exist for the Gradle plugin. ### Cleanthat -[homepage](https://github.com/solven-eu/cleanthat). CleanThat enables automatic refactoring of Java code +[homepage](https://github.com/solven-eu/cleanthat). CleanThat enables automatic refactoring of Java code. [ChangeLog](https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD) ```xml From 9aefc2ebc1e901e899e279f501879e83f77c0cf5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 8 Feb 2023 10:56:45 -0800 Subject: [PATCH 0469/1120] Bump equo-ide to latest release. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 28bc589212..0b00b4c9f1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md - id 'dev.equo.ide' version '0.12.1' + id 'dev.equo.ide' version '0.13.0' } equoIde { branding().title('Spotless').icon(file('_images/spotless_logo.png')) From a5c8b4da6975b69e5d62ea29246a422a269610e1 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Feb 2023 23:06:46 +0400 Subject: [PATCH 0470/1120] Fix classLoader issue --- .../java/JavaCleanthatRefactorerFunc.java | 19 +++++++++++++++++++ .../java/CleanthatJavaRefactorerTest.java | 15 +++++++++++++-- .../cleanthat/MultipleMutators.clean.java | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java index 7432ebf3f9..c94fd3c7c4 100644 --- a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java +++ b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.java; +import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -25,6 +26,7 @@ import com.diffplug.spotless.FormatterFunc; import eu.solven.cleanthat.config.pojo.CleanthatEngineProperties; +import eu.solven.cleanthat.config.pojo.SourceCodeProperties; import eu.solven.cleanthat.engine.java.IJdkVersionConstants; import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorerProperties; @@ -53,8 +55,25 @@ public JavaCleanthatRefactorerFunc() { @Override public String apply(String input) throws Exception { + // https://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader + ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); + try { + // Ensure CleanThat main Thread has its custom classLoader while executing its refactoring + Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); + return doApply(input); + } finally { + // Restore the originalClassLoader + Thread.currentThread().setContextClassLoader(originalClassLoader); + } + } + + private String doApply(String input) throws InterruptedException, IOException { + // call some API that uses reflection without taking ClassLoader param CleanthatEngineProperties engineProperties = CleanthatEngineProperties.builder().engineVersion(jdkVersion).build(); + // Spotless will push us LF content + engineProperties.setSourceCode(SourceCodeProperties.builder().lineEnding(LineEnding.LF).build()); + JavaRefactorerProperties refactorerProperties = new JavaRefactorerProperties(); refactorerProperties.setIncluded(included); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java index 833b19dda8..edb7a69cd5 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -35,11 +35,21 @@ void testLiteralsFirstInComparisons() throws Exception { } @Test - void testMultipleMutators() throws Exception { + void testMultipleMutators_defaultIsJdk7() throws Exception { writePomWithJavaSteps( "", ""); + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + } + + @Test + void testMultipleMutators_Jdk11IntroducedOptionalisPresent() throws Exception { + writePomWithJavaSteps( + "", + "11", + ""); + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.java"); } @@ -70,7 +80,8 @@ void testIncludeOnlyLiteralsFirstInComparisons() throws Exception { private void runTest(String dirtyPath, String cleanPath) throws Exception { String path = "src/main/java/test.java"; setFile(path).toResource("java/cleanthat/" + dirtyPath); - Assertions.assertThat(mavenRunner().withArguments("spotless:apply").withRemoteDebug(21654).runNoError().stdOutUtf8()).doesNotContain("[ERROR]"); + // .withRemoteDebug(21654) + Assertions.assertThat(mavenRunner().withArguments("spotless:apply").runNoError().stdOutUtf8()).doesNotContain("[ERROR]"); assertFile(path).sameAsResource("java/cleanthat/" + cleanPath); } } diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java index 0829602dc1..318e1efa15 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java @@ -5,7 +5,7 @@ public class LiteralsFirstInComparisonsCases { public boolean isHardcoded(String input) { - return input.equals("hardcoded"); + return "hardcoded".equals(input); } public boolean isPresent(Optional optional) { From 14122d0f9254c570c4fb894560db91d6b681a528 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Feb 2023 23:35:47 +0400 Subject: [PATCH 0471/1120] Add Gradle compatibility --- .../gradle/spotless/JavaExtension.java | 74 ++++++++++++++++++- .../CleanthatJavaIntegrationTest.java | 42 +++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index 0f5926ec66..e65d0601e7 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -34,6 +34,7 @@ import com.diffplug.spotless.extra.EclipseBasedStepBuilder; import com.diffplug.spotless.extra.java.EclipseJdtFormatterStep; import com.diffplug.spotless.generic.LicenseHeaderStep; +import com.diffplug.spotless.java.CleanthatJavaStep; import com.diffplug.spotless.java.FormatAnnotationsStep; import com.diffplug.spotless.java.GoogleJavaFormatStep; import com.diffplug.spotless.java.ImportOrderStep; @@ -270,6 +271,77 @@ private FormatterStep createStep() { } } + /** Apply CleanThat refactoring rules. */ + public CleanthatJavaConfig cleanthat() { + return new CleanthatJavaConfig(); + } + + public class CleanthatJavaConfig { + private String groupArtifact = CleanthatJavaStep.defaultGroupArtifact(); + + private String version = CleanthatJavaStep.defaultVersion(); + + private String sourceJdk = CleanthatJavaStep.defaultJdkVersion(); + + private List mutators = CleanthatJavaStep.defaultMutators(); + + private List excludedMutators = CleanthatJavaStep.defaultExcludedMutators(); + + CleanthatJavaConfig() { + addStep(createStep()); + } + + public CleanthatJavaConfig groupArtifact(String groupArtifact) { + Objects.requireNonNull(groupArtifact); + this.groupArtifact = groupArtifact; + replaceStep(createStep()); + return this; + } + + public CleanthatJavaConfig version(String version) { + Objects.requireNonNull(version); + this.version = version; + replaceStep(createStep()); + return this; + } + + public CleanthatJavaConfig sourceJdk(String sourceJdk) { + Objects.requireNonNull(sourceJdk); + this.sourceJdk = sourceJdk; + replaceStep(createStep()); + return this; + } + + // Especially useful to clear default mutators + public CleanthatJavaConfig clearMutators() { + this.mutators.clear(); + replaceStep(createStep()); + return this; + } + + // The fully qualified name of a class implementing eu.solven.cleanthat.engine.java.refactorer.meta.IMutator + // or '*' to include all default mutators + public CleanthatJavaConfig addMutator(String mutator) { + this.mutators.add(mutator); + replaceStep(createStep()); + return this; + } + + // useful to exclude a mutator amongst the default list of mutators + public CleanthatJavaConfig excludeMutator(String mutator) { + this.excludedMutators.add(mutator); + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return CleanthatJavaStep.create( + groupArtifact, + version, + sourceJdk, mutators, excludedMutators, provisioner()); + } + } + /** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */ @Override protected void setupTask(SpotlessTask task) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java new file mode 100644 index 0000000000..2b3ede1472 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022-2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +class CleanthatJavaIntegrationTest extends GradleIntegrationHarness { + @Test + void integration() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "", + "spotless {", + " java {", + " target file('test.java')", + " cleanthat().sourceJdk('11')", + " }", + "}"); + + setFile("test.java").toResource("java/cleanthat/MultipleMutators.dirty.java"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("test.java").sameAsResource("java/cleanthat/MultipleMutators.clean.java"); + } +} From cfd07b06952840df641eea1c59d6f495e86544e6 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Feb 2023 23:44:50 +0400 Subject: [PATCH 0472/1120] Improve Gradle integration --- .../spotless/java/CleanthatJavaStep.java | 6 ++--- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 22 ++++++++++++++++++- .../gradle/spotless/JavaExtension.java | 8 +++---- plugin-maven/CHANGES.md | 2 +- .../spotless/maven/java/CleanthatJava.java | 2 +- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 1cd032a304..b5cc5452d1 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -52,10 +52,10 @@ public static FormatterStep create(Provisioner provisioner) { /** Creates a step which apply default CleanThat mutators. */ public static FormatterStep create(String version, Provisioner provisioner) { - return create(MAVEN_COORDINATE, version, defaultJdkVersion(), defaultExcludedMutators(), defaultMutators(), provisioner); + return create(MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), provisioner); } - public static String defaultJdkVersion() { + public static String defaultSourceJdk() { // see IJdkVersionConstants.JDK_7 // https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source // 1.7 is the default for 'maven-compiler-plugin' since 3.9.0 @@ -114,7 +114,7 @@ static final class JavaRefactorerState implements Serializable { final List excluded; JavaRefactorerState(String stepName, String version, Provisioner provisioner) throws IOException { - this(stepName, MAVEN_COORDINATE, version, defaultJdkVersion(), defaultExcludedMutators(), defaultMutators(), provisioner); + this(stepName, MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), provisioner); } JavaRefactorerState(String stepName, diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e3234584b8..1a5458c436 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* CleanThat Java Refactorer ([#1560](https://github.com/diffplug/spotless/pull/1560)) ## [6.14.1] - 2023-02-05 ### Fixed diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f61280bc7e..c0f8adebfb 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -54,7 +54,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [**Quickstart**](#quickstart) - [Requirements](#requirements) - **Languages** - - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations)) + - [Java](#java) ([google-java-format](#google-java-format), [eclipse jdt](#eclipse-jdt), [clang-format](#clang-format), [prettier](#prettier), [palantir-java-format](#palantir-java-format), [formatAnnotations](#formatAnnotations), [cleanthat](#cleanthat)) - [Groovy](#groovy) ([eclipse groovy](#eclipse-groovy)) - [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier)) - [Scala](#scala) ([scalafmt](#scalafmt)) @@ -154,6 +154,9 @@ spotless { removeUnusedImports() + // Cleanthat will refactor your code, but it may break your style: apply it before your formatter + cleanthat() // has its own section below + // Choose one of these formatters. googleJavaFormat() // has its own section below eclipse() // has its own section below @@ -257,6 +260,23 @@ You can use `addTypeAnnotation()` and `removeTypeAnnotation()` to override its d You can make a pull request to add new annotations to Spotless's default list. +### cleanthat + +[homepage](https://github.com/solven-eu/cleanthat). CleanThat enables automatic refactoring of Java code. [ChangeLog](https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD) + +```gradle +spotless { + java { + cleanthat() + // optional: you can specify a specific version and/or config file + cleanthat() + .groupArtifact('1.7') // default is 'io.github.solven-eu.cleanthat:java' + .version('2.1') // You may force a past of -SNAPSHOT + .sourceCompatibility('1.7') // default is '1.7' + .addMutator('your.custom.MagicMutator') + .excludeMutator('UseCollectionIsEmpty') +``` + diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index e65d0601e7..6e9f6de005 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -281,7 +281,7 @@ public class CleanthatJavaConfig { private String version = CleanthatJavaStep.defaultVersion(); - private String sourceJdk = CleanthatJavaStep.defaultJdkVersion(); + private String sourceJdk = CleanthatJavaStep.defaultSourceJdk(); private List mutators = CleanthatJavaStep.defaultMutators(); @@ -305,9 +305,9 @@ public CleanthatJavaConfig version(String version) { return this; } - public CleanthatJavaConfig sourceJdk(String sourceJdk) { - Objects.requireNonNull(sourceJdk); - this.sourceJdk = sourceJdk; + public CleanthatJavaConfig sourceCompatibility(String jdkVersion) { + Objects.requireNonNull(jdkVersion); + this.sourceJdk = jdkVersion; replaceStep(createStep()); return this; } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index fc276f7c8d..a13353e68e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* CleanThat Java Refactorer ([#???](https://github.com/diffplug/spotless/pull/???)) +* CleanThat Java Refactorer ([#1560](https://github.com/diffplug/spotless/pull/1560)) ## [2.32.0] - 2023-02-05 ### Added diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java index 7460ab67b9..d7dd1f2530 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java @@ -33,7 +33,7 @@ public class CleanthatJava implements FormatterStepFactory { // https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#source @Parameter(property = "maven.compiler.source") - private String sourceJdk = CleanthatJavaStep.defaultJdkVersion(); + private String sourceJdk = CleanthatJavaStep.defaultSourceJdk(); @Parameter private List mutators = CleanthatJavaStep.defaultMutators(); From 374acb6fec5484f92a1119e05e3a80e9f92a1bc0 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 9 Feb 2023 00:01:28 +0400 Subject: [PATCH 0473/1120] Fix unitTests --- README.md | 2 +- lib/build.gradle | 9 ++- .../java/JavaCleanthatRefactorerFuncTest.java | 72 ------------------- .../glue/java/JavaCleanthatRefactorerFuncTest | 28 ++++++++ .../CleanthatJavaIntegrationTest.java | 2 +- 5 files changed, 37 insertions(+), 76 deletions(-) delete mode 100644 lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java create mode 100644 lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest diff --git a/README.md b/README.md index 5f59368677..420c13ab53 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ lib('java.PalantirJavaFormatStep') +'{{yes}} | {{yes}} lib('java.RemoveUnusedImportsStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('java.EclipseJdtFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('java.FormatAnnotationsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', -lib('java.CleanthatJavaStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('java.CleanthatJavaStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.gson.GsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.JacksonJsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('json.JsonSimpleStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', diff --git a/lib/build.gradle b/lib/build.gradle index cd6996a979..154b2acd6a 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -40,6 +40,12 @@ versionCompatibility { ] targetSourceSetName = 'ktlint' } + namespaces.register('Cleanthat') { + versions = [ + '2.1', + ] + targetSourceSetName = 'cleanthat' + } } } @@ -103,9 +109,8 @@ dependencies { gsonCompileOnly 'com.google.code.gson:gson:2.10.1' - // TODO How can one add a test module like 'compatKtLint0Dot48Dot0'? - // cleanthatCompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.1' cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.1' + compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.1' } // we'll hold the core lib to a high standard diff --git a/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java b/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java deleted file mode 100644 index c811b51233..0000000000 --- a/lib/src/testCleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.ktlint.compat; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; - -public class KtLintCompat0Dot48Dot0AdapterTest { - @Test - public void testDefaults(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - String text = loadAndWriteText(path, "empty_class_body.kt"); - final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); - - Map userData = new HashMap<>(); - - Map editorConfigOverrideMap = new HashMap<>(); - - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); - assertEquals("class empty_class_body\n", formatted); - } - - @Test - public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - String text = loadAndWriteText(path, "fails_no_semicolons.kt"); - final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); - - Map userData = new HashMap<>(); - - Map editorConfigOverrideMap = new HashMap<>(); - editorConfigOverrideMap.put("indent_style", "tab"); - editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - // ktlint_filename is an invalid rule in ktlint 0.48.0 - editorConfigOverrideMap.put("ktlint_filename", "disabled"); - - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); - assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); - } - - private static String loadAndWriteText(Path path, String name) throws IOException { - try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/" + name)) { - Files.copy(is, path.resolve(name)); - } - return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8); - } - -} diff --git a/lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest b/lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest new file mode 100644 index 0000000000..2f3cdc9646 --- /dev/null +++ b/lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest @@ -0,0 +1,28 @@ +/* + * 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.java; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; + +public class JavaCleanthatRefactorerFuncTest { + @Test + public void testMutatorsDetection() { + Assertions.assertThat(JavaRefactorer.getAllIncluded()).isNotEmpty(); + } +} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java index 2b3ede1472..a754b963f2 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java @@ -31,7 +31,7 @@ void integration() throws IOException { "spotless {", " java {", " target file('test.java')", - " cleanthat().sourceJdk('11')", + " cleanthat().sourceCompatibility('11')", " }", "}"); From 8fbbb7165a840fb8d5435266617a342e8fd21846 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 9 Feb 2023 00:02:25 +0400 Subject: [PATCH 0474/1120] Remove useless dependency --- lib/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 154b2acd6a..21181cd54b 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -61,7 +61,6 @@ dependencies { testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ" testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" - testCommonImplementation 'io.github.solven-eu.cleanthat:java:2.1' // used for pom sorting sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' From 640a1c20426f1f5ef114a8b15176bf618d6b4d0d Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 9 Feb 2023 00:08:01 +0400 Subject: [PATCH 0475/1120] Remove irrelevant test file --- README.md | 2 +- .../java/JavaCleanthatRefactorerFuncTest.java | 28 ------------------- 2 files changed, 1 insertion(+), 29 deletions(-) delete mode 100644 lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java diff --git a/README.md b/README.md index 420c13ab53..662c624bdf 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | [`java.RemoveUnusedImportsStep`](lib/src/main/java/com/diffplug/spotless/java/RemoveUnusedImportsStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.EclipseJdtFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.FormatAnnotationsStep`](lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | -| [`java.CleanthatJavaStep`](lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`java.CleanthatJavaStep`](lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.JacksonJsonStep`](lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | diff --git a/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java b/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java deleted file mode 100644 index 2f3cdc9646..0000000000 --- a/lib/src/test/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.java; - -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; - -public class JavaCleanthatRefactorerFuncTest { - @Test - public void testMutatorsDetection() { - Assertions.assertThat(JavaRefactorer.getAllIncluded()).isNotEmpty(); - } -} From fdee03ce774ceff7ef92b3d4db680b0e361ed0fd Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 9 Feb 2023 00:25:00 +0400 Subject: [PATCH 0476/1120] Fix extention of unitTest --- ...RefactorerFuncTest => JavaCleanthatRefactorerFuncTest.java} | 0 plugin-maven/README.md | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) rename lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/{JavaCleanthatRefactorerFuncTest => JavaCleanthatRefactorerFuncTest.java} (100%) diff --git a/lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest b/lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java similarity index 100% rename from lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest rename to lib/src/testCompatCleanthat2Dot1/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFuncTest.java diff --git a/plugin-maven/README.md b/plugin-maven/README.md index b1b9098bfe..f59a1d9004 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -182,6 +182,7 @@ any other maven phase (i.e. compile) then it can be configured as below; src/test/java/**/*.java + @@ -285,7 +286,7 @@ These mechanisms already exist for the Gradle plugin. 2.0 ${maven.compiler.source} - * + * LiteralsFirstInComparisons From ce086ba1382f618a2cb0b93c9f2fac02f19cfdb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Wed, 8 Feb 2023 21:34:29 +0100 Subject: [PATCH 0477/1120] adds entry about continuation indent to the other changelogs --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5f1a1ffa9f..86a9eeabf2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Maven plugin with `ktfmt` default style uses correct continuation indent ([#1562](https://github.com/diffplug/spotless/pull/1562)) ## [2.34.1] - 2023-02-05 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e3234584b8..9927b56f07 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Maven plugin with `ktfmt` default style uses correct continuation indent ([#1562](https://github.com/diffplug/spotless/pull/1562)) ## [6.14.1] - 2023-02-05 ### Fixed From 3e1ea286ca1d203e32f80b557e3fde54c91fa79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Thu, 9 Feb 2023 12:33:03 +0100 Subject: [PATCH 0478/1120] updates copyright --- .../com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java index e34f7b4755..80f4a42fcd 100644 --- a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java +++ b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 1b990ab98d23561c4433bcab4175356903b2e5c2 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 26 Jan 2023 16:35:21 +0100 Subject: [PATCH 0479/1120] 1162: adding tests verifying issue results in 'Couldn't resolve parser "php"' on gradle side and 'Couldn't resolve parser "java"' on maven side --- .../spotless/PrettierIntegrationTest.java | 42 +++++++++++++++ .../maven/MavenIntegrationHarness.java | 15 ++++-- .../prettier/PrettierFormatStepTest.java | 52 +++++++++++++++++++ 3 files changed, 105 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index 4c458e3ca7..8819d5bc07 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -183,6 +183,48 @@ void usePhpCommunityPlugin() throws IOException { assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); } + /** + * This test is to ensure that we can have multiple prettier instances in one spotless config. + * + * @see Issue #1162 on github + */ + @Test + void usePhpAndJavaCommunityPlugin() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "def prettierConfigPhp = [:]", + "prettierConfigPhp['tabWidth'] = 3", + "prettierConfigPhp['parser'] = 'php'", + "def prettierPackagesPhp = [:]", + "prettierPackagesPhp['prettier'] = '2.0.5'", + "prettierPackagesPhp['@prettier/plugin-php'] = '0.14.2'", + "def prettierConfigJava = [:]", + "prettierConfigJava['tabWidth'] = 4", + "prettierConfigJava['parser'] = 'java'", + "def prettierPackagesJava = [:]", + "prettierPackagesJava['prettier'] = '2.0.5'", + "prettierPackagesJava['prettier-plugin-java'] = '0.8.0'", + "spotless {", + " format 'php', {", + " target 'php-example.php'", + " prettier(prettierPackagesPhp).config(prettierConfigPhp)", + " }", + " java {", + " target 'JavaTest.java'", + " prettier(prettierPackagesJava).config(prettierConfigJava)", + " }", + "}"); + setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty"); + setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty"); + final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); + assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); + } + @Test void autodetectNpmrcFileConfig() throws IOException { setFile(".npmrc").toLines( 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 fdc4a745a1..2891ee3b2c 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 @@ -285,7 +285,7 @@ private static String getSystemProperty(String name) { return value; } - private static String[] groupWithSteps(String group, String[] includes, String... steps) { + protected static String[] groupWithSteps(String group, String[] includes, String... steps) { String[] result = new String[steps.length + includes.length + 2]; result[0] = "<" + group + ">"; System.arraycopy(includes, 0, result, 1, includes.length); @@ -294,15 +294,22 @@ private static String[] groupWithSteps(String group, String[] includes, String.. return result; } - private static String[] groupWithSteps(String group, String... steps) { + protected static String[] groupWithSteps(String group, String... steps) { return groupWithSteps(group, new String[]{}, steps); } - private static String[] including(String... includes) { + protected static String[] including(String... includes) { return groupWithSteps("includes", groupWithSteps("include", includes)); } - private static String[] formats(String... formats) { + protected static String[] formats(String... formats) { return groupWithSteps("formats", formats); } + + protected static String[] formats(String[]... formats) { + String[] formatsArray = Arrays.stream(formats) + .flatMap(Arrays::stream) + .toArray(String[]::new); + return formats(formatsArray); + } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java index 47dab5d152..78a0fc30ff 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java @@ -106,6 +106,58 @@ void unique_dependency_config() throws Exception { assertThat(result.stdOutUtf8()).contains(Prettier.ERROR_MESSAGE_ONLY_ONE_CONFIG); } + /** + * This test is to ensure that we can have multiple prettier instances in one spotless config. + * + * @see Issue #1162 on github + */ + @Test + void multiple_prettier_configs() throws Exception { + writePom( + formats( + groupWithSteps("format", including("php-example.php"), + "", + " ", + " ", + " prettier", + " 2.0.5", + " ", + " ", + " @prettier/plugin-php", + " 0.14.2", + " ", + " ", + " ", + " 3", + " php", + " ", + ""), + groupWithSteps("java", including("JavaTest.java"), + "", + " ", + " ", + " prettier", + " 2.0.5", + " ", + " ", + " prettier-plugin-java", + " 0.8.0", + " ", + " ", + " ", + " 4", + " java", + " ", + ""))); + + setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty"); + setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); + assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); + + } + @Test void custom_plugin() throws Exception { writePomWithFormatSteps( From fdbbd024158911d65cb567b04340f875d45dd46b Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 27 Jan 2023 20:21:18 +0100 Subject: [PATCH 0480/1120] 1162: add unique suffix reflecting package.json content --- .../diffplug/spotless/npm/NodeServerLayout.java | 4 ++-- .../spotless/npm/NpmFormatterStepStateBase.java | 9 ++++++++- .../spotless/npm/NpmResourceHelper.java | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java index 63a6a923da..60c34bcc8c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java @@ -29,8 +29,8 @@ class NodeServerLayout { private final File serveJsFile; private final File npmrcFile; - NodeServerLayout(File buildDir, String stepName) { - this.nodeModulesDir = new File(buildDir, "spotless-node-modules-" + stepName); + NodeServerLayout(File buildDir, String stepName, String stepSuffix) { + this.nodeModulesDir = new File(buildDir, String.format("spotless-node-modules-%s-%s", stepName, stepSuffix)); this.packageJsonFile = new File(nodeModulesDir, "package.json"); this.serveJsFile = new File(nodeModulesDir, "serve.js"); this.npmrcFile = new File(nodeModulesDir, ".npmrc"); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 92ac7df6f2..412a827d9e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -56,7 +56,14 @@ protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFor this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); this.locations = locations; - this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), stepName); + String stateSuffix = stateSuffix(); + logger.info("Creating {} with name {} and state suffix {}", this.getClass().getSimpleName(), stepName, stateSuffix); + this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), stepName, stateSuffix); + } + + protected String stateSuffix() { + String packageJsonContent = npmConfig.getPackageJsonContent(); + return NpmResourceHelper.md5(packageJsonContent); } protected void prepareNodeServerLayout() throws IOException { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index 2acf3a180d..aa66c54fcf 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -21,6 +21,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.security.MessageDigest; import java.time.Duration; import java.util.Arrays; import java.util.Objects; @@ -122,4 +123,20 @@ static File copyFileToDirAtSubpath(File file, File targetDir, String relativePat throw ThrowingEx.asRuntime(e); } } + + static String md5(File file) { + return md5(readUtf8StringFromFile(file)); + } + + static String md5(String fileContent) { + MessageDigest md = ThrowingEx.get(() -> MessageDigest.getInstance("MD5")); + md.update(fileContent.getBytes(StandardCharsets.UTF_8)); + byte[] digest = md.digest(); + // convert byte array digest to hex string + StringBuilder sb = new StringBuilder(); + for (byte b : digest) { + sb.append(String.format("%02x", b & 0xff)); + } + return sb.toString(); + } } From e0a290a2b784b073eb13bac62f77dff57b9cee11 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 8 Feb 2023 21:09:13 +0100 Subject: [PATCH 0481/1120] 1162: separate node dirs per package.json --- .../spotless/npm/NodeServerLayout.java | 40 ++++++++++++++++--- .../npm/NpmFormatterStepStateBase.java | 18 ++++----- .../diffplug/spotless/npm/eslint-package.json | 2 +- .../spotless/npm/prettier-package.json | 2 +- .../diffplug/spotless/npm/tsfmt-package.json | 2 +- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java index 60c34bcc8c..8b39c5e4ab 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java @@ -18,25 +18,44 @@ import java.io.File; import java.nio.file.Files; import java.nio.file.Path; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Stream; import com.diffplug.spotless.ThrowingEx; class NodeServerLayout { + private static final Pattern PACKAGE_JSON_NAME_PATTERN = Pattern.compile("\"name\"\\s*:\\s*\"([^\"]+)\""); + private final File nodeModulesDir; private final File packageJsonFile; + + private final File packageLockJsonFile; + private final File serveJsFile; private final File npmrcFile; - NodeServerLayout(File buildDir, String stepName, String stepSuffix) { - this.nodeModulesDir = new File(buildDir, String.format("spotless-node-modules-%s-%s", stepName, stepSuffix)); + NodeServerLayout(File buildDir, String packageJsonContent) { + this.nodeModulesDir = new File(buildDir, nodeModulesDirName(packageJsonContent)); this.packageJsonFile = new File(nodeModulesDir, "package.json"); + this.packageLockJsonFile = new File(nodeModulesDir, "package-lock.json"); this.serveJsFile = new File(nodeModulesDir, "serve.js"); this.npmrcFile = new File(nodeModulesDir, ".npmrc"); } + private static String nodeModulesDirName(String packageJsonContent) { + String md5Hash = NpmResourceHelper.md5(packageJsonContent); + Matcher matcher = PACKAGE_JSON_NAME_PATTERN.matcher(packageJsonContent); + if (!matcher.find()) { + throw new IllegalArgumentException("package.json must contain a name property"); + } + String packageName = matcher.group(1); + return String.format("%s-node-modules-%s", packageName, md5Hash); + } + File nodeModulesDir() { + return nodeModulesDir; } @@ -52,10 +71,6 @@ public File npmrcFile() { return npmrcFile; } - static File getBuildDirFromNodeModulesDir(File nodeModulesDir) { - return nodeModulesDir.getParentFile(); - } - public boolean isLayoutPrepared() { if (!nodeModulesDir().isDirectory()) { return false; @@ -63,6 +78,9 @@ public boolean isLayoutPrepared() { if (!packageJsonFile().isFile()) { return false; } + if (!packageLockJsonFile.isFile()) { + return false; + } if (!serveJsFile().isFile()) { return false; } @@ -82,4 +100,14 @@ public boolean isNodeModulesPrepared() { } }); } + + @Override + public String toString() { + return String.format( + "NodeServerLayout[nodeModulesDir=%s, packageJsonFile=%s, serveJsFile=%s, npmrcFile=%s]", + this.nodeModulesDir, + this.packageJsonFile, + this.serveJsFile, + this.npmrcFile); + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 412a827d9e..f3f8a80fe8 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -56,17 +56,13 @@ protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFor this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); this.locations = locations; - String stateSuffix = stateSuffix(); - logger.info("Creating {} with name {} and state suffix {}", this.getClass().getSimpleName(), stepName, stateSuffix); - this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), stepName, stateSuffix); - } - - protected String stateSuffix() { - String packageJsonContent = npmConfig.getPackageJsonContent(); - return NpmResourceHelper.md5(packageJsonContent); + this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), npmConfig.getPackageJsonContent()); } protected void prepareNodeServerLayout() throws IOException { + final long started = System.currentTimeMillis(); + // maybe introduce trace logger? + logger.info("Preparing {} for npm step {}.", this.nodeServerLayout, getClass().getName()); NpmResourceHelper.assertDirectoryExists(nodeServerLayout.nodeModulesDir()); NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.packageJsonFile(), this.npmConfig.getPackageJsonContent()); @@ -77,12 +73,14 @@ protected void prepareNodeServerLayout() throws IOException { } else { NpmResourceHelper.deleteFileIfExists(nodeServerLayout.npmrcFile()); } + logger.info("Prepared {} for npm step {} in {} ms.", this.nodeServerLayout, getClass().getName(), System.currentTimeMillis() - started); } protected void prepareNodeServer() throws IOException { - FormattedPrinter.SYSOUT.print("running npm install"); + final long started = System.currentTimeMillis(); + logger.info("running npm install in {} for npm step {}", this.nodeServerLayout.nodeModulesDir(), getClass().getName()); runNpmInstall(nodeServerLayout.nodeModulesDir()); - FormattedPrinter.SYSOUT.print("npm install finished"); + logger.info("npm install finished in {} ms in {} for npm step {}", System.currentTimeMillis() - started, this.nodeServerLayout.nodeModulesDir(), getClass().getName()); } private void runNpmInstall(File npmProjectDir) throws IOException { diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json index dcd91e729d..0d7ce930f7 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json @@ -1,5 +1,5 @@ { - "name": "spotless-eslint-formatter-step", + "name": "spotless-eslint", "version": "2.0.0", "description": "Spotless formatter step for running eslint as a rest service.", "repository": "https://github.com/diffplug/spotless", diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json index 7bda08db8a..395a05da67 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json @@ -1,5 +1,5 @@ { - "name": "spotless-prettier-formatter-step", + "name": "spotless-prettier", "version": "2.0.0", "description": "Spotless formatter step for running prettier as a rest service.", "repository": "https://github.com/diffplug/spotless", diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json index 7037bd2ec1..483dd0753d 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json @@ -1,5 +1,5 @@ { - "name": "spotless-tsfmt-formatter-step", + "name": "spotless-tsfmt", "version": "2.0.0", "description": "Spotless formatter step for running tsfmt as a rest service.", "repository": "https://github.com/diffplug/spotless", From 080f2378af86d3fa8e8db5be207a03415dc47fe8 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 9 Feb 2023 20:44:38 +0100 Subject: [PATCH 0482/1120] 1162: use slf4j for logging --- .../com/diffplug/spotless/LazyArgLogger.java | 40 ++++++++++++++++++ .../spotless/npm/EslintFormatterStep.java | 9 ++-- .../spotless/npm/FormattedPrinter.java | 42 ------------------- .../spotless/npm/PrettierFormatterStep.java | 7 ++-- .../spotless/PrettierIntegrationTest.java | 4 +- 5 files changed, 52 insertions(+), 50 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/LazyArgLogger.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/npm/FormattedPrinter.java diff --git a/lib/src/main/java/com/diffplug/spotless/LazyArgLogger.java b/lib/src/main/java/com/diffplug/spotless/LazyArgLogger.java new file mode 100644 index 0000000000..e3456a2317 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/LazyArgLogger.java @@ -0,0 +1,40 @@ +/* + * 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; + +import java.util.function.Supplier; + +/** + * This is a utility class to allow for lazy evaluation of arguments to be passed to a logger + * and thus avoid unnecessary computation of the arguments if the log level is not enabled. + */ +public final class LazyArgLogger { + + private final Supplier argSupplier; + + private LazyArgLogger(Supplier argSupplier) { + this.argSupplier = argSupplier; + } + + public static LazyArgLogger lazy(Supplier argSupplier) { + return new LazyArgLogger(argSupplier); + } + + @Override + public String toString() { + return String.valueOf(argSupplier.get()); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 221a745ad7..b262bb4b98 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.npm; +import static com.diffplug.spotless.LazyArgLogger.lazy; import static java.util.Objects.requireNonNull; import java.io.File; @@ -115,7 +116,7 @@ protected void prepareNodeServerLayout() throws IOException { // If any config files are provided, we need to make sure they are at the same location as the node modules // as eslint will try to resolve plugin/config names relatively to the config file location and some // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) - FormattedPrinter.SYSOUT.print("Copying config file <%s> to <%s> and using the copy", origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); + logger.info("Copying config file <{}> to <{}> and using the copy", origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); File configFileCopy = NpmResourceHelper.copyFileToDir(origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); this.eslintConfigInUse = this.origEslintConfig.withEslintConfigPath(configFileCopy).verify(); } @@ -125,7 +126,7 @@ protected void prepareNodeServerLayout() throws IOException { @Nonnull public FormatterFunc createFormatterFunc() { try { - FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); + logger.info("Creating formatter function (starting server)"); ServerProcessInfo eslintRestServer = npmRunServer(); EslintRestService restService = new EslintRestService(eslintRestServer.getBaseUrl()); return Closeable.ofDangerous(() -> endServer(restService, eslintRestServer), new EslintFilePathPassingFormatterFunc(locations.projectDir(), nodeServerLayout.nodeModulesDir(), eslintConfigInUse, restService)); @@ -135,7 +136,7 @@ public FormatterFunc createFormatterFunc() { } private void endServer(BaseNpmRestService restService, ServerProcessInfo restServer) throws Exception { - FormattedPrinter.SYSOUT.print("Closing formatting function (ending server)."); + logger.info("Closing formatting function (ending server)."); try { restService.shutdown(); } catch (Throwable t) { @@ -161,7 +162,7 @@ public EslintFilePathPassingFormatterFunc(File projectDir, File nodeModulesDir, @Override public String applyWithFile(String unix, File file) throws Exception { - FormattedPrinter.SYSOUT.print("formatting String '" + unix.substring(0, Math.min(50, unix.length())) + "[...]' in file '" + file + "'"); + logger.info("formatting String '{}[...]' in file '{}'", lazy(() -> unix.substring(0, Math.min(50, unix.length()))), file); Map eslintCallOptions = new HashMap<>(); setConfigToCallOptions(eslintCallOptions); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/FormattedPrinter.java b/lib/src/main/java/com/diffplug/spotless/npm/FormattedPrinter.java deleted file mode 100644 index 97d5cdb4c6..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/npm/FormattedPrinter.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2020 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.npm; - -import static java.util.Objects.requireNonNull; - -import java.io.PrintStream; -import java.time.LocalDateTime; - -enum FormattedPrinter { - SYSOUT(System.out); - - private static final boolean enabled = false; - - private final PrintStream printStream; - - FormattedPrinter(PrintStream printStream) { - this.printStream = requireNonNull(printStream); - } - - public void print(String msg, Object... paramsForStringFormat) { - if (!enabled) { - return; - } - String formatted = String.format(msg, paramsForStringFormat); - String prefixed = String.format("[%s] %s", LocalDateTime.now().toString(), formatted); - this.printStream.println(prefixed); - } -} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 22f1a69e7c..05c61f9bdf 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.npm; +import static com.diffplug.spotless.LazyArgLogger.lazy; import static java.util.Objects.requireNonNull; import java.io.File; @@ -86,7 +87,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ @Nonnull public FormatterFunc createFormatterFunc() { try { - FormattedPrinter.SYSOUT.print("creating formatter function (starting server)"); + logger.info("creating formatter function (starting server)"); ServerProcessInfo prettierRestServer = npmRunServer(); PrettierRestService restService = new PrettierRestService(prettierRestServer.getBaseUrl()); String prettierConfigOptions = restService.resolveConfig(this.prettierConfig.getPrettierConfigPath(), this.prettierConfig.getOptions()); @@ -97,7 +98,7 @@ public FormatterFunc createFormatterFunc() { } private void endServer(PrettierRestService restService, ServerProcessInfo restServer) throws Exception { - FormattedPrinter.SYSOUT.print("Closing formatting function (ending server)."); + logger.info("Closing formatting function (ending server)."); try { restService.shutdown(); } catch (Throwable t) { @@ -119,7 +120,7 @@ public PrettierFilePathPassingFormatterFunc(String prettierConfigOptions, Pretti @Override public String applyWithFile(String unix, File file) throws Exception { - FormattedPrinter.SYSOUT.print("formatting String '" + unix.substring(0, Math.min(50, unix.length())) + "[...]' in file '" + file + "'"); + logger.info("formatting String '{}[...]' in file '{}'", lazy(() -> unix.substring(0, Math.min(50, unix.length()))), file); final String prettierConfigOptionsWithFilepath = assertFilepathInConfigOptions(file); try { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java index 8819d5bc07..a6b2ea9dc8 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java @@ -219,8 +219,10 @@ void usePhpAndJavaCommunityPlugin() throws IOException { "}"); setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty"); setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty"); - final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + final BuildResult spotlessApply = gradleRunner().forwardOutput().withArguments("--stacktrace", "--info", "spotlessApply").build(); Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + final BuildResult spotlessApply2 = gradleRunner().forwardOutput().withArguments("--stacktrace", "--info", "spotlessApply").build(); + Assertions.assertThat(spotlessApply2.getOutput()).contains("BUILD SUCCESSFUL"); assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean"); } From 92eb869d8a50a86dacc416b0d49052ccd4137ec5 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Thu, 9 Feb 2023 20:54:10 +0100 Subject: [PATCH 0483/1120] 1162: prepare changelog --- CHANGES.md | 5 ++++- plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 5f1a1ffa9f..0e2e994a22 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,10 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] - +### Added +* Introduce `LazyArgLogger` to allow for lazy evaluation of log messages in slf4j logging. ([#1565](https://github.com/diffplug/spotless/pull/1565)) +### Fixed +* Allow multiple instances of the same npm-based formatter to be used by separating their `node_modules` directories. ([#1565](https://github.com/diffplug/spotless/pull/1565)) ## [2.34.1] - 2023-02-05 ### Changes * **POTENTIALLY BREAKING** Bump bytecode from Java 8 to 11 ([#1530](https://github.com/diffplug/spotless/pull/1530) part 2 of [#1337](https://github.com/diffplug/spotless/issues/1337)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e3234584b8..ec5ae54c27 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Allow multiple instances of the same npm-based formatter to be used simultaneously. E.g. use prettier for typescript + *and* Java (using the community prettier-plugin-java) without messing up their respective `node_module` dependencies. ([#1565](https://github.com/diffplug/spotless/pull/1565)) ## [6.14.1] - 2023-02-05 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 567d880f4f..cce049488a 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Allow multiple instances of the same npm-based formatter to be used simultaneously. E.g. use prettier for typescript + *and* Java (using the community prettier-plugin-java) without messing up their respective `node_module` dependencies. ([#1565](https://github.com/diffplug/spotless/pull/1565)) ## [2.32.0] - 2023-02-05 ### Added From 4cb02f30d815992dc23ef9dc8f4e20bd9b9c3147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Fri, 10 Feb 2023 12:59:00 +0100 Subject: [PATCH 0484/1120] runs spotlessApply and removes an unused import --- .../test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 25ecbc598d..e452c5d56b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java @@ -19,8 +19,6 @@ import com.diffplug.spotless.maven.MavenIntegrationHarness; -import java.io.IOException; - class KtfmtTest extends MavenIntegrationHarness { @Test void testKtfmt() throws Exception { From 2204510cec06405430325d7f41a0abb93a90f0f8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Feb 2023 10:05:05 -0800 Subject: [PATCH 0485/1120] Update default KtFmtStep version to 0.43 --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java index b6f7a533eb..d6a20bc5b3 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -39,7 +39,7 @@ public class KtfmtStep { // prevent direct instantiation private KtfmtStep() {} - private static final String DEFAULT_VERSION = "0.42"; + private static final String DEFAULT_VERSION = "0.43"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; From 4fac2e978c36e1688784cf44541853731aa240b9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Feb 2023 10:10:13 -0800 Subject: [PATCH 0486/1120] Bump default version of jackston steps 2.14.1 -> 2.14.2 --- lib/build.gradle | 2 +- .../main/java/com/diffplug/spotless/json/JacksonJsonStep.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index fa80767047..81a6229f35 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -63,7 +63,7 @@ dependencies { // used jackson-based formatters jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.2' - jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.1' + jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.2' String VER_KTFMT = '0.42' ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" diff --git a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java index f15edbbd42..94c48e0c5c 100644 --- a/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java +++ b/lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java @@ -33,7 +33,7 @@ public class JacksonJsonStep { static final String MAVEN_COORDINATE = "com.fasterxml.jackson.core:jackson-databind:"; // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind - static final String DEFAULT_VERSION = "2.14.1"; + static final String DEFAULT_VERSION = "2.14.2"; private JacksonJsonStep() {} From 4f92a676b191aa109fb09d5f29c522e6ddf27810 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Feb 2023 10:22:37 -0800 Subject: [PATCH 0487/1120] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7c96483595..4909423395 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Allow multiple instances of the same npm-based formatter to be used by separating their `node_modules` directories. ([#1565](https://github.com/diffplug/spotless/pull/1565)) * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) +### Changes +* Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) ## [2.34.1] - 2023-02-05 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 5148a11e10..8cba44831d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -9,6 +9,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Allow multiple instances of the same npm-based formatter to be used simultaneously. E.g. use prettier for typescript *and* Java (using the community prettier-plugin-java) without messing up their respective `node_module` dependencies. ([#1565](https://github.com/diffplug/spotless/pull/1565)) * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) +### Changes +* Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) ## [6.14.1] - 2023-02-05 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8600825903..035520076d 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -9,6 +9,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Allow multiple instances of the same npm-based formatter to be used simultaneously. E.g. use prettier for typescript *and* Java (using the community prettier-plugin-java) without messing up their respective `node_module` dependencies. ([#1565](https://github.com/diffplug/spotless/pull/1565)) * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) +### Changes +* Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) ## [2.32.0] - 2023-02-05 ### Added From c2979127467ee7abd976d3503779d9f4a1c2637c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Feb 2023 10:28:58 -0800 Subject: [PATCH 0488/1120] Bump changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 4909423395..b59568d1d4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) ### Changes * Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) +* Bump default `jackson` version to latest `2.14.1` -> `2.14.2` ([#1536](https://github.com/diffplug/spotless/pull/1536)) ## [2.34.1] - 2023-02-05 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 8cba44831d..10b2adaac7 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) ### Changes * Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) +* Bump default `jackson` version to latest `2.14.1` -> `2.14.2` ([#1536](https://github.com/diffplug/spotless/pull/1536)) ## [6.14.1] - 2023-02-05 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 035520076d..6de9a15d5e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `ktfmt` default style uses correct continuation indent. ([#1562](https://github.com/diffplug/spotless/pull/1562)) ### Changes * Bump default `ktfmt` version to latest `0.42` -> `0.43` ([#1561](https://github.com/diffplug/spotless/pull/1561)) +* Bump default `jackson` version to latest `2.14.1` -> `2.14.2` ([#1536](https://github.com/diffplug/spotless/pull/1536)) ## [2.32.0] - 2023-02-05 ### Added From c04253f80b7f8dfa9bdfafde9f7272e88c6db6ad Mon Sep 17 00:00:00 2001 From: runner Date: Fri, 10 Feb 2023 18:43:54 +0000 Subject: [PATCH 0489/1120] Published lib/2.35.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b59568d1d4..eec8753271 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.35.0] - 2023-02-10 ### Added * CleanThat Java Refactorer. ([#1560](https://github.com/diffplug/spotless/pull/1560)) * Introduce `LazyArgLogger` to allow for lazy evaluation of log messages in slf4j logging. ([#1565](https://github.com/diffplug/spotless/pull/1565)) From 32a240d7f3f46b1be5ffe133b4fbf6502eeb2028 Mon Sep 17 00:00:00 2001 From: runner Date: Fri, 10 Feb 2023 18:46:05 +0000 Subject: [PATCH 0490/1120] Published gradle/6.15.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 50 ++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 10b2adaac7..087c1ade89 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.15.0] - 2023-02-10 ### Added * CleanThat Java Refactorer. ([#1560](https://github.com/diffplug/spotless/pull/1560)) ### Fixed diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index c0f8adebfb..7471138c60 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.14.1-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.15.0-blue.svg)](CHANGES.md) [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -123,10 +123,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -138,7 +138,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -282,8 +282,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -334,8 +334,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -406,7 +406,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -438,7 +438,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -470,7 +470,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -504,7 +504,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -525,7 +525,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -550,7 +550,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -590,7 +590,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -682,7 +682,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -746,7 +746,7 @@ For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#n ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -821,7 +821,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -1034,7 +1034,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1107,9 +1107,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1142,11 +1142,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.14.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 7f0807f20c96fcf46c3d9d6fff6a35ad3745d15f Mon Sep 17 00:00:00 2001 From: runner Date: Fri, 10 Feb 2023 18:48:45 +0000 Subject: [PATCH 0491/1120] Published maven/2.33.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6de9a15d5e..74c6a0299a 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.33.0] - 2023-02-10 ### Added * CleanThat Java Refactorer. ([#1560](https://github.com/diffplug/spotless/pull/1560)) ### Fixed diff --git a/plugin-maven/README.md b/plugin-maven/README.md index f59a1d9004..51ea9c23d7 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.32.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.32.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.33.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.33.0/index.html) the failed test case execution log + * @return String bugID + */ + public static String createIssue(List files, String testCaseName, String description) { + setup(); + try { + Response response = given() + .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("application/json", ContentType.JSON))) + .relaxedHTTPSValidation().contentType("application/json") + .header("Authorization", authType + _JiraAuthorization) + .when() + .body(getCreateIssueRequestBody() + .replace("${PROJECT_KEY}", _ProjectKey) + .replace("${BUG_SUMMERY}", "Execution Bug: " + testCaseName) + .replace("${BUG_DESCRIPTION}", description + .replaceAll("[^a-zA-Z0-9.?=*$%@#&!<>|\\{\\}\\[\\]\"' /]", "") + .replaceAll("\"", "'") + ) + .replace("${ASSIGNEE_NAME}", System.getProperty("assignee")) + ) + .post("/rest/api/2/issue") + .then().log().all().extract().response(); + + String id = response.jsonPath().get("key").toString(); + + ReportManager.logDiscrete("BugID: " + id); + attachFilesToIssue(id, files); + return id; + + } catch (Exception e) { + ReportManagerHelper.logDiscrete(e); + return null; + } + } + + /** + * Update the created issue with the attachments. + * + * @param issueID -> the created bug ID. + * @param files -> list of the failed testcase attachments. + */ + public static void attachFilesToIssue(String issueID, List files) { + setup(); + try { + RequestSpecification req = given() + .relaxedHTTPSValidation().contentType(ContentType.MULTIPART) + .header("Authorization", authType + _JiraAuthorization) + .header("X-Atlassian-Token", "nocheck"); + for (String file : files) + req.multiPart("file", new File(file)); + + ReportManager.logDiscrete("BugID: " + issueID); + req.when() + .post("/rest/api/2/issue/" + issueID + "/attachments") + .then().log().all().extract().response(); + } catch (Exception e) { + ReportManagerHelper.logDiscrete(e); + } + } + + /** + * Link any jira 2 tickets using the tickets IDs through PUT API request. the covered relation is relates. + * + * @param ticketID -> the main ticket ID. + * @param linkedToID -> the one to be linked to. + */ + public static void link2Tickets(String ticketID, String linkedToID) { + setup(); + try { + given() + .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("application/json", ContentType.JSON))) + .relaxedHTTPSValidation().contentType("application/json") + .header("Authorization", authType + _JiraAuthorization) + .when() + .body(getLinkJIRATicketRequestBody() + .replace("${TICKET_ID}", linkedToID) + ) + .put("/rest/api/2/issue/" + ticketID) + .then().log().all().extract().response(); + } catch (Exception e) { + ReportManagerHelper.logDiscrete(e); + } + } + + private static String getCreateIssueRequestBody() { + return """ + { + "fields":{ + "project":{ + "key":"${PROJECT_KEY}" + }, + "summary":"${BUG_SUMMERY}", + "description":"Reported By SHAFT Automation Engine|| Execution Log ${BUG_DESCRIPTION}", + "assignee":{ + "name":"${ASSIGNEE_NAME}" + }, + "issuetype":{ + "name":"Bug" + } + } + } + """; + } + + private static String getLinkJIRATicketRequestBody() { + return """ + { + "update":{ + "issuelinks":[ + { + "add":{ + "type":{ + "name":"Relates" + }, + "outwardIssue":{ + "key":"${TICKET_ID}" + } + } + } + ] + } + } + """; + } +} diff --git a/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test b/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test new file mode 100644 index 0000000000..c5abb923c3 --- /dev/null +++ b/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test @@ -0,0 +1,264 @@ +package io.github.shafthq.shaft.tools.tms; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.shaft.cli.FileActions; +import com.shaft.tools.io.ReportManager; +import io.github.shafthq.shaft.tools.io.helpers.ReportManagerHelper; +import io.restassured.config.RestAssuredConfig; +import io.restassured.config.SSLConfig; +import io.restassured.http.ContentType; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Base64; +import java.util.Calendar; +import java.util.List; + +import static io.restassured.RestAssured.*; +import static io.restassured.config.EncoderConfig.encoderConfig; + + +public class XrayIntegrationHelper { + + private static String _JiraAuthorization =System.getProperty("authorization").trim(); + private static final String authType= System.getProperty("authType").trim()+" "; + private static final String _ProjectKey = System.getProperty("projectKey").trim(); + private static String _TestExecutionID = null; + + private static void setup() { + baseURI = System.getProperty("jiraUrl"); + if(authType.equals("Basic ")) + _JiraAuthorization=Base64.getEncoder().encodeToString(_JiraAuthorization.getBytes()); + given() + .config(RestAssuredConfig.config().sslConfig(SSLConfig.sslConfig().allowAllHostnames())) + .relaxedHTTPSValidation(); + } + + /** + * Import cucumber results recorded in cucumber.jsom file through /import/execution/cucumber endpoint + * + * @param filepath > the report relative path + */ + public static void importCucumberResults(String filepath) throws Exception { + + setup(); + String reportPath = FileActions.getInstance().getAbsolutePath(filepath); + ReportManager.logDiscrete("uploading file: " + reportPath); + ReportManager.logDiscrete("Length: " + new File(reportPath).length()); + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + JsonElement je = JsonParser.parseString(new String(Files.readAllBytes(Paths.get(reportPath)))); + String prettyJsonString = gson.toJson(je); + + try { + Response response = given() + .contentType("application/json") + .header("Authorization", authType + _JiraAuthorization) + .body(prettyJsonString) + .expect().statusCode(200) + .when() + .post("/rest/raven/1.0/import/execution/cucumber").then().extract().response(); + + _TestExecutionID = response.jsonPath().get("testExecIssue.key").toString(); + ReportManager.logDiscrete("ExecutionID: " + _TestExecutionID); + } catch (Exception e) { + ReportManagerHelper.logDiscrete(e); + } + } + + /** + * Import TestNG results recorded in testng-results.jsom file through /import/execution/testng?projectKey=[projectKey] endpoint + * + * @param executionName > The execution name mentioned in JiraXray.properties + * @param executionDescription > The execution Description mentioned in JiraXray.properties + */ + public static void renameTestExecutionSuit(String executionName, String executionDescription) { + + if (_TestExecutionID == null) return; + setup(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + String body = "{\r\n \"fields\" : {\r\n " + + " \"summary\": " + + "\"Execution results " + executionName + " | " + sdf.format(Calendar.getInstance().getTime()) + "\",\r\n " + + "\"description\": " + + "\"" + executionDescription + "\"\r\n }\r\n}"; + try { + given() + .contentType("application/json") + .header("Authorization", authType + _JiraAuthorization) + .body(body) + .expect().statusCode(204) + .when() + .put("/rest/api/2/issue/" + _TestExecutionID).then().extract().response(); + + } catch (Exception e) { + ReportManagerHelper.logDiscrete(e); + } + } + + /** + * Import TestNG results recorded in testng-results.jsom file through /import/execution/testng?projectKey=[projectKey] endpoint + * + * @param filepath > the report relative path + */ + public static void importTestNGResults(String filepath) { + setup(); + String reportPath = FileActions.getInstance().getAbsolutePath(filepath); + ReportManager.logDiscrete("uploading file: " + reportPath); + ReportManager.logDiscrete("Length: " + new File(reportPath).length()); + try { + Response response = given() + .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("multipart/form-data", ContentType.TEXT))) + .relaxedHTTPSValidation().contentType("multipart/form-data") + .header("Authorization", authType + _JiraAuthorization) + .multiPart(new File(reportPath)) + .when() + .post("/rest/raven/1.0/import/execution/testng?projectKey=" + _ProjectKey) + .then().log().all().extract().response(); + + _TestExecutionID = response.jsonPath().get("testExecIssue.key").toString(); + ReportManager.logDiscrete("ExecutionID: " + _TestExecutionID); + + } catch (Exception e) { + ReportManagerHelper.logDiscrete(e); + } + } + + /** + * Create JIRA Bug to report execution failure. + * + * @param files -> list of the failed testcase attachments. + * @param testCaseName -> the failed testcase name + * @param description --> the failed test case execution log + * @return String bugID + */ + public static String createIssue(List files, String testCaseName, String description) { + setup(); + try { + Response response = given() + .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("application/json", ContentType.JSON))) + .relaxedHTTPSValidation().contentType("application/json") + .header("Authorization", authType + _JiraAuthorization) + .when() + .body(getCreateIssueRequestBody() + .replace("${PROJECT_KEY}", _ProjectKey) + .replace("${BUG_SUMMERY}", "Execution Bug: " + testCaseName) + .replace("${BUG_DESCRIPTION}", description + .replaceAll("[^a-zA-Z0-9.?=*$%@#&!<>|\\{\\}\\[\\]\"' /]", "") + .replaceAll("\"", "'") + ) + .replace("${ASSIGNEE_NAME}", System.getProperty("assignee")) + ) + .post("/rest/api/2/issue") + .then().log().all().extract().response(); + + String id = response.jsonPath().get("key").toString(); + + ReportManager.logDiscrete("BugID: " + id); + attachFilesToIssue(id, files); + return id; + + } catch (Exception e) { + ReportManagerHelper.logDiscrete(e); + return null; + } + } + + /** + * Update the created issue with the attachments. + * + * @param issueID -> the created bug ID. + * @param files -> list of the failed testcase attachments. + */ + public static void attachFilesToIssue(String issueID, List files) { + setup(); + try { + RequestSpecification req = given() + .relaxedHTTPSValidation().contentType(ContentType.MULTIPART) + .header("Authorization", authType + _JiraAuthorization) + .header("X-Atlassian-Token", "nocheck"); + for (String file : files) + req.multiPart("file", new File(file)); + + ReportManager.logDiscrete("BugID: " + issueID); + req.when() + .post("/rest/api/2/issue/" + issueID + "/attachments") + .then().log().all().extract().response(); + } catch (Exception e) { + ReportManagerHelper.logDiscrete(e); + } + } + + /** + * Link any jira 2 tickets using the tickets IDs through PUT API request. the covered relation is relates. + * + * @param ticketID -> the main ticket ID. + * @param linkedToID -> the one to be linked to. + */ + public static void link2Tickets(String ticketID, String linkedToID) { + setup(); + try { + given() + .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("application/json", ContentType.JSON))) + .relaxedHTTPSValidation().contentType("application/json") + .header("Authorization", authType + _JiraAuthorization) + .when() + .body(getLinkJIRATicketRequestBody() + .replace("${TICKET_ID}", linkedToID) + ) + .put("/rest/api/2/issue/" + ticketID) + .then().log().all().extract().response(); + } catch (Exception e) { + ReportManagerHelper.logDiscrete(e); + } + } + + private static String getCreateIssueRequestBody() { + return """ + { + "fields":{ + "project":{ + "key":"${PROJECT_KEY}" + }, + "summary":"${BUG_SUMMERY}", + "description":"Reported By SHAFT Automation Engine|| Execution Log ${BUG_DESCRIPTION}", + "assignee":{ + "name":"${ASSIGNEE_NAME}" + }, + "issuetype":{ + "name":"Bug" + } + } + } + """; + } + + private static String getLinkJIRATicketRequestBody() { + return """ + { + "update":{ + "issuelinks":[ + { + "add":{ + "type":{ + "name":"Relates" + }, + "outwardIssue":{ + "key":"${TICKET_ID}" + } + } + } + ] + } + } + """; + } +} diff --git a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java index 5e0baa86c2..199ef5486b 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java @@ -30,7 +30,8 @@ void behavior() throws Exception { .testResource("java/removeunusedimports/JavaCodeUnformatted.test", "java/removeunusedimports/JavaCodeFormatted.test") .testResource("java/removeunusedimports/JavaCodeWithLicenseUnformatted.test", "java/removeunusedimports/JavaCodeWithLicenseFormatted.test") .testResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test", "java/removeunusedimports/JavaCodeWithLicensePackageFormatted.test") - .testResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test", "java/removeunusedimports/JavaCodeWithPackageFormatted.test"); + .testResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test", "java/removeunusedimports/JavaCodeWithPackageFormatted.test") + .testResource("java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test", "java/removeunusedimports/Jdk17MultineStringBlockFormatted.test"); } @Test From a899b8cd83312d8e0a8b481121175e14d23bd836 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 26 Feb 2023 13:52:22 +0400 Subject: [PATCH 0515/1120] Simplify testCase --- .../Jdk17MultineStringBlockFormatted.test | 215 ------------------ .../Jdk17MultineStringBlockUnformatted.test | 215 ------------------ 2 files changed, 430 deletions(-) diff --git a/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockFormatted.test b/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockFormatted.test index c5abb923c3..1bfad32664 100644 --- a/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockFormatted.test +++ b/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockFormatted.test @@ -26,221 +26,6 @@ import static io.restassured.config.EncoderConfig.encoderConfig; public class XrayIntegrationHelper { - - private static String _JiraAuthorization =System.getProperty("authorization").trim(); - private static final String authType= System.getProperty("authType").trim()+" "; - private static final String _ProjectKey = System.getProperty("projectKey").trim(); - private static String _TestExecutionID = null; - - private static void setup() { - baseURI = System.getProperty("jiraUrl"); - if(authType.equals("Basic ")) - _JiraAuthorization=Base64.getEncoder().encodeToString(_JiraAuthorization.getBytes()); - given() - .config(RestAssuredConfig.config().sslConfig(SSLConfig.sslConfig().allowAllHostnames())) - .relaxedHTTPSValidation(); - } - - /** - * Import cucumber results recorded in cucumber.jsom file through /import/execution/cucumber endpoint - * - * @param filepath > the report relative path - */ - public static void importCucumberResults(String filepath) throws Exception { - - setup(); - String reportPath = FileActions.getInstance().getAbsolutePath(filepath); - ReportManager.logDiscrete("uploading file: " + reportPath); - ReportManager.logDiscrete("Length: " + new File(reportPath).length()); - - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - JsonElement je = JsonParser.parseString(new String(Files.readAllBytes(Paths.get(reportPath)))); - String prettyJsonString = gson.toJson(je); - - try { - Response response = given() - .contentType("application/json") - .header("Authorization", authType + _JiraAuthorization) - .body(prettyJsonString) - .expect().statusCode(200) - .when() - .post("/rest/raven/1.0/import/execution/cucumber").then().extract().response(); - - _TestExecutionID = response.jsonPath().get("testExecIssue.key").toString(); - ReportManager.logDiscrete("ExecutionID: " + _TestExecutionID); - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - } - } - - /** - * Import TestNG results recorded in testng-results.jsom file through /import/execution/testng?projectKey=[projectKey] endpoint - * - * @param executionName > The execution name mentioned in JiraXray.properties - * @param executionDescription > The execution Description mentioned in JiraXray.properties - */ - public static void renameTestExecutionSuit(String executionName, String executionDescription) { - - if (_TestExecutionID == null) return; - setup(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - String body = "{\r\n \"fields\" : {\r\n " + - " \"summary\": " + - "\"Execution results " + executionName + " | " + sdf.format(Calendar.getInstance().getTime()) + "\",\r\n " + - "\"description\": " + - "\"" + executionDescription + "\"\r\n }\r\n}"; - try { - given() - .contentType("application/json") - .header("Authorization", authType + _JiraAuthorization) - .body(body) - .expect().statusCode(204) - .when() - .put("/rest/api/2/issue/" + _TestExecutionID).then().extract().response(); - - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - } - } - - /** - * Import TestNG results recorded in testng-results.jsom file through /import/execution/testng?projectKey=[projectKey] endpoint - * - * @param filepath > the report relative path - */ - public static void importTestNGResults(String filepath) { - setup(); - String reportPath = FileActions.getInstance().getAbsolutePath(filepath); - ReportManager.logDiscrete("uploading file: " + reportPath); - ReportManager.logDiscrete("Length: " + new File(reportPath).length()); - try { - Response response = given() - .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("multipart/form-data", ContentType.TEXT))) - .relaxedHTTPSValidation().contentType("multipart/form-data") - .header("Authorization", authType + _JiraAuthorization) - .multiPart(new File(reportPath)) - .when() - .post("/rest/raven/1.0/import/execution/testng?projectKey=" + _ProjectKey) - .then().log().all().extract().response(); - - _TestExecutionID = response.jsonPath().get("testExecIssue.key").toString(); - ReportManager.logDiscrete("ExecutionID: " + _TestExecutionID); - - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - } - } - - /** - * Create JIRA Bug to report execution failure. - * - * @param files -> list of the failed testcase attachments. - * @param testCaseName -> the failed testcase name - * @param description --> the failed test case execution log - * @return String bugID - */ - public static String createIssue(List files, String testCaseName, String description) { - setup(); - try { - Response response = given() - .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("application/json", ContentType.JSON))) - .relaxedHTTPSValidation().contentType("application/json") - .header("Authorization", authType + _JiraAuthorization) - .when() - .body(getCreateIssueRequestBody() - .replace("${PROJECT_KEY}", _ProjectKey) - .replace("${BUG_SUMMERY}", "Execution Bug: " + testCaseName) - .replace("${BUG_DESCRIPTION}", description - .replaceAll("[^a-zA-Z0-9.?=*$%@#&!<>|\\{\\}\\[\\]\"' /]", "") - .replaceAll("\"", "'") - ) - .replace("${ASSIGNEE_NAME}", System.getProperty("assignee")) - ) - .post("/rest/api/2/issue") - .then().log().all().extract().response(); - - String id = response.jsonPath().get("key").toString(); - - ReportManager.logDiscrete("BugID: " + id); - attachFilesToIssue(id, files); - return id; - - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - return null; - } - } - - /** - * Update the created issue with the attachments. - * - * @param issueID -> the created bug ID. - * @param files -> list of the failed testcase attachments. - */ - public static void attachFilesToIssue(String issueID, List files) { - setup(); - try { - RequestSpecification req = given() - .relaxedHTTPSValidation().contentType(ContentType.MULTIPART) - .header("Authorization", authType + _JiraAuthorization) - .header("X-Atlassian-Token", "nocheck"); - for (String file : files) - req.multiPart("file", new File(file)); - - ReportManager.logDiscrete("BugID: " + issueID); - req.when() - .post("/rest/api/2/issue/" + issueID + "/attachments") - .then().log().all().extract().response(); - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - } - } - - /** - * Link any jira 2 tickets using the tickets IDs through PUT API request. the covered relation is relates. - * - * @param ticketID -> the main ticket ID. - * @param linkedToID -> the one to be linked to. - */ - public static void link2Tickets(String ticketID, String linkedToID) { - setup(); - try { - given() - .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("application/json", ContentType.JSON))) - .relaxedHTTPSValidation().contentType("application/json") - .header("Authorization", authType + _JiraAuthorization) - .when() - .body(getLinkJIRATicketRequestBody() - .replace("${TICKET_ID}", linkedToID) - ) - .put("/rest/api/2/issue/" + ticketID) - .then().log().all().extract().response(); - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - } - } - - private static String getCreateIssueRequestBody() { - return """ - { - "fields":{ - "project":{ - "key":"${PROJECT_KEY}" - }, - "summary":"${BUG_SUMMERY}", - "description":"Reported By SHAFT Automation Engine|| Execution Log ${BUG_DESCRIPTION}", - "assignee":{ - "name":"${ASSIGNEE_NAME}" - }, - "issuetype":{ - "name":"Bug" - } - } - } - """; - } - private static String getLinkJIRATicketRequestBody() { return """ { diff --git a/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test b/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test index c5abb923c3..1bfad32664 100644 --- a/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test +++ b/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test @@ -26,221 +26,6 @@ import static io.restassured.config.EncoderConfig.encoderConfig; public class XrayIntegrationHelper { - - private static String _JiraAuthorization =System.getProperty("authorization").trim(); - private static final String authType= System.getProperty("authType").trim()+" "; - private static final String _ProjectKey = System.getProperty("projectKey").trim(); - private static String _TestExecutionID = null; - - private static void setup() { - baseURI = System.getProperty("jiraUrl"); - if(authType.equals("Basic ")) - _JiraAuthorization=Base64.getEncoder().encodeToString(_JiraAuthorization.getBytes()); - given() - .config(RestAssuredConfig.config().sslConfig(SSLConfig.sslConfig().allowAllHostnames())) - .relaxedHTTPSValidation(); - } - - /** - * Import cucumber results recorded in cucumber.jsom file through /import/execution/cucumber endpoint - * - * @param filepath > the report relative path - */ - public static void importCucumberResults(String filepath) throws Exception { - - setup(); - String reportPath = FileActions.getInstance().getAbsolutePath(filepath); - ReportManager.logDiscrete("uploading file: " + reportPath); - ReportManager.logDiscrete("Length: " + new File(reportPath).length()); - - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - JsonElement je = JsonParser.parseString(new String(Files.readAllBytes(Paths.get(reportPath)))); - String prettyJsonString = gson.toJson(je); - - try { - Response response = given() - .contentType("application/json") - .header("Authorization", authType + _JiraAuthorization) - .body(prettyJsonString) - .expect().statusCode(200) - .when() - .post("/rest/raven/1.0/import/execution/cucumber").then().extract().response(); - - _TestExecutionID = response.jsonPath().get("testExecIssue.key").toString(); - ReportManager.logDiscrete("ExecutionID: " + _TestExecutionID); - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - } - } - - /** - * Import TestNG results recorded in testng-results.jsom file through /import/execution/testng?projectKey=[projectKey] endpoint - * - * @param executionName > The execution name mentioned in JiraXray.properties - * @param executionDescription > The execution Description mentioned in JiraXray.properties - */ - public static void renameTestExecutionSuit(String executionName, String executionDescription) { - - if (_TestExecutionID == null) return; - setup(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - String body = "{\r\n \"fields\" : {\r\n " + - " \"summary\": " + - "\"Execution results " + executionName + " | " + sdf.format(Calendar.getInstance().getTime()) + "\",\r\n " + - "\"description\": " + - "\"" + executionDescription + "\"\r\n }\r\n}"; - try { - given() - .contentType("application/json") - .header("Authorization", authType + _JiraAuthorization) - .body(body) - .expect().statusCode(204) - .when() - .put("/rest/api/2/issue/" + _TestExecutionID).then().extract().response(); - - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - } - } - - /** - * Import TestNG results recorded in testng-results.jsom file through /import/execution/testng?projectKey=[projectKey] endpoint - * - * @param filepath > the report relative path - */ - public static void importTestNGResults(String filepath) { - setup(); - String reportPath = FileActions.getInstance().getAbsolutePath(filepath); - ReportManager.logDiscrete("uploading file: " + reportPath); - ReportManager.logDiscrete("Length: " + new File(reportPath).length()); - try { - Response response = given() - .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("multipart/form-data", ContentType.TEXT))) - .relaxedHTTPSValidation().contentType("multipart/form-data") - .header("Authorization", authType + _JiraAuthorization) - .multiPart(new File(reportPath)) - .when() - .post("/rest/raven/1.0/import/execution/testng?projectKey=" + _ProjectKey) - .then().log().all().extract().response(); - - _TestExecutionID = response.jsonPath().get("testExecIssue.key").toString(); - ReportManager.logDiscrete("ExecutionID: " + _TestExecutionID); - - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - } - } - - /** - * Create JIRA Bug to report execution failure. - * - * @param files -> list of the failed testcase attachments. - * @param testCaseName -> the failed testcase name - * @param description --> the failed test case execution log - * @return String bugID - */ - public static String createIssue(List files, String testCaseName, String description) { - setup(); - try { - Response response = given() - .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("application/json", ContentType.JSON))) - .relaxedHTTPSValidation().contentType("application/json") - .header("Authorization", authType + _JiraAuthorization) - .when() - .body(getCreateIssueRequestBody() - .replace("${PROJECT_KEY}", _ProjectKey) - .replace("${BUG_SUMMERY}", "Execution Bug: " + testCaseName) - .replace("${BUG_DESCRIPTION}", description - .replaceAll("[^a-zA-Z0-9.?=*$%@#&!<>|\\{\\}\\[\\]\"' /]", "") - .replaceAll("\"", "'") - ) - .replace("${ASSIGNEE_NAME}", System.getProperty("assignee")) - ) - .post("/rest/api/2/issue") - .then().log().all().extract().response(); - - String id = response.jsonPath().get("key").toString(); - - ReportManager.logDiscrete("BugID: " + id); - attachFilesToIssue(id, files); - return id; - - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - return null; - } - } - - /** - * Update the created issue with the attachments. - * - * @param issueID -> the created bug ID. - * @param files -> list of the failed testcase attachments. - */ - public static void attachFilesToIssue(String issueID, List files) { - setup(); - try { - RequestSpecification req = given() - .relaxedHTTPSValidation().contentType(ContentType.MULTIPART) - .header("Authorization", authType + _JiraAuthorization) - .header("X-Atlassian-Token", "nocheck"); - for (String file : files) - req.multiPart("file", new File(file)); - - ReportManager.logDiscrete("BugID: " + issueID); - req.when() - .post("/rest/api/2/issue/" + issueID + "/attachments") - .then().log().all().extract().response(); - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - } - } - - /** - * Link any jira 2 tickets using the tickets IDs through PUT API request. the covered relation is relates. - * - * @param ticketID -> the main ticket ID. - * @param linkedToID -> the one to be linked to. - */ - public static void link2Tickets(String ticketID, String linkedToID) { - setup(); - try { - given() - .config(config().encoderConfig(encoderConfig().encodeContentTypeAs("application/json", ContentType.JSON))) - .relaxedHTTPSValidation().contentType("application/json") - .header("Authorization", authType + _JiraAuthorization) - .when() - .body(getLinkJIRATicketRequestBody() - .replace("${TICKET_ID}", linkedToID) - ) - .put("/rest/api/2/issue/" + ticketID) - .then().log().all().extract().response(); - } catch (Exception e) { - ReportManagerHelper.logDiscrete(e); - } - } - - private static String getCreateIssueRequestBody() { - return """ - { - "fields":{ - "project":{ - "key":"${PROJECT_KEY}" - }, - "summary":"${BUG_SUMMERY}", - "description":"Reported By SHAFT Automation Engine|| Execution Log ${BUG_DESCRIPTION}", - "assignee":{ - "name":"${ASSIGNEE_NAME}" - }, - "issuetype":{ - "name":"Bug" - } - } - } - """; - } - private static String getLinkJIRATicketRequestBody() { return """ { From 0bef59b146f9e66b93f94e6281df9b3e63ede3cd Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 26 Feb 2023 13:55:43 +0400 Subject: [PATCH 0516/1120] Fix style --- .../com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java index 199ef5486b..171d6753e0 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.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. From e01cc9ac8ac8685a819f6ae8115d2a33505338f8 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 26 Feb 2023 21:05:54 +0400 Subject: [PATCH 0517/1120] Propose a JavaParser-based removeUnunsedImports --- lib/build.gradle | 6 +- .../JavaparserRemoveUnusedImportsFunc.java | 213 ++++++++++++++++++ .../JavaparserRemoveUnusedImportsStep.java | 104 +++++++++ .../Jdk17MultineStringBlockFormatted.test | 22 -- .../removeunusedimports/RevelcFormatted.test | 81 +++++++ .../RevelcUnformatted.test | 89 ++++++++ ...JavaparserRemoveUnusedImportsStepTest.java | 54 +++++ .../java/RemoveUnusedImportsStepTest.java | 4 +- 8 files changed, 549 insertions(+), 24 deletions(-) create mode 100644 lib/src/javaparser/java/com/diffplug/spotless/glue/java/JavaparserRemoveUnusedImportsFunc.java create mode 100644 lib/src/main/java/com/diffplug/spotless/java/JavaparserRemoveUnusedImportsStep.java create mode 100644 testlib/src/main/resources/java/removeunusedimports/RevelcFormatted.test create mode 100644 testlib/src/main/resources/java/removeunusedimports/RevelcUnformatted.test create mode 100644 testlib/src/test/java/com/diffplug/spotless/java/JavaparserRemoveUnusedImportsStepTest.java diff --git a/lib/build.gradle b/lib/build.gradle index bfa54aaa13..041c706657 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -17,7 +17,8 @@ def NEEDS_GLUE = [ 'scalafmt', 'jackson', 'gson', - 'cleanthat' + 'cleanthat', + 'javaparser' ] for (glue in NEEDS_GLUE) { sourceSets.register(glue) { @@ -110,6 +111,9 @@ dependencies { cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.2' compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.2' + + javaparserCompileOnly 'com.github.javaparser:javaparser-core:3.25.0' + javaparserCompileOnly 'org.slf4j:slf4j-api:2.0.6' } // we'll hold the core lib to a high standard diff --git a/lib/src/javaparser/java/com/diffplug/spotless/glue/java/JavaparserRemoveUnusedImportsFunc.java b/lib/src/javaparser/java/com/diffplug/spotless/glue/java/JavaparserRemoveUnusedImportsFunc.java new file mode 100644 index 0000000000..035daacadf --- /dev/null +++ b/lib/src/javaparser/java/com/diffplug/spotless/glue/java/JavaparserRemoveUnusedImportsFunc.java @@ -0,0 +1,213 @@ +/* + * 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.java; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.github.javaparser.JavaParser; +import com.github.javaparser.JavaToken; +import com.github.javaparser.ParseResult; +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.TokenRange; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.ImportDeclaration; +import com.github.javaparser.ast.Node; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.PackageDeclaration; +import com.github.javaparser.ast.comments.JavadocComment; +import com.github.javaparser.javadoc.Javadoc; +import com.github.javaparser.javadoc.JavadocBlockTag; +import com.github.javaparser.javadoc.description.JavadocDescription; +import com.github.javaparser.javadoc.description.JavadocInlineTag; +import com.github.javaparser.javadoc.description.JavadocSnippet; +import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter; + +import com.diffplug.spotless.FormatterFunc; + +/** + * Remove imports from a Java source file by analyzing {@link ImportDeclaration}. + *

+ * More precisely, it will analyze each Tokens beinh used in the code-base, and remove imports not matching given import. + *

+ * One limitation is it will not strip away wildcard imports. + */ +// https://github.com/javaparser/javaparser/issues/1590 +// https://github.com/revelc/impsort-maven-plugin/blob/main/src/main/java/net/revelc/code/impsort/ImpSort.java +public class JavaparserRemoveUnusedImportsFunc implements FormatterFunc { + private static final Logger LOGGER = LoggerFactory.getLogger(JavaparserRemoveUnusedImportsFunc.class); + + public String apply(String input) throws InterruptedException, IOException { + // We consider the source is very recent, as source is retro-compatible (i.e. not feature get deprecated) + ParserConfiguration.LanguageLevel languageLevel = ParserConfiguration.LanguageLevel.BLEEDING_EDGE; + ParseResult parseResult = new JavaParser(new ParserConfiguration().setLanguageLevel(languageLevel)).parse(input); + CompilationUnit unit = parseResult.getResult().orElseThrow(() -> { + return new IllegalArgumentException("Issue parsing the input: " + parseResult.getProblems()); + }); + if (!parseResult.isSuccessful()) { + throw new IllegalArgumentException("Issue parsing the input: " + parseResult.getProblems()); + } + + NodeList importDeclarations = unit.getImports(); + if (importDeclarations.isEmpty()) { + return input; + } + + Set tokensInUse = tokensInUse(unit); + + List unusedImports = removeUnusedImports(importDeclarations, tokensInUse); + + if (unusedImports.isEmpty()) { + return input; + } else { + // This is necessary to get, after mutations, a source as similar as possible to the original one + LexicalPreservingPrinter.setup(unit); + + // Remove all unused imports + unusedImports.forEach(importDeclaration -> { + try { + importDeclaration.remove(); + } catch (RuntimeException e) { + throw new RuntimeException("Issue removing an import statement: " + importDeclaration, e); + } + }); + + // print the CompilationUnit after mutations + return LexicalPreservingPrinter.print(unit); + } + } + + /* + * Extract all of the tokens from the main body of the file. + * + * This set of tokens represents all of the file's dependencies, and is used to figure out whether + * or not an import is unused. + */ + // https://github.com/revelc/impsort-maven-plugin/blob/main/src/main/java/net/revelc/code/impsort/ImpSort.java#L278 + private static Set tokensInUse(CompilationUnit unit) { + // Extract tokens from the java code: + Stream packageDecl = unit.getPackageDeclaration().isPresent() + ? Stream.of(unit.getPackageDeclaration().get()).map(PackageDeclaration::getAnnotations) + .flatMap(NodeList::stream) + : Stream.empty(); + Stream typesInCode = Stream.concat(packageDecl, unit.getTypes().stream()) + .map(Node::getTokenRange).filter(Optional::isPresent).map(Optional::get) + .filter(r -> r != TokenRange.INVALID).flatMap(r -> { + // get all JavaTokens as strings from each range + return StreamSupport.stream(r.spliterator(), false); + }).map(JavaToken::asString); + + // Extract referenced class names from parsed javadoc comments: + Stream typesInJavadocs = unit.getAllComments().stream() + .filter(c -> c instanceof JavadocComment).map(JavadocComment.class::cast) + .map(JavadocComment::parse).flatMap(JavaparserRemoveUnusedImportsFunc::parseJavadoc); + + return Stream.concat(typesInCode, typesInJavadocs) + .filter(t -> t != null && !t.isEmpty() && Character.isJavaIdentifierStart(t.charAt(0))) + .collect(Collectors.toSet()); + } + + /* + * Remove unused imports. + * + * This algorithm only looks at the file itself, and evaluates whether or not a given import is + * unused, by checking if the last segment of the import path (typically a class name or a static + * function name) appears in the file. + * + * This means that it is not possible to remove import statements with wildcards. + */ + // https://github.com/revelc/impsort-maven-plugin/blob/main/src/main/java/net/revelc/code/impsort/ImpSort.java#L350 + private static List removeUnusedImports(Collection imports, Set tokensInUse) { + // We clone the input Collection as it typically reflects dynamically the imports from the CompilationUnit + // Hence, removal during iteration may lead to issues + imports = new ArrayList<>(imports); + + return imports.stream().filter(i -> { + String[] segments = i.getNameAsString().split("[.]"); + if (segments.length == 0) { + throw new AssertionError("Parse tree includes invalid import statements"); + } + + String lastSegment = segments[segments.length - 1]; + if (lastSegment.equals("*")) { + return false; + } + + return !tokensInUse.contains(lastSegment); + }).collect(Collectors.toList()); + } + + // https://github.com/revelc/impsort-maven-plugin/blob/main/src/main/java/net/revelc/code/impsort/ImpSort.java#L366 + static void removeSamePackageImports(Set imports, + Optional packageDeclaration) { + String packageName = packageDeclaration.map(p -> p.getName().toString()).orElse(""); + imports.removeIf(i -> { + String imp = i.getNameAsString(); + if (packageName.isEmpty()) { + return !imp.contains("."); + } + return imp.startsWith(packageName) && imp.lastIndexOf(".") <= packageName.length(); + }); + } + + // parse both main doc description and any block tags + // https://github.com/revelc/impsort-maven-plugin/blob/main/src/main/java/net/revelc/code/impsort/ImpSort.java#L304 + private static Stream parseJavadoc(Javadoc javadoc) { + // parse main doc description + Stream stringsFromJavadocDescription = Stream.of(javadoc.getDescription()).flatMap(JavaparserRemoveUnusedImportsFunc::parseJavadocDescription); + // grab tag names and parsed descriptions for block tags + Stream stringsFromBlockTags = javadoc.getBlockTags().stream().flatMap(tag -> { + // only @throws and @exception have names who are importable; @param and others don't + EnumSet blockTagTypesWithImportableNames = EnumSet.of(JavadocBlockTag.Type.THROWS, JavadocBlockTag.Type.EXCEPTION); + Stream importableTagNames = blockTagTypesWithImportableNames.contains(tag.getType()) + ? Stream.of(tag.getName()).filter(Optional::isPresent).map(Optional::get) + : Stream.empty(); + Stream tagDescriptions = Stream.of(tag.getContent()).flatMap(JavaparserRemoveUnusedImportsFunc::parseJavadocDescription); + return Stream.concat(importableTagNames, tagDescriptions); + }); + return Stream.concat(stringsFromJavadocDescription, stringsFromBlockTags); + } + + // https://github.com/revelc/impsort-maven-plugin/blob/main/src/main/java/net/revelc/code/impsort/ImpSort.java#L323 + private static Stream parseJavadocDescription(JavadocDescription description) { + return description.getElements().stream().map(element -> { + if (element instanceof JavadocInlineTag) { + // inline tags like {@link Foo} + return ((JavadocInlineTag) element).getContent(); + } else if (element instanceof JavadocSnippet) { + // snippets like @see Foo + return element.toText(); + } else { + // try to handle unknown elements as best we can + return element.toText(); + } + }).flatMap(s -> { + // split text descriptions into word tokens + return Stream.of(s.split("\\W+")); + }); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/java/JavaparserRemoveUnusedImportsStep.java b/lib/src/main/java/com/diffplug/spotless/java/JavaparserRemoveUnusedImportsStep.java new file mode 100644 index 0000000000..1399498afb --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/java/JavaparserRemoveUnusedImportsStep.java @@ -0,0 +1,104 @@ +/* + * 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.java; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Constructor; +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; + +/** Uses java-parser, but only to remove unused imports. */ +public class JavaparserRemoveUnusedImportsStep { + private static final String MAVEN_COORDINATE = "com.github.javaparser:javaparser-core"; + + // prevent direct instantiation + private JavaparserRemoveUnusedImportsStep() {} + + static final String NAME = "removeUnusedImports_javaParser"; + + public static FormatterStep create(Provisioner provisioner) { + return create(defaultGroupArtifact(), JavaparserRemoveUnusedImportsStep.defaultVersion(), provisioner); + } + + /** Creates a step which apply selected CleanThat mutators. */ + public static FormatterStep create(String groupArtifact, + String version, + Provisioner provisioner) { + Objects.requireNonNull(groupArtifact, "groupArtifact"); + if (groupArtifact.chars().filter(ch -> ch == ':').count() != 1) { + throw new IllegalArgumentException("groupArtifact must be in the form 'groupId:artifactId'. It was: " + groupArtifact); + } + Objects.requireNonNull(version, "version"); + Objects.requireNonNull(provisioner, "provisioner"); + return FormatterStep.createLazy(NAME, + () -> new JavaParserUnusedImportsState(groupArtifact, version, provisioner), + JavaparserRemoveUnusedImportsStep.JavaParserUnusedImportsState::createFormat); + } + + /** Get default formatter version */ + public static String defaultVersion() { + return "3.25.0"; + } + + public static String defaultGroupArtifact() { + return MAVEN_COORDINATE; + } + + static final class JavaParserUnusedImportsState implements Serializable { + private static final long serialVersionUID = 1L; + + final JarState jarState; + + JavaParserUnusedImportsState(String version, Provisioner provisioner) throws IOException { + this(MAVEN_COORDINATE, version, provisioner); + } + + JavaParserUnusedImportsState( + String groupArtifact, + String version, + Provisioner provisioner) throws IOException { + ModuleHelper.doOpenInternalPackagesIfRequired(); + this.jarState = JarState.from(groupArtifact + ":" + version, provisioner); + } + + @SuppressWarnings("PMD.UseProperClassLoader") + FormatterFunc createFormat() { + ClassLoader classLoader = jarState.getClassLoader(); + + Object formatter; + Method formatterMethod; + try { + Class formatterClazz = classLoader.loadClass("com.diffplug.spotless.glue.java.JavaparserRemoveUnusedImportsFunc"); + Constructor formatterConstructor = formatterClazz.getConstructor(); + + formatter = formatterConstructor.newInstance(); + formatterMethod = formatterClazz.getMethod("apply", String.class); + } catch (ReflectiveOperationException e) { + throw new IllegalStateException("Issue executing the formatter", e); + } + return input -> { + return (String) formatterMethod.invoke(formatter, input); + }; + } + + } +} diff --git a/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockFormatted.test b/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockFormatted.test index 1bfad32664..91692463a6 100644 --- a/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockFormatted.test +++ b/testlib/src/main/resources/java/removeunusedimports/Jdk17MultineStringBlockFormatted.test @@ -1,28 +1,6 @@ package io.github.shafthq.shaft.tools.tms; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import com.shaft.cli.FileActions; -import com.shaft.tools.io.ReportManager; -import io.github.shafthq.shaft.tools.io.helpers.ReportManagerHelper; -import io.restassured.config.RestAssuredConfig; -import io.restassured.config.SSLConfig; -import io.restassured.http.ContentType; -import io.restassured.response.Response; -import io.restassured.specification.RequestSpecification; -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.text.SimpleDateFormat; -import java.util.Base64; -import java.util.Calendar; -import java.util.List; - -import static io.restassured.RestAssured.*; -import static io.restassured.config.EncoderConfig.encoderConfig; public class XrayIntegrationHelper { diff --git a/testlib/src/main/resources/java/removeunusedimports/RevelcFormatted.test b/testlib/src/main/resources/java/removeunusedimports/RevelcFormatted.test new file mode 100644 index 0000000000..672400fdb8 --- /dev/null +++ b/testlib/src/main/resources/java/removeunusedimports/RevelcFormatted.test @@ -0,0 +1,81 @@ +/* + * 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. + */ + +@XmlSchema( + xmlns = { + @XmlNs(prefix = "order", namespaceURI = "http://www.camel.apache.org/jaxb/example/order/1"), + @XmlNs(prefix = "address", namespaceURI = "http://www.camel.apache.org/jaxb/example/address/1") + } +) +package net.revelc.code.imp; + +import com.foo.Type1; +import com.foo.Type2; +import com.foo.Type3; +import com.foo.Type4; +import com.foo.Type5; +import com.foo.Type6; +import com.foo.Type7; +import com.foo.Type8; +import com.foo.Type9; +import com.foo.Type10; + +import com.google.common.collect.ImmutableMap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.springframework.stereotype.Component; + +import com.foo.Type11; +import com.foo.internal.Type12; +import com.foo.params.Type13; +import javax.xml.bind.annotation.XmlNs; +import javax.xml.bind.annotation.XmlSchema; + +import static org.junit.Assert.assertFalse; + +import static org.junit.Assert.*; + +/** + * The import of {@link HashMap} should not be stripped away, since it + * is used in this comment. + */ +// https://github.com/revelc/impsort-maven-plugin/blob/main/src/test/resources/UnusedImports.java +@Component +public class UnusedImports { + ImmutableMap immutable; + + /** + * The following should also not be removed: + * + * @param blah when {@link Type13} blah + * @see Map + */ + public List getList(String blah) { + assertFalse(false); + return null; + } + + /** + * {@link Type1#method()} + * {@link Type2#method(Type3, Type4)} + * {@link #method(Type5, Type6)} + * {@value Type7#field} + * @see Type8#method() + * @see Type9#method(Type10) + * @throws Type11 when {@link Type12} is seen + */ + public void foo() { + } +} diff --git a/testlib/src/main/resources/java/removeunusedimports/RevelcUnformatted.test b/testlib/src/main/resources/java/removeunusedimports/RevelcUnformatted.test new file mode 100644 index 0000000000..bb43884a82 --- /dev/null +++ b/testlib/src/main/resources/java/removeunusedimports/RevelcUnformatted.test @@ -0,0 +1,89 @@ +/* + * 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. + */ + +@XmlSchema( + xmlns = { + @XmlNs(prefix = "order", namespaceURI = "http://www.camel.apache.org/jaxb/example/order/1"), + @XmlNs(prefix = "address", namespaceURI = "http://www.camel.apache.org/jaxb/example/address/1") + } +) +package net.revelc.code.imp; + +import com.foo.Type1; +import com.foo.Type2; +import com.foo.Type3; +import com.foo.Type4; +import com.foo.Type5; +import com.foo.Type6; +import com.foo.Type7; +import com.foo.Type8; +import com.foo.Type9; +import com.foo.Type10; +import net.revelc.code.imp.Something; +import net.revelc.code.imp.Something.Else; +import net.revelc.code.imp.*; + +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableMap; +import io.swagger.annotations.ApiOperation; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.foo.Type11; +import com.foo.internal.Type12; +import com.foo.params.Type13; +import javax.xml.bind.annotation.XmlNs; +import javax.xml.bind.annotation.XmlSchema; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import static org.junit.Assert.*; + +/** + * The import of {@link HashMap} should not be stripped away, since it + * is used in this comment. + */ +// https://github.com/revelc/impsort-maven-plugin/blob/main/src/test/resources/UnusedImports.java +@Component +public class UnusedImports { + ImmutableMap immutable; + + /** + * The following should also not be removed: + * + * @param blah when {@link Type13} blah + * @see Map + */ + public List getList(String blah) { + assertFalse(false); + return null; + } + + /** + * {@link Type1#method()} + * {@link Type2#method(Type3, Type4)} + * {@link #method(Type5, Type6)} + * {@value Type7#field} + * @see Type8#method() + * @see Type9#method(Type10) + * @throws Type11 when {@link Type12} is seen + */ + public void foo() { + } +} diff --git a/testlib/src/test/java/com/diffplug/spotless/java/JavaparserRemoveUnusedImportsStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/JavaparserRemoveUnusedImportsStepTest.java new file mode 100644 index 0000000000..e1681f2c79 --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/java/JavaparserRemoveUnusedImportsStepTest.java @@ -0,0 +1,54 @@ +/* + * 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. + * 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.java; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.SerializableEqualityTester; +import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.TestProvisioner; + +class JavaparserRemoveUnusedImportsStepTest { + @Test + void behavior() throws Exception { + FormatterStep step = JavaparserRemoveUnusedImportsStep.create(TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("java/removeunusedimports/JavaCodeUnformatted.test", "java/removeunusedimports/JavaCodeFormatted.test") + .testResource("java/removeunusedimports/JavaCodeWithLicenseUnformatted.test", "java/removeunusedimports/JavaCodeWithLicenseFormatted.test") + .testResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test", "java/removeunusedimports/JavaCodeWithLicensePackageFormatted.test") + .testResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test", "java/removeunusedimports/JavaCodeWithPackageFormatted.test") + .testResource("java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test", "java/removeunusedimports/Jdk17MultineStringBlockFormatted.test") + // JavaParser is failing over an annotated package: https://github.com/javaparser/javaparser/issues/3924 + // .testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test") + ; + } + + @Test + void equality() throws Exception { + new SerializableEqualityTester() { + @Override + protected void setupTest(API api) { + api.areDifferentThan(); + } + + @Override + protected FormatterStep create() { + return JavaparserRemoveUnusedImportsStep.create(TestProvisioner.mavenCentral()); + } + }.testEquals(); + } +} diff --git a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java index 171d6753e0..d3c0b55732 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStepTest.java @@ -31,7 +31,9 @@ void behavior() throws Exception { .testResource("java/removeunusedimports/JavaCodeWithLicenseUnformatted.test", "java/removeunusedimports/JavaCodeWithLicenseFormatted.test") .testResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test", "java/removeunusedimports/JavaCodeWithLicensePackageFormatted.test") .testResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test", "java/removeunusedimports/JavaCodeWithPackageFormatted.test") - .testResource("java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test", "java/removeunusedimports/Jdk17MultineStringBlockFormatted.test"); + // GoogleFormat requires running over a JDK17 to handle JDK17 features + // .testResource("java/removeunusedimports/Jdk17MultineStringBlockUnformatted.test", "java/removeunusedimports/Jdk17MultineStringBlockFormatted.test") + .testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test"); } @Test From 2e58bd8af29abf5eb71ca2f474eaccd75ac4c424 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 10 Feb 2023 16:49:15 +0100 Subject: [PATCH 0518/1120] 1480: introduce timing logger --- lib/build.gradle | 2 + .../com/diffplug/spotless/TimedLogger.java | 218 +++++++++++++++ .../diffplug/spotless/TimedLoggerTest.java | 255 ++++++++++++++++++ 3 files changed, 475 insertions(+) create mode 100644 lib/src/main/java/com/diffplug/spotless/TimedLogger.java create mode 100644 lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java diff --git a/lib/build.gradle b/lib/build.gradle index f6e0446f73..9a6e7913d5 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -56,6 +56,8 @@ tasks.named("check").configure { dependencies { compileOnly 'org.slf4j:slf4j-api:2.0.0' + testCommonImplementation 'org.slf4j:slf4j-api:2.0.0' + // zero runtime reqs is a hard requirements for spotless-lib // if you need a dep, put it in lib-extra testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" diff --git a/lib/src/main/java/com/diffplug/spotless/TimedLogger.java b/lib/src/main/java/com/diffplug/spotless/TimedLogger.java new file mode 100644 index 0000000000..f67d90c0ea --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/TimedLogger.java @@ -0,0 +1,218 @@ +/* + * 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; + +import static com.diffplug.spotless.LazyArgLogger.lazy; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Stream; + +import javax.annotation.Nonnull; + +import org.slf4j.Logger; + +/** + * A logger that logs the time it took to execute a block of code. + */ +public class TimedLogger { + + public static final String MESSAGE_PREFIX_BEGIN = "[BEGIN] "; + + public static final String MESSAGE_PREFIX_END = "[END] "; + + public static final String MESSAGE_SUFFIX_TOOK = " (took {})"; + + private final Logger logger; + private final Ticker ticker; + + private TimedLogger(@Nonnull Logger logger, Ticker ticker) { + this.logger = Objects.requireNonNull(logger); + this.ticker = ticker; + } + + public static TimedLogger forLogger(@Nonnull Logger logger) { + return forLogger(logger, Ticker.systemTicker()); + } + + public static TimedLogger forLogger(@Nonnull Logger logger, Ticker ticker) { + return new TimedLogger(logger, ticker); + } + + public TimedExec withInfo(@Nonnull String message, Object... args) { + return new TimedExec(logger::isInfoEnabled, logger::info, ticker, message, args); + } + + public TimedExec withDebug(@Nonnull String message, Object... args) { + return new TimedExec(logger::isDebugEnabled, logger::debug, ticker, message, args); + } + + public TimedExec withTrace(@Nonnull String message, Object... args) { + return new TimedExec(logger::isTraceEnabled, logger::trace, ticker, message, args); + } + + public TimedExec withWarn(@Nonnull String message, Object... args) { + return new TimedExec(logger::isWarnEnabled, logger::warn, ticker, message, args); + } + + public TimedExec withError(@Nonnull String message, Object... args) { + return new TimedExec(logger::isErrorEnabled, logger::error, ticker, message, args); + } + + public static class Timed implements AutoCloseable { + + @Nonnull + private final String msg; + + @Nonnull + private final List params; + @Nonnull + private final LogToLevelMethod delegatedLogger; + @Nonnull + private final Ticker ticker; + + private final long startedAt; + + public Timed(@Nonnull Ticker ticker, @Nonnull String msg, @Nonnull List params, @Nonnull LogToLevelMethod delegatedLogger) { + this.ticker = Objects.requireNonNull(ticker); + this.msg = Objects.requireNonNull(msg); + this.params = List.copyOf(Objects.requireNonNull(params)); + this.delegatedLogger = Objects.requireNonNull(delegatedLogger); + this.startedAt = ticker.read(); + logStart(); + } + + private void logStart() { + delegatedLogger.log(MESSAGE_PREFIX_BEGIN + msg, params.toArray()); + } + + private void logEnd() { + delegatedLogger.log(MESSAGE_PREFIX_END + msg + MESSAGE_SUFFIX_TOOK, paramsForEnd()); + } + + @Override + public final void close() { + logEnd(); + } + + private Object[] paramsForEnd() { + if (params.isEmpty() || !(params.get(params.size() - 1) instanceof Throwable)) { + // if the last element is not a throwable, we can add the duration as the last element + return Stream.concat(params.stream(), Stream.of(lazy(this::durationString))).toArray(); + } + // if the last element is a throwable, we have to add the duration before the last element + return Stream.concat( + params.stream().limit(params.size() - 1), + Stream.of(lazy(this::durationString), + params.get(params.size() - 1))) + .toArray(); + } + + private String durationString() { + long duration = ticker.read() - startedAt; + if (duration < 1000) { + return duration + "ms"; + } else if (duration < 1000 * 60) { + return (duration / 1000) + "s"; + } else { + // output in the format 3m 4.321s + long minutes = duration / (1000 * 60); + long seconds = (duration - minutes * 1000 * 60) / 1000; + long millis = duration - minutes * 1000 * 60 - seconds * 1000; + return minutes + "m" + (seconds + millis > 0 ? " " + seconds + "." + millis + "s" : ""); + } + } + } + + public static final class NullStopWatchLogger extends Timed { + private static final NullStopWatchLogger INSTANCE = new NullStopWatchLogger(); + + private NullStopWatchLogger() { + super(Ticker.systemTicker(), "", List.of(), (m, a) -> {}); + } + } + + interface Ticker { + long read(); + + static Ticker systemTicker() { + return System::currentTimeMillis; + } + } + + static class TestTicker implements Ticker { + private long time = 0; + + @Override + public long read() { + return time; + } + + public void tickMillis(long millis) { + time += millis; + } + } + + public static class TimedExec { + @Nonnull + private final LogActiveMethod logActiveMethod; + @Nonnull + private final LogToLevelMethod logMethod; + @Nonnull + private final Ticker ticker; + @Nonnull + private final String message; + @Nonnull + private final Object[] args; + + public TimedExec(LogActiveMethod logActiveMethod, LogToLevelMethod logMethod, Ticker ticker, String message, Object... args) { + this.logActiveMethod = Objects.requireNonNull(logActiveMethod); + this.logMethod = Objects.requireNonNull(logMethod); + this.ticker = Objects.requireNonNull(ticker); + this.message = Objects.requireNonNull(message); + this.args = Objects.requireNonNull(args); + } + + public void run(ThrowingEx.Runnable r) { + try (Timed ignore = timed()) { + ThrowingEx.run(r); + } + } + + public void runChecked(ThrowingEx.Runnable r) throws Exception { + try (Timed ignore = timed()) { + r.run(); + } + } + + private Timed timed() { + if (logActiveMethod.isLogLevelActive()) { + return new Timed(ticker, message, List.of(args), logMethod); + } + return NullStopWatchLogger.INSTANCE; + } + } + + @FunctionalInterface + private interface LogActiveMethod { + boolean isLogLevelActive(); + } + + @FunctionalInterface + private interface LogToLevelMethod { + void log(String message, Object... args); + } +} diff --git a/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java b/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java new file mode 100644 index 0000000000..167b5d24de --- /dev/null +++ b/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java @@ -0,0 +1,255 @@ +/* + * 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; + +import static com.diffplug.spotless.TimedLogger.MESSAGE_PREFIX_BEGIN; +import static com.diffplug.spotless.TimedLogger.MESSAGE_PREFIX_END; +import static com.diffplug.spotless.TimedLogger.MESSAGE_SUFFIX_TOOK; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import org.assertj.core.api.Assertions; +import org.assertj.core.api.Condition; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Marker; +import org.slf4j.event.Level; +import org.slf4j.helpers.LegacyAbstractLogger; + +import com.diffplug.spotless.TimedLogger.TestTicker; + +class TimedLoggerTest { + + private TestLogger testLogger; + + private TestTicker testTicker; + + private TimedLogger timedLogger; + + @BeforeEach + void setUp() { + testLogger = new TestLogger(); + testTicker = new TestTicker(); + timedLogger = TimedLogger.forLogger(testLogger, testTicker); + } + + @Test + void itDoesNotLogWhenLevelDisabled() throws InterruptedException { + + TestLogger logger = new TestLogger() { + @Override + public boolean isInfoEnabled() { + return false; + } + + @Override + public boolean isDebugEnabled() { + return false; + } + + @Override + public boolean isTraceEnabled() { + return false; + } + }; + TimedLogger timedLogger = TimedLogger.forLogger(logger); + + timedLogger.withInfo("This should not be logged").run(() -> Thread.sleep(1)); + logger.assertNoEvents(); + } + + @Test + void itLogsMillisWhenTakingMillis() { + timedLogger.withInfo("This should be logged").run(() -> testTicker.tickMillis(999)); + + testLogger.assertEvents(2); + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_SUFFIX_TOOK, "999ms"); + } + + @Test + void itLogsSecondsOnlyWhenTakingSeconds() { + timedLogger.withInfo("This should be logged").run(() -> testTicker.tickMillis(2_000)); + + testLogger.assertEvents(2); + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_SUFFIX_TOOK, "2s"); + } + + @Test + void itLogsMinutesOnlyWhenTakingMinutes() { + timedLogger.withInfo("This should be logged").run(() -> testTicker.tickMillis(2 * 60 * 1_000)); + + testLogger.assertEvents(2); + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_SUFFIX_TOOK, "2m"); + } + + @Test + void itLogsMinutesAndSecondsWhenTakingMinutesAndSeconds() { + timedLogger.withInfo("This should be logged").run(() -> testTicker.tickMillis(2 * 60 * 1_000 + 3 * 1_000)); + + testLogger.assertEvents(2); + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_SUFFIX_TOOK, "2m 3.0s"); + } + + @Test + void itLogsBeginAndEndPrefixes() { + timedLogger.withInfo("This should be logged").run(() -> testTicker.tickMillis(1)); + + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_PREFIX_BEGIN); + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_PREFIX_END, "1ms"); + } + + @Test + void itThrowsExceptionsInChecked() { + Assertions.assertThatThrownBy(() -> timedLogger.withInfo("This should be logged").runChecked(() -> { + throw new Exception("This is an exception"); + })).isInstanceOf(Exception.class).hasMessage("This is an exception"); + } + + @Test + void itLogsEvenWhenExceptionsAreThrown() { + Assertions.assertThatThrownBy(() -> timedLogger.withInfo("This should be logged").run(() -> { + testTicker.tickMillis(2); + throw new Exception("This is an exception"); + })).isInstanceOf(RuntimeException.class) + .hasMessageContaining("This is an exception") + .hasCauseInstanceOf(Exception.class); + + testLogger.assertEvents(2); + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_PREFIX_BEGIN); + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_PREFIX_END, "2ms"); + } + + private static class TestLogger extends LegacyAbstractLogger { + + private final List events = new LinkedList<>(); + + @Override + protected String getFullyQualifiedCallerName() { + return TestLogger.class.getName(); + } + + @Override + protected void handleNormalizedLoggingCall(Level level, Marker marker, String msg, Object[] arguments, Throwable throwable) { + events.add(new TestLoggingEvent(level, marker, msg, arguments, throwable)); + } + + @Override + public boolean isTraceEnabled() { + return true; + } + + @Override + public boolean isDebugEnabled() { + return true; + } + + @Override + public boolean isInfoEnabled() { + return true; + } + + @Override + public boolean isWarnEnabled() { + return true; + } + + @Override + public boolean isErrorEnabled() { + return true; + } + + public List getEvents() { + return events; + } + + public void assertNoEvents() { + Assertions.assertThat(getEvents()).isEmpty(); + } + + public void assertEvents(int eventCount) { + Assertions.assertThat(getEvents()).hasSize(eventCount); + } + + public void assertHasEventWithMessageAndArguments(String message, Object... arguments) { + + Assertions.assertThat(getEvents()).haveAtLeastOne(new Condition<>(event -> { + if (!event.msg().contains(message)) { + return false; + } + if (event.arguments().length != arguments.length) { + return false; + } + for (int i = 0; i < arguments.length; i++) { + if (!String.valueOf(event.arguments()[i]).equals(arguments[i])) { + return false; + } + } + return true; + }, "Event with message containing '%s' and arguments '%s'", message, Arrays.toString(arguments))); + } + } + + private static class TestLoggingEvent { + + private final Level level; + private final Marker marker; + private final String msg; + private final Object[] arguments; + private final Throwable throwable; + + public TestLoggingEvent(Level level, Marker marker, String msg, Object[] arguments, Throwable throwable) { + this.level = level; + this.marker = marker; + this.msg = msg; + this.arguments = arguments; + this.throwable = throwable; + } + + public Level level() { + return level; + } + + public Marker marker() { + return marker; + } + + public String msg() { + return msg; + } + + public Object[] arguments() { + return arguments; + } + + public Throwable throwable() { + return throwable; + } + + @Override + public String toString() { + return String.format( + "TestLoggingEvent[level=%s, marker=%s, msg=%s, arguments=%s, throwable=%s]", + this.level, + this.marker, + this.msg, + Arrays.toString(this.arguments), + this.throwable); + } + } + +} From 4b663d48639633cc64bef0e9cb6292dab6d30e94 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 13 Feb 2023 20:10:02 +0100 Subject: [PATCH 0519/1120] 1480: add trace logger --- .../npm/NpmFormatterStepStateBase.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index f3f8a80fe8..66b1c51009 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -34,6 +34,7 @@ import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.ProcessRunner.LongRunningProcess; import com.diffplug.spotless.ThrowingEx; +import com.diffplug.spotless.TimedLogger; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -41,6 +42,8 @@ abstract class NpmFormatterStepStateBase implements Serializable { private static final Logger logger = LoggerFactory.getLogger(NpmFormatterStepStateBase.class); + private static final TimedLogger timedLogger = TimedLogger.forLogger(logger); + private static final long serialVersionUID = 1460749955865959948L; @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") @@ -61,26 +64,24 @@ protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFor protected void prepareNodeServerLayout() throws IOException { final long started = System.currentTimeMillis(); - // maybe introduce trace logger? - logger.info("Preparing {} for npm step {}.", this.nodeServerLayout, getClass().getName()); - NpmResourceHelper.assertDirectoryExists(nodeServerLayout.nodeModulesDir()); - NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.packageJsonFile(), - this.npmConfig.getPackageJsonContent()); - NpmResourceHelper - .writeUtf8StringToFile(nodeServerLayout.serveJsFile(), this.npmConfig.getServeScriptContent()); - if (this.npmConfig.getNpmrcContent() != null) { - NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.npmrcFile(), this.npmConfig.getNpmrcContent()); - } else { - NpmResourceHelper.deleteFileIfExists(nodeServerLayout.npmrcFile()); - } - logger.info("Prepared {} for npm step {} in {} ms.", this.nodeServerLayout, getClass().getName(), System.currentTimeMillis() - started); + + timedLogger.withInfo("Preparing {} for npm step {}.", this.nodeServerLayout, getClass().getName()).run(() -> { + NpmResourceHelper.assertDirectoryExists(nodeServerLayout.nodeModulesDir()); + NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.packageJsonFile(), + this.npmConfig.getPackageJsonContent()); + NpmResourceHelper + .writeUtf8StringToFile(nodeServerLayout.serveJsFile(), this.npmConfig.getServeScriptContent()); + if (this.npmConfig.getNpmrcContent() != null) { + NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.npmrcFile(), this.npmConfig.getNpmrcContent()); + } else { + NpmResourceHelper.deleteFileIfExists(nodeServerLayout.npmrcFile()); + } + }); } protected void prepareNodeServer() throws IOException { - final long started = System.currentTimeMillis(); - logger.info("running npm install in {} for npm step {}", this.nodeServerLayout.nodeModulesDir(), getClass().getName()); - runNpmInstall(nodeServerLayout.nodeModulesDir()); - logger.info("npm install finished in {} ms in {} for npm step {}", System.currentTimeMillis() - started, this.nodeServerLayout.nodeModulesDir(), getClass().getName()); + timedLogger.withInfo("Running npm install in {} for npm step {}.", this.nodeServerLayout.nodeModulesDir(), getClass().getName()) + .run(() -> runNpmInstall(nodeServerLayout.nodeModulesDir())); } private void runNpmInstall(File npmProjectDir) throws IOException { From 050bb4503d9015717fd072024f51d0567b86bee5 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 13 Feb 2023 20:26:00 +0100 Subject: [PATCH 0520/1120] 1480: extract npm process as interface to allow introducing another implementation --- .../npm/NpmFormatterStepStateBase.java | 4 +- .../com/diffplug/spotless/npm/NpmProcess.java | 94 +-------------- .../spotless/npm/StandardNpmProcess.java | 112 ++++++++++++++++++ 3 files changed, 118 insertions(+), 92 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcess.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 66b1c51009..140aff048e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -85,7 +85,7 @@ protected void prepareNodeServer() throws IOException { } private void runNpmInstall(File npmProjectDir) throws IOException { - new NpmProcess(npmProjectDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).install(); + new StandardNpmProcess(npmProjectDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).install(); } protected void assertNodeServerDirReady() throws IOException { @@ -116,7 +116,7 @@ protected ServerProcessInfo npmRunServer() throws ServerStartException, IOExcept final File serverPortFile = new File(this.nodeServerLayout.nodeModulesDir(), "server.port"); NpmResourceHelper.deleteFileIfExists(serverPortFile); // start the http server in node - server = new NpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); + server = new StandardNpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); // await the readiness of the http server - wait for at most 60 seconds try { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index 6384900d82..1459d3fc6f 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * 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. @@ -15,96 +15,10 @@ */ package com.diffplug.spotless.npm; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; - import com.diffplug.spotless.ProcessRunner; -import com.diffplug.spotless.ProcessRunner.LongRunningProcess; - -class NpmProcess { - - private final File workingDir; - - private final File npmExecutable; - - private final File nodeExecutable; - - private final ProcessRunner processRunner; - - NpmProcess(File workingDir, File npmExecutable, File nodeExecutable) { - this.workingDir = workingDir; - this.npmExecutable = npmExecutable; - this.nodeExecutable = nodeExecutable; - processRunner = ProcessRunner.usingRingBuffersOfCapacity(100 * 1024); // 100kB - } - - void install() { - npmAwait("install", - "--no-audit", - "--no-package-lock", - "--no-fund", - "--prefer-offline"); - } - - LongRunningProcess start() { - // adding --scripts-prepend-node-path=true due to https://github.com/diffplug/spotless/issues/619#issuecomment-648018679 - return npm("start", "--scripts-prepend-node-path=true"); - } - - private void npmAwait(String... args) { - try (LongRunningProcess npmProcess = npm(args)) { - if (npmProcess.waitFor() != 0) { - throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed with exit code: " + npmProcess.exitValue() + "\n\n" + npmProcess.result()); - } - } catch (InterruptedException e) { - throw new NpmProcessException("Running npm command '" + commandLine(args) + "' was interrupted.", e); - } catch (ExecutionException e) { - throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed.", e); - } - } - - private LongRunningProcess npm(String... args) { - List processCommand = processCommand(args); - try { - return processRunner.start(this.workingDir, environmentVariables(), null, true, processCommand); - } catch (IOException e) { - throw new NpmProcessException("Failed to launch npm command '" + commandLine(args) + "'.", e); - } - } - - private List processCommand(String... args) { - List command = new ArrayList<>(args.length + 1); - command.add(this.npmExecutable.getAbsolutePath()); - command.addAll(Arrays.asList(args)); - return command; - } - - private Map environmentVariables() { - Map environmentVariables = new HashMap<>(); - environmentVariables.put("PATH", this.nodeExecutable.getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); - return environmentVariables; - } - - private String commandLine(String... args) { - return "npm " + Arrays.stream(args).collect(Collectors.joining(" ")); - } - - static class NpmProcessException extends RuntimeException { - private static final long serialVersionUID = 6424331316676759525L; - public NpmProcessException(String message) { - super(message); - } +interface NpmProcess { + void install(); - public NpmProcessException(String message, Throwable cause) { - super(message, cause); - } - } + ProcessRunner.LongRunningProcess start(); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcess.java new file mode 100644 index 0000000000..7524be4e74 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcess.java @@ -0,0 +1,112 @@ +/* + * 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. + * 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.npm; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import com.diffplug.spotless.ProcessRunner; +import com.diffplug.spotless.ProcessRunner.LongRunningProcess; + +class StandardNpmProcess implements NpmProcess { + + private final File workingDir; + + private final File npmExecutable; + + private final File nodeExecutable; + + private final ProcessRunner processRunner; + + StandardNpmProcess(File workingDir, File npmExecutable, File nodeExecutable) { + this.workingDir = workingDir; + this.npmExecutable = npmExecutable; + this.nodeExecutable = nodeExecutable; + processRunner = ProcessRunner.usingRingBuffersOfCapacity(100 * 1024); // 100kB + } + + @Override + public void install() { + npmAwait("install", + "--no-audit", + "--no-package-lock", + "--no-fund", + "--prefer-offline"); + } + + @Override + public LongRunningProcess start() { + // adding --scripts-prepend-node-path=true due to https://github.com/diffplug/spotless/issues/619#issuecomment-648018679 + return npm("start", "--scripts-prepend-node-path=true"); + } + + private void npmAwait(String... args) { + try (LongRunningProcess npmProcess = npm(args)) { + if (npmProcess.waitFor() != 0) { + throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed with exit code: " + npmProcess.exitValue() + "\n\n" + npmProcess.result()); + } + } catch (InterruptedException e) { + throw new NpmProcessException("Running npm command '" + commandLine(args) + "' was interrupted.", e); + } catch (ExecutionException e) { + throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed.", e); + } + } + + private LongRunningProcess npm(String... args) { + List processCommand = processCommand(args); + try { + return processRunner.start(this.workingDir, environmentVariables(), null, true, processCommand); + } catch (IOException e) { + throw new NpmProcessException("Failed to launch npm command '" + commandLine(args) + "'.", e); + } + } + + private List processCommand(String... args) { + List command = new ArrayList<>(args.length + 1); + command.add(this.npmExecutable.getAbsolutePath()); + command.addAll(Arrays.asList(args)); + return command; + } + + private Map environmentVariables() { + Map environmentVariables = new HashMap<>(); + environmentVariables.put("PATH", this.nodeExecutable.getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); + return environmentVariables; + } + + private String commandLine(String... args) { + return "npm " + Arrays.stream(args).collect(Collectors.joining(" ")); + } + + static class NpmProcessException extends RuntimeException { + private static final long serialVersionUID = 6424331316676759525L; + + public NpmProcessException(String message) { + super(message); + } + + public NpmProcessException(String message, Throwable cause) { + super(message, cause); + } + } +} From e724d884fa05bc41d9a4cf2a22693b1522a732b7 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 14 Feb 2023 20:48:19 +0100 Subject: [PATCH 0521/1120] 1480: extract NpmApp and npm exec calls so they can be overwritten later for pnpm --- .../com/diffplug/spotless/TimedLogger.java | 6 + .../spotless/npm/EslintFormatterStep.java | 1 - .../com/diffplug/spotless/npm/NodeApp.java | 81 +++++++++++++ .../diffplug/spotless/npm/NodeServeApp.java | 41 +++++++ .../com/diffplug/spotless/npm/NpmConfig.java | 17 +-- .../npm/NpmFormatterStepStateBase.java | 33 ++---- .../com/diffplug/spotless/npm/NpmProcess.java | 35 +++++- .../spotless/npm/NpmProcessFactory.java | 27 +++++ .../spotless/npm/PrettierFormatterStep.java | 1 - .../spotless/npm/StandardNpmProcess.java | 112 ------------------ .../npm/StandardNpmProcessFactory.java | 104 ++++++++++++++++ .../spotless/npm/TsFmtFormatterStep.java | 1 - .../diffplug/spotless/TimedLoggerTest.java | 14 +++ 13 files changed, 320 insertions(+), 153 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java delete mode 100644 lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcess.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java diff --git a/lib/src/main/java/com/diffplug/spotless/TimedLogger.java b/lib/src/main/java/com/diffplug/spotless/TimedLogger.java index f67d90c0ea..f009a000f5 100644 --- a/lib/src/main/java/com/diffplug/spotless/TimedLogger.java +++ b/lib/src/main/java/com/diffplug/spotless/TimedLogger.java @@ -192,6 +192,12 @@ public void run(ThrowingEx.Runnable r) { } } + public T call(ThrowingEx.Supplier s) { + try (Timed ignore = timed()) { + return ThrowingEx.get(s); + } + } + public void runChecked(ThrowingEx.Runnable r) throws Exception { try (Timed ignore = timed()) { r.run(); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index b262bb4b98..89a1bbddaa 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -95,7 +95,6 @@ private static class State extends NpmFormatterStepStateBase implements Serializ replaceDevDependencies( NpmResourceHelper.readUtf8StringFromClasspath(EslintFormatterStep.class, "/com/diffplug/spotless/npm/eslint-package.json"), new TreeMap<>(devDependencies)), - "eslint", NpmResourceHelper.readUtf8StringFromClasspath(EslintFormatterStep.class, "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/eslint-serve.js"), diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java new file mode 100644 index 0000000000..42e2a2d77d --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java @@ -0,0 +1,81 @@ +/* + * 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.npm; + +import java.util.Objects; + +import javax.annotation.Nonnull; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.TimedLogger; + +public class NodeApp { + + private static final Logger logger = LoggerFactory.getLogger(NodeApp.class); + + private static final TimedLogger timedLogger = TimedLogger.forLogger(logger); + + @Nonnull + protected final NodeServerLayout nodeServerLayout; + + @Nonnull + protected final NpmConfig npmConfig; + + @Nonnull + protected final NpmProcessFactory npmProcessFactory; + + @Nonnull + protected final NpmFormatterStepLocations formatterStepLocations; + + public NodeApp(@Nonnull NodeServerLayout nodeServerLayout, @Nonnull NpmConfig npmConfig, @Nonnull NpmProcessFactory npmProcessFactory, @Nonnull NpmFormatterStepLocations formatterStepLocations) { + this.nodeServerLayout = Objects.requireNonNull(nodeServerLayout); + this.npmConfig = Objects.requireNonNull(npmConfig); + this.npmProcessFactory = Objects.requireNonNull(npmProcessFactory); + this.formatterStepLocations = Objects.requireNonNull(formatterStepLocations); + } + + boolean needsNpmInstall() { + return !this.nodeServerLayout.isNodeModulesPrepared(); + } + + boolean needsPrepareNodeAppLayout() { + return !this.nodeServerLayout.isLayoutPrepared(); + } + + void prepareNodeAppLayout() { + timedLogger.withInfo("Preparing {} for npm step {}.", this.nodeServerLayout, getClass().getName()).run(() -> { + NpmResourceHelper.assertDirectoryExists(nodeServerLayout.nodeModulesDir()); + NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.packageJsonFile(), this.npmConfig.getPackageJsonContent()); + if (this.npmConfig.getServeScriptContent() != null) { + NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.serveJsFile(), this.npmConfig.getServeScriptContent()); + } else { + NpmResourceHelper.deleteFileIfExists(nodeServerLayout.serveJsFile()); + } + if (this.npmConfig.getNpmrcContent() != null) { + NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.npmrcFile(), this.npmConfig.getNpmrcContent()); + } else { + NpmResourceHelper.deleteFileIfExists(nodeServerLayout.npmrcFile()); + } + }); + } + + void npmInstall() { + timedLogger.withInfo("Installing npm dependencies for {} with {}.", this.nodeServerLayout, this.npmProcessFactory.describe()) + .run(() -> npmProcessFactory.createNpmInstallProcess(nodeServerLayout, formatterStepLocations).waitFor()); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java new file mode 100644 index 0000000000..34b2e3d869 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java @@ -0,0 +1,41 @@ +/* + * 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.npm; + +import javax.annotation.Nonnull; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.ProcessRunner; +import com.diffplug.spotless.TimedLogger; + +public class NodeServeApp extends NodeApp { + + private static final Logger logger = LoggerFactory.getLogger(NodeApp.class); + + private static final TimedLogger timedLogger = TimedLogger.forLogger(logger); + + public NodeServeApp(@Nonnull NodeServerLayout nodeServerLayout, @Nonnull NpmConfig npmConfig, @Nonnull NpmProcessFactory npmProcessFactory, @Nonnull NpmFormatterStepLocations formatterStepLocations) { + super(nodeServerLayout, npmConfig, npmProcessFactory, formatterStepLocations); + } + + ProcessRunner.LongRunningProcess startNpmServeProcess() { + return timedLogger.withInfo("Starting npm based server in {} with {}.", this.nodeServerLayout.nodeModulesDir(), this.npmProcessFactory.describe()) + .call(() -> npmProcessFactory.createNpmServeProcess(nodeServerLayout, formatterStepLocations).start()); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmConfig.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmConfig.java index 1492fe7a99..863be41193 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -16,6 +16,7 @@ package com.diffplug.spotless.npm; import java.io.Serializable; +import java.util.Objects; import javax.annotation.Nonnull; @@ -23,30 +24,24 @@ class NpmConfig implements Serializable { private static final long serialVersionUID = 684264546497914877L; + @Nonnull private final String packageJsonContent; - private final String npmModule; - private final String serveScriptContent; private final String npmrcContent; - public NpmConfig(String packageJsonContent, String npmModule, String serveScriptContent, String npmrcContent) { - this.packageJsonContent = packageJsonContent; - this.npmModule = npmModule; + public NpmConfig(@Nonnull String packageJsonContent, String serveScriptContent, String npmrcContent) { + this.packageJsonContent = Objects.requireNonNull(packageJsonContent); this.serveScriptContent = serveScriptContent; this.npmrcContent = npmrcContent; } + @Nonnull public String getPackageJsonContent() { return packageJsonContent; } - public String getNpmModule() { - return npmModule; - } - - @Nonnull public String getServeScriptContent() { return serveScriptContent; } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index 140aff048e..dbb561e54e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -55,37 +55,22 @@ abstract class NpmFormatterStepStateBase implements Serializable { private final String stepName; + private final transient NodeServeApp nodeServeApp; + protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFormatterStepLocations locations) throws IOException { this.stepName = requireNonNull(stepName); this.npmConfig = requireNonNull(npmConfig); this.locations = locations; this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), npmConfig.getPackageJsonContent()); + this.nodeServeApp = new NodeServeApp(nodeServerLayout, npmConfig, new StandardNpmProcessFactory(), locations); } protected void prepareNodeServerLayout() throws IOException { - final long started = System.currentTimeMillis(); - - timedLogger.withInfo("Preparing {} for npm step {}.", this.nodeServerLayout, getClass().getName()).run(() -> { - NpmResourceHelper.assertDirectoryExists(nodeServerLayout.nodeModulesDir()); - NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.packageJsonFile(), - this.npmConfig.getPackageJsonContent()); - NpmResourceHelper - .writeUtf8StringToFile(nodeServerLayout.serveJsFile(), this.npmConfig.getServeScriptContent()); - if (this.npmConfig.getNpmrcContent() != null) { - NpmResourceHelper.writeUtf8StringToFile(nodeServerLayout.npmrcFile(), this.npmConfig.getNpmrcContent()); - } else { - NpmResourceHelper.deleteFileIfExists(nodeServerLayout.npmrcFile()); - } - }); + nodeServeApp.prepareNodeAppLayout(); } protected void prepareNodeServer() throws IOException { - timedLogger.withInfo("Running npm install in {} for npm step {}.", this.nodeServerLayout.nodeModulesDir(), getClass().getName()) - .run(() -> runNpmInstall(nodeServerLayout.nodeModulesDir())); - } - - private void runNpmInstall(File npmProjectDir) throws IOException { - new StandardNpmProcess(npmProjectDir, this.locations.npmExecutable(), this.locations.nodeExecutable()).install(); + nodeServeApp.npmInstall(); } protected void assertNodeServerDirReady() throws IOException { @@ -100,11 +85,11 @@ protected void assertNodeServerDirReady() throws IOException { } protected boolean needsPrepareNodeServer() { - return !this.nodeServerLayout.isNodeModulesPrepared(); + return nodeServeApp.needsNpmInstall(); } protected boolean needsPrepareNodeServerLayout() { - return !this.nodeServerLayout.isLayoutPrepared(); + return nodeServeApp.needsPrepareNodeAppLayout(); } protected ServerProcessInfo npmRunServer() throws ServerStartException, IOException { @@ -116,7 +101,7 @@ protected ServerProcessInfo npmRunServer() throws ServerStartException, IOExcept final File serverPortFile = new File(this.nodeServerLayout.nodeModulesDir(), "server.port"); NpmResourceHelper.deleteFileIfExists(serverPortFile); // start the http server in node - server = new StandardNpmProcess(this.nodeServerLayout.nodeModulesDir(), this.locations.npmExecutable(), this.locations.nodeExecutable()).start(); + server = nodeServeApp.startNpmServeProcess(); // await the readiness of the http server - wait for at most 60 seconds try { @@ -207,7 +192,7 @@ protected static class ServerStartException extends RuntimeException { private static final long serialVersionUID = -8803977379866483002L; public ServerStartException(String message, Throwable cause) { - super(cause); + super(message, cause); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index 1459d3fc6f..be675eecb7 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -15,10 +15,39 @@ */ package com.diffplug.spotless.npm; -import com.diffplug.spotless.ProcessRunner; +import java.util.concurrent.ExecutionException; + +import com.diffplug.spotless.ProcessRunner.LongRunningProcess; +import com.diffplug.spotless.ProcessRunner.Result; interface NpmProcess { - void install(); - ProcessRunner.LongRunningProcess start(); + String describe(); + + LongRunningProcess start(); + + default Result waitFor() { + try (LongRunningProcess npmProcess = start()) { + if (npmProcess.waitFor() != 0) { + throw new NpmProcessException("Running npm command '" + describe() + "' failed with exit code: " + npmProcess.exitValue() + "\n\n" + npmProcess.result()); + } + return npmProcess.result(); + } catch (InterruptedException e) { + throw new NpmProcessException("Running npm command '" + describe() + "' was interrupted.", e); + } catch (ExecutionException e) { + throw new NpmProcessException("Running npm command '" + describe() + "' failed.", e); + } + } + + class NpmProcessException extends RuntimeException { + private static final long serialVersionUID = 6424331316676759525L; + + public NpmProcessException(String message) { + super(message); + } + + public NpmProcessException(String message, Throwable cause) { + super(message, cause); + } + } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java new file mode 100644 index 0000000000..f588792f79 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java @@ -0,0 +1,27 @@ +/* + * 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.npm; + +public interface NpmProcessFactory { + NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations); + + NpmProcess createNpmServeProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations); + + default String describe() { + return getClass().getSimpleName(); + } + +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 05c61f9bdf..b09493792b 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -70,7 +70,6 @@ private static class State extends NpmFormatterStepStateBase implements Serializ replaceDevDependencies( NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/prettier-package.json"), new TreeMap<>(devDependencies)), - "prettier", NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/prettier-serve.js"), diff --git a/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcess.java deleted file mode 100644 index 7524be4e74..0000000000 --- a/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcess.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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. - * 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.npm; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; - -import com.diffplug.spotless.ProcessRunner; -import com.diffplug.spotless.ProcessRunner.LongRunningProcess; - -class StandardNpmProcess implements NpmProcess { - - private final File workingDir; - - private final File npmExecutable; - - private final File nodeExecutable; - - private final ProcessRunner processRunner; - - StandardNpmProcess(File workingDir, File npmExecutable, File nodeExecutable) { - this.workingDir = workingDir; - this.npmExecutable = npmExecutable; - this.nodeExecutable = nodeExecutable; - processRunner = ProcessRunner.usingRingBuffersOfCapacity(100 * 1024); // 100kB - } - - @Override - public void install() { - npmAwait("install", - "--no-audit", - "--no-package-lock", - "--no-fund", - "--prefer-offline"); - } - - @Override - public LongRunningProcess start() { - // adding --scripts-prepend-node-path=true due to https://github.com/diffplug/spotless/issues/619#issuecomment-648018679 - return npm("start", "--scripts-prepend-node-path=true"); - } - - private void npmAwait(String... args) { - try (LongRunningProcess npmProcess = npm(args)) { - if (npmProcess.waitFor() != 0) { - throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed with exit code: " + npmProcess.exitValue() + "\n\n" + npmProcess.result()); - } - } catch (InterruptedException e) { - throw new NpmProcessException("Running npm command '" + commandLine(args) + "' was interrupted.", e); - } catch (ExecutionException e) { - throw new NpmProcessException("Running npm command '" + commandLine(args) + "' failed.", e); - } - } - - private LongRunningProcess npm(String... args) { - List processCommand = processCommand(args); - try { - return processRunner.start(this.workingDir, environmentVariables(), null, true, processCommand); - } catch (IOException e) { - throw new NpmProcessException("Failed to launch npm command '" + commandLine(args) + "'.", e); - } - } - - private List processCommand(String... args) { - List command = new ArrayList<>(args.length + 1); - command.add(this.npmExecutable.getAbsolutePath()); - command.addAll(Arrays.asList(args)); - return command; - } - - private Map environmentVariables() { - Map environmentVariables = new HashMap<>(); - environmentVariables.put("PATH", this.nodeExecutable.getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); - return environmentVariables; - } - - private String commandLine(String... args) { - return "npm " + Arrays.stream(args).collect(Collectors.joining(" ")); - } - - static class NpmProcessException extends RuntimeException { - private static final long serialVersionUID = 6424331316676759525L; - - public NpmProcessException(String message) { - super(message); - } - - public NpmProcessException(String message, Throwable cause) { - super(message, cause); - } - } -} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java new file mode 100644 index 0000000000..393fba98e1 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java @@ -0,0 +1,104 @@ +/* + * 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.npm; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import com.diffplug.spotless.ProcessRunner; + +public class StandardNpmProcessFactory implements NpmProcessFactory { + @Override + public NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations) { + return new NpmInstall(nodeServerLayout.nodeModulesDir(), formatterStepLocations); + } + + @Override + public NpmProcess createNpmServeProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations) { + return new NpmServe(nodeServerLayout.nodeModulesDir(), formatterStepLocations); + } + + private static abstract class AbstractStandardNpmProcess implements NpmProcess { + protected final ProcessRunner processRunner = ProcessRunner.usingRingBuffersOfCapacity(100 * 1024); // 100kB + + protected final File workingDir; + protected final NpmFormatterStepLocations formatterStepLocations; + + public AbstractStandardNpmProcess(File workingDir, NpmFormatterStepLocations formatterStepLocations) { + this.formatterStepLocations = formatterStepLocations; + this.workingDir = workingDir; + } + + protected String npmExecutable() { + return formatterStepLocations.npmExecutable().getAbsolutePath(); + } + + protected abstract List commandLine(); + + protected Map environmentVariables() { + return Map.of( + "PATH", formatterStepLocations.nodeExecutable().getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); + } + + @Override + public ProcessRunner.LongRunningProcess start() { + try { + return processRunner.start(workingDir, environmentVariables(), null, true, commandLine()); + } catch (IOException e) { + throw new NpmProcessException("Failed to launch npm command '" + describe() + "'.", e); + } + } + + @Override + public String describe() { + return String.format("%s in %s [%s]", getClass().getSimpleName(), workingDir, String.join(" ", commandLine())); + } + } + + private static class NpmInstall extends AbstractStandardNpmProcess { + + public NpmInstall(File workingDir, NpmFormatterStepLocations formatterStepLocations) { + super(workingDir, formatterStepLocations); + } + + @Override + protected List commandLine() { + return List.of( + npmExecutable(), + "install", + "--no-audit", + "--no-fund", + "--prefer-offline"); + } + } + + private static class NpmServe extends AbstractStandardNpmProcess { + + public NpmServe(File workingDir, NpmFormatterStepLocations formatterStepLocations) { + super(workingDir, formatterStepLocations); + } + + @Override + protected List commandLine() { + return List.of( + npmExecutable(), + "start", + "--scripts-prepend-node-path=true"); + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index 4bd665c764..c42d8b8361 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -75,7 +75,6 @@ public State(String stepName, Map versions, File projectDir, Fil super(stepName, new NpmConfig( replaceDevDependencies(NpmResourceHelper.readUtf8StringFromClasspath(TsFmtFormatterStep.class, "/com/diffplug/spotless/npm/tsfmt-package.json"), new TreeMap<>(versions)), - "typescript-formatter", NpmResourceHelper.readUtf8StringFromClasspath(PrettierFormatterStep.class, "/com/diffplug/spotless/npm/common-serve.js", "/com/diffplug/spotless/npm/tsfmt-serve.js"), diff --git a/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java b/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java index 167b5d24de..3c84ca09ce 100644 --- a/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java +++ b/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java @@ -134,6 +134,20 @@ void itLogsEvenWhenExceptionsAreThrown() { testLogger.assertHasEventWithMessageAndArguments(MESSAGE_PREFIX_END, "2ms"); } + @Test + void itReturnsValueOfCallableWhileStillLogging() { + String result = timedLogger.withInfo("This should be logged").call(() -> { + testTicker.tickMillis(2); + return "This is the result"; + }); + + Assertions.assertThat(result).isEqualTo("This is the result"); + + testLogger.assertEvents(2); + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_PREFIX_BEGIN); + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_PREFIX_END, "2ms"); + } + private static class TestLogger extends LegacyAbstractLogger { private final List events = new LinkedList<>(); From c2bba799f158e482573ecc123863bec37932c755 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 21 Feb 2023 20:46:32 +0100 Subject: [PATCH 0522/1120] 1480: introduce facility to keep copies of node modules --- .../spotless/npm/NpmResourceHelper.java | 12 ++ .../com/diffplug/spotless/npm/ShadowCopy.java | 171 ++++++++++++++++ .../diffplug/spotless/npm/ShadowCopyTest.java | 193 ++++++++++++++++++ 3 files changed, 376 insertions(+) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java create mode 100644 testlib/src/test/java/com/diffplug/spotless/npm/ShadowCopyTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java index aa66c54fcf..7a28685de0 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java @@ -103,6 +103,18 @@ static void awaitReadableFile(File file, Duration maxWaitTime) throws TimeoutExc if ((System.currentTimeMillis() - startedAt) > maxWaitTime.toMillis()) { throw new TimeoutException("The file did not appear within " + maxWaitTime); } + ThrowingEx.run(() -> Thread.sleep(100)); + } + } + + static void awaitFileDeleted(File file, Duration maxWaitTime) throws TimeoutException { + final long startedAt = System.currentTimeMillis(); + while (file.exists()) { + // wait for at most maxWaitTime + if ((System.currentTimeMillis() - startedAt) > maxWaitTime.toMillis()) { + throw new TimeoutException("The file did not disappear within " + maxWaitTime); + } + ThrowingEx.run(() -> Thread.sleep(100)); } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java b/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java new file mode 100644 index 0000000000..295f8f6017 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java @@ -0,0 +1,171 @@ +/* + * 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.npm; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.FileSystemException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.time.Duration; +import java.util.concurrent.TimeoutException; + +import javax.annotation.Nonnull; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.ThrowingEx; + +class ShadowCopy { + + private static final Logger logger = LoggerFactory.getLogger(ShadowCopy.class); + + private final File shadowCopyRoot; + + public ShadowCopy(@Nonnull File shadowCopyRoot) { + this.shadowCopyRoot = shadowCopyRoot; + if (!shadowCopyRoot.isDirectory()) { + throw new IllegalArgumentException("Shadow copy root must be a directory: " + shadowCopyRoot); + } + } + + public void addEntry(String key, File orig) { + if (!reserveSubFolder(key)) { + logger.debug("Shadow copy entry already on the way: {}. Awaiting finalization.", key); + try { + // maybe make the duration configurable? + NpmResourceHelper.awaitFileDeleted(markerFilePath(key).toFile(), Duration.ofSeconds(120)); + } catch (TimeoutException e) { + throw new RuntimeException(e); + } + } + try { + storeEntry(key, orig); + } finally { + cleanupReservation(key); + } + } + + public File getEntry(String key, String fileName) { + return entry(key, fileName); + } + + private void storeEntry(String key, File orig) { + File target = entry(key, orig.getName()); + if (target.exists()) { + logger.debug("Shadow copy entry already exists: {}", key); + // delete directory "target" recursively + // https://stackoverflow.com/questions/3775694/deleting-folder-from-java + ThrowingEx.run(() -> Files.walkFileTree(target.toPath(), new DeleteDirectoryRecursively())); + } + // copy directory "orig" to "target" using hard links if possible or a plain copy otherwise + ThrowingEx.run(() -> Files.walkFileTree(orig.toPath(), new CopyDirectoryRecursively(target, orig))); + } + + private void cleanupReservation(String key) { + ThrowingEx.run(() -> Files.delete(markerFilePath(key))); + } + + private Path markerFilePath(String key) { + return Paths.get(shadowCopyRoot.getAbsolutePath(), key + ".marker"); + } + + private File entry(String key, String origName) { + return Paths.get(shadowCopyRoot.getAbsolutePath(), key, origName).toFile(); + } + + private boolean reserveSubFolder(String key) { + // put a marker file named "key".marker in "shadowCopyRoot" to make sure no other process is using it or return false if it already exists + try { + Files.createFile(Paths.get(shadowCopyRoot.getAbsolutePath(), key + ".marker")); + return true; + } catch (FileAlreadyExistsException e) { + return false; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public File copyEntryInto(String key, String origName, File targetParentFolder) { + File target = Paths.get(targetParentFolder.getAbsolutePath(), origName).toFile(); + if (target.exists()) { + logger.warn("Shadow copy destination already exists, deleting! {}: {}", key, target); + ThrowingEx.run(() -> Files.walkFileTree(target.toPath(), new DeleteDirectoryRecursively())); + } + // copy directory "orig" to "target" using hard links if possible or a plain copy otherwise + ThrowingEx.run(() -> Files.walkFileTree(entry(key, origName).toPath(), new CopyDirectoryRecursively(target, entry(key, origName)))); + return target; + } + + private static class CopyDirectoryRecursively extends SimpleFileVisitor { + private final File target; + private final File orig; + + private boolean tryHardLink = true; + + public CopyDirectoryRecursively(File target, File orig) { + this.target = target; + this.orig = orig; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + // create directory on target + Files.createDirectories(target.toPath().resolve(orig.toPath().relativize(dir))); + return super.preVisitDirectory(dir, attrs); + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + // first try to hardlink, if that fails, copy + if (tryHardLink) { + try { + Files.createLink(target.toPath().resolve(orig.toPath().relativize(file)), file); + return super.visitFile(file, attrs); + } catch (UnsupportedOperationException | SecurityException | FileSystemException e) { + logger.debug("Shadow copy entry does not support hard links: {}", file, e); + tryHardLink = false; // remember that hard links are not supported + } catch (IOException e) { + logger.debug("Shadow copy entry failed to create hard link: {}", file, e); + tryHardLink = false; // remember that hard links are not supported + } + } + // copy file to target + Files.copy(file, target.toPath().resolve(orig.toPath().relativize(file))); + return super.visitFile(file, attrs); + } + } + + private static class DeleteDirectoryRecursively extends SimpleFileVisitor { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return super.visitFile(file, attrs); + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + Files.delete(dir); + return super.postVisitDirectory(dir, exc); + } + } +} diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/ShadowCopyTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/ShadowCopyTest.java new file mode 100644 index 0000000000..c164b54092 --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/npm/ShadowCopyTest.java @@ -0,0 +1,193 @@ +/* + * 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.npm; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Random; +import java.util.stream.Collectors; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.ResourceHarness; + +class ShadowCopyTest extends ResourceHarness { + + public static final char[] CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray(); + private File shadowCopyRoot; + + private ShadowCopy shadowCopy; + + private final Random random = new Random(); + + @BeforeEach + void setUp() throws IOException { + shadowCopyRoot = newFolder("shadowCopyRoot"); + shadowCopy = new ShadowCopy(shadowCopyRoot); + } + + @Test + void anAddedEntryCanBeRetrieved() throws IOException { + File folderWithRandomFile = newFolderWithRandomFile(); + shadowCopy.addEntry("someEntry", folderWithRandomFile); + File shadowCopyFile = shadowCopy.getEntry("someEntry", folderWithRandomFile.getName()); + Assertions.assertThat(shadowCopyFile.listFiles()).hasSize(folderWithRandomFile.listFiles().length); + assertAllFilesAreEqualButNotSameAbsolutePath(folderWithRandomFile, shadowCopyFile); + } + + @Test + void twoAddedEntriesCanBeRetrieved() throws IOException { + File folderWithRandomFile = newFolderWithRandomFile(); + File folderWithRandomFile2 = newFolderWithRandomFile(); + shadowCopy.addEntry("someEntry", folderWithRandomFile); + shadowCopy.addEntry("someOtherEntry", folderWithRandomFile2); + File shadowCopyFile = shadowCopy.getEntry("someEntry", folderWithRandomFile.getName()); + File shadowCopyFile2 = shadowCopy.getEntry("someOtherEntry", folderWithRandomFile2.getName()); + Assertions.assertThat(shadowCopyFile.listFiles()).hasSize(folderWithRandomFile.listFiles().length); + Assertions.assertThat(shadowCopyFile2.listFiles()).hasSize(folderWithRandomFile2.listFiles().length); + assertAllFilesAreEqualButNotSameAbsolutePath(folderWithRandomFile, shadowCopyFile); + assertAllFilesAreEqualButNotSameAbsolutePath(folderWithRandomFile2, shadowCopyFile2); + } + + @Test + void addingTheSameEntryTwiceWorks() throws IOException { + File folderWithRandomFile = newFolderWithRandomFile(); + shadowCopy.addEntry("someEntry", folderWithRandomFile); + shadowCopy.addEntry("someEntry", folderWithRandomFile); + File shadowCopyFile = shadowCopy.getEntry("someEntry", folderWithRandomFile.getName()); + Assertions.assertThat(shadowCopyFile.listFiles()).hasSize(folderWithRandomFile.listFiles().length); + assertAllFilesAreEqualButNotSameAbsolutePath(folderWithRandomFile, shadowCopyFile); + } + + @Test + void changingAFolderAfterAddingItDoesNotChangeTheShadowCopy() throws IOException { + File folderWithRandomFile = newFolderWithRandomFile(); + shadowCopy.addEntry("someEntry", folderWithRandomFile); + + // now change the orig + Files.delete(folderWithRandomFile.listFiles()[0].toPath()); + File newRandomFile = new File(folderWithRandomFile, "replacedFile.txt"); + writeRandomStringOfLengthToFile(newRandomFile, 100); + + // now check that they are different + File shadowCopy = this.shadowCopy.getEntry("someEntry", folderWithRandomFile.getName()); + Assertions.assertThat(shadowCopy.listFiles()).hasSize(folderWithRandomFile.listFiles().length); + Assertions.assertThat(shadowCopy.listFiles()[0].getName()).isNotEqualTo(folderWithRandomFile.listFiles()[0].getName()); + } + + @Test + void addingTheSameEntryTwiceResultsInSecondEntryBeingRetained() throws IOException { + File folderWithRandomFile = newFolderWithRandomFile(); + shadowCopy.addEntry("someEntry", folderWithRandomFile); + + // now change the orig + Files.delete(folderWithRandomFile.listFiles()[0].toPath()); + File newRandomFile = new File(folderWithRandomFile, "replacedFile.txt"); + writeRandomStringOfLengthToFile(newRandomFile, 100); + + // and then add the same entry with new content again and check that they now are the same again + shadowCopy.addEntry("someEntry", folderWithRandomFile); + File shadowCopyFile = shadowCopy.getEntry("someEntry", folderWithRandomFile.getName()); + Assertions.assertThat(shadowCopyFile.listFiles()).hasSize(folderWithRandomFile.listFiles().length); + assertAllFilesAreEqualButNotSameAbsolutePath(folderWithRandomFile, shadowCopyFile); + } + + @Test + void aFolderCanBeCopiedUsingShadowCopy() throws IOException { + File folderWithRandomFile = newFolderWithRandomFile(); + shadowCopy.addEntry("someEntry", folderWithRandomFile); + File copiedFolder = newFolder("copyDest"); + File copiedEntry = shadowCopy.copyEntryInto("someEntry", folderWithRandomFile.getName(), copiedFolder); + + Assertions.assertThat(copiedEntry.listFiles()).hasSize(folderWithRandomFile.listFiles().length); + assertAllFilesAreEqualButNotSameAbsolutePath(folderWithRandomFile, copiedEntry); + } + + @Test + void aCopiedFolderIsDifferentFromShadowCopyEntry() throws IOException { + File folderWithRandomFile = newFolderWithRandomFile(); + shadowCopy.addEntry("someEntry", folderWithRandomFile); + File copiedFolder = newFolder("copyDest"); + File copiedEntry = shadowCopy.copyEntryInto("someEntry", folderWithRandomFile.getName(), copiedFolder); + + File shadowCopyFile = shadowCopy.getEntry("someEntry", folderWithRandomFile.getName()); + Assertions.assertThat(shadowCopyFile.listFiles()).hasSize(copiedEntry.listFiles().length); + assertAllFilesAreEqualButNotSameAbsolutePath(copiedEntry, shadowCopyFile); + } + + private void assertAllFilesAreEqualButNotSameAbsolutePath(File expected, File actual) { + if (expected.isFile()) { + assertFileIsEqualButNotSameAbsolutePath(expected, actual); + } else { + assertDirectoryIsEqualButNotSameAbsolutePath(expected, actual); + } + } + + private void assertDirectoryIsEqualButNotSameAbsolutePath(File expected, File actual) { + Assertions.assertThat(actual.getAbsolutePath()).as("absolute path should be different").isNotEqualTo(expected.getAbsolutePath()); + Assertions.assertThat(actual.listFiles()).as("folder should have same amount of files").hasSize(expected.listFiles().length); + List actualContent = filesInAlphabeticalOrder(actual); + List expectedContent = filesInAlphabeticalOrder(expected); + + for (int i = 0; i < expectedContent.size(); i++) { + assertAllFilesAreEqualButNotSameAbsolutePath(expectedContent.get(i), actualContent.get(i)); + } + } + + private List filesInAlphabeticalOrder(File folder) { + if (!folder.isDirectory()) { + throw new IllegalArgumentException("folder must be a directory"); + } + return Arrays.stream(folder.listFiles()) + .sorted(Comparator.comparing(File::getName).thenComparing(File::getAbsolutePath)) + .collect(Collectors.toList()); + } + + private void assertFileIsEqualButNotSameAbsolutePath(File expected, File actual) { + Assertions.assertThat(actual).as("Files have same name").hasName(expected.getName()); + Assertions.assertThat(actual.getAbsolutePath()).as("absolute path is different").isNotEqualTo(expected.getAbsolutePath()); + Assertions.assertThat(actual).as("files have same content").hasSameTextualContentAs(expected, StandardCharsets.UTF_8); + } + + private File newFolderWithRandomFile() throws IOException { + File folder = newFolder(randomStringOfLength(10)); + File file = new File(folder, randomStringOfLength(10) + ".txt"); + writeRandomStringOfLengthToFile(file, 10); + return folder; + } + + private void writeRandomStringOfLengthToFile(File file, int length) throws IOException { + Files.write(file.toPath(), randomStringOfLength(length).getBytes(StandardCharsets.UTF_8)); + } + + private String randomStringOfLength(int length) { + // returns a string of length containing characters a-z, A-Z, 0-9 + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < length; i++) { + sb.append(CHARS[random.nextInt(CHARS.length)]); + } + return sb.toString(); + } + +} From 6efa928eb8b933f2d4c3b3536422bc4f5b7a9d5a Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 21 Feb 2023 21:37:28 +0100 Subject: [PATCH 0523/1120] 1480: add caching around npm install --- .../com/diffplug/spotless/TimedLogger.java | 4 +- .../NodeModulesCachingNpmProcessFactory.java | 112 ++++++++++++++++++ .../spotless/npm/NodeServerLayout.java | 4 +- .../npm/NpmFormatterStepStateBase.java | 2 +- .../spotless/npm/NpmLongRunningProcess.java | 26 ++++ .../com/diffplug/spotless/npm/NpmProcess.java | 29 +---- .../spotless/npm/NpmProcessException.java | 28 +++++ .../spotless/npm/NpmProcessFactory.java | 2 +- .../com/diffplug/spotless/npm/ShadowCopy.java | 4 + .../npm/StandardNpmProcessFactory.java | 53 +++++++-- .../diffplug/spotless/npm/ShadowCopyTest.java | 13 ++ 11 files changed, 236 insertions(+), 41 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/NpmLongRunningProcess.java create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java diff --git a/lib/src/main/java/com/diffplug/spotless/TimedLogger.java b/lib/src/main/java/com/diffplug/spotless/TimedLogger.java index f009a000f5..2badd435d2 100644 --- a/lib/src/main/java/com/diffplug/spotless/TimedLogger.java +++ b/lib/src/main/java/com/diffplug/spotless/TimedLogger.java @@ -126,7 +126,9 @@ private String durationString() { if (duration < 1000) { return duration + "ms"; } else if (duration < 1000 * 60) { - return (duration / 1000) + "s"; + long seconds = duration / 1000; + long millis = duration - seconds * 1000; + return seconds + "." + millis + "s"; } else { // output in the format 3m 4.321s long minutes = duration / (1000 * 60); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java new file mode 100644 index 0000000000..69dda788cc --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java @@ -0,0 +1,112 @@ +/* + * 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.npm; + +import java.io.File; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.ProcessRunner.Result; +import com.diffplug.spotless.TimedLogger; + +public class NodeModulesCachingNpmProcessFactory implements NpmProcessFactory { + + private static final Logger logger = LoggerFactory.getLogger(NodeModulesCachingNpmProcessFactory.class); + + private static final TimedLogger timedLogger = TimedLogger.forLogger(logger); + + private final File cacheDir; + + private final ShadowCopy shadowCopy; + + private NodeModulesCachingNpmProcessFactory(File cacheDir) { + this.cacheDir = cacheDir; + assertDir(cacheDir); + this.shadowCopy = new ShadowCopy(cacheDir); + } + + private void assertDir(File cacheDir) { + if (cacheDir.exists() && !cacheDir.isDirectory()) { + throw new IllegalArgumentException("Cache dir must be a directory"); + } + if (!cacheDir.exists()) { + if (!cacheDir.mkdirs()) { + throw new IllegalArgumentException("Cache dir could not be created."); + } + } + } + + public static NodeModulesCachingNpmProcessFactory forCacheDir(File cacheDir) { + return new NodeModulesCachingNpmProcessFactory(cacheDir); + } + + @Override + public NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations) { + NpmProcess actualNpmInstallProcess = StandardNpmProcessFactory.INSTANCE.createNpmInstallProcess(nodeServerLayout, formatterStepLocations); + return new CachingNmpInstall(actualNpmInstallProcess, nodeServerLayout); + } + + @Override + public NpmLongRunningProcess createNpmServeProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations) { + return StandardNpmProcessFactory.INSTANCE.createNpmServeProcess(nodeServerLayout, formatterStepLocations); + } + + private class CachingNmpInstall implements NpmProcess { + + private final NpmProcess actualNpmInstallProcess; + private final NodeServerLayout nodeServerLayout; + + public CachingNmpInstall(NpmProcess actualNpmInstallProcess, NodeServerLayout nodeServerLayout) { + this.actualNpmInstallProcess = actualNpmInstallProcess; + this.nodeServerLayout = nodeServerLayout; + } + + @Override + public Result waitFor() { + String entryName = entryName(); + if (shadowCopy.entryExists(entryName, NodeServerLayout.NODE_MODULES)) { + timedLogger.withInfo("Using cached node_modules for {} from {}", entryName, cacheDir) + .run(() -> shadowCopy.copyEntryInto(entryName(), NodeServerLayout.NODE_MODULES, nodeServerLayout.nodeModulesDir())); + return new CachedResult(); + } else { + Result result = actualNpmInstallProcess.waitFor(); + assert result.exitCode() == 0; + // TODO: maybe spawn a thread to do this in the background? + timedLogger.withInfo("Caching node_modules for {} in {}", entryName, cacheDir) + .run(() -> shadowCopy.addEntry(entryName(), new File(nodeServerLayout.nodeModulesDir(), NodeServerLayout.NODE_MODULES))); + return result; + } + } + + private String entryName() { + return nodeServerLayout.nodeModulesDir().getName(); + } + + @Override + public String describe() { + return String.format("Wrapper around [%s] to cache node_modules in [%s]", actualNpmInstallProcess.describe(), cacheDir.getAbsolutePath()); + } + } + + private class CachedResult extends Result { + + public CachedResult() { + super(List.of("(from cache dir " + cacheDir + ")"), 0, new byte[0], new byte[0]); + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java index 8b39c5e4ab..850ea4eb6b 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java @@ -27,6 +27,7 @@ class NodeServerLayout { private static final Pattern PACKAGE_JSON_NAME_PATTERN = Pattern.compile("\"name\"\\s*:\\s*\"([^\"]+)\""); + static final String NODE_MODULES = "node_modules"; private final File nodeModulesDir; private final File packageJsonFile; @@ -55,7 +56,6 @@ private static String nodeModulesDirName(String packageJsonContent) { } File nodeModulesDir() { - return nodeModulesDir; } @@ -89,7 +89,7 @@ public boolean isLayoutPrepared() { } public boolean isNodeModulesPrepared() { - Path nodeModulesInstallDirPath = new File(nodeModulesDir(), "node_modules").toPath(); + Path nodeModulesInstallDirPath = new File(nodeModulesDir(), NODE_MODULES).toPath(); if (!Files.isDirectory(nodeModulesInstallDirPath)) { return false; } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index dbb561e54e..b92b43d0ef 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -62,7 +62,7 @@ protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFor this.npmConfig = requireNonNull(npmConfig); this.locations = locations; this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), npmConfig.getPackageJsonContent()); - this.nodeServeApp = new NodeServeApp(nodeServerLayout, npmConfig, new StandardNpmProcessFactory(), locations); + this.nodeServeApp = new NodeServeApp(nodeServerLayout, npmConfig, NodeModulesCachingNpmProcessFactory.forCacheDir(new File(locations.buildDir(), "spotless-npm-cache"))/*StandardNpmProcessFactory.INSTANCE*/, locations); } protected void prepareNodeServerLayout() throws IOException { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmLongRunningProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmLongRunningProcess.java new file mode 100644 index 0000000000..f5bece3e06 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmLongRunningProcess.java @@ -0,0 +1,26 @@ +/* + * 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.npm; + +import com.diffplug.spotless.ProcessRunner.LongRunningProcess; + +interface NpmLongRunningProcess { + + String describe(); + + LongRunningProcess start(); + +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java index be675eecb7..473057a769 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java @@ -15,39 +15,12 @@ */ package com.diffplug.spotless.npm; -import java.util.concurrent.ExecutionException; - -import com.diffplug.spotless.ProcessRunner.LongRunningProcess; import com.diffplug.spotless.ProcessRunner.Result; interface NpmProcess { String describe(); - LongRunningProcess start(); - - default Result waitFor() { - try (LongRunningProcess npmProcess = start()) { - if (npmProcess.waitFor() != 0) { - throw new NpmProcessException("Running npm command '" + describe() + "' failed with exit code: " + npmProcess.exitValue() + "\n\n" + npmProcess.result()); - } - return npmProcess.result(); - } catch (InterruptedException e) { - throw new NpmProcessException("Running npm command '" + describe() + "' was interrupted.", e); - } catch (ExecutionException e) { - throw new NpmProcessException("Running npm command '" + describe() + "' failed.", e); - } - } - - class NpmProcessException extends RuntimeException { - private static final long serialVersionUID = 6424331316676759525L; - - public NpmProcessException(String message) { - super(message); - } + Result waitFor(); - public NpmProcessException(String message, Throwable cause) { - super(message, cause); - } - } } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java new file mode 100644 index 0000000000..bff621df07 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java @@ -0,0 +1,28 @@ +/* + * 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.npm; + +public class NpmProcessException extends RuntimeException { + private static final long serialVersionUID = 6424331316676759525L; + + public NpmProcessException(String message) { + super(message); + } + + public NpmProcessException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java index f588792f79..41543a2099 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessFactory.java @@ -18,7 +18,7 @@ public interface NpmProcessFactory { NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations); - NpmProcess createNpmServeProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations); + NpmLongRunningProcess createNpmServeProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations); default String describe() { return getClass().getSimpleName(); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java b/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java index 295f8f6017..82ce1f3ecf 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java @@ -116,6 +116,10 @@ public File copyEntryInto(String key, String origName, File targetParentFolder) return target; } + public boolean entryExists(String key, String origName) { + return entry(key, origName).exists(); + } + private static class CopyDirectoryRecursively extends SimpleFileVisitor { private final File target; private final File orig; diff --git a/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java index 393fba98e1..2c82768da2 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java @@ -19,21 +19,29 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutionException; import com.diffplug.spotless.ProcessRunner; public class StandardNpmProcessFactory implements NpmProcessFactory { + + public static final StandardNpmProcessFactory INSTANCE = new StandardNpmProcessFactory(); + + private StandardNpmProcessFactory() { + // only one instance neeeded + } + @Override public NpmProcess createNpmInstallProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations) { return new NpmInstall(nodeServerLayout.nodeModulesDir(), formatterStepLocations); } @Override - public NpmProcess createNpmServeProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations) { + public NpmLongRunningProcess createNpmServeProcess(NodeServerLayout nodeServerLayout, NpmFormatterStepLocations formatterStepLocations) { return new NpmServe(nodeServerLayout.nodeModulesDir(), formatterStepLocations); } - private static abstract class AbstractStandardNpmProcess implements NpmProcess { + private static abstract class AbstractStandardNpmProcess { protected final ProcessRunner processRunner = ProcessRunner.usingRingBuffersOfCapacity(100 * 1024); // 100kB protected final File workingDir; @@ -55,8 +63,7 @@ protected Map environmentVariables() { "PATH", formatterStepLocations.nodeExecutable().getParentFile().getAbsolutePath() + File.pathSeparator + System.getenv("PATH")); } - @Override - public ProcessRunner.LongRunningProcess start() { + protected ProcessRunner.LongRunningProcess doStart() { try { return processRunner.start(workingDir, environmentVariables(), null, true, commandLine()); } catch (IOException e) { @@ -64,13 +71,14 @@ public ProcessRunner.LongRunningProcess start() { } } - @Override - public String describe() { + protected abstract String describe(); + + public String doDescribe() { return String.format("%s in %s [%s]", getClass().getSimpleName(), workingDir, String.join(" ", commandLine())); } } - private static class NpmInstall extends AbstractStandardNpmProcess { + private static class NpmInstall extends AbstractStandardNpmProcess implements NpmProcess { public NpmInstall(File workingDir, NpmFormatterStepLocations formatterStepLocations) { super(workingDir, formatterStepLocations); @@ -85,9 +93,28 @@ protected List commandLine() { "--no-fund", "--prefer-offline"); } + + @Override + public String describe() { + return doDescribe(); + } + + @Override + public ProcessRunner.Result waitFor() { + try (ProcessRunner.LongRunningProcess npmProcess = doStart()) { + if (npmProcess.waitFor() != 0) { + throw new NpmProcessException("Running npm command '" + describe() + "' failed with exit code: " + npmProcess.exitValue() + "\n\n" + npmProcess.result()); + } + return npmProcess.result(); + } catch (InterruptedException e) { + throw new NpmProcessException("Running npm command '" + describe() + "' was interrupted.", e); + } catch (ExecutionException e) { + throw new NpmProcessException("Running npm command '" + describe() + "' failed.", e); + } + } } - private static class NpmServe extends AbstractStandardNpmProcess { + private static class NpmServe extends AbstractStandardNpmProcess implements NpmLongRunningProcess { public NpmServe(File workingDir, NpmFormatterStepLocations formatterStepLocations) { super(workingDir, formatterStepLocations); @@ -100,5 +127,15 @@ protected List commandLine() { "start", "--scripts-prepend-node-path=true"); } + + @Override + public String describe() { + return doDescribe(); + } + + @Override + public ProcessRunner.LongRunningProcess start() { + return doStart(); + } } } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/ShadowCopyTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/ShadowCopyTest.java index c164b54092..1ef1b77caa 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/ShadowCopyTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/ShadowCopyTest.java @@ -135,6 +135,19 @@ void aCopiedFolderIsDifferentFromShadowCopyEntry() throws IOException { assertAllFilesAreEqualButNotSameAbsolutePath(copiedEntry, shadowCopyFile); } + @Test + void anAddedEntryExistsAfterAdding() throws IOException { + File folderWithRandomFile = newFolderWithRandomFile(); + shadowCopy.addEntry("someEntry", folderWithRandomFile); + Assertions.assertThat(shadowCopy.entryExists("someEntry", folderWithRandomFile.getName())).isTrue(); + } + + @Test + void aEntryThatHasNotBeenAddedDoesNotExist() throws IOException { + File folderWithRandomFile = newFolderWithRandomFile(); + Assertions.assertThat(shadowCopy.entryExists("someEntry", folderWithRandomFile.getName())).isFalse(); + } + private void assertAllFilesAreEqualButNotSameAbsolutePath(File expected, File actual) { if (expected.isFile()) { assertFileIsEqualButNotSameAbsolutePath(expected, actual); From bdceb884fad5f8b7307d809de05f33095a77e0f2 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 22 Feb 2023 06:12:35 +0100 Subject: [PATCH 0524/1120] 1480: improve logging --- .../spotless/npm/NodeModulesCachingNpmProcessFactory.java | 3 ++- lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java | 4 ++-- .../com/diffplug/gradle/spotless/JavascriptExtensionTest.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java index 69dda788cc..e9368b4555 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java @@ -84,7 +84,8 @@ public Result waitFor() { .run(() -> shadowCopy.copyEntryInto(entryName(), NodeServerLayout.NODE_MODULES, nodeServerLayout.nodeModulesDir())); return new CachedResult(); } else { - Result result = actualNpmInstallProcess.waitFor(); + Result result = timedLogger.withInfo("calling actual npm install {}", actualNpmInstallProcess.describe()) + .call(actualNpmInstallProcess::waitFor); assert result.exitCode() == 0; // TODO: maybe spawn a thread to do this in the background? timedLogger.withInfo("Caching node_modules for {} in {}", entryName, cacheDir) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java b/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java index 82ce1f3ecf..8cd4098d82 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java @@ -146,10 +146,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO Files.createLink(target.toPath().resolve(orig.toPath().relativize(file)), file); return super.visitFile(file, attrs); } catch (UnsupportedOperationException | SecurityException | FileSystemException e) { - logger.debug("Shadow copy entry does not support hard links: {}", file, e); + logger.info("Shadow copy entry does not support hard links: {}. Switching to copy.", file, e); tryHardLink = false; // remember that hard links are not supported } catch (IOException e) { - logger.debug("Shadow copy entry failed to create hard link: {}", file, e); + logger.info("Shadow copy entry failed to create hard link: {}. Switching to copy.", file, e); tryHardLink = false; // remember that hard links are not supported } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java index 26354b93be..f1b00706d3 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavascriptExtensionTest.java @@ -178,7 +178,7 @@ void formattingUsingStyleguide(String styleguide) throws Exception { " }", "}"); setFile("test.js").toResource(styleguidePath + "javascript-es6.dirty"); - gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + gradleRunner().forwardOutput().withArguments("--info", "--stacktrace", "spotlessApply").build(); assertFile("test.js").sameAsResource(styleguidePath + "javascript-es6.clean"); } } From e97764ff2152c6ab29daa7fc5b445d59fe675cf5 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 24 Feb 2023 06:03:23 +0100 Subject: [PATCH 0525/1120] 1480: allow dynamic npmInstall process based on cacheDir --- .../spotless/npm/EslintFormatterStep.java | 7 ++++--- .../com/diffplug/spotless/npm/NodeApp.java | 13 +++++++++++-- .../NodeModulesCachingNpmProcessFactory.java | 18 ++++++++++++------ .../diffplug/spotless/npm/NodeServeApp.java | 4 ++-- .../npm/NpmFormatterStepLocations.java | 12 +++++++++++- .../npm/NpmFormatterStepStateBase.java | 2 +- .../spotless/npm/PrettierFormatterStep.java | 7 ++++--- .../spotless/npm/TsFmtFormatterStep.java | 7 ++++--- .../spotless/npm/EslintFormatterStepTest.java | 3 +++ .../npm/NpmFormatterStepCommonTests.java | 9 +++++++++ .../npm/PrettierFormatterStepTest.java | 5 +++++ .../spotless/npm/TsFmtFormatterStepTest.java | 2 ++ 12 files changed, 68 insertions(+), 21 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index 89a1bbddaa..e1055731a8 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -71,13 +71,13 @@ public static Map defaultDevDependenciesWithEslint(String versio return Collections.singletonMap("eslint", version); } - public static FormatterStep create(Map devDependencies, Provisioner provisioner, File projectDir, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) { + public static FormatterStep create(Map devDependencies, Provisioner provisioner, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) { requireNonNull(devDependencies); requireNonNull(provisioner); requireNonNull(projectDir); requireNonNull(buildDir); return FormatterStep.createLazy(NAME, - () -> new State(NAME, devDependencies, projectDir, buildDir, npmPathResolver, eslintConfig), + () -> new State(NAME, devDependencies, projectDir, buildDir, cacheDir, npmPathResolver, eslintConfig), State::createFormatterFunc); } @@ -89,7 +89,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") private transient EslintConfig eslintConfigInUse; - State(String stepName, Map devDependencies, File projectDir, File buildDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { + State(String stepName, Map devDependencies, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, EslintConfig eslintConfig) throws IOException { super(stepName, new NpmConfig( replaceDevDependencies( @@ -102,6 +102,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ new NpmFormatterStepLocations( projectDir, buildDir, + cacheDir, npmPathResolver::resolveNpmExecutable, npmPathResolver::resolveNodeExecutable)); this.origEslintConfig = requireNonNull(eslintConfig.verify()); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java index 42e2a2d77d..50ce8ccc5c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java @@ -42,13 +42,22 @@ public class NodeApp { @Nonnull protected final NpmFormatterStepLocations formatterStepLocations; - public NodeApp(@Nonnull NodeServerLayout nodeServerLayout, @Nonnull NpmConfig npmConfig, @Nonnull NpmProcessFactory npmProcessFactory, @Nonnull NpmFormatterStepLocations formatterStepLocations) { + public NodeApp(@Nonnull NodeServerLayout nodeServerLayout, @Nonnull NpmConfig npmConfig, @Nonnull NpmFormatterStepLocations formatterStepLocations) { this.nodeServerLayout = Objects.requireNonNull(nodeServerLayout); this.npmConfig = Objects.requireNonNull(npmConfig); - this.npmProcessFactory = Objects.requireNonNull(npmProcessFactory); + this.npmProcessFactory = processFactory(formatterStepLocations); this.formatterStepLocations = Objects.requireNonNull(formatterStepLocations); } + private static NpmProcessFactory processFactory(NpmFormatterStepLocations formatterStepLocations) { + if (formatterStepLocations.cacheDir() != null) { + logger.info("Caching npm install results in {}.", formatterStepLocations.cacheDir()); + return NodeModulesCachingNpmProcessFactory.create(formatterStepLocations.cacheDir()); + } + logger.debug("Not caching npm install results."); + return StandardNpmProcessFactory.INSTANCE; + } + boolean needsNpmInstall() { return !this.nodeServerLayout.isNodeModulesPrepared(); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java index e9368b4555..a995aac59f 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java @@ -17,6 +17,9 @@ import java.io.File; import java.util.List; +import java.util.Objects; + +import javax.annotation.Nonnull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,8 +37,8 @@ public class NodeModulesCachingNpmProcessFactory implements NpmProcessFactory { private final ShadowCopy shadowCopy; - private NodeModulesCachingNpmProcessFactory(File cacheDir) { - this.cacheDir = cacheDir; + private NodeModulesCachingNpmProcessFactory(@Nonnull File cacheDir) { + this.cacheDir = Objects.requireNonNull(cacheDir); assertDir(cacheDir); this.shadowCopy = new ShadowCopy(cacheDir); } @@ -51,7 +54,7 @@ private void assertDir(File cacheDir) { } } - public static NodeModulesCachingNpmProcessFactory forCacheDir(File cacheDir) { + public static NodeModulesCachingNpmProcessFactory create(@Nonnull File cacheDir) { return new NodeModulesCachingNpmProcessFactory(cacheDir); } @@ -87,13 +90,16 @@ public Result waitFor() { Result result = timedLogger.withInfo("calling actual npm install {}", actualNpmInstallProcess.describe()) .call(actualNpmInstallProcess::waitFor); assert result.exitCode() == 0; - // TODO: maybe spawn a thread to do this in the background? - timedLogger.withInfo("Caching node_modules for {} in {}", entryName, cacheDir) - .run(() -> shadowCopy.addEntry(entryName(), new File(nodeServerLayout.nodeModulesDir(), NodeServerLayout.NODE_MODULES))); + storeShadowCopy(entryName); return result; } } + private void storeShadowCopy(String entryName) { + timedLogger.withInfo("Caching node_modules for {} in {}", entryName, cacheDir) + .run(() -> shadowCopy.addEntry(entryName(), new File(nodeServerLayout.nodeModulesDir(), NodeServerLayout.NODE_MODULES))); + } + private String entryName() { return nodeServerLayout.nodeModulesDir().getName(); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java index 34b2e3d869..d811515971 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java @@ -29,8 +29,8 @@ public class NodeServeApp extends NodeApp { private static final TimedLogger timedLogger = TimedLogger.forLogger(logger); - public NodeServeApp(@Nonnull NodeServerLayout nodeServerLayout, @Nonnull NpmConfig npmConfig, @Nonnull NpmProcessFactory npmProcessFactory, @Nonnull NpmFormatterStepLocations formatterStepLocations) { - super(nodeServerLayout, npmConfig, npmProcessFactory, formatterStepLocations); + public NodeServeApp(@Nonnull NodeServerLayout nodeServerLayout, @Nonnull NpmConfig npmConfig, @Nonnull NpmFormatterStepLocations formatterStepLocations) { + super(nodeServerLayout, npmConfig, formatterStepLocations); } ProcessRunner.LongRunningProcess startNpmServeProcess() { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java index 0e99e1afab..67763e59ec 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepLocations.java @@ -21,6 +21,8 @@ import java.io.Serializable; import java.util.function.Supplier; +import javax.annotation.Nonnull; + import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; class NpmFormatterStepLocations implements Serializable { @@ -32,15 +34,19 @@ class NpmFormatterStepLocations implements Serializable { @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") private final transient File buildDir; + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + private final transient File cacheDir; + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") private final transient Supplier npmExecutable; @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") private final transient Supplier nodeExecutable; - public NpmFormatterStepLocations(File projectDir, File buildDir, Supplier npmExecutable, Supplier nodeExecutable) { + public NpmFormatterStepLocations(@Nonnull File projectDir, @Nonnull File buildDir, File cacheDir, @Nonnull Supplier npmExecutable, @Nonnull Supplier nodeExecutable) { this.projectDir = requireNonNull(projectDir); this.buildDir = requireNonNull(buildDir); + this.cacheDir = cacheDir; this.npmExecutable = requireNonNull(npmExecutable); this.nodeExecutable = requireNonNull(nodeExecutable); } @@ -53,6 +59,10 @@ public File buildDir() { return buildDir; } + public File cacheDir() { + return cacheDir; + } + public File npmExecutable() { return npmExecutable.get(); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index b92b43d0ef..e4a8dd0fcb 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -62,7 +62,7 @@ protected NpmFormatterStepStateBase(String stepName, NpmConfig npmConfig, NpmFor this.npmConfig = requireNonNull(npmConfig); this.locations = locations; this.nodeServerLayout = new NodeServerLayout(locations.buildDir(), npmConfig.getPackageJsonContent()); - this.nodeServeApp = new NodeServeApp(nodeServerLayout, npmConfig, NodeModulesCachingNpmProcessFactory.forCacheDir(new File(locations.buildDir(), "spotless-npm-cache"))/*StandardNpmProcessFactory.INSTANCE*/, locations); + this.nodeServeApp = new NodeServeApp(nodeServerLayout, npmConfig, locations); } protected void prepareNodeServerLayout() throws IOException { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index b09493792b..afd490b63b 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -50,12 +50,12 @@ public static final Map defaultDevDependenciesWithPrettier(Strin return Collections.singletonMap("prettier", version); } - public static FormatterStep create(Map devDependencies, Provisioner provisioner, File projectDir, File buildDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) { + public static FormatterStep create(Map devDependencies, Provisioner provisioner, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) { requireNonNull(devDependencies); requireNonNull(provisioner); requireNonNull(buildDir); return FormatterStep.createLazy(NAME, - () -> new State(NAME, devDependencies, projectDir, buildDir, npmPathResolver, prettierConfig), + () -> new State(NAME, devDependencies, projectDir, buildDir, cacheDir, npmPathResolver, prettierConfig), State::createFormatterFunc); } @@ -64,7 +64,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ private static final long serialVersionUID = -539537027004745812L; private final PrettierConfig prettierConfig; - State(String stepName, Map devDependencies, File projectDir, File buildDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) throws IOException { + State(String stepName, Map devDependencies, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, PrettierConfig prettierConfig) throws IOException { super(stepName, new NpmConfig( replaceDevDependencies( @@ -77,6 +77,7 @@ private static class State extends NpmFormatterStepStateBase implements Serializ new NpmFormatterStepLocations( projectDir, buildDir, + cacheDir, npmPathResolver::resolveNpmExecutable, npmPathResolver::resolveNodeExecutable)); this.prettierConfig = requireNonNull(prettierConfig); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java index c42d8b8361..a83c3e202a 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java @@ -40,11 +40,11 @@ public class TsFmtFormatterStep { public static final String NAME = "tsfmt-format"; - public static FormatterStep create(Map versions, Provisioner provisioner, File projectDir, File buildDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) { + public static FormatterStep create(Map versions, Provisioner provisioner, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) { requireNonNull(provisioner); requireNonNull(buildDir); return FormatterStep.createLazy(NAME, - () -> new State(NAME, versions, projectDir, buildDir, npmPathResolver, configFile, inlineTsFmtSettings), + () -> new State(NAME, versions, projectDir, buildDir, cacheDir, npmPathResolver, configFile, inlineTsFmtSettings), State::createFormatterFunc); } @@ -71,7 +71,7 @@ public static class State extends NpmFormatterStepStateBase implements Serializa @Nullable private final TypedTsFmtConfigFile configFile; - public State(String stepName, Map versions, File projectDir, File buildDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) throws IOException { + public State(String stepName, Map versions, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map inlineTsFmtSettings) throws IOException { super(stepName, new NpmConfig( replaceDevDependencies(NpmResourceHelper.readUtf8StringFromClasspath(TsFmtFormatterStep.class, "/com/diffplug/spotless/npm/tsfmt-package.json"), new TreeMap<>(versions)), @@ -82,6 +82,7 @@ public State(String stepName, Map versions, File projectDir, Fil new NpmFormatterStepLocations( projectDir, buildDir, + cacheDir, npmPathResolver::resolveNpmExecutable, npmPathResolver::resolveNodeExecutable)); this.buildDir = requireNonNull(buildDir); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index 1bc0915ed3..fe1f33ccc6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -64,6 +64,7 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), + cacheDir(), npmPathResolver(), new EslintConfig(eslintRc, null)); @@ -107,6 +108,7 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), + cacheDir(), npmPathResolver(), new EslintTypescriptConfig(eslintRc, null, tsconfigFile)); @@ -164,6 +166,7 @@ void formattingUsingInlineXoConfig() throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), + cacheDir(), npmPathResolver(), new EslintTypescriptConfig(null, esLintConfig, tsconfigFile)); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java index 60dd42801a..93e70b4129 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java @@ -56,4 +56,13 @@ protected File projectDir() throws IOException { } return this.projectDir; } + + private File cacheDir = null; + + protected File cacheDir() throws IOException { + if (this.cacheDir == null) { + this.cacheDir = newFolder("cache-dir"); + } + return this.cacheDir; + } } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index acc756fa31..d308e6085a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -52,6 +52,7 @@ void formattingUsingConfigFile(String fileType) throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), + cacheDir(), npmPathResolver(), new PrettierConfig(prettierRc, null)); @@ -77,6 +78,7 @@ void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), + cacheDir(), npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("filepath", "anyname.json"))); // should select parser based on this name @@ -97,6 +99,7 @@ void parserInferenceBasedOnFilenameIsWorking() throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), + cacheDir(), npmPathResolver(), new PrettierConfig(null, Collections.emptyMap())); @@ -112,6 +115,7 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), + cacheDir(), npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { @@ -137,6 +141,7 @@ void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exc TestProvisioner.mavenCentral(), projectDir(), buildDir(), + cacheDir(), npmPathResolver(), config); // should select parser based on this name diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java index a774c7c1ee..9233239443 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java @@ -59,6 +59,7 @@ void formattingUsingConfigFile(String formattingConfigFile) throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), + cacheDir(), npmPathResolver(), TypedTsFmtConfigFile.named(configFileNameWithoutExtension, configFile), Collections.emptyMap()); @@ -82,6 +83,7 @@ void formattingUsingInlineConfigWorks() throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), + cacheDir(), npmPathResolver(), null, inlineConfig); From 6f0dd0b27172ff5830fa93ecb84525305275f414 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 24 Feb 2023 06:05:14 +0100 Subject: [PATCH 0526/1120] 1480: add npmInstallCache to api --- .../gradle/spotless/FormatExtension.java | 20 +++++++++++++++++++ .../gradle/spotless/JavascriptExtension.java | 1 + .../gradle/spotless/TypescriptExtension.java | 2 ++ .../spotless/maven/generic/Prettier.java | 3 ++- .../maven/javascript/AbstractEslint.java | 3 ++- .../npm/AbstractNpmFormatterStepFactory.java | 14 +++++++++++++ .../spotless/maven/typescript/Tsfmt.java | 3 ++- 7 files changed, 43 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 8012102200..c42d340b8b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -528,6 +528,9 @@ public abstract static class NpmStepConfig> { @Nullable protected Object nodeFile; + @Nullable + protected Object npmInstallCache; + @Nullable protected Object npmrcFile; @@ -560,6 +563,18 @@ public T npmrc(final Object npmrcFile) { return (T) this; } + public T npmInstallCache(final Object npmInstallCache) { + this.npmInstallCache = npmInstallCache; + replaceStep(); + return (T) this; + } + + public T npmInstallCache() { + this.npmInstallCache = new File(project.getBuildDir(), "spotless-npm-install-cache"); + replaceStep(); + return (T) this; + } + File npmFileOrNull() { return fileOrNull(npmFile); } @@ -572,6 +587,10 @@ File npmrcFileOrNull() { return fileOrNull(npmrcFile); } + File npmModulesCacheOrNull() { + return fileOrNull(npmInstallCache); + } + private File fileOrNull(Object npmFile) { return npmFile != null ? project.file(npmFile) : null; } @@ -619,6 +638,7 @@ protected FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), + npmModulesCacheOrNull(), new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), new com.diffplug.spotless.npm.PrettierConfig( this.prettierConfigFile != null ? project.file(this.prettierConfigFile) : null, diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index e829c2b53a..e8a76166bc 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -108,6 +108,7 @@ public FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), + npmModulesCacheOrNull(), new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index a11f1b0c39..0e1e04bd02 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -117,6 +117,7 @@ public FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), + npmModulesCacheOrNull(), new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), typedConfigFile(), config); @@ -213,6 +214,7 @@ public FormatterStep createStep() { provisioner(), project.getProjectDir(), project.getBuildDir(), + npmModulesCacheOrNull(), new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index 01ce2a5394..e92b2814bd 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -95,9 +95,10 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { // create the format step File baseDir = baseDir(stepConfig); File buildDir = buildDir(stepConfig); + File cacheDir = cacheDir(stepConfig); PrettierConfig prettierConfig = new PrettierConfig(configFileHandler, configInline); NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); - return PrettierFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, prettierConfig); + return PrettierFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, cacheDir, npmPathResolver, prettierConfig); } private static IllegalArgumentException onlyOneConfig() { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java index b06d3079e7..ad113de833 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/AbstractEslint.java @@ -67,8 +67,9 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File buildDir = buildDir(stepConfig); File baseDir = baseDir(stepConfig); + File cacheDir = cacheDir(stepConfig); NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); - return EslintFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, eslintConfig(stepConfig)); + return EslintFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, cacheDir, npmPathResolver, eslintConfig(stepConfig)); } private static IllegalArgumentException onlyOneConfig() { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java index e4a052106a..9e184045bb 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java @@ -19,6 +19,7 @@ import java.util.AbstractMap; import java.util.Arrays; import java.util.Collections; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Properties; @@ -41,6 +42,9 @@ public abstract class AbstractNpmFormatterStepFactory implements FormatterStepFa @Parameter private String npmrc; + @Parameter + private String npmInstallCache; + protected File npm(FormatterStepConfig stepConfig) { File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; return npm; @@ -60,6 +64,16 @@ protected File buildDir(FormatterStepConfig stepConfig) { return stepConfig.getFileLocator().getBuildDir(); } + protected File cacheDir(FormatterStepConfig stepConfig) { + if (this.npmInstallCache == null) { + return null; + } + if ("true".equals(this.npmInstallCache.toLowerCase(Locale.ROOT))) { + return new File(buildDir(stepConfig), "spotless-npm-install-cache"); + } + return stepConfig.getFileLocator().locateFile(this.npmInstallCache); + } + protected File baseDir(FormatterStepConfig stepConfig) { return stepConfig.getFileLocator().getBaseDir(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java index 685d473072..396c688635 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java @@ -111,8 +111,9 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File buildDir = buildDir(stepConfig); File baseDir = baseDir(stepConfig); + File cacheDir = cacheDir(stepConfig); NpmPathResolver npmPathResolver = npmPathResolver(stepConfig); - return TsFmtFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, npmPathResolver, configFile, configInline); + return TsFmtFormatterStep.create(devDependencies, stepConfig.getProvisioner(), baseDir, buildDir, cacheDir, npmPathResolver, configFile, configInline); } private static IllegalArgumentException onlyOneConfig() { From c2c46bb63e5d140faf3e98b154479dbfe95c5de3 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 24 Feb 2023 06:13:49 +0100 Subject: [PATCH 0527/1120] 1582: cleanup logging --- .../java/com/diffplug/spotless/npm/EslintFormatterStep.java | 5 +---- .../com/diffplug/spotless/npm/PrettierFormatterStep.java | 3 --- lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java | 4 ++-- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java index e1055731a8..a4480fe7fc 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.npm; -import static com.diffplug.spotless.LazyArgLogger.lazy; import static java.util.Objects.requireNonNull; import java.io.File; @@ -116,7 +115,7 @@ protected void prepareNodeServerLayout() throws IOException { // If any config files are provided, we need to make sure they are at the same location as the node modules // as eslint will try to resolve plugin/config names relatively to the config file location and some // eslint configs contain relative paths to additional config files (such as tsconfig.json e.g.) - logger.info("Copying config file <{}> to <{}> and using the copy", origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); + logger.debug("Copying config file <{}> to <{}> and using the copy", origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); File configFileCopy = NpmResourceHelper.copyFileToDir(origEslintConfig.getEslintConfigPath(), nodeServerLayout.nodeModulesDir()); this.eslintConfigInUse = this.origEslintConfig.withEslintConfigPath(configFileCopy).verify(); } @@ -162,8 +161,6 @@ public EslintFilePathPassingFormatterFunc(File projectDir, File nodeModulesDir, @Override public String applyWithFile(String unix, File file) throws Exception { - logger.info("formatting String '{}[...]' in file '{}'", lazy(() -> unix.substring(0, Math.min(50, unix.length()))), file); - Map eslintCallOptions = new HashMap<>(); setConfigToCallOptions(eslintCallOptions); setFilePathToCallOptions(eslintCallOptions, file); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index afd490b63b..11a6230e4c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.npm; -import static com.diffplug.spotless.LazyArgLogger.lazy; import static java.util.Objects.requireNonNull; import java.io.File; @@ -120,8 +119,6 @@ public PrettierFilePathPassingFormatterFunc(String prettierConfigOptions, Pretti @Override public String applyWithFile(String unix, File file) throws Exception { - logger.info("formatting String '{}[...]' in file '{}'", lazy(() -> unix.substring(0, Math.min(50, unix.length()))), file); - final String prettierConfigOptionsWithFilepath = assertFilepathInConfigOptions(file); try { return restService.format(unix, prettierConfigOptionsWithFilepath); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java b/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java index 8cd4098d82..179a1278b1 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java @@ -146,10 +146,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO Files.createLink(target.toPath().resolve(orig.toPath().relativize(file)), file); return super.visitFile(file, attrs); } catch (UnsupportedOperationException | SecurityException | FileSystemException e) { - logger.info("Shadow copy entry does not support hard links: {}. Switching to copy.", file, e); + logger.debug("Shadow copy entry does not support hard links: {}. Switching to 'copy'.", file, e); tryHardLink = false; // remember that hard links are not supported } catch (IOException e) { - logger.info("Shadow copy entry failed to create hard link: {}. Switching to copy.", file, e); + logger.debug("Shadow copy entry failed to create hard link: {}. Switching to 'copy'.", file, e); tryHardLink = false; // remember that hard links are not supported } } From 3a20930672ebeba378bbd3d64132d3acdc3769b6 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 24 Feb 2023 14:44:29 +0100 Subject: [PATCH 0528/1120] 1480: add integration test for gradle side --- .../gradle/spotless/FormatExtension.java | 5 +- .../NpmInstallCacheIntegrationTests.java | 129 ++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index c42d340b8b..fd613e82e1 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -522,6 +522,9 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile, String de } public abstract static class NpmStepConfig> { + + public static final String SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME = "spotless-npm-install-cache"; + @Nullable protected Object npmFile; @@ -570,7 +573,7 @@ public T npmInstallCache(final Object npmInstallCache) { } public T npmInstallCache() { - this.npmInstallCache = new File(project.getBuildDir(), "spotless-npm-install-cache"); + this.npmInstallCache = new File(project.getBuildDir(), SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME); replaceStep(); return (T) this; } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java new file mode 100644 index 0000000000..b4318b8771 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java @@ -0,0 +1,129 @@ +/* + * 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.gradle.spotless; + +import static com.diffplug.gradle.spotless.FormatExtension.NpmStepConfig.SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; + +import org.assertj.core.api.Assertions; +import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import com.diffplug.common.base.Errors; +import com.diffplug.spotless.tag.NpmTest; + +@NpmTest +class NpmInstallCacheIntegrationTests extends GradleIntegrationHarness { + + static File pertainingCacheDir; + + private static final File DEFAULT_DIR_FOR_NPM_INSTALL_CACHE_DO_NEVER_WRITE_TO_THIS = new File("."); + + @BeforeAll + static void beforeAll(@TempDir File pertainingCacheDir) { + NpmInstallCacheIntegrationTests.pertainingCacheDir = Errors.rethrow().get(pertainingCacheDir::getCanonicalFile); + } + + @Test + void prettierWithDefaultInstallCacheTest() throws IOException { + File dir1 = newFolder("npm-prettier-1"); + File cacheDir = DEFAULT_DIR_FOR_NPM_INSTALL_CACHE_DO_NEVER_WRITE_TO_THIS; + BuildResult result = runPhpPrettierOnDir(dir1, cacheDir); + Assertions.assertThat(result.getOutput()) + .doesNotContain("Using cached node_modules for") + .contains("Caching node_modules for ") + .contains(Paths.get(dir1.getAbsolutePath(), "build", SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME).toString()); + + } + + @Test + void prettierWithSpecificInstallCacheTest() throws IOException { + File dir1 = newFolder("npm-prettier-1"); + File cacheDir = newFolder("npm-prettier-cache"); + BuildResult result = runPhpPrettierOnDir(dir1, cacheDir); + Assertions.assertThat(result.getOutput()).doesNotContainPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); + File dir2 = newFolder("npm-prettier-2"); + BuildResult result2 = runPhpPrettierOnDir(dir2, cacheDir); + Assertions.assertThat(result2.getOutput()).containsPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); + } + + @Test + @Order(1) + void prettierWithSpecificGlobalInstallCacheTest() throws IOException { + File dir1 = newFolder("npm-prettier-global-1"); + File cacheDir = pertainingCacheDir; + BuildResult result = runPhpPrettierOnDir(dir1, cacheDir); + Assertions.assertThat(result.getOutput()) + .doesNotContainPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E") + .containsPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); + } + + @Test + @Order(2) + void prettierWithSpecificGlobalInstallCacheTest2() throws IOException { + File dir2 = newFolder("npm-prettier-global-2"); + File cacheDir = pertainingCacheDir; + BuildResult result = runPhpPrettierOnDir(dir2, cacheDir); + Assertions.assertThat(result.getOutput()) + .containsPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E") + .doesNotContainPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); + } + + private BuildResult runPhpPrettierOnDir(File projDir, File cacheDir) throws IOException { + String baseDir = projDir.getName(); + String cacheDirEnabled = cacheDirEnabledStringForCacheDir(cacheDir); + setFile(baseDir + "/build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "def prettierConfig = [:]", + "prettierConfig['tabWidth'] = 3", + "prettierConfig['parser'] = 'php'", + "def prettierPackages = [:]", + "prettierPackages['prettier'] = '2.0.5'", + "prettierPackages['@prettier/plugin-php'] = '0.14.2'", + "spotless {", + " format 'php', {", + " target 'php-example.php'", + " prettier(prettierPackages).config(prettierConfig)" + cacheDirEnabled, + " }", + "}"); + setFile(baseDir + "/php-example.php").toResource("npm/prettier/plugins/php.dirty"); + final BuildResult spotlessApply = gradleRunner().withProjectDir(projDir).withArguments("--stacktrace", "--info", "spotlessApply").build(); + Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile(baseDir + "/php-example.php").sameAsResource("npm/prettier/plugins/php.clean"); + return spotlessApply; + } + + private static String cacheDirEnabledStringForCacheDir(File cacheDir) { + String cacheDirEnabled; + if (cacheDir == null) { + cacheDirEnabled = ""; + } else if (cacheDir == DEFAULT_DIR_FOR_NPM_INSTALL_CACHE_DO_NEVER_WRITE_TO_THIS) { + cacheDirEnabled = ".npmInstallCache()"; + } else { + cacheDirEnabled = ".npmInstallCache('" + cacheDir.getAbsolutePath() + "')"; + } + return cacheDirEnabled; + } +} From 3c4b5bc8e21a9090d816ba2a15f65805afab2799 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 24 Feb 2023 14:57:25 +0100 Subject: [PATCH 0529/1120] 1480: add integration test for tsfmt (and fix api issue) --- .../gradle/spotless/TypescriptExtension.java | 22 +++++---- .../NpmInstallCacheIntegrationTests.java | 48 +++++++++++++++++++ 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 0e1e04bd02..9f1d04abfd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -82,31 +82,33 @@ public class TypescriptFormatExtension extends NpmStepConfig config) { + public TypescriptFormatExtension config(final Map config) { this.config = new TreeMap<>(requireNonNull(config)); replaceStep(); + return this; } - public void tsconfigFile(final Object path) { - configFile(TsConfigFileType.TSCONFIG, path); + public TypescriptFormatExtension tsconfigFile(final Object path) { + return configFile(TsConfigFileType.TSCONFIG, path); } - public void tslintFile(final Object path) { - configFile(TsConfigFileType.TSLINT, path); + public TypescriptFormatExtension tslintFile(final Object path) { + return configFile(TsConfigFileType.TSLINT, path); } - public void vscodeFile(final Object path) { - configFile(TsConfigFileType.VSCODE, path); + public TypescriptFormatExtension vscodeFile(final Object path) { + return configFile(TsConfigFileType.VSCODE, path); } - public void tsfmtFile(final Object path) { - configFile(TsConfigFileType.TSFMT, path); + public TypescriptFormatExtension tsfmtFile(final Object path) { + return configFile(TsConfigFileType.TSFMT, path); } - private void configFile(TsConfigFileType filetype, Object path) { + private TypescriptFormatExtension configFile(TsConfigFileType filetype, Object path) { this.configFileType = requireNonNull(filetype); this.configFilePath = requireNonNull(path); replaceStep(); + return this; } public FormatterStep createStep() { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java index b4318b8771..893a834bca 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java @@ -24,13 +24,16 @@ import org.assertj.core.api.Assertions; import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.io.TempDir; import com.diffplug.common.base.Errors; import com.diffplug.spotless.tag.NpmTest; +@TestMethodOrder(OrderAnnotation.class) @NpmTest class NpmInstallCacheIntegrationTests extends GradleIntegrationHarness { @@ -115,6 +118,51 @@ private BuildResult runPhpPrettierOnDir(File projDir, File cacheDir) throws IOEx return spotlessApply; } + @Test + @Order(3) + void tsfmtWithSpecificGlobalInstallCacheTest() throws IOException { + File dir1 = newFolder("npm-tsfmt-global-1"); + File cacheDir = pertainingCacheDir; + BuildResult result = runTsfmtOnDir(dir1, cacheDir); + Assertions.assertThat(result.getOutput()) + .doesNotContainPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E") + .containsPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); + } + + @Test + @Order(4) + void tsfmtWithSpecificGlobalInstallCacheTest2() throws IOException { + File dir2 = newFolder("npm-tsfmt-global-2"); + File cacheDir = pertainingCacheDir; + BuildResult result = runTsfmtOnDir(dir2, cacheDir); + Assertions.assertThat(result.getOutput()) + .containsPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E") + .doesNotContainPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); + } + + private BuildResult runTsfmtOnDir(File projDir, File cacheDir) throws IOException { + String baseDir = projDir.getName(); + String cacheDirEnabled = cacheDirEnabledStringForCacheDir(cacheDir); + setFile(baseDir + "/build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "def tsfmtconfig = [:]", + "tsfmtconfig['indentSize'] = 1", + "tsfmtconfig['convertTabsToSpaces'] = true", + "spotless {", + " typescript {", + " target 'test.ts'", + " tsfmt().config(tsfmtconfig)" + cacheDirEnabled, + " }", + "}"); + setFile(baseDir + "/test.ts").toResource("npm/tsfmt/tsfmt/tsfmt.dirty"); + final BuildResult spotlessApply = gradleRunner().withProjectDir(projDir).withArguments("--stacktrace", "--info", "spotlessApply").build(); + assertFile(baseDir + "/test.ts").sameAsResource("npm/tsfmt/tsfmt/tsfmt.clean"); + return spotlessApply; + } + private static String cacheDirEnabledStringForCacheDir(File cacheDir) { String cacheDirEnabled; if (cacheDir == null) { From 64b201b6ea55d5ecdc8e62db8cf23fadb2715503 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 24 Feb 2023 15:49:17 +0100 Subject: [PATCH 0530/1120] 1480: adding tests without cache and for eslint --- .../NpmInstallCacheIntegrationTests.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java index 893a834bca..5bef2b17a9 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java @@ -69,6 +69,16 @@ void prettierWithSpecificInstallCacheTest() throws IOException { Assertions.assertThat(result2.getOutput()).containsPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); } + @Test + void prettierWithNoCacheTest() throws IOException { + File dir2 = newFolder("npm-prettier-1"); + File cacheDir = null; + BuildResult result = runPhpPrettierOnDir(dir2, cacheDir); + Assertions.assertThat(result.getOutput()) + .doesNotContainPattern("Using cached node_modules for .*") + .doesNotContainPattern("Caching node_modules for .*"); + } + @Test @Order(1) void prettierWithSpecificGlobalInstallCacheTest() throws IOException { @@ -140,6 +150,16 @@ void tsfmtWithSpecificGlobalInstallCacheTest2() throws IOException { .doesNotContainPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); } + @Test + void tsfmtWithNoCacheTest() throws IOException { + File dir2 = newFolder("npm-tsfmt-1"); + File cacheDir = null; + BuildResult result = runTsfmtOnDir(dir2, cacheDir); + Assertions.assertThat(result.getOutput()) + .doesNotContainPattern("Using cached node_modules for .*") + .doesNotContainPattern("Caching node_modules for .*"); + } + private BuildResult runTsfmtOnDir(File projDir, File cacheDir) throws IOException { String baseDir = projDir.getName(); String cacheDirEnabled = cacheDirEnabledStringForCacheDir(cacheDir); @@ -163,6 +183,60 @@ private BuildResult runTsfmtOnDir(File projDir, File cacheDir) throws IOExceptio return spotlessApply; } + @Test + @Order(5) + void eslintWithSpecificGlobalInstallCacheTest() throws IOException { + File dir1 = newFolder("npm-eslint-global-1"); + File cacheDir = pertainingCacheDir; + BuildResult result = runEslintOnDir(dir1, cacheDir); + Assertions.assertThat(result.getOutput()) + .doesNotContainPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E") + .containsPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); + } + + @Test + @Order(6) + void eslintWithSpecificGlobalInstallCacheTest2() throws IOException { + File dir2 = newFolder("npm-eslint-global-2"); + File cacheDir = pertainingCacheDir; + BuildResult result = runEslintOnDir(dir2, cacheDir); + Assertions.assertThat(result.getOutput()) + .containsPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E") + .doesNotContainPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); + } + + @Test + void eslintWithNoCacheTest() throws IOException { + File dir2 = newFolder("npm-eslint-1"); + File cacheDir = null; + BuildResult result = runEslintOnDir(dir2, cacheDir); + Assertions.assertThat(result.getOutput()) + .doesNotContainPattern("Using cached node_modules for .*") + .doesNotContainPattern("Caching node_modules for .*"); + } + + private BuildResult runEslintOnDir(File projDir, File cacheDir) throws IOException { + String baseDir = projDir.getName(); + String cacheDirEnabled = cacheDirEnabledStringForCacheDir(cacheDir); + + setFile(baseDir + "/.eslintrc.js").toResource("npm/eslint/typescript/custom_rules/.eslintrc.js"); + setFile(baseDir + "/build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target 'test.ts'", + " eslint().configFile('.eslintrc.js')" + cacheDirEnabled, + " }", + "}"); + setFile(baseDir + "/test.ts").toResource("npm/eslint/typescript/custom_rules/typescript.dirty"); + BuildResult spotlessApply = gradleRunner().withProjectDir(projDir).withArguments("--stacktrace", "--info", "spotlessApply").build(); + assertFile(baseDir + "/test.ts").sameAsResource("npm/eslint/typescript/custom_rules/typescript.clean"); + return spotlessApply; + } + private static String cacheDirEnabledStringForCacheDir(File cacheDir) { String cacheDirEnabled; if (cacheDir == null) { From de33c705bc833fdbeb4d838e2d7cfa522bf2dbd5 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 24 Feb 2023 20:06:26 +0100 Subject: [PATCH 0531/1120] 1480: clarifications/renamings --- .../com/diffplug/spotless/npm/ShadowCopy.java | 4 +-- .../NpmInstallCacheIntegrationTests.java | 28 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java b/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java index 179a1278b1..044b5d70ea 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java @@ -49,10 +49,10 @@ public ShadowCopy(@Nonnull File shadowCopyRoot) { } public void addEntry(String key, File orig) { + // prevent concurrent adding of entry with same key if (!reserveSubFolder(key)) { - logger.debug("Shadow copy entry already on the way: {}. Awaiting finalization.", key); + logger.debug("Shadow copy entry already in progress: {}. Awaiting finalization.", key); try { - // maybe make the duration configurable? NpmResourceHelper.awaitFileDeleted(markerFilePath(key).toFile(), Duration.ofSeconds(120)); } catch (TimeoutException e) { throw new RuntimeException(e); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java index 5bef2b17a9..3a690fbc55 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java @@ -47,7 +47,7 @@ static void beforeAll(@TempDir File pertainingCacheDir) { } @Test - void prettierWithDefaultInstallCacheTest() throws IOException { + void prettierCachesNodeModulesToADefaultFolderWhenCachingEnabled() throws IOException { File dir1 = newFolder("npm-prettier-1"); File cacheDir = DEFAULT_DIR_FOR_NPM_INSTALL_CACHE_DO_NEVER_WRITE_TO_THIS; BuildResult result = runPhpPrettierOnDir(dir1, cacheDir); @@ -59,7 +59,7 @@ void prettierWithDefaultInstallCacheTest() throws IOException { } @Test - void prettierWithSpecificInstallCacheTest() throws IOException { + void prettierCachesAndReusesNodeModulesInSpecificInstallCacheFolder() throws IOException { File dir1 = newFolder("npm-prettier-1"); File cacheDir = newFolder("npm-prettier-cache"); BuildResult result = runPhpPrettierOnDir(dir1, cacheDir); @@ -70,10 +70,9 @@ void prettierWithSpecificInstallCacheTest() throws IOException { } @Test - void prettierWithNoCacheTest() throws IOException { + void prettierDoesNotCacheNodeModulesIfNotExplicitlyEnabled() throws IOException { File dir2 = newFolder("npm-prettier-1"); - File cacheDir = null; - BuildResult result = runPhpPrettierOnDir(dir2, cacheDir); + BuildResult result = runPhpPrettierOnDir(dir2, null); Assertions.assertThat(result.getOutput()) .doesNotContainPattern("Using cached node_modules for .*") .doesNotContainPattern("Caching node_modules for .*"); @@ -81,7 +80,7 @@ void prettierWithNoCacheTest() throws IOException { @Test @Order(1) - void prettierWithSpecificGlobalInstallCacheTest() throws IOException { + void prettierCachesNodeModuleInGlobalInstallCacheDir() throws IOException { File dir1 = newFolder("npm-prettier-global-1"); File cacheDir = pertainingCacheDir; BuildResult result = runPhpPrettierOnDir(dir1, cacheDir); @@ -92,7 +91,7 @@ void prettierWithSpecificGlobalInstallCacheTest() throws IOException { @Test @Order(2) - void prettierWithSpecificGlobalInstallCacheTest2() throws IOException { + void prettierUsesCachedNodeModulesFromGlobalInstallCacheDir() throws IOException { File dir2 = newFolder("npm-prettier-global-2"); File cacheDir = pertainingCacheDir; BuildResult result = runPhpPrettierOnDir(dir2, cacheDir); @@ -130,7 +129,7 @@ private BuildResult runPhpPrettierOnDir(File projDir, File cacheDir) throws IOEx @Test @Order(3) - void tsfmtWithSpecificGlobalInstallCacheTest() throws IOException { + void tsfmtCachesNodeModuleInGlobalInstallCacheDir() throws IOException { File dir1 = newFolder("npm-tsfmt-global-1"); File cacheDir = pertainingCacheDir; BuildResult result = runTsfmtOnDir(dir1, cacheDir); @@ -141,7 +140,7 @@ void tsfmtWithSpecificGlobalInstallCacheTest() throws IOException { @Test @Order(4) - void tsfmtWithSpecificGlobalInstallCacheTest2() throws IOException { + void tsfmtUsesCachedNodeModulesFromGlobalInstallCacheDir() throws IOException { File dir2 = newFolder("npm-tsfmt-global-2"); File cacheDir = pertainingCacheDir; BuildResult result = runTsfmtOnDir(dir2, cacheDir); @@ -151,10 +150,9 @@ void tsfmtWithSpecificGlobalInstallCacheTest2() throws IOException { } @Test - void tsfmtWithNoCacheTest() throws IOException { + void tsfmtDoesNotCacheNodeModulesIfNotExplicitlyEnabled() throws IOException { File dir2 = newFolder("npm-tsfmt-1"); - File cacheDir = null; - BuildResult result = runTsfmtOnDir(dir2, cacheDir); + BuildResult result = runTsfmtOnDir(dir2, null); Assertions.assertThat(result.getOutput()) .doesNotContainPattern("Using cached node_modules for .*") .doesNotContainPattern("Caching node_modules for .*"); @@ -185,7 +183,7 @@ private BuildResult runTsfmtOnDir(File projDir, File cacheDir) throws IOExceptio @Test @Order(5) - void eslintWithSpecificGlobalInstallCacheTest() throws IOException { + void eslintCachesNodeModuleInGlobalInstallCacheDir() throws IOException { File dir1 = newFolder("npm-eslint-global-1"); File cacheDir = pertainingCacheDir; BuildResult result = runEslintOnDir(dir1, cacheDir); @@ -196,7 +194,7 @@ void eslintWithSpecificGlobalInstallCacheTest() throws IOException { @Test @Order(6) - void eslintWithSpecificGlobalInstallCacheTest2() throws IOException { + void eslintUsesCachedNodeModulesFromGlobalInstallCacheDir() throws IOException { File dir2 = newFolder("npm-eslint-global-2"); File cacheDir = pertainingCacheDir; BuildResult result = runEslintOnDir(dir2, cacheDir); @@ -206,7 +204,7 @@ void eslintWithSpecificGlobalInstallCacheTest2() throws IOException { } @Test - void eslintWithNoCacheTest() throws IOException { + void eslintDoesNotCacheNodeModulesIfNotExplicitlyEnabled() throws IOException { File dir2 = newFolder("npm-eslint-1"); File cacheDir = null; BuildResult result = runEslintOnDir(dir2, cacheDir); From cd84167cc20cf9b97e25d1d2ba741b5f2cf04ed4 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 26 Feb 2023 19:42:21 +0100 Subject: [PATCH 0532/1120] 1480: integration tests for maven + cleanup --- .../npm/AbstractNpmFormatterStepFactory.java | 7 +- .../npm/NpmStepsWithNpmInstallCacheTest.java | 188 ++++++++++++++++++ .../spotless/npm/EslintFormatterStepTest.java | 6 +- .../npm/NpmFormatterStepCommonTests.java | 8 - .../npm/PrettierFormatterStepTest.java | 10 +- .../spotless/npm/TsFmtFormatterStepTest.java | 4 +- 6 files changed, 203 insertions(+), 20 deletions(-) create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmStepsWithNpmInstallCacheTest.java diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java index 9e184045bb..b0645c151e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/npm/AbstractNpmFormatterStepFactory.java @@ -16,6 +16,7 @@ package com.diffplug.spotless.maven.npm; import java.io.File; +import java.nio.file.Paths; import java.util.AbstractMap; import java.util.Arrays; import java.util.Collections; @@ -33,6 +34,8 @@ public abstract class AbstractNpmFormatterStepFactory implements FormatterStepFactory { + public static final String SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME = "spotless-npm-install-cache"; + @Parameter private String npmExecutable; @@ -69,9 +72,9 @@ protected File cacheDir(FormatterStepConfig stepConfig) { return null; } if ("true".equals(this.npmInstallCache.toLowerCase(Locale.ROOT))) { - return new File(buildDir(stepConfig), "spotless-npm-install-cache"); + return new File(buildDir(stepConfig), SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME); } - return stepConfig.getFileLocator().locateFile(this.npmInstallCache); + return Paths.get(this.npmInstallCache).toFile(); } protected File baseDir(FormatterStepConfig stepConfig) { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmStepsWithNpmInstallCacheTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmStepsWithNpmInstallCacheTest.java new file mode 100644 index 0000000000..aae587aadb --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/npm/NpmStepsWithNpmInstallCacheTest.java @@ -0,0 +1,188 @@ +/* + * 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.npm; + +import static com.diffplug.spotless.maven.npm.AbstractNpmFormatterStepFactory.SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.ProcessRunner.Result; +import com.diffplug.spotless.maven.MavenIntegrationHarness; +import com.diffplug.spotless.tag.NpmTest; + +@NpmTest +public class NpmStepsWithNpmInstallCacheTest extends MavenIntegrationHarness { + + // TODO implement tests without cache and with various cache paths + // using only prettier is enough since the other cases are covered by gradle-side integration tests + + @Test + void prettierTypescriptWithoutCache() throws Exception { + String suffix = "ts"; + writePomWithPrettierSteps("**/*." + suffix, + "", + " 1.16.4", + " .prettierrc.yml", + ""); + Result result = run("typescript", suffix); + Assertions.assertThat(result.stdOutUtf8()).doesNotContain("Caching node_modules for").doesNotContain("Using cached node_modules for"); + } + + @Test + void prettierTypescriptWithDefaultCache() throws Exception { + String suffix = "ts"; + writePomWithPrettierSteps("**/*." + suffix, + "", + " 1.16.4", + " .prettierrc.yml", + " true", + ""); + Result result = run("typescript", suffix); + Assertions.assertThat(result.stdOutUtf8()) + .contains("Caching node_modules for") + .contains(SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME) + .doesNotContain("Using cached node_modules for"); + } + + @Test + void prettierTypescriptWithDefaultCacheIsReusedOnSecondRun() throws Exception { + String suffix = "ts"; + writePomWithPrettierSteps("**/*." + suffix, + "", + " 1.16.4", + " .prettierrc.yml", + " true", + ""); + Result result1 = run("typescript", suffix); + Assertions.assertThat(result1.stdOutUtf8()) + .contains("Caching node_modules for") + .contains(SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME) + .doesNotContain("Using cached node_modules for"); + + // recursively delete target folder to simulate a fresh run (except the default cache folder) + recursiveDelete(Paths.get(rootFolder().getAbsolutePath(), "target"), SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME); + + Result result2 = run("typescript", suffix); + Assertions.assertThat(result2.stdOutUtf8()) + .doesNotContain("Caching node_modules for") + .contains(SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME) + .contains("Using cached node_modules for"); + } + + @Test + void prettierTypescriptWithSpecificCache() throws Exception { + String suffix = "ts"; + File cacheDir = newFolder("cache-prettier-1"); + writePomWithPrettierSteps("**/*." + suffix, + "", + " 1.16.4", + " .prettierrc.yml", + " " + cacheDir.getAbsolutePath() + "", + ""); + Result result = run("typescript", suffix); + Assertions.assertThat(result.stdOutUtf8()) + .contains("Caching node_modules for") + .contains(Path.of(cacheDir.getAbsolutePath()).toAbsolutePath().toString()) + .doesNotContain("Using cached node_modules for"); + } + + @Test + void prettierTypescriptWithSpecificCacheIsUsedOnSecondRun() throws Exception { + String suffix = "ts"; + File cacheDir = newFolder("cache-prettier-1"); + writePomWithPrettierSteps("**/*." + suffix, + "", + " 1.16.4", + " .prettierrc.yml", + " " + cacheDir.getAbsolutePath() + "", + ""); + Result result1 = run("typescript", suffix); + Assertions.assertThat(result1.stdOutUtf8()) + .contains("Caching node_modules for") + .contains(Path.of(cacheDir.getAbsolutePath()).toAbsolutePath().toString()) + .doesNotContain("Using cached node_modules for"); + + // recursively delete target folder to simulate a fresh run + recursiveDelete(Paths.get(rootFolder().getAbsolutePath(), "target"), null); + + Result result2 = run("typescript", suffix); + Assertions.assertThat(result2.stdOutUtf8()) + .doesNotContain("Caching node_modules for") + .contains(Path.of(cacheDir.getAbsolutePath()).toAbsolutePath().toString()) + .contains("Using cached node_modules for"); + } + + private void recursiveDelete(Path path, String exclusion) throws IOException { + Files.walkFileTree(path, new RecursiveDelete(exclusion)); + } + + private Result run(String kind, String suffix) throws IOException, InterruptedException { + String path = prepareRun(kind, suffix); + Result result = mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("npm/prettier/filetypes/" + kind + "/" + kind + ".clean"); + return result; + } + + private String prepareRun(String kind, String suffix) throws IOException { + String configPath = ".prettierrc.yml"; + setFile(configPath).toResource("npm/prettier/filetypes/" + kind + "/" + ".prettierrc.yml"); + String path = "src/main/" + kind + "/test." + suffix; + setFile(path).toResource("npm/prettier/filetypes/" + kind + "/" + kind + ".dirty"); + return path; + } + + private static class RecursiveDelete extends SimpleFileVisitor { + private final String exclusionDirectory; + + public RecursiveDelete(String exclusionDirectory) { + this.exclusionDirectory = exclusionDirectory; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + if (exclusionDirectory != null && dir.toFile().getName().equals(exclusionDirectory)) { + return FileVisitResult.SKIP_SUBTREE; + } + return super.preVisitDirectory(dir, attrs); + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return super.visitFile(file, attrs); + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (dir.toFile().listFiles().length != 0) { + // skip non-empty dir + return super.postVisitDirectory(dir, exc); + } + Files.delete(dir); + return super.postVisitDirectory(dir, exc); + } + } +} diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java index fe1f33ccc6..631a4beaa7 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/EslintFormatterStepTest.java @@ -64,7 +64,7 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), - cacheDir(), + null, npmPathResolver(), new EslintConfig(eslintRc, null)); @@ -108,7 +108,7 @@ void formattingUsingRulesetsFile(String ruleSetName) throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), - cacheDir(), + null, npmPathResolver(), new EslintTypescriptConfig(eslintRc, null, tsconfigFile)); @@ -166,7 +166,7 @@ void formattingUsingInlineXoConfig() throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), - cacheDir(), + null, npmPathResolver(), new EslintTypescriptConfig(null, esLintConfig, tsconfigFile)); diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java index 93e70b4129..5eff34ef29 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/NpmFormatterStepCommonTests.java @@ -57,12 +57,4 @@ protected File projectDir() throws IOException { return this.projectDir; } - private File cacheDir = null; - - protected File cacheDir() throws IOException { - if (this.cacheDir == null) { - this.cacheDir = newFolder("cache-dir"); - } - return this.cacheDir; - } } diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java index d308e6085a..c0e587aa98 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java @@ -52,7 +52,7 @@ void formattingUsingConfigFile(String fileType) throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), - cacheDir(), + null, npmPathResolver(), new PrettierConfig(prettierRc, null)); @@ -78,7 +78,7 @@ void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), - cacheDir(), + null, npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("filepath", "anyname.json"))); // should select parser based on this name @@ -99,7 +99,7 @@ void parserInferenceBasedOnFilenameIsWorking() throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), - cacheDir(), + null, npmPathResolver(), new PrettierConfig(null, Collections.emptyMap())); @@ -115,7 +115,7 @@ void verifyPrettierErrorMessageIsRelayed() throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), - cacheDir(), + null, npmPathResolver(), new PrettierConfig(null, ImmutableMap.of("parser", "postcss"))); try (StepHarnessWithFile stepHarness = StepHarnessWithFile.forStep(this, formatterStep)) { @@ -141,7 +141,7 @@ void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exc TestProvisioner.mavenCentral(), projectDir(), buildDir(), - cacheDir(), + null, npmPathResolver(), config); // should select parser based on this name diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java index 9233239443..66fe6e05ac 100644 --- a/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/npm/TsFmtFormatterStepTest.java @@ -59,7 +59,7 @@ void formattingUsingConfigFile(String formattingConfigFile) throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), - cacheDir(), + null, npmPathResolver(), TypedTsFmtConfigFile.named(configFileNameWithoutExtension, configFile), Collections.emptyMap()); @@ -83,7 +83,7 @@ void formattingUsingInlineConfigWorks() throws Exception { TestProvisioner.mavenCentral(), projectDir(), buildDir(), - cacheDir(), + null, npmPathResolver(), null, inlineConfig); From ed95a7ca9ffa129ec2bb9942b337c1bff82e1a4c Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 26 Feb 2023 20:19:36 +0100 Subject: [PATCH 0533/1120] 1480: add configuration to readme --- plugin-gradle/README.md | 27 +++++++++++++++++++++------ plugin-maven/README.md | 23 +++++++++++++++++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 106cf3dcfd..6c181c9330 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -67,7 +67,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript)) - [JSON](#json) - Multiple languages - - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) + - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection), [caching `npm install` results](#caching-results-of-npm-install)) - javascript, jsx, angular, vue, flow, typescript, css, less, scss, html, json, graphql, markdown, ymaml - [clang-format](#clang-format) - c, c++, c#, objective-c, protobuf, javascript, java @@ -630,7 +630,8 @@ spotless { **Prerequisite: tsfmt requires a working NodeJS version** -For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt. +For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection) and [caching results of `npm install`](#caching-results-of-npm-install) sections of prettier, which apply also to tsfmt. + ### ESLint (Typescript) @@ -678,7 +679,7 @@ spotless { **Prerequisite: ESLint requires a working NodeJS version** -For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. +For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection) and [caching results of `npm install`](#caching-results-of-npm-install) sections of prettier, which apply also to ESLint. ## Javascript @@ -742,7 +743,7 @@ spotless { **Prerequisite: ESLint requires a working NodeJS version** -For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. +For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection) and [caching results of `npm install`](#caching-results-of-npm-install) sections of prettier, which apply also to ESLint. ## JSON @@ -926,8 +927,6 @@ node- and npm-binaries dynamically installed by this plugin. See [this](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle) or [this](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle) example. -```gradle - ### `.npmrc` detection Spotless picks up npm configuration stored in a `.npmrc` file either in the project directory or in your user home. @@ -940,6 +939,22 @@ spotless { prettier().npmrc("$projectDir/config/.npmrc").config(...) ``` +### Caching results of `npm install` + +Spotless uses `npm` behind the scenes to install `prettier`. This can be a slow process, especially if you are using a slow internet connection or +if you need large plugins. You can instruct spotless to cache the results of the `npm install` calls, so that for the next installation, +it will not need to download the packages again, but instead reuse the cached version. + +```gradle +spotless { + typescript { + prettier().npmInstallCache() // will use the default cache directory (the build-directory of the respective module) + prettier().npmInstallCache("${rootProject.rootDir}/.gradle/spotless-npm-cache") // will use the specified directory (creating it if not existing) +``` + +Depending on your filesystem and the location of the cache directory, spotless will use hardlinks when caching the npm packages. If that is not +possible, it will fall back to copying the files. + ## clang-format [homepage](https://clang.llvm.org/docs/ClangFormat.html). [changelog](https://releases.llvm.org/download.html). `clang-format` is a formatter for c, c++, c#, objective-c, protobuf, javascript, and java. You can use clang-format in any language-specific format, but usually you will be creating a generic format. diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 51ea9c23d7..c91c73f80a 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -54,7 +54,7 @@ user@machine repo % mvn spotless:check - [JSON](#json) - [YAML](#yaml) - Multiple languages - - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) + - [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) - **Language independent** - [Generic steps](#generic-steps) @@ -731,7 +731,7 @@ The auto-discovery of config files (up the file tree) will not work when using t **Prerequisite: tsfmt requires a working NodeJS version** -For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to tsfmt. +For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection) and [caching results of `npm install`](#caching-results-of-npm-install) sections of prettier, which apply also to tsfmt. ### ESLint (typescript) @@ -787,7 +787,7 @@ reference to a `tsconfig.json` is required. **Prerequisite: ESLint requires a working NodeJS version** -For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. +For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection) and [caching results of `npm install`](#caching-results-of-npm-install) sections of prettier, which apply also to ESLint. ## Javascript @@ -863,7 +863,7 @@ The configuration is very similar to the [ESLint (Typescript)](#eslint-typescrip **Prerequisite: ESLint requires a working NodeJS version** -For details, see the [npm detection](#npm-detection) and [`.npmrc` detection](#npmrc-detection) sections of prettier, which apply also to ESLint. +For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection) and [caching results of `npm install`](#caching-results-of-npm-install) sections of prettier, which apply also to ESLint. ## JSON @@ -1113,6 +1113,21 @@ Alternatively you can supply spotless with a location of the `.npmrc` file to us /usr/local/shared/.npmrc ``` +### Caching results of `npm install` + +Spotless uses `npm` behind the scenes to install `prettier`. This can be a slow process, especially if you are using a slow internet connection or +if you need large plugins. You can instruct spotless to cache the results of the `npm install` calls, so that for the next installation, +it will not need to download the packages again, but instead reuse the cached version. + +```xml + + true + /usr/local/shared/.spotless-npm-install-cache +``` + +Depending on your filesystem and the location of the cache directory, spotless will use hardlinks when caching the npm packages. If that is not +possible, it will fall back to copying the files. + ## Eclipse web tools platform From 00990dc16e948276e4cf671ac265096192100770 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 26 Feb 2023 20:20:53 +0100 Subject: [PATCH 0534/1120] 1480: update changes.md --- CHANGES.md | 5 +++++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 9 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index eec8753271..c7526360c5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,11 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Introduce `TimedLogger` to allow for logging of time taken by a task using slf4j ([#1590](https://github.com/diffplug/spotless/pull/1590)) +* `npm`-based formatters now support caching of `node_modules` directory ([#1590](https://github.com/diffplug/spotless/pull/1590)) +### Fixed +* Reduce logging-noise created by `npm`-based formatters ([#1590](https://github.com/diffplug/spotless/pull/1590) fixes [#1582](https://github.com/diffplug/spotless/issues/1582)) ## [2.35.0] - 2023-02-10 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 0b2185ba61..c2b5940a71 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add `includeDraft` option, to include draft mutators from composite mutators ([#1574](https://github.com/diffplug/spotless/pull/1574)) +* `npm`-based formatters (`prettier`, `tsfmt` and `eslint`) now support caching of `node_modules` directory. + To enable it, provide `npmInstallCache()` option. ([#1590](https://github.com/diffplug/spotless/pull/1590)) ### Changes * Bump default `cleanthat` version to latest `2.2` -> `2.6` ([#1574](https://github.com/diffplug/spotless/pull/1574)) * Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 4912e4ff52..c2b0c1bbc1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add `includeDraft` option, to include draft mutators from composite mutators ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) +* `npm`-based formatters (`prettier`, `tsfmt` and `eslint`) now support caching of `node_modules` directory. + To enable it, provide the `` option. ([#1590](https://github.com/diffplug/spotless/pull/1590)) ### Changes * Bump default `cleanthat` version to latest `2.2` -> `2.6` ([#1574](https://github.com/diffplug/spotless/pull/1574)) * Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569)) From 37694c18b4bfa3294f58fd4036df19a02c2b1f25 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sun, 26 Feb 2023 20:32:28 +0100 Subject: [PATCH 0535/1120] 1480: adapt test to actual output --- lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java b/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java index 3c84ca09ce..cb36bbfbc0 100644 --- a/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java +++ b/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java @@ -86,7 +86,7 @@ void itLogsSecondsOnlyWhenTakingSeconds() { timedLogger.withInfo("This should be logged").run(() -> testTicker.tickMillis(2_000)); testLogger.assertEvents(2); - testLogger.assertHasEventWithMessageAndArguments(MESSAGE_SUFFIX_TOOK, "2s"); + testLogger.assertHasEventWithMessageAndArguments(MESSAGE_SUFFIX_TOOK, "2.0s"); } @Test From b4d9de586c6ca7d40a9f1c2ed21584c91e73497f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 26 Feb 2023 12:15:32 -0800 Subject: [PATCH 0536/1120] Adopt the latest version of Equo now that it's production ready on Gradle. --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0b00b4c9f1..312f84727d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,11 @@ plugins { // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md - id 'dev.equo.ide' version '0.13.0' + id 'dev.equo.ide' version '0.16.0' } equoIde { branding().title('Spotless').icon(file('_images/spotless_logo.png')) welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') + gradleBuildship() } repositories { From c7e46d84cc7e81134d1b1df258ca9a51fd328dfb Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 26 Feb 2023 12:20:31 -0800 Subject: [PATCH 0537/1120] Update plugin changelogs. --- plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 2 ++ 2 files changed, 5 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index afba5abdc7..7d70a74149 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* `json { jackson()` can now handle `Array` as a root element. ([#1585](https://github.com/diffplug/spotless/pull/1585)) +### Changes * Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569)) ## [6.15.0] - 2023-02-10 diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8d4c67a9b6..e3ff459b33 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `` can now handle `Array` as a root element. ([#1585](https://github.com/diffplug/spotless/pull/1585)) ### Changes * Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569)) From 2a54d8475296baeaa6557e8d269ccb441b7f11f8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 26 Feb 2023 12:27:18 -0800 Subject: [PATCH 0538/1120] Update changelogs. --- CHANGES.md | 5 +++++ plugin-gradle/CHANGES.md | 4 ++-- plugin-maven/CHANGES.md | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index efb88d972d..11f3f9da3b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,8 +10,13 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `gradlew equoIde` opens a repeatable clean Spotless dev environment. ([#1523](https://github.com/diffplug/spotless/pull/1523)) +* `cleanthat` added `includeDraft` option, to include draft mutators from composite mutators. ([#1574](https://github.com/diffplug/spotless/pull/1574)) ### Fixed * `JacksonJsonFormatterFunc` handles json files with an Array as root. ([#1585](https://github.com/diffplug/spotless/pull/1585)) +### Changes +* Bump default `cleanthat` version to latest `2.1` -> `2.6` ([#1569](https://github.com/diffplug/spotless/pull/1569) and [#1574](https://github.com/diffplug/spotless/pull/1574)) ## [2.35.0] - 2023-02-10 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 84b02012b8..63aef7c8d9 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,11 +4,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `cleanthat` now has `includeDraft` option, to include draft mutators from composite mutators ([#1574](https://github.com/diffplug/spotless/pull/1574)) +* `cleanthat` now has `includeDraft` option, to include draft mutators from composite mutators. ([#1574](https://github.com/diffplug/spotless/pull/1574)) ### Fixed * `json { jackson()` can now handle `Array` as a root element. ([#1585](https://github.com/diffplug/spotless/pull/1585)) ### Changes -* Bump default `cleanthat` version to latest `2.1` -> `2.6` ([#1569](https://github.com/diffplug/spotless/pull/1569) and [#1574](https://github.com/diffplug/spotless/pull/1574)) +* Bump default `cleanthat` version to latest `2.1` -> `2.6`. ([#1569](https://github.com/diffplug/spotless/pull/1569) and [#1574](https://github.com/diffplug/spotless/pull/1574)) ## [6.15.0] - 2023-02-10 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c21ec5dcb9..f8930c6873 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,10 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* `cleanthat` added `includeDraft` option, to include draft mutators from composite mutators. ([#1574](https://github.com/diffplug/spotless/pull/1574)) ### Fixed * `` can now handle `Array` as a root element. ([#1585](https://github.com/diffplug/spotless/pull/1585)) -### Added -* `cleanthat` added `includeDraft` option, to include draft mutators from composite mutators ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) ### Changes * Bump default `cleanthat` version to latest `2.1` -> `2.6` ([#1569](https://github.com/diffplug/spotless/pull/1569) and [#1574](https://github.com/diffplug/spotless/pull/1574)) From cd2ff0f345f854f44a87f0944f400c98031b5f8c Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Mon, 27 Feb 2023 10:26:37 +0400 Subject: [PATCH 0539/1120] Less errors in equoIde --- .../maven/java/CleanthatJavaRefactorerTest.java | 12 ++++++------ .../cleanthat/LiteralsFirstInComparisons.clean.java | 8 -------- .../cleanthat/LiteralsFirstInComparisons.dirty.java | 8 -------- .../cleanthat/LiteralsFirstInComparisons_clean.java | 8 ++++++++ .../cleanthat/LiteralsFirstInComparisons_dirty.java | 8 ++++++++ ...tators.clean.java => MultipleMutators_clean.java} | 4 ++-- ...=> MultipleMutators_clean_onlyLiteralsFirst.java} | 4 ++-- ...ultipleMutators_clean_onlyOptionalIsPresent.java} | 4 ++-- ...tators.dirty.java => MultipleMutators_dirty.java} | 4 ++-- 9 files changed, 30 insertions(+), 30 deletions(-) delete mode 100644 testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java delete mode 100644 testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java create mode 100644 testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_clean.java create mode 100644 testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_dirty.java rename testlib/src/main/resources/java/cleanthat/{MultipleMutators.clean.java => MultipleMutators_clean.java} (62%) rename testlib/src/main/resources/java/cleanthat/{MultipleMutators.clean.onlyLiteralsFirst.java => MultipleMutators_clean_onlyLiteralsFirst.java} (61%) rename testlib/src/main/resources/java/cleanthat/{MultipleMutators.clean.onlyOptionalIsPresent.java => MultipleMutators_clean_onlyOptionalIsPresent.java} (62%) rename testlib/src/main/resources/java/cleanthat/{MultipleMutators.dirty.java => MultipleMutators_dirty.java} (61%) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java index 379397f55b..67a4c2efb2 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -33,7 +33,7 @@ void testEnableDraft() throws Exception { " true", ""); - runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyOptionalIsPresent.java"); + runTest("MultipleMutators_dirty.java", "MultipleMutators_clean_onlyOptionalIsPresent.java"); } @Test @@ -45,7 +45,7 @@ void testLiteralsFirstInComparisons() throws Exception { " ", ""); - runTest("LiteralsFirstInComparisons.dirty.java", "LiteralsFirstInComparisons.clean.java"); + runTest("LiteralsFirstInComparisons_dirty.java", "LiteralsFirstInComparisons_clean.java"); } @Test @@ -59,7 +59,7 @@ void testMultipleMutators_defaultIsJdk7() throws Exception { " ", ""); - runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + runTest("MultipleMutators_dirty.java", "MultipleMutators_clean_onlyLiteralsFirst.java"); } @Test @@ -73,7 +73,7 @@ void testMultipleMutators_Jdk11IntroducedOptionalisPresent() throws Exception { " ", ""); - runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.java"); + runTest("MultipleMutators_dirty.java", "MultipleMutators_clean.java"); } @Test @@ -89,7 +89,7 @@ void testExcludeOptionalNotEmpty() throws Exception { " ", ""); - runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + runTest("MultipleMutators_dirty.java", "MultipleMutators_clean_onlyLiteralsFirst.java"); } @Test @@ -101,7 +101,7 @@ void testIncludeOnlyLiteralsFirstInComparisons() throws Exception { " ", ""); - runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + runTest("MultipleMutators_dirty.java", "MultipleMutators_clean_onlyLiteralsFirst.java"); } private void runTest(String dirtyPath, String cleanPath) throws Exception { diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java deleted file mode 100644 index 8bacfa58db..0000000000 --- a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java +++ /dev/null @@ -1,8 +0,0 @@ -package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; - -public class LiteralsFirstInComparisonsCases { - - public boolean isHardcoded(String input) { - return "hardcoded".equals(input); - } -} diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java deleted file mode 100644 index 3a1e074c91..0000000000 --- a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java +++ /dev/null @@ -1,8 +0,0 @@ -package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; - -public class LiteralsFirstInComparisonsCases { - - public boolean isHardcoded(String input) { - return input.equals("hardcoded"); - } -} diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_clean.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_clean.java new file mode 100644 index 0000000000..07807a6721 --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_clean.java @@ -0,0 +1,8 @@ +package java.cleanthat; + +public class LiteralsFirstInComparisons_clean { + + public boolean isHardcoded(String input) { + return "hardcoded".equals(input); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_dirty.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_dirty.java new file mode 100644 index 0000000000..249b8da8b3 --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_dirty.java @@ -0,0 +1,8 @@ +package java.cleanthat; + +public class LiteralsFirstInComparisons_dirty { + + public boolean isHardcoded(String input) { + return input.equals("hardcoded"); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean.java similarity index 62% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators_clean.java index 318e1efa15..76837b6893 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean.java @@ -1,8 +1,8 @@ -package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; +package java.cleanthat; import java.util.Optional; -public class LiteralsFirstInComparisonsCases { +public class MultipleMutators_clean { public boolean isHardcoded(String input) { return "hardcoded".equals(input); diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyLiteralsFirst.java similarity index 61% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyLiteralsFirst.java index 629d24504b..d9fb87dd80 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyLiteralsFirst.java @@ -1,8 +1,8 @@ -package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; +package java.cleanthat; import java.util.Optional; -public class LiteralsFirstInComparisonsCases { +public class MultipleMutators_clean_onlyLiteralsFirst { public boolean isHardcoded(String input) { return "hardcoded".equals(input); diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyOptionalIsPresent.java similarity index 62% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyOptionalIsPresent.java index 0829602dc1..54600ebc1c 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyOptionalIsPresent.java @@ -1,8 +1,8 @@ -package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; +package java.cleanthat; import java.util.Optional; -public class LiteralsFirstInComparisonsCases { +public class MultipleMutators_clean_onlyOptionalIsPresent { public boolean isHardcoded(String input) { return input.equals("hardcoded"); diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators_dirty.java similarity index 61% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators_dirty.java index 8ac230cabc..e71b810e2f 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators_dirty.java @@ -1,8 +1,8 @@ -package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; +package java.cleanthat; import java.util.Optional; -public class LiteralsFirstInComparisonsCases { +public class MultipleMutators_dirty { public boolean isHardcoded(String input) { return input.equals("hardcoded"); From 78ccbc9f4847c292eff3ed17350bee8e746b0f61 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 27 Feb 2023 13:18:36 +0100 Subject: [PATCH 0540/1120] 1480: make TimedLogger package-private (PR feedback) --- CHANGES.md | 1 - .../main/java/com/diffplug/spotless/npm/NodeApp.java | 2 -- .../npm/NodeModulesCachingNpmProcessFactory.java | 1 - .../java/com/diffplug/spotless/npm/NodeServeApp.java | 1 - .../spotless/npm/NpmFormatterStepStateBase.java | 1 - .../com/diffplug/spotless/{ => npm}/TimedLogger.java | 6 ++++-- .../diffplug/spotless/{ => npm}/TimedLoggerTest.java | 12 ++++++------ 7 files changed, 10 insertions(+), 14 deletions(-) rename lib/src/main/java/com/diffplug/spotless/{ => npm}/TimedLogger.java (98%) rename lib/src/test/java/com/diffplug/spotless/{ => npm}/TimedLoggerTest.java (95%) diff --git a/CHANGES.md b/CHANGES.md index c7526360c5..462f93cadb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Introduce `TimedLogger` to allow for logging of time taken by a task using slf4j ([#1590](https://github.com/diffplug/spotless/pull/1590)) * `npm`-based formatters now support caching of `node_modules` directory ([#1590](https://github.com/diffplug/spotless/pull/1590)) ### Fixed * Reduce logging-noise created by `npm`-based formatters ([#1590](https://github.com/diffplug/spotless/pull/1590) fixes [#1582](https://github.com/diffplug/spotless/issues/1582)) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java index 50ce8ccc5c..edac59bbfd 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeApp.java @@ -22,8 +22,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.diffplug.spotless.TimedLogger; - public class NodeApp { private static final Logger logger = LoggerFactory.getLogger(NodeApp.class); diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java index a995aac59f..0086064194 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java @@ -25,7 +25,6 @@ import org.slf4j.LoggerFactory; import com.diffplug.spotless.ProcessRunner.Result; -import com.diffplug.spotless.TimedLogger; public class NodeModulesCachingNpmProcessFactory implements NpmProcessFactory { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java index d811515971..c9311a5589 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServeApp.java @@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory; import com.diffplug.spotless.ProcessRunner; -import com.diffplug.spotless.TimedLogger; public class NodeServeApp extends NodeApp { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java index e4a8dd0fcb..3f262c813c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java @@ -34,7 +34,6 @@ import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.ProcessRunner.LongRunningProcess; import com.diffplug.spotless.ThrowingEx; -import com.diffplug.spotless.TimedLogger; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; diff --git a/lib/src/main/java/com/diffplug/spotless/TimedLogger.java b/lib/src/main/java/com/diffplug/spotless/npm/TimedLogger.java similarity index 98% rename from lib/src/main/java/com/diffplug/spotless/TimedLogger.java rename to lib/src/main/java/com/diffplug/spotless/npm/TimedLogger.java index 2badd435d2..537234fcee 100644 --- a/lib/src/main/java/com/diffplug/spotless/TimedLogger.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/TimedLogger.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless; +package com.diffplug.spotless.npm; import static com.diffplug.spotless.LazyArgLogger.lazy; @@ -25,10 +25,12 @@ import org.slf4j.Logger; +import com.diffplug.spotless.ThrowingEx; + /** * A logger that logs the time it took to execute a block of code. */ -public class TimedLogger { +class TimedLogger { public static final String MESSAGE_PREFIX_BEGIN = "[BEGIN] "; diff --git a/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java b/lib/src/test/java/com/diffplug/spotless/npm/TimedLoggerTest.java similarity index 95% rename from lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java rename to lib/src/test/java/com/diffplug/spotless/npm/TimedLoggerTest.java index cb36bbfbc0..f08d4f1622 100644 --- a/lib/src/test/java/com/diffplug/spotless/TimedLoggerTest.java +++ b/lib/src/test/java/com/diffplug/spotless/npm/TimedLoggerTest.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless; +package com.diffplug.spotless.npm; -import static com.diffplug.spotless.TimedLogger.MESSAGE_PREFIX_BEGIN; -import static com.diffplug.spotless.TimedLogger.MESSAGE_PREFIX_END; -import static com.diffplug.spotless.TimedLogger.MESSAGE_SUFFIX_TOOK; +import static com.diffplug.spotless.npm.TimedLogger.MESSAGE_PREFIX_BEGIN; +import static com.diffplug.spotless.npm.TimedLogger.MESSAGE_PREFIX_END; +import static com.diffplug.spotless.npm.TimedLogger.MESSAGE_SUFFIX_TOOK; import java.util.Arrays; import java.util.LinkedList; @@ -31,7 +31,7 @@ import org.slf4j.event.Level; import org.slf4j.helpers.LegacyAbstractLogger; -import com.diffplug.spotless.TimedLogger.TestTicker; +import com.diffplug.spotless.npm.TimedLogger.TestTicker; class TimedLoggerTest { @@ -49,7 +49,7 @@ void setUp() { } @Test - void itDoesNotLogWhenLevelDisabled() throws InterruptedException { + void itDoesNotLogWhenLevelDisabled() { TestLogger logger = new TestLogger() { @Override From a601efc10714797a0324ed280f0578176752b84b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 27 Feb 2023 15:05:20 -0800 Subject: [PATCH 0541/1120] Revert "Less errors in equoIde" This reverts commit cd2ff0f345f854f44a87f0944f400c98031b5f8c. --- .../maven/java/CleanthatJavaRefactorerTest.java | 12 ++++++------ .../cleanthat/LiteralsFirstInComparisons.clean.java | 8 ++++++++ .../cleanthat/LiteralsFirstInComparisons.dirty.java | 8 ++++++++ .../cleanthat/LiteralsFirstInComparisons_clean.java | 8 -------- .../cleanthat/LiteralsFirstInComparisons_dirty.java | 8 -------- ...tators_clean.java => MultipleMutators.clean.java} | 4 ++-- ...=> MultipleMutators.clean.onlyLiteralsFirst.java} | 4 ++-- ...ultipleMutators.clean.onlyOptionalIsPresent.java} | 4 ++-- ...tators_dirty.java => MultipleMutators.dirty.java} | 4 ++-- 9 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java create mode 100644 testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java delete mode 100644 testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_clean.java delete mode 100644 testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_dirty.java rename testlib/src/main/resources/java/cleanthat/{MultipleMutators_clean.java => MultipleMutators.clean.java} (62%) rename testlib/src/main/resources/java/cleanthat/{MultipleMutators_clean_onlyLiteralsFirst.java => MultipleMutators.clean.onlyLiteralsFirst.java} (61%) rename testlib/src/main/resources/java/cleanthat/{MultipleMutators_clean_onlyOptionalIsPresent.java => MultipleMutators.clean.onlyOptionalIsPresent.java} (62%) rename testlib/src/main/resources/java/cleanthat/{MultipleMutators_dirty.java => MultipleMutators.dirty.java} (61%) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java index 67a4c2efb2..379397f55b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -33,7 +33,7 @@ void testEnableDraft() throws Exception { " true", ""); - runTest("MultipleMutators_dirty.java", "MultipleMutators_clean_onlyOptionalIsPresent.java"); + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyOptionalIsPresent.java"); } @Test @@ -45,7 +45,7 @@ void testLiteralsFirstInComparisons() throws Exception { " ", ""); - runTest("LiteralsFirstInComparisons_dirty.java", "LiteralsFirstInComparisons_clean.java"); + runTest("LiteralsFirstInComparisons.dirty.java", "LiteralsFirstInComparisons.clean.java"); } @Test @@ -59,7 +59,7 @@ void testMultipleMutators_defaultIsJdk7() throws Exception { " ", ""); - runTest("MultipleMutators_dirty.java", "MultipleMutators_clean_onlyLiteralsFirst.java"); + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); } @Test @@ -73,7 +73,7 @@ void testMultipleMutators_Jdk11IntroducedOptionalisPresent() throws Exception { " ", ""); - runTest("MultipleMutators_dirty.java", "MultipleMutators_clean.java"); + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.java"); } @Test @@ -89,7 +89,7 @@ void testExcludeOptionalNotEmpty() throws Exception { " ", ""); - runTest("MultipleMutators_dirty.java", "MultipleMutators_clean_onlyLiteralsFirst.java"); + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); } @Test @@ -101,7 +101,7 @@ void testIncludeOnlyLiteralsFirstInComparisons() throws Exception { " ", ""); - runTest("MultipleMutators_dirty.java", "MultipleMutators_clean_onlyLiteralsFirst.java"); + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); } private void runTest(String dirtyPath, String cleanPath) throws Exception { diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java new file mode 100644 index 0000000000..8bacfa58db --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java @@ -0,0 +1,8 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return "hardcoded".equals(input); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java new file mode 100644 index 0000000000..3a1e074c91 --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java @@ -0,0 +1,8 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return input.equals("hardcoded"); + } +} diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_clean.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_clean.java deleted file mode 100644 index 07807a6721..0000000000 --- a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_clean.java +++ /dev/null @@ -1,8 +0,0 @@ -package java.cleanthat; - -public class LiteralsFirstInComparisons_clean { - - public boolean isHardcoded(String input) { - return "hardcoded".equals(input); - } -} diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_dirty.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_dirty.java deleted file mode 100644 index 249b8da8b3..0000000000 --- a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons_dirty.java +++ /dev/null @@ -1,8 +0,0 @@ -package java.cleanthat; - -public class LiteralsFirstInComparisons_dirty { - - public boolean isHardcoded(String input) { - return input.equals("hardcoded"); - } -} diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java similarity index 62% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators_clean.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java index 76837b6893..318e1efa15 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java @@ -1,8 +1,8 @@ -package java.cleanthat; +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; import java.util.Optional; -public class MultipleMutators_clean { +public class LiteralsFirstInComparisonsCases { public boolean isHardcoded(String input) { return "hardcoded".equals(input); diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyLiteralsFirst.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java similarity index 61% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyLiteralsFirst.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java index d9fb87dd80..629d24504b 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyLiteralsFirst.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java @@ -1,8 +1,8 @@ -package java.cleanthat; +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; import java.util.Optional; -public class MultipleMutators_clean_onlyLiteralsFirst { +public class LiteralsFirstInComparisonsCases { public boolean isHardcoded(String input) { return "hardcoded".equals(input); diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyOptionalIsPresent.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java similarity index 62% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyOptionalIsPresent.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java index 54600ebc1c..0829602dc1 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators_clean_onlyOptionalIsPresent.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java @@ -1,8 +1,8 @@ -package java.cleanthat; +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; import java.util.Optional; -public class MultipleMutators_clean_onlyOptionalIsPresent { +public class LiteralsFirstInComparisonsCases { public boolean isHardcoded(String input) { return input.equals("hardcoded"); diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators_dirty.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java similarity index 61% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators_dirty.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java index e71b810e2f..8ac230cabc 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators_dirty.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java @@ -1,8 +1,8 @@ -package java.cleanthat; +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; import java.util.Optional; -public class MultipleMutators_dirty { +public class LiteralsFirstInComparisonsCases { public boolean isHardcoded(String input) { return input.equals("hardcoded"); From 5560214545a3d2655298bcb50691c1bf9325dc7f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 27 Feb 2023 15:08:12 -0800 Subject: [PATCH 0542/1120] Rename `.java` to `.test` to match other java formatters. --- .../spotless/CleanthatJavaIntegrationTest.java | 4 ++-- .../maven/java/CleanthatJavaRefactorerTest.java | 14 +++++++------- ....java => LiteralsFirstInComparisons.clean.test} | 0 ....java => LiteralsFirstInComparisons.dirty.test} | 0 ... MultipleMutators.clean.onlyLiteralsFirst.test} | 0 ...tipleMutators.clean.onlyOptionalIsPresent.test} | 0 ...tors.clean.java => MultipleMutators.clean.test} | 0 ...tors.dirty.java => MultipleMutators.dirty.test} | 0 8 files changed, 9 insertions(+), 9 deletions(-) rename testlib/src/main/resources/java/cleanthat/{LiteralsFirstInComparisons.clean.java => LiteralsFirstInComparisons.clean.test} (100%) rename testlib/src/main/resources/java/cleanthat/{LiteralsFirstInComparisons.dirty.java => LiteralsFirstInComparisons.dirty.test} (100%) rename testlib/src/main/resources/java/cleanthat/{MultipleMutators.clean.onlyLiteralsFirst.java => MultipleMutators.clean.onlyLiteralsFirst.test} (100%) rename testlib/src/main/resources/java/cleanthat/{MultipleMutators.clean.onlyOptionalIsPresent.java => MultipleMutators.clean.onlyOptionalIsPresent.test} (100%) rename testlib/src/main/resources/java/cleanthat/{MultipleMutators.clean.java => MultipleMutators.clean.test} (100%) rename testlib/src/main/resources/java/cleanthat/{MultipleMutators.dirty.java => MultipleMutators.dirty.test} (100%) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java index 581bfe89b2..ad6fff9112 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java @@ -37,8 +37,8 @@ void integration() throws IOException { " }", "}"); - setFile("test.java").toResource("java/cleanthat/MultipleMutators.dirty.java"); + setFile("test.java").toResource("java/cleanthat/MultipleMutators.dirty.test"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("test.java").sameAsResource("java/cleanthat/MultipleMutators.clean.java"); + assertFile("test.java").sameAsResource("java/cleanthat/MultipleMutators.clean.test"); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java index 379397f55b..738624cd57 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.maven.java; +package com.diffplug.spotless.maven.test; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -33,7 +33,7 @@ void testEnableDraft() throws Exception { " true", ""); - runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyOptionalIsPresent.java"); + runTest("MultipleMutators.dirty.test", "MultipleMutators.clean.onlyOptionalIsPresent.test"); } @Test @@ -45,7 +45,7 @@ void testLiteralsFirstInComparisons() throws Exception { " ", ""); - runTest("LiteralsFirstInComparisons.dirty.java", "LiteralsFirstInComparisons.clean.java"); + runTest("LiteralsFirstInComparisons.dirty.test", "LiteralsFirstInComparisons.clean.test"); } @Test @@ -59,7 +59,7 @@ void testMultipleMutators_defaultIsJdk7() throws Exception { " ", ""); - runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + runTest("MultipleMutators.dirty.test", "MultipleMutators.clean.onlyLiteralsFirst.test"); } @Test @@ -73,7 +73,7 @@ void testMultipleMutators_Jdk11IntroducedOptionalisPresent() throws Exception { " ", ""); - runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.java"); + runTest("MultipleMutators.dirty.test", "MultipleMutators.clean.test"); } @Test @@ -89,7 +89,7 @@ void testExcludeOptionalNotEmpty() throws Exception { " ", ""); - runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + runTest("MultipleMutators.dirty.test", "MultipleMutators.clean.onlyLiteralsFirst.test"); } @Test @@ -101,7 +101,7 @@ void testIncludeOnlyLiteralsFirstInComparisons() throws Exception { " ", ""); - runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java"); + runTest("MultipleMutators.dirty.test", "MultipleMutators.clean.onlyLiteralsFirst.test"); } private void runTest(String dirtyPath, String cleanPath) throws Exception { diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.test similarity index 100% rename from testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.java rename to testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.clean.test diff --git a/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java b/testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.test similarity index 100% rename from testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.java rename to testlib/src/main/resources/java/cleanthat/LiteralsFirstInComparisons.dirty.test diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.test similarity index 100% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyLiteralsFirst.test diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.test similarity index 100% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.test diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.test similarity index 100% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.test diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.test similarity index 100% rename from testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.java rename to testlib/src/main/resources/java/cleanthat/MultipleMutators.dirty.test From 78e00498120b9dbce12510982995b2783d0b026c Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 27 Feb 2023 23:15:13 +0000 Subject: [PATCH 0543/1120] Published lib/2.36.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 87af50c159..53ceeedfaf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.36.0] - 2023-02-27 ### Added * `gradlew equoIde` opens a repeatable clean Spotless dev environment. ([#1523](https://github.com/diffplug/spotless/pull/1523)) * `cleanthat` added `includeDraft` option, to include draft mutators from composite mutators. ([#1574](https://github.com/diffplug/spotless/pull/1574)) From c4d612d125e668231f428697014c6abc78b39336 Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 27 Feb 2023 23:16:43 +0000 Subject: [PATCH 0544/1120] Published gradle/6.16.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 50 ++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 41bb70e556..c19a7de733 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.16.0] - 2023-02-27 ### Added * `cleanthat` now has `includeDraft` option, to include draft mutators from composite mutators. ([#1574](https://github.com/diffplug/spotless/pull/1574)) * `npm`-based formatters (`prettier`, `tsfmt` and `eslint`) now support caching of `node_modules` directory. diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 6c181c9330..b66d423e6b 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.15.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.16.0-blue.svg)](CHANGES.md) [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -123,10 +123,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -138,7 +138,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -282,8 +282,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -334,8 +334,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -406,7 +406,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -438,7 +438,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -470,7 +470,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -504,7 +504,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -525,7 +525,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -550,7 +550,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -590,7 +590,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -683,7 +683,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -747,7 +747,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -822,7 +822,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -1049,7 +1049,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1122,9 +1122,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1157,11 +1157,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.15.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From d95083d260138f09005fdcfc452c3d763bd193a3 Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 27 Feb 2023 23:18:45 +0000 Subject: [PATCH 0545/1120] Published maven/2.34.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f39449fb15..36a51d6ef2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.34.0] - 2023-02-27 ### Added * `cleanthat` added `includeDraft` option, to include draft mutators from composite mutators. ([#1574](https://github.com/diffplug/spotless/pull/1574)) * `npm`-based formatters (`prettier`, `tsfmt` and `eslint`) now support caching of `node_modules` directory. diff --git a/plugin-maven/README.md b/plugin-maven/README.md index c91c73f80a..426b00184e 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.33.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.33.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.34.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.34.0/index.html) + 2.8 ${maven.compiler.source} - * + SafeAndConsensual - + LiteralsFirstInComparisons OptionalNotEmpty + false ``` From c836a673025c1854ba9d0f4fca284ffc27141a20 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 5 Mar 2023 19:00:21 +0400 Subject: [PATCH 0569/1120] Improve documentation --- plugin-gradle/README.md | 11 +++++++++++ plugin-maven/README.md | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 171504e4df..a345e45e23 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -180,6 +180,17 @@ spotless { target 'src/*/java/**/*.java' ``` +### removeUnusedImports + +``` +spotless { + java { + removeUnusedImports() + // optional: you may switch for `google-java-format` as underlying engine to `cleanthat-javaparser-unnecessaryimport` + // which enables processing any language level source file with a JDK8+ Runtime + removeUnusedImports().engine('cleanthat-javaparser-unnecessaryimport') +``` + ### google-java-format [homepage](https://github.com/google/google-java-format). [changelog](https://github.com/google/google-java-format/releases). diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 0520aa6d97..82217a26f7 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -207,6 +207,14 @@ any other maven phase (i.e. compile) then it can be configured as below; ``` +### removeUnusedImports + +```xml + + google-java-format + +``` + ### google-java-format [homepage](https://github.com/google/google-java-format). [changelog](https://github.com/google/google-java-format/releases). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/GoogleJavaFormat.java). From 3bcdda8aa510b7ddf8b7ee2e7608ec1ee5a5ccff Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 7 Mar 2023 06:08:34 +0000 Subject: [PATCH 0570/1120] chore(deps): update plugin io.github.gradle-nexus.publish-plugin to v1.3.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 1478f5af31..dbca443e3e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,7 +10,7 @@ plugins { // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.1.0' apply false // https://github.com/gradle-nexus/publish-plugin/releases - id 'io.github.gradle-nexus.publish-plugin' version '1.2.0' apply false + id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases id 'com.github.spotbugs' version '5.0.13' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md From f3c57711afe80079b2973a27250189192f957c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Dragojevi=C4=87?= Date: Tue, 7 Mar 2023 14:40:43 +0100 Subject: [PATCH 0571/1120] Use correct property for scalafmt The example uses an outdated property for configuring scalafmt. --- plugin-gradle/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index b66d423e6b..267136e4ac 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -430,8 +430,8 @@ spotless { ```gradle spotless { scala { - // version and configFile, majorScalaVersion are all optional - scalafmt('3.5.9').configFile('scalafmt.conf').majorScalaVersion('2.13') + // version and configFile, scalaMajorVersion are all optional + scalafmt('3.5.9').configFile('scalafmt.conf').scalaMajorVersion('2.13') ``` From 7ad63c95f8983d1925ccc1a52605c515e551ea7b Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Tue, 7 Mar 2023 20:49:17 +0400 Subject: [PATCH 0572/1120] Add sealed class testCases --- .../SealedClassTestsFormatted.test | 45 ++++++++++++++++++ .../SealedClassTestsUnformatted.test | 46 +++++++++++++++++++ ...portsStep_withCleanthatJavaparserTest.java | 4 +- ...dImportsStep_withGoogleJavaFormatTest.java | 8 ++-- 4 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 testlib/src/main/resources/java/removeunusedimports/SealedClassTestsFormatted.test create mode 100644 testlib/src/main/resources/java/removeunusedimports/SealedClassTestsUnformatted.test diff --git a/testlib/src/main/resources/java/removeunusedimports/SealedClassTestsFormatted.test b/testlib/src/main/resources/java/removeunusedimports/SealedClassTestsFormatted.test new file mode 100644 index 0000000000..2ef96e6c72 --- /dev/null +++ b/testlib/src/main/resources/java/removeunusedimports/SealedClassTestsFormatted.test @@ -0,0 +1,45 @@ +/* + * Copyright 2015-2023 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package java.removeunusedimports; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; + +class SealedClassTests extends AbstractJupiterTestEngineTests { + + @Test + void sealedTestClassesAreTestClasses() { + executeTestsForClass(TestCase.class).testEvents() // + .assertStatistics(stats -> stats.finished(2).succeeded(1).failed(1)); + } + + sealed + abstract static class AbstractTestCase + permits TestCase + { + + @Test + void succeedingTest() { + assertTrue(true); + } + + @Test + void failingTest() { + fail("always fails"); + } + } + + static final class TestCase extends AbstractTestCase { + } + +} diff --git a/testlib/src/main/resources/java/removeunusedimports/SealedClassTestsUnformatted.test b/testlib/src/main/resources/java/removeunusedimports/SealedClassTestsUnformatted.test new file mode 100644 index 0000000000..942aa4d235 --- /dev/null +++ b/testlib/src/main/resources/java/removeunusedimports/SealedClassTestsUnformatted.test @@ -0,0 +1,46 @@ +/* + * Copyright 2015-2023 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package java.removeunusedimports; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; +import useless.project.UnusedClass; + +class SealedClassTests extends AbstractJupiterTestEngineTests { + + @Test + void sealedTestClassesAreTestClasses() { + executeTestsForClass(TestCase.class).testEvents() // + .assertStatistics(stats -> stats.finished(2).succeeded(1).failed(1)); + } + + sealed + abstract static class AbstractTestCase + permits TestCase + { + + @Test + void succeedingTest() { + assertTrue(true); + } + + @Test + void failingTest() { + fail("always fails"); + } + } + + static final class TestCase extends AbstractTestCase { + } + +} diff --git a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withCleanthatJavaparserTest.java b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withCleanthatJavaparserTest.java index d34096de87..11e31aeae2 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withCleanthatJavaparserTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withCleanthatJavaparserTest.java @@ -32,7 +32,9 @@ void behavior() throws Exception { .testResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test", "java/removeunusedimports/JavaCodeWithLicensePackageFormatted.test") .testResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test", "java/removeunusedimports/JavaCodeWithPackageFormatted.test") .testResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test", "java/removeunusedimports/Jdk17TextBlockFormatted.test") - .testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test"); + .testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test") + // Sealed classes are introduced with JDK15: This syntax is not supported by javaParser: such files are not trimmed from unused imports (for now) + .testResource("java/removeunusedimports/SealedClassTestsUnformatted.test", "java/removeunusedimports/SealedClassTestsUnformatted.test"); } @Test diff --git a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withGoogleJavaFormatTest.java b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withGoogleJavaFormatTest.java index ba7dfef4a3..44699a8215 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withGoogleJavaFormatTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/RemoveUnusedImportsStep_withGoogleJavaFormatTest.java @@ -31,9 +31,11 @@ void behavior() throws Exception { .testResource("java/removeunusedimports/JavaCodeWithLicenseUnformatted.test", "java/removeunusedimports/JavaCodeWithLicenseFormatted.test") .testResource("java/removeunusedimports/JavaCodeWithLicensePackageUnformatted.test", "java/removeunusedimports/JavaCodeWithLicensePackageFormatted.test") .testResource("java/removeunusedimports/JavaCodeWithPackageUnformatted.test", "java/removeunusedimports/JavaCodeWithPackageFormatted.test") - // GoogleFormat requires running over a JDK17 to handle JDK17 features - // .testResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test", "java/removeunusedimports/Jdk17TextBlockFormatted.test") - .testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test"); + .testResource("java/removeunusedimports/RevelcUnformatted.test", "java/removeunusedimports/RevelcFormatted.test") + // GoogleFormat requires running over a JDK17 to handle JDK17 features + // .testResource("java/removeunusedimports/Jdk17TextBlockUnformatted.test", "java/removeunusedimports/Jdk17TextBlockFormatted.test") + //.testResource("java/removeunusedimports/SealedClassTestsUnformatted.test", "java/removeunusedimports/SealedClassTestsFormatted.test") + ; } @Test From d3c081262ac8ada9440ffff2c6b4c751822ac34e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 7 Mar 2023 23:51:50 +0000 Subject: [PATCH 0573/1120] fix(deps): update dependency org.eclipse.jgit:org.eclipse.jgit to v6.5.0.202303070854-r --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 8820a36e30..3f3ae9a2ee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -29,7 +29,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 -VER_JGIT=6.4.0.202211300538-r +VER_JGIT=6.5.0.202303070854-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 VER_MOCKITO=5.1.1 From d8b0e20ef0a22d0aa03e668a4917f3f1ba4dc725 Mon Sep 17 00:00:00 2001 From: Kenji Abe Date: Wed, 8 Mar 2023 09:11:51 +0900 Subject: [PATCH 0574/1120] Use StepHarnessWithFile --- .../java/com/diffplug/spotless/StepHarness.java | 14 +++----------- .../spotless/generic/LicenseHeaderStepTest.java | 12 +++++++----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java index 032345827d..c611cc738a 100644 --- a/testlib/src/main/java/com/diffplug/spotless/StepHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/StepHarness.java @@ -57,22 +57,14 @@ public static StepHarness forFormatter(Formatter formatter) { /** Asserts that the given element is transformed as expected, and that the result is idempotent. */ public StepHarness test(String before, String after) { - return test(before, after, ""); - } - - public StepHarness test(String before, String after, String fileName) { - String actual = formatter.compute(LineEnding.toUnix(before), new File(fileName)); + String actual = formatter.compute(LineEnding.toUnix(before), new File("")); assertEquals(after, actual, "Step application failed"); - return testUnaffected(after, fileName); + return testUnaffected(after); } /** Asserts that the given element is idempotent w.r.t the step under test. */ public StepHarness testUnaffected(String idempotentElement) { - return testUnaffected(idempotentElement, ""); - } - - public StepHarness testUnaffected(String idempotentElement, String fileName) { - String actual = formatter.compute(LineEnding.toUnix(idempotentElement), new File(fileName)); + String actual = formatter.compute(LineEnding.toUnix(idempotentElement), new File("")); assertEquals(idempotentElement, actual, "Step is not idempotent"); return this; } diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java index d8d7700be5..6df0c23950 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java @@ -21,6 +21,8 @@ import java.time.YearMonth; import java.time.ZoneOffset; +import com.diffplug.spotless.StepHarnessWithFile; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -266,18 +268,18 @@ void should_preserve_year_for_license_with_address() throws Throwable { @Test void should_apply_license_containing_filename_token() throws Exception { FormatterStep step = LicenseHeaderStep.headerDelimiter(header(HEADER_WITH_$FILE), package_).build(); - StepHarness.forStep(step) - .test(getTestResource(FILE_NO_LICENSE), hasHeaderFileName(HEADER_WITH_$FILE, "Test.java"), "Test.java"); + StepHarnessWithFile.forStep(this, step) + .test(new File("Test.java"), getTestResource(FILE_NO_LICENSE), hasHeaderFileName(HEADER_WITH_$FILE, "Test.java")); } @Test void should_apply_license_containing_YEAR_filename_token() throws Exception { FormatterStep step = LicenseHeaderStep.headerDelimiter(header(HEADER_WITH_$YEAR_$FILE), package_).build(); - StepHarness.forStep(step) + StepHarnessWithFile.forStep(this, step) .test( + new File("Test.java"), getTestResource(FILE_NO_LICENSE), - hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java"), - "Test.java" + hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java") ); } } From a414e937e2c89e56ea038096c8f0ac1ee6fb1eff Mon Sep 17 00:00:00 2001 From: Kenji Abe Date: Wed, 8 Mar 2023 09:16:38 +0900 Subject: [PATCH 0575/1120] Fix CHANGES.md --- CHANGES.md | 3 ++- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f5033f6d2a..c44dfd9050 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,9 +10,10 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* You can now put the filename into a license header template with `$FILE`. ([#1605](https://github.com/diffplug/spotless/pull/1605) fixes [#1147](https://github.com/diffplug/spotless/issues/1147)) ### Changes * We are now opting in to Gradle's new stable configuration cache. ([#1591](https://github.com/diffplug/spotless/pull/1591)) -* Support a file name field in license headers. ([#1605](https://github.com/diffplug/spotless/pull/1605)) ## [2.36.0] - 2023-02-27 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c19a7de733..3ecf10d071 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* You can now put the filename into a license header template with `$FILE`. ([#1605](https://github.com/diffplug/spotless/pull/1605) fixes [#1147](https://github.com/diffplug/spotless/issues/1147)) ## [6.16.0] - 2023-02-27 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 36a51d6ef2..5c50b62027 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* You can now put the filename into a license header template with `$FILE`. ([#1605](https://github.com/diffplug/spotless/pull/1605) fixes [#1147](https://github.com/diffplug/spotless/issues/1147)) ## [2.34.0] - 2023-02-27 ### Added From bc34a4b8e0b2fe5063df528411163d19e2ee8d85 Mon Sep 17 00:00:00 2001 From: Kenji Abe Date: Wed, 8 Mar 2023 09:19:04 +0900 Subject: [PATCH 0576/1120] Run spotlessApply --- .../generic/LicenseHeaderStepTest.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java index 6df0c23950..7d2e018028 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java @@ -21,8 +21,6 @@ import java.time.YearMonth; import java.time.ZoneOffset; -import com.diffplug.spotless.StepHarnessWithFile; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -30,6 +28,7 @@ import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.StepHarnessWithFile; import com.diffplug.spotless.generic.LicenseHeaderStep.YearMode; class LicenseHeaderStepTest extends ResourceHarness { @@ -173,8 +172,8 @@ private String hasHeaderFileName(String license, String fileName) throws IOExcep private String hasHeaderYearFileName(String license, String year, String fileName) throws IOException { return header(license) - .replace("$YEAR", year) - .replace("$FILE", fileName) + getTestResource(FILE_NO_LICENSE); + .replace("$YEAR", year) + .replace("$FILE", fileName) + getTestResource(FILE_NO_LICENSE); } private static String currentYear() { @@ -269,17 +268,16 @@ void should_preserve_year_for_license_with_address() throws Throwable { void should_apply_license_containing_filename_token() throws Exception { FormatterStep step = LicenseHeaderStep.headerDelimiter(header(HEADER_WITH_$FILE), package_).build(); StepHarnessWithFile.forStep(this, step) - .test(new File("Test.java"), getTestResource(FILE_NO_LICENSE), hasHeaderFileName(HEADER_WITH_$FILE, "Test.java")); + .test(new File("Test.java"), getTestResource(FILE_NO_LICENSE), hasHeaderFileName(HEADER_WITH_$FILE, "Test.java")); } @Test void should_apply_license_containing_YEAR_filename_token() throws Exception { FormatterStep step = LicenseHeaderStep.headerDelimiter(header(HEADER_WITH_$YEAR_$FILE), package_).build(); StepHarnessWithFile.forStep(this, step) - .test( - new File("Test.java"), - getTestResource(FILE_NO_LICENSE), - hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java") - ); + .test( + new File("Test.java"), + getTestResource(FILE_NO_LICENSE), + hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java")); } } From 97ab64cb02f9e339be5d8f8cf5c610c1edc635f5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 7 Mar 2023 16:24:25 -0800 Subject: [PATCH 0577/1120] Move `GrEclipseFormatterStepImpl` --- .../extra/glue}/groovy/GrEclipseFormatterStepImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename {_ext/eclipse-groovy/src/main/java/com/diffplug/spotless/extra/eclipse => lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue}/groovy/GrEclipseFormatterStepImpl.java (97%) diff --git a/_ext/eclipse-groovy/src/main/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java similarity index 97% rename from _ext/eclipse-groovy/src/main/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImpl.java rename to lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index 1d2b71c69f..122eabf471 100644 --- a/_ext/eclipse-groovy/src/main/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.diffplug.spotless.extra.eclipse.groovy; +package com.diffplug.spotless.extra.glue.groovy; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -106,7 +106,7 @@ public GroovyErrorListener() { errors = Collections.synchronizedList(new ArrayList()); ILog groovyLogger = GroovyCoreActivator.getDefault().getLog(); groovyLogger.addLogListener(this); - synchronized(GroovyLogManager.manager) { + synchronized (GroovyLogManager.manager) { GroovyLogManager.manager.addLogger(this); } } @@ -119,7 +119,7 @@ public void logging(final IStatus status, final String plugin) { public boolean errorsDetected() { ILog groovyLogger = GroovyCoreActivator.getDefault().getLog(); groovyLogger.removeLogListener(this); - synchronized(GroovyLogManager.manager) { + synchronized (GroovyLogManager.manager) { GroovyLogManager.manager.removeLogger(this); } return 0 != errors.size(); From 060f3dbcbe66560c984d2b96c025a4ffca5a7727 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 7 Mar 2023 16:29:26 -0800 Subject: [PATCH 0578/1120] Prune GrEclipseFormatterStepImpl, details below: - `org.codehaus.groovy` contains `eclipse-trace.jar` - unless we do `NestedJars` stuff, GroovyLogManager jars will not be available - let's see if we can run without them (not clear, we'll find out) --- .../groovy/GrEclipseFormatterStepImpl.java | 47 +------------------ 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index 122eabf471..1077eeaaf6 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -23,9 +23,6 @@ import java.util.List; import java.util.Properties; -import org.codehaus.groovy.eclipse.GroovyLogManager; -import org.codehaus.groovy.eclipse.IGroovyLogger; -import org.codehaus.groovy.eclipse.TraceCategory; import org.codehaus.groovy.eclipse.core.GroovyCoreActivator; import org.codehaus.groovy.eclipse.refactoring.formatter.DefaultGroovyFormatter; import org.codehaus.groovy.eclipse.refactoring.formatter.FormatterPreferencesOnStore; @@ -39,11 +36,6 @@ import org.eclipse.jface.text.TextSelection; import org.eclipse.text.edits.TextEdit; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; - /** Spotless-Formatter step which calls out to the Groovy-Eclipse formatter. */ public class GrEclipseFormatterStepImpl { /** @@ -58,25 +50,11 @@ public class GrEclipseFormatterStepImpl { private final boolean ignoreFormatterProblems; public GrEclipseFormatterStepImpl(final Properties properties) throws Exception { - SpotlessEclipseFramework.setup(new FrameworkConfig()); PreferenceStore preferences = createPreferences(properties); preferencesStore = new FormatterPreferencesOnStore(preferences); ignoreFormatterProblems = Boolean.parseBoolean(properties.getProperty(IGNORE_FORMATTER_PROBLEMS, "false")); } - private static class FrameworkConfig implements SpotlessEclipseConfig { - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - config.useSlf4J(GrEclipseFormatterStepImpl.class.getPackage().getName()); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.add(new GroovyCoreActivator()); - } - } - /** Formatting Groovy string */ public String format(String raw) throws Exception { IDocument doc = new Document(raw); @@ -94,7 +72,7 @@ public String format(String raw) throws Exception { /** * Eclipse Groovy formatter does not signal problems by its return value, but by logging errors. */ - private static class GroovyErrorListener implements ILogListener, IGroovyLogger { + private static class GroovyErrorListener implements ILogListener { private final List errors; @@ -106,9 +84,6 @@ public GroovyErrorListener() { errors = Collections.synchronizedList(new ArrayList()); ILog groovyLogger = GroovyCoreActivator.getDefault().getLog(); groovyLogger.addLogListener(this); - synchronized (GroovyLogManager.manager) { - GroovyLogManager.manager.addLogger(this); - } } @Override @@ -119,9 +94,6 @@ public void logging(final IStatus status, final String plugin) { public boolean errorsDetected() { ILog groovyLogger = GroovyCoreActivator.getDefault().getLog(); groovyLogger.removeLogListener(this); - synchronized (GroovyLogManager.manager) { - GroovyLogManager.manager.removeLogger(this); - } return 0 != errors.size(); } @@ -140,23 +112,6 @@ public String toString() { return string.toString(); } - - @Override - public boolean isCategoryEnabled(TraceCategory cat) { - /* - * Note that the compiler errors are just additionally caught here. - * They are also printed directly to System.err. - * See org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.recordProblems - * for details. - */ - return TraceCategory.COMPILER.equals(cat); - } - - @Override - public void log(TraceCategory arg0, String arg1) { - errors.add(arg1); - } - } private static PreferenceStore createPreferences(final Properties properties) throws IOException { From 39aaa0a65f05027589b9783908d39820b13fbc14 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 7 Mar 2023 18:03:05 -0800 Subject: [PATCH 0579/1120] Remove _ext/eclipse-groovy --- _ext/eclipse-groovy/CHANGES.md | 66 ----------- _ext/eclipse-groovy/LICENSE.txt | 70 ------------ _ext/eclipse-groovy/README.md | 13 --- _ext/eclipse-groovy/build.gradle | 56 ---------- _ext/eclipse-groovy/gradle.properties | 14 --- .../GrEclipseFormatterStepImplTest.java | 105 ------------------ .../extra/eclipse/groovy/TestData.java | 67 ----------- .../src/test/resources/expected/nominal.test | 13 --- .../src/test/resources/input/nominal.test | 15 --- 9 files changed, 419 deletions(-) delete mode 100644 _ext/eclipse-groovy/CHANGES.md delete mode 100644 _ext/eclipse-groovy/LICENSE.txt delete mode 100644 _ext/eclipse-groovy/README.md delete mode 100644 _ext/eclipse-groovy/build.gradle delete mode 100644 _ext/eclipse-groovy/gradle.properties delete mode 100644 _ext/eclipse-groovy/src/test/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImplTest.java delete mode 100644 _ext/eclipse-groovy/src/test/java/com/diffplug/spotless/extra/eclipse/groovy/TestData.java delete mode 100644 _ext/eclipse-groovy/src/test/resources/expected/nominal.test delete mode 100644 _ext/eclipse-groovy/src/test/resources/input/nominal.test diff --git a/_ext/eclipse-groovy/CHANGES.md b/_ext/eclipse-groovy/CHANGES.md deleted file mode 100644 index b0f909ccb2..0000000000 --- a/_ext/eclipse-groovy/CHANGES.md +++ /dev/null @@ -1,66 +0,0 @@ -# spotless-eclipse-groovy - -We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.5.0`). - -## [Unreleased] -### Fixed -* Fix typo in gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) - -## [4.3.0] - 2021-10-13 -### Added -* Switch to Groovy-Eclipse release 4.3.0 for Eclipse 4.21 using Groovy 4.0.0 Beta 1. - -## [4.2.0] - 2021-09-14 -### Added -* Switch to Groovy-Eclipse release 4.2.0 for Eclipse 4.20 using Groovy 4.0.0 Alpha 3. - -### Fixed -* Fixed IndexOutOfBoundsException in parallel execution of `eclipse-groovy` formatter ([#877](https://github.com/diffplug/spotless/issues/877)) - -## [4.1.0] - 2021-06-05 -### Added -* Switch to Groovy-Eclipse release 4.1.0 for Eclipse 4.19 using Groovy 4.0.0 Alpha 2. - -## [4.0.0] - 2021-04-10 -### Added -* Switch to Groovy-Eclipse release 4.0.0 for Eclipse 4.18 using Groovy 4.0.0 Alpha 2. -* **BREAKING** Keep spotless-eclipse-groovy major version in sync with Groovy-Eclipse version. - -## [3.9.0] - 2020-10-17 -### Added -* Fixed version number determined by change log. - -## [3.8.1] - 2020-10-17 -### Added -* Switch to Groovy-Eclipse release 3.9.0 for Eclipse 4.17 using Groovy-Indy 3.0.6. - -## [3.8.0] - 2020-10-04 -### Added -* Switch to Groovy-Eclipse release 3.8.0 for Eclipse 4.16 using Groovy-Indy 3.0.4. - -## [3.7.0] - 2020-10-03 -### Added -* Switch to Groovy-Eclipse release 3.7.0 for Eclipse 4.15 using Groovy-Indy 3.0.2. - -## [3.6.0] - 2020-09-26 -### Added -* Switch to Groovy-Eclipse release 3.6.0 for Eclipse 4.14. - -## [3.5.0] - 2019-09-01 -* Switch to Groovy-Eclipse release 3.5.0 for Eclipse 4.13 ([#480](https://github.com/diffplug/spotless/issues/480)). - -## [3.4.0] - 2019-07-24 -* Switch to Groovy-Eclipse release 3.4.0 for Eclipse 4.12 using Groovy-Indy 3.0.0 ([#423](https://github.com/diffplug/spotless/pull/423)). - -## [3.2.0] - 2019-03-16 -* Switch to Groovy-Eclipse release 3.2.0 for Eclipse 4.10 ([#375](https://github.com/diffplug/spotless/pull/375)). -* Include Eclipse logging allowing formatter warnings/errors to be logged via SLF4J ([#236](https://github.com/diffplug/spotless/issues/236)). - -## [3.0.1] - 2019-02-25 -* Replaced `http` update-site with `https` ([#360](https://github.com/diffplug/spotless/issues/360)). - -## [3.0.0] - 2018-09-04 -* Switch to Groovy-Eclipse release 3.0.0 and Groovy 2.6 ([#288](https://github.com/diffplug/spotless/issues/288)). - -## [2.9.2] - 2018-07-19 -* Initial release! diff --git a/_ext/eclipse-groovy/LICENSE.txt b/_ext/eclipse-groovy/LICENSE.txt deleted file mode 100644 index 3d967aee74..0000000000 --- a/_ext/eclipse-groovy/LICENSE.txt +++ /dev/null @@ -1,70 +0,0 @@ -Eclipse Public License - v 1.0 - -THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. - -1. DEFINITIONS - -"Contribution" means: - -a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and -b) in the case of each subsequent Contributor: -i) changes to the Program, and -ii) additions to the Program; -where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. -"Contributor" means any person or entity that distributes the Program. - -"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. - -"Program" means the Contributions distributed in accordance with this Agreement. - -"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. - -2. GRANT OF RIGHTS - -a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. -b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. -c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. -d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. -3. REQUIREMENTS - -A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: - -a) it complies with the terms and conditions of this Agreement; and -b) its license agreement: -i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; -ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; -iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and -iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. -When the Program is made available in source code form: - -a) it must be made available under this Agreement; and -b) a copy of this Agreement must be included with each copy of the Program. -Contributors may not remove or alter any copyright notices contained within the Program. - -Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. - -4. COMMERCIAL DISTRIBUTION - -Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. - -For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. - -5. NO WARRANTY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. - -6. DISCLAIMER OF LIABILITY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -7. GENERAL - -If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. - -If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. - -All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. - -Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. - -This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. \ No newline at end of file diff --git a/_ext/eclipse-groovy/README.md b/_ext/eclipse-groovy/README.md deleted file mode 100644 index 687ed7a132..0000000000 --- a/_ext/eclipse-groovy/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# spotless-eclipse-groovy - -Groovy-Eclipse is not available in a form which can be easily consumed by maven or gradle. -To fix this, we publish Groovy-Eclipse's formatter and all its dependencies, along with a small amount of glue code, into the `com.diffplug.gradle.spotless:spotless-eclipse-groovy` artifact. - -## Build - -To publish a new version, update the `_ext/eclipse-groovy/gradle.properties` appropriately and see [CONTRIBUTING.md](../../CONTRIBUTING.md) how to enable -`_ext` projects. - -## License - -Spotless at large is under the Apache 2.0 license, but this jar is under the EPL v1. diff --git a/_ext/eclipse-groovy/build.gradle b/_ext/eclipse-groovy/build.gradle deleted file mode 100644 index a45590fada..0000000000 --- a/_ext/eclipse-groovy/build.gradle +++ /dev/null @@ -1,56 +0,0 @@ -ext { - developers = [ - fvgh: [ name: 'Frank Vennemeyer', email: 'frankgh@zoho.com' ], - ] - - p2Repository = "https://dist.springsource.org/release/GRECLIPSE/${VER_GRECLIPSE}/e${VER_ECLIPSE}" - - p2Dependencies = [ - 'org.codehaus.groovy.eclipse.refactoring':'+', // GroovyFormatter and related - - // The following lists does not reflect the complete transitive required packages, but - // the once used during code formatting - 'org.codehaus.groovy':'+', // Groovy compiler patches supporting use within GrEclipse and Groovy itself - 'org.codehaus.groovy.eclipse.core':'+', // Groovy core classes (provides central logging used by formatter) - 'org.eclipse.jdt.core':"${VAR_GRECLIPSE_JDT_PATCH}", // Patches org.eclipse.jdt.core classes supporting use within GrEclipse (provides AST generator) - 'org.eclipse.jdt.groovy.core':'+' // Extends org.eclipse.jdt.core for Groovy - ] - - internalJars = [ - //Jars included by org.codehaus.groovy - ////////////////////////////////////////////////////////////////////////// - // Use Groovy compiler compatible with GrEclipse instead of localGroovy - "**/groovy-${VER_GROOVY}", - "**/groovy-parser2", - // Patches/Overrides some of the Groovy compiler classes - '**/groovy-eclipse', - // Provides logging capabilities for groovy-eclipse - '**/eclipse-trace', - //Jars included by org.eclipse.jdt.groovy.core - ////////////////////////////////////////////////////////////////////////// - //Non locking class loader used by groovy compiler - '**/nlcl' - ] - -} - -apply from: rootProject.file('_ext/gradle/update-lockfile.gradle') -apply from: rootProject.file('_ext/gradle/p2-fat-jar-setup.gradle') -apply from: rootProject.file('gradle/java-publish.gradle') - -dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" - // Provides text partitioners for formatters - implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { - exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' - } - testImplementation("org.slf4j:slf4j-simple:${VER_SLF4J}") -} - -////////// -// Test // -////////// -sourceSets { - // Use JAR file with all resources for Eclipse-Groovy integration-tests - test.runtimeClasspath = jar.outputs.files + sourceSets.test.output + sourceSets.test.compileClasspath -} diff --git a/_ext/eclipse-groovy/gradle.properties b/_ext/eclipse-groovy/gradle.properties deleted file mode 100644 index c1c6101caa..0000000000 --- a/_ext/eclipse-groovy/gradle.properties +++ /dev/null @@ -1,14 +0,0 @@ -artifactId=spotless-eclipse-groovy -description=Groovy Eclipse's formatter bundled for Spotless - -# Build requirements -VER_JAVA=11 - -# Compile -VER_ECLIPSE=4.21 -VER_SPOTLESS_ECLIPSE_BASE=[3.4.2,4.0.0[ -VER_ECLIPSE_JFACE=[3.15.300,4.0.0[ -VER_GRECLIPSE=4.3.0 -VER_GROOVY=4.0.0 -# Use org.eclipse.jdt.core patched for Groovy-Eclipse -VAR_GRECLIPSE_JDT_PATCH=3.27.0.v202109301420-e2109-RELEASE diff --git a/_ext/eclipse-groovy/src/test/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImplTest.java b/_ext/eclipse-groovy/src/test/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImplTest.java deleted file mode 100644 index 011c68e148..0000000000 --- a/_ext/eclipse-groovy/src/test/java/com/diffplug/spotless/extra/eclipse/groovy/GrEclipseFormatterStepImplTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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.spotless.extra.eclipse.groovy; - -import static com.diffplug.spotless.extra.eclipse.groovy.GrEclipseFormatterStepImpl.IGNORE_FORMATTER_PROBLEMS; -import static org.codehaus.groovy.eclipse.refactoring.PreferenceConstants.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.util.Properties; -import java.util.function.Consumer; - -import org.eclipse.jdt.core.JavaCore; -import org.junit.jupiter.api.Test; - -/** Smoke test checking that transitive dependencies are complete. */ -class GrEclipseFormatterStepImplTest { - - private final static TestData TEST_DATA = TestData.getTestDataOnFileSystem(); - private final static String PARSER_EXCEPTION = "class Test { void method() {} "; - private final static String SCANNER_EXCEPTION = "{"; - private final static String BOUNDED_WILDCARDS_UNFORMATTED = "foo(Map e)\n{\ne.clear();\n}"; - private final static String BOUNDED_WILDCARDS_FORMATTED = "foo(Map e) {\n\te.clear();\n}"; - - @Test - void defaultFormat() throws Throwable { - String output = format(TEST_DATA.input("nominal.test"), config -> {}); - assertEquals(TEST_DATA.expected("nominal.test"), - output, "Unexpected default formatting."); - } - - @Test - void validConfiguration() throws Throwable { - String output = format(TEST_DATA.input("nominal.test"), config -> { - config.put(GROOVY_FORMATTER_REMOVE_UNNECESSARY_SEMICOLONS, "true"); - }); - assertEquals(TEST_DATA.expected("nominal.test").replace(";", ""), - output, "Unexpected formatting for custom configuration."); - } - - @Test - void invalidConfiguration() throws Throwable { - String output = format(TEST_DATA.input("nominal.test"), config -> { - config.put(GROOVY_FORMATTER_INDENTATION, JavaCore.SPACE); - config.put(GROOVY_FORMATTER_INDENTATION_SIZE, "noInteger"); - }); - assertEquals(TEST_DATA.expected("nominal.test").replace("\t", " "), - output, "Groovy formatter does not replace invalid preferences by their defaults."); - } - - /** Test the handling AntlrParserPlugin exceptions by GroovyLogManager.manager logging */ - @Test - void parserException() throws Throwable { - assertThrows(IllegalArgumentException.class, () -> format(PARSER_EXCEPTION, config -> {})); - } - - /** Test the handling GroovyDocumentScanner exceptions by GroovyCore logging */ - @Test - void scannerException() throws Throwable { - assertThrows(IllegalArgumentException.class, () -> format(SCANNER_EXCEPTION, config -> {})); - } - - /** - * Test the handling bounded wildcards templates - * No exception since Groovy-Eclipse 3.0.0. - * Formatting fixed with Groovy-Eclipse 3.14 (org.codehaus.groovy:groovy[3.+]). - */ - @Test - void boundedWildCards() throws Throwable { - String output = format(BOUNDED_WILDCARDS_UNFORMATTED, config -> {}); - assertEquals(BOUNDED_WILDCARDS_FORMATTED, - output, "Unexpected formatting after bounded wildcards."); - } - - @Test - void ignoreCompilerProblems() throws Throwable { - Consumer ignoreCompilerProblems = config -> { - config.setProperty(IGNORE_FORMATTER_PROBLEMS, "true"); - }; - format(PARSER_EXCEPTION, ignoreCompilerProblems); - format(SCANNER_EXCEPTION, ignoreCompilerProblems); - //Test is passed if it does not throw an exception. See issue 237. - } - - private static String format(final String input, final Consumer config) throws Exception { - Properties properties = new Properties(); - config.accept(properties); - GrEclipseFormatterStepImpl formatter = new GrEclipseFormatterStepImpl(properties); - return formatter.format(input); - } - -} diff --git a/_ext/eclipse-groovy/src/test/java/com/diffplug/spotless/extra/eclipse/groovy/TestData.java b/_ext/eclipse-groovy/src/test/java/com/diffplug/spotless/extra/eclipse/groovy/TestData.java deleted file mode 100644 index b0e4f525da..0000000000 --- a/_ext/eclipse-groovy/src/test/java/com/diffplug/spotless/extra/eclipse/groovy/TestData.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.spotless.extra.eclipse.groovy; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class TestData { - public static TestData getTestDataOnFileSystem() { - final String userDir = System.getProperty("user.dir", "."); - Path dataPath = Paths.get(userDir, "src", "test", "resources"); - if (Files.isDirectory(dataPath)) { - return new TestData(dataPath); - } - return null; - } - - private final Path inputPath; - private final Path expectedPath; - - private TestData(Path dataPath) { - inputPath = dataPath.resolve("input").toAbsolutePath(); - expectedPath = dataPath.resolve("expected").toAbsolutePath(); - for (Path testDataDir : new Path[]{inputPath, expectedPath}) { - if (!Files.isDirectory(testDataDir)) { - throw new IllegalArgumentException(String.format("'%1$s' is not a directory.", testDataDir)); - } - } - } - - public String input(final String fileName) throws Exception { - return read(inputPath.resolve(fileName)); - } - - public String expected(final String fileName) { - Path path = expectedPath.resolve(fileName); - return read(path); - } - - private String read(final Path xmlPath) { - if (!Files.isRegularFile(xmlPath)) { - throw new IllegalArgumentException(String.format("'%1$s' is not a regular file.", xmlPath)); - } - try { - String checkedOutFileContent = new String(java.nio.file.Files.readAllBytes(xmlPath), "UTF8"); - return checkedOutFileContent.replace("\r", ""); //Align GIT end-of-line normalization - } catch (IOException e) { - throw new IllegalArgumentException(String.format("Failed to read '%1$s'.", xmlPath), e); - } - } - -} diff --git a/_ext/eclipse-groovy/src/test/resources/expected/nominal.test b/_ext/eclipse-groovy/src/test/resources/expected/nominal.test deleted file mode 100644 index a40d247bad..0000000000 --- a/_ext/eclipse-groovy/src/test/resources/expected/nominal.test +++ /dev/null @@ -1,13 +0,0 @@ -class TestClass { - def a; - - TestClass(String s) { - this.a = s - } - def methodNamedArgs(Map args) { - "named args: $args" - } -} - -def t = new TestClass() -def arr = [4, 'string1', 'string2'] diff --git a/_ext/eclipse-groovy/src/test/resources/input/nominal.test b/_ext/eclipse-groovy/src/test/resources/input/nominal.test deleted file mode 100644 index 85f742677f..0000000000 --- a/_ext/eclipse-groovy/src/test/resources/input/nominal.test +++ /dev/null @@ -1,15 +0,0 @@ -class TestClass { - def a; - -TestClass(String s) { -this.a = s -} - def methodNamedArgs(Map args) { - "named args: $args" - } -} - -def t = new TestClass() -def arr = [4, -'string1', -'string2'] From cd2efd3348a20de5352590e7be9d9a4476d180ef Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 8 Mar 2023 21:36:30 +0400 Subject: [PATCH 0580/1120] Improve LicenseHeader default regex for Java --- .../spotless/generic/LicenseHeaderStep.java | 1 + .../gradle/spotless/JavaExtension.java | 4 +--- .../spotless/maven/groovy/Groovy.java | 3 ++- .../diffplug/spotless/maven/java/Java.java | 3 ++- .../diffplug/spotless/maven/scala/Scala.java | 3 ++- .../resources/license/HelloWorld_java.test | 5 +++++ .../license/HelloWorld_withImport_java.test | 7 +++++++ .../main/resources/license/module-info.test | 5 +++++ .../generic/LicenseHeaderStepTest.java | 20 ++++++++++++++++++- 9 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 testlib/src/main/resources/license/HelloWorld_java.test create mode 100644 testlib/src/main/resources/license/HelloWorld_withImport_java.test create mode 100644 testlib/src/main/resources/license/module-info.test diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index b4c0cf2a6f..3b0bf829f8 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -45,6 +45,7 @@ /** Prefixes a license header before the package statement. */ public final class LicenseHeaderStep { + public static final String DEFAULT_JAVA_HEADER_DELIMITER = "(package|import|public|class|module) "; private static final Logger LOGGER = LoggerFactory.getLogger(LicenseHeaderStep.class); public enum YearMode { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index f351dd6188..bfe1a96955 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -50,9 +50,7 @@ public JavaExtension(SpotlessExtension spotless) { super(spotless); } - // If this constant changes, don't forget to change the similarly-named one in - // testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java as well - static final String LICENSE_HEADER_DELIMITER = "package "; + static final String LICENSE_HEADER_DELIMITER = LicenseHeaderStep.DEFAULT_JAVA_HEADER_DELIMITER; @Override public LicenseHeaderConfig licenseHeader(String licenseHeader) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java index 8041b812f9..35b91f3677 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java @@ -20,6 +20,7 @@ import org.apache.maven.project.MavenProject; import com.diffplug.common.collect.ImmutableSet; +import com.diffplug.spotless.generic.LicenseHeaderStep; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -32,7 +33,7 @@ public class Groovy extends FormatterFactory { private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/groovy/**/*.groovy", "src/test/groovy/**/*.groovy"); - private static final String LICENSE_HEADER_DELIMITER = "package "; + private static final String LICENSE_HEADER_DELIMITER = LicenseHeaderStep.DEFAULT_JAVA_HEADER_DELIMITER; @Override public Set defaultIncludes(MavenProject project) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index efdf0827db..b0692446b7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -26,6 +26,7 @@ import org.apache.maven.model.Build; import org.apache.maven.project.MavenProject; +import com.diffplug.spotless.generic.LicenseHeaderStep; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -37,7 +38,7 @@ */ public class Java extends FormatterFactory { - private static final String LICENSE_HEADER_DELIMITER = "package "; + private static final String LICENSE_HEADER_DELIMITER = LicenseHeaderStep.DEFAULT_JAVA_HEADER_DELIMITER; @Override public Set defaultIncludes(MavenProject project) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java index 7a9e455f5f..116d89263c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/scala/Scala.java @@ -20,6 +20,7 @@ import org.apache.maven.project.MavenProject; import com.diffplug.common.collect.ImmutableSet; +import com.diffplug.spotless.generic.LicenseHeaderStep; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.generic.LicenseHeader; @@ -33,7 +34,7 @@ public class Scala extends FormatterFactory { private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/main/scala/**/*.scala", "src/test/scala/**/*.scala", "src/main/scala/**/*.sc", "src/test/scala/**/*.sc"); - private static final String LICENSE_HEADER_DELIMITER = "package "; + private static final String LICENSE_HEADER_DELIMITER = LicenseHeaderStep.DEFAULT_JAVA_HEADER_DELIMITER; @Override public Set defaultIncludes(MavenProject project) { diff --git a/testlib/src/main/resources/license/HelloWorld_java.test b/testlib/src/main/resources/license/HelloWorld_java.test new file mode 100644 index 0000000000..d9be2ea939 --- /dev/null +++ b/testlib/src/main/resources/license/HelloWorld_java.test @@ -0,0 +1,5 @@ +public class HelloWorld { + public static void main(String[] args) { + System.out.print("Hello World"); + } +} diff --git a/testlib/src/main/resources/license/HelloWorld_withImport_java.test b/testlib/src/main/resources/license/HelloWorld_withImport_java.test new file mode 100644 index 0000000000..fcfb64117e --- /dev/null +++ b/testlib/src/main/resources/license/HelloWorld_withImport_java.test @@ -0,0 +1,7 @@ +import java.time.LocalDate; + +public class HelloWorld { + public static void main(String[] args) { + System.out.print("Hello World. Date: " + LocalDate.now()); + } +} diff --git a/testlib/src/main/resources/license/module-info.test b/testlib/src/main/resources/license/module-info.test new file mode 100644 index 0000000000..6678147b68 --- /dev/null +++ b/testlib/src/main/resources/license/module-info.test @@ -0,0 +1,5 @@ +module java.sql { + exports java.sql; + exports javax.sql; + exports javax.transaction.xa; +} diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java index 2b1d0aff07..912975dda5 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java @@ -32,7 +32,7 @@ class LicenseHeaderStepTest extends ResourceHarness { private static final String FILE_NO_LICENSE = "license/FileWithoutLicenseHeader.test"; - private static final String package_ = "package "; + private static final String package_ = LicenseHeaderStep.DEFAULT_JAVA_HEADER_DELIMITER; private static final String HEADER_WITH_$YEAR = "This is a fake license, $YEAR. ACME corp."; private static final String HEADER_WITH_RANGE_TO_$YEAR = "This is a fake license with range, 2009-$YEAR. ACME corp."; @@ -250,4 +250,22 @@ void should_preserve_year_for_license_with_address() throws Throwable { hasHeader(licenceWithAddress().replace("$YEAR", "2015").replace("FooBar Inc. All", "FooBar Inc. All")), hasHeader(licenceWithAddress().replace("$YEAR", "2015"))); } + + @Test + void noPackage() throws Throwable { + String header = header(getTestResource("license/TestLicense")); + FormatterStep step = LicenseHeaderStep.headerDelimiter(header, package_).build(); + StepHarness.forStep(step) + .test(ResourceHarness.getTestResource("license/HelloWorld_java.test"), header + ResourceHarness.getTestResource("license/HelloWorld_java.test")) + .test(ResourceHarness.getTestResource("license/HelloWorld_withImport_java.test"), header + ResourceHarness.getTestResource("license/HelloWorld_withImport_java.test")); + } + + // The following demonstrate the use of 'module' keyword + @Test + void moduleInfo() throws Throwable { + String header = header(getTestResource("license/TestLicense")); + FormatterStep step = LicenseHeaderStep.headerDelimiter(header, package_).build(); + StepHarness.forStep(step) + .test(ResourceHarness.getTestResource("license/module-info.test"), header + ResourceHarness.getTestResource("license/module-info.test")); + } } From 318f453ee003aaf16b787ab5e947f44deb95fafb Mon Sep 17 00:00:00 2001 From: Kenji Abe Date: Thu, 9 Mar 2023 11:59:13 +0900 Subject: [PATCH 0581/1120] Fix file name not applied --- .../java/com/diffplug/spotless/generic/LicenseHeaderStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 624ea16cc6..ccc665bb0d 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -323,7 +323,7 @@ private String addOrUpdateLicenseHeader(String raw, File file) { // fastpath where we don't need to make any changes at all boolean noPadding = beforeYearIdx == 0 && afterYearIdx + afterYear.length() == contentMatcher.start(); // allows fastpath return raw if (noPadding) { - return raw; + return replaceFileName(raw.substring(0, contentMatcher.start()), file) + content; } } header = beforeYear + newYear + afterYear; From 02338b9066d50d9809491686959f7431e8ae338d Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 9 Mar 2023 10:03:08 +0400 Subject: [PATCH 0582/1120] Homogeneize gradle and maven behavior around Formatter issues on a specific file --- .../gradle/spotless/SpotlessTaskImpl.java | 18 +++++++++++++----- .../spotless/maven/SpotlessApplyMojo.java | 2 +- .../spotless/maven/SpotlessCheckMojo.java | 17 +++++++++++++++-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java index b37e9f283a..d90c0441ac 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -94,26 +94,34 @@ public void performAction(InputChanges inputs) throws Exception { private void processInputFile(@Nullable GitRatchet ratchet, Formatter formatter, File input) throws IOException { File output = getOutputFile(input); - getLogger().debug("Applying format to " + input + " and writing to " + output); + getLogger().debug("Applying format to {} and writing to {}", input, output); PaddedCell.DirtyState dirtyState; if (ratchet != null && ratchet.isClean(getProjectDir().get().getAsFile(), getRootTreeSha(), input)) { dirtyState = PaddedCell.isClean(); } else { - dirtyState = PaddedCell.calculateDirtyState(formatter, input); + try { + dirtyState = PaddedCell.calculateDirtyState(formatter, input); + } catch (IOException e) { + throw new IOException("Issue processing file: " + input, e); + } catch (RuntimeException e) { + throw new IllegalArgumentException("Issue processing file: " + input, e); + } } if (dirtyState.isClean()) { // Remove previous output if it exists Files.deleteIfExists(output.toPath()); } else if (dirtyState.didNotConverge()) { - getLogger().warn("Skipping '" + input + "' because it does not converge. Run {@code spotlessDiagnose} to understand why"); + getLogger().warn("Skipping '{}}' because it does not converge. Run {@code spotlessDiagnose} to understand why", input); } else { Path parentDir = output.toPath().getParent(); if (parentDir == null) { - throw new IllegalStateException("Every file has a parent folder."); + throw new IllegalStateException("Every file has a parent folder. But not: " + output); } Files.createDirectories(parentDir); // Need to copy the original file to the tmp location just to remember the file attributes Files.copy(input.toPath(), output.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); + + getLogger().info(String.format("Writing clean file: %s", output)); dirtyState.writeCanonicalTo(output); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java index 028cc3fb9c..5ebe2885c9 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java @@ -54,7 +54,7 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke } else { counter.checkedButAlreadyClean(); } - } catch (IOException e) { + } catch (IOException | RuntimeException e) { throw new MojoExecutionException("Unable to format file " + file, e); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessCheckMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessCheckMojo.java index ad3230f583..03e55e224a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessCheckMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessCheckMojo.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. @@ -38,9 +38,12 @@ public class SpotlessCheckMojo extends AbstractSpotlessMojo { @Override protected void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException { + ImpactedFilesTracker counter = new ImpactedFilesTracker(); + List problemFiles = new ArrayList<>(); for (File file : files) { if (upToDateChecker.isUpToDate(file.toPath())) { + counter.skippedAsCleanCache(); if (getLog().isDebugEnabled()) { getLog().debug("Spotless will not check an up-to-date file: " + file); } @@ -51,14 +54,24 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke PaddedCell.DirtyState dirtyState = PaddedCell.calculateDirtyState(formatter, file); if (!dirtyState.isClean() && !dirtyState.didNotConverge()) { problemFiles.add(file); + counter.cleaned(); } else { + counter.checkedButAlreadyClean(); upToDateChecker.setUpToDate(file.toPath()); } - } catch (IOException e) { + } catch (IOException | RuntimeException e) { throw new MojoExecutionException("Unable to format file " + file, e); } } + // We print the number of considered files which is useful when ratchetFrom is setup + if (counter.getTotal() > 0) { + getLog().info(String.format("Spotless.%s is keeping %s files clean - %s needs changes to be clean, %s were already clean, %s were skipped because caching determined they were already clean", + formatter.getName(), counter.getTotal(), counter.getCleaned(), counter.getCheckedButAlreadyClean(), counter.getSkippedAsCleanCache())); + } else { + getLog().debug(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName())); + } + if (!problemFiles.isEmpty()) { throw new MojoExecutionException(DiffMessageFormatter.builder() .runToFix("Run 'mvn spotless:apply' to fix these violations.") From 86818f1c24db9f58db75fadeb61c94991c73ac55 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 9 Mar 2023 22:06:31 +0000 Subject: [PATCH 0583/1120] fix(deps): update dependency org.mockito:mockito-core to v5.2.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 8820a36e30..8d9f90f8b0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,4 +32,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.4.0.202211300538-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.1.1 +VER_MOCKITO=5.2.0 From 52d7bf74a22217e6c87aee78ccb3a7bf2d128e78 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Fri, 10 Mar 2023 09:02:28 +0400 Subject: [PATCH 0584/1120] Fix typo, add Unittest --- .../gradle/spotless/SpotlessTaskImpl.java | 6 ++- .../gradle/spotless/SpotlessTaskImplTest.java | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java index d90c0441ac..ab584fa7b6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java @@ -35,6 +35,7 @@ import org.gradle.work.FileChange; import org.gradle.work.InputChanges; +import com.diffplug.common.annotations.VisibleForTesting; import com.diffplug.common.base.StringPrinter; import com.diffplug.spotless.Formatter; import com.diffplug.spotless.PaddedCell; @@ -92,7 +93,8 @@ public void performAction(InputChanges inputs) throws Exception { } } - private void processInputFile(@Nullable GitRatchet ratchet, Formatter formatter, File input) throws IOException { + @VisibleForTesting + void processInputFile(@Nullable GitRatchet ratchet, Formatter formatter, File input) throws IOException { File output = getOutputFile(input); getLogger().debug("Applying format to {} and writing to {}", input, output); PaddedCell.DirtyState dirtyState; @@ -111,7 +113,7 @@ private void processInputFile(@Nullable GitRatchet ratchet, Formatter formatter, // Remove previous output if it exists Files.deleteIfExists(output.toPath()); } else if (dirtyState.didNotConverge()) { - getLogger().warn("Skipping '{}}' because it does not converge. Run {@code spotlessDiagnose} to understand why", input); + getLogger().warn("Skipping '{}' because it does not converge. Run {@code spotlessDiagnose} to understand why", input); } else { Path parentDir = output.toPath().getParent(); if (parentDir == null) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java new file mode 100644 index 0000000000..26ad28ae23 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java @@ -0,0 +1,45 @@ +/* + * 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.gradle.spotless; + +import java.io.File; + +import org.assertj.core.api.Assertions; +import org.gradle.api.file.DirectoryProperty; +import org.gradle.api.logging.Logger; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import com.diffplug.spotless.Formatter; + +public class SpotlessTaskImplTest { + @Test + public void testThrowsMessageContainsFilename() throws Exception { + SpotlessTaskImpl task = Mockito.mock(SpotlessTaskImpl.class, Mockito.CALLS_REAL_METHODS); + Mockito.when(task.getLogger()).thenReturn(Mockito.mock(Logger.class)); + + File projectDir = new File("unitTests/projectDir"); + DirectoryProperty projectDirProperty = Mockito.mock(DirectoryProperty.class, Mockito.RETURNS_DEEP_STUBS); + Mockito.when(projectDirProperty.get().getAsFile()).thenReturn(projectDir); + + Mockito.when(task.getProjectDir()).thenReturn(projectDirProperty); + + File input = new File("unitTests/projectDir/someInput"); + Formatter formatter = Mockito.mock(Formatter.class); + + Assertions.assertThatThrownBy(() -> task.processInputFile(null, formatter, input)).hasMessageContaining("unitTests/projectDir/someInput"); + } +} From b6cad0e4af5e5ec8b6b9a00d074447c2fa789fe0 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Fri, 10 Mar 2023 09:05:53 +0400 Subject: [PATCH 0585/1120] Add changelog entries --- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c19a7de733..c39aff545d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +* `licenseHeader` default pattern for Java files is updated to `(package|import|public|class|module) `. ([#1614](https://github.com/diffplug/spotless/pull/1614)) ## [6.16.0] - 2023-02-27 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 36a51d6ef2..635459368a 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `licenseHeader` default pattern for Java files is updated to `(package|import|public|class|module) `. ([#1614](https://github.com/diffplug/spotless/pull/1614)) ## [2.34.0] - 2023-02-27 ### Added From e579b74e5f7fb69cd1b5d23ae0be388001400ddc Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Fri, 10 Mar 2023 09:45:58 +0400 Subject: [PATCH 0586/1120] Fix filePath for both Windows and Unix --- .../com/diffplug/gradle/spotless/SpotlessTaskImplTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java index 26ad28ae23..5f5200d8e5 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java @@ -16,6 +16,7 @@ package com.diffplug.gradle.spotless; import java.io.File; +import java.nio.file.Paths; import org.assertj.core.api.Assertions; import org.gradle.api.file.DirectoryProperty; @@ -31,15 +32,15 @@ public void testThrowsMessageContainsFilename() throws Exception { SpotlessTaskImpl task = Mockito.mock(SpotlessTaskImpl.class, Mockito.CALLS_REAL_METHODS); Mockito.when(task.getLogger()).thenReturn(Mockito.mock(Logger.class)); - File projectDir = new File("unitTests/projectDir"); + File projectDir = Paths.get("unitTests","projectDir").toFile(); DirectoryProperty projectDirProperty = Mockito.mock(DirectoryProperty.class, Mockito.RETURNS_DEEP_STUBS); Mockito.when(projectDirProperty.get().getAsFile()).thenReturn(projectDir); Mockito.when(task.getProjectDir()).thenReturn(projectDirProperty); - File input = new File("unitTests/projectDir/someInput"); + File input = Paths.get("unitTests","projectDir", "someInput").toFile(); Formatter formatter = Mockito.mock(Formatter.class); - Assertions.assertThatThrownBy(() -> task.processInputFile(null, formatter, input)).hasMessageContaining("unitTests/projectDir/someInput"); + Assertions.assertThatThrownBy(() -> task.processInputFile(null, formatter, input)).hasMessageContaining(input.toString()); } } From 7e261671a90b156a0d4077b81f97a5c5f05b4052 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Fri, 10 Mar 2023 09:54:54 +0400 Subject: [PATCH 0587/1120] Fix style --- .../com/diffplug/gradle/spotless/SpotlessTaskImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java index 5f5200d8e5..fc7fab9980 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessTaskImplTest.java @@ -32,13 +32,13 @@ public void testThrowsMessageContainsFilename() throws Exception { SpotlessTaskImpl task = Mockito.mock(SpotlessTaskImpl.class, Mockito.CALLS_REAL_METHODS); Mockito.when(task.getLogger()).thenReturn(Mockito.mock(Logger.class)); - File projectDir = Paths.get("unitTests","projectDir").toFile(); + File projectDir = Paths.get("unitTests", "projectDir").toFile(); DirectoryProperty projectDirProperty = Mockito.mock(DirectoryProperty.class, Mockito.RETURNS_DEEP_STUBS); Mockito.when(projectDirProperty.get().getAsFile()).thenReturn(projectDir); Mockito.when(task.getProjectDir()).thenReturn(projectDirProperty); - File input = Paths.get("unitTests","projectDir", "someInput").toFile(); + File input = Paths.get("unitTests", "projectDir", "someInput").toFile(); Formatter formatter = Mockito.mock(Formatter.class); Assertions.assertThatThrownBy(() -> task.processInputFile(null, formatter, input)).hasMessageContaining(input.toString()); From 95bf5320716208df4326c0bb59b7ed4182d93b3d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 9 Mar 2023 23:27:19 -0800 Subject: [PATCH 0588/1120] Remove EquoBasedStepBuilder.State import. --- .../diffplug/spotless/extra/java/EclipseJdtFormatterStep.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java index 67318c113a..f618750b4e 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java @@ -22,7 +22,6 @@ import com.diffplug.spotless.Jvm; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.extra.EquoBasedStepBuilder; -import com.diffplug.spotless.extra.EquoBasedStepBuilder.State; import dev.equo.solstice.p2.P2Model; @@ -38,7 +37,6 @@ public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); } - /** Provides default configuration */ public static EquoBasedStepBuilder createBuilder(Provisioner provisioner) { return new EquoBasedStepBuilder(NAME, provisioner, EclipseJdtFormatterStep::apply) { @Override @@ -61,7 +59,7 @@ public void setVersion(String version) { }; } - private static FormatterFunc apply(State state) throws Exception { + private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exception { JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion()); Class formatterClazz = state.getJarState().getClassLoader().loadClass("com.diffplug.spotless.extra.glue.jdt.EclipseJdtFormatterStepImpl"); var formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences()); From 67daeac3b4d6209f8c156a70f1f98d2228327d44 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 9 Mar 2023 23:43:10 -0800 Subject: [PATCH 0589/1120] Enforce a consistent version of Solstice between the build and runtime. --- lib-extra/build.gradle | 22 +++++++++++++++++-- .../spotless/extra/EquoBasedStepBuilder.java | 13 ++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index df99e12f37..a5a35fbde4 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -7,6 +7,7 @@ version = rootProject.spotlessChangelog.versionNext apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') +String VER_SOLSTICE = '0.18.0' dependencies { api project(':lib') // misc useful utilities @@ -16,7 +17,7 @@ dependencies { implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" implementation "com.googlecode.concurrent-trees:concurrent-trees:2.6.1" // for eclipse - implementation "dev.equo.ide:solstice:0.17.0" + implementation "dev.equo.ide:solstice:${VER_SOLSTICE}" // testing testImplementation project(':testlib') @@ -24,6 +25,11 @@ dependencies { testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" } +spotless { + java { + replaceRegex 'enforceSolsticeVersion', '"dev.equo.ide:solstice:(.*)"', '"dev.equo.ide:solstice:' + VER_SOLSTICE + '"' + } +} apply from: rootProject.file('gradle/special-tests.gradle') tasks.withType(Test).configureEach { @@ -34,7 +40,8 @@ tasks.withType(Test).configureEach { } def NEEDS_P2_DEPS = [ - 'jdt' + 'jdt', + 'groovy' ] for (needsP2 in NEEDS_P2_DEPS) { sourceSets.register(needsP2) { @@ -42,6 +49,9 @@ for (needsP2 in NEEDS_P2_DEPS) { runtimeClasspath += sourceSets.main.output java {} } + dependencies { + add("${needsP2}CompileOnly", "dev.equo.ide:solstice:${VER_SOLSTICE}") + } } jar { for (needsP2 in NEEDS_P2_DEPS) { @@ -61,6 +71,14 @@ p2deps { p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' install 'org.eclipse.jdt.core' } + into 'groovyCompileOnly', { + p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' + p2repo 'https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/4.8.0/e4.26/' + install 'org.codehaus.groovy.eclipse.refactoring' + install 'org.codehaus.groovy.eclipse.core' + install 'org.eclipse.jdt.groovy.core' + install 'org.codehaus.groovy' + } } // we'll hold the core lib to a high standard diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index e52ec55f1c..f49ded688a 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -28,9 +28,9 @@ import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.ThrowingEx; -import dev.equo.solstice.p2.P2Client; +import dev.equo.solstice.p2.P2ClientCache; import dev.equo.solstice.p2.P2Model; -import dev.equo.solstice.p2.QueryCache; +import dev.equo.solstice.p2.P2QueryCache; /** * Generic Eclipse based formatter step {@link State} builder. @@ -66,11 +66,12 @@ public FormatterStep build() { /** Creates the state of the configuration. */ EquoBasedStepBuilder.State get() throws Exception { - var query = model(formatterVersion).query(P2Client.Caching.PREFER_OFFLINE, QueryCache.ALLOW); + var query = model(formatterVersion).query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW); var classpath = new ArrayList(); - if (!query.getJarsOnMavenCentral().isEmpty()) { - classpath.addAll(mavenProvisioner.provisionWithTransitives(false, query.getJarsOnMavenCentral())); - } + var mavenDeps = new ArrayList(); + mavenDeps.add("dev.equo.ide:solstice:0.18.0"); + mavenDeps.addAll(query.getJarsOnMavenCentral()); + classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); classpath.addAll(query.getJarsNotOnMavenCentral()); var jarState = JarState.forFiles(classpath); return new State(formatterVersion, jarState, FileSignature.signAsList(settingsFiles)); From bdfda85316d073f7d15b449f546c05b94e608c4e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Mar 2023 16:03:21 -0800 Subject: [PATCH 0590/1120] Adapt the GrEclipse plugins and tests to Equo. --- .../com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 8 ++++++++ .../spotless/extra/groovy/GrEclipseFormatterStepTest.java | 8 ++++---- .../com/diffplug/gradle/spotless/GroovyExtension.java | 6 +++--- .../com/diffplug/spotless/maven/groovy/GrEclipse.java | 6 +++--- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index f49ded688a..b5cc09f2fb 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -15,8 +15,12 @@ */ package com.diffplug.spotless.extra; +import dev.equo.solstice.NestedJars; + import java.io.File; import java.io.Serializable; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Properties; @@ -73,6 +77,10 @@ EquoBasedStepBuilder.State get() throws Exception { mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); classpath.addAll(query.getJarsNotOnMavenCentral()); + File nestedDir = new File("/Users/ntwigg/.equo/p2-blah"); + for (var nested : NestedJars.inFiles(query.getJarsNotOnMavenCentral()).extractAllNestedJars(nestedDir)) { + classpath.add(nested.getValue()); + } var jarState = JarState.forFiles(classpath); return new State(formatterVersion, jarState, FileSignature.signAsList(settingsFiles)); } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java index f1823e5f52..d655008bbc 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.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. @@ -22,10 +22,10 @@ import com.diffplug.spotless.Jvm; import com.diffplug.spotless.TestProvisioner; -import com.diffplug.spotless.extra.eclipse.EclipseResourceHarness; +import com.diffplug.spotless.extra.eclipse.EquoResourceHarness; -class GrEclipseFormatterStepTest extends EclipseResourceHarness { - private final static Jvm.Support JVM_SUPPORT = Jvm. support("Oldest Version").add(8, "2.3.0").add(11, "4.17.0"); +class GrEclipseFormatterStepTest extends EquoResourceHarness { + private final static Jvm.Support JVM_SUPPORT = Jvm. support("Oldest Version").add(8, "4.8").add(11, "4.18"); private final static String INPUT = "class F{ def m(){} }"; private final static String EXPECTED = "class F{\n\tdef m(){}\n}"; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java index 5e528e1b79..2062946b32 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.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. @@ -30,7 +30,7 @@ import org.gradle.api.tasks.GroovySourceSet; import org.gradle.api.tasks.SourceSet; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.EquoBasedStepBuilder; import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; import com.diffplug.spotless.generic.LicenseHeaderStep; import com.diffplug.spotless.java.ImportOrderStep; @@ -83,7 +83,7 @@ public GrEclipseConfig greclipse(String version) { } public static class GrEclipseConfig { - private final EclipseBasedStepBuilder builder; + private final EquoBasedStepBuilder builder; private final FormatExtension extension; GrEclipseConfig(String version, FormatExtension extension) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java index 81da109e04..8836993cce 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.EquoBasedStepBuilder; import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -36,7 +36,7 @@ public class GrEclipse implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - EclipseBasedStepBuilder grEclipseConfig = GrEclipseFormatterStep.createBuilder(stepConfig.getProvisioner()); + EquoBasedStepBuilder grEclipseConfig = GrEclipseFormatterStep.createBuilder(stepConfig.getProvisioner()); grEclipseConfig.setVersion(version == null ? GrEclipseFormatterStep.defaultVersion() : version); if (null != file) { File settingsFile = stepConfig.getFileLocator().locateFile(file); From 719ee0d4ca419402be23c45522f9a11e1213c80f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Mar 2023 16:54:31 -0800 Subject: [PATCH 0591/1120] JarState.forFiles now preserves classpath order rather than sorting. --- .../com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 4 +--- lib/src/main/java/com/diffplug/spotless/JarState.java | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index b5cc09f2fb..e3b8b37129 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -19,8 +19,6 @@ import java.io.File; import java.io.Serializable; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Properties; @@ -81,7 +79,7 @@ EquoBasedStepBuilder.State get() throws Exception { for (var nested : NestedJars.inFiles(query.getJarsNotOnMavenCentral()).extractAllNestedJars(nestedDir)) { classpath.add(nested.getValue()); } - var jarState = JarState.forFiles(classpath); + var jarState = JarState.preserveOrder(classpath); return new State(formatterVersion, jarState, FileSignature.signAsList(settingsFiles)); } diff --git a/lib/src/main/java/com/diffplug/spotless/JarState.java b/lib/src/main/java/com/diffplug/spotless/JarState.java index d79451b70c..afd7c1ddf2 100644 --- a/lib/src/main/java/com/diffplug/spotless/JarState.java +++ b/lib/src/main/java/com/diffplug/spotless/JarState.java @@ -74,9 +74,9 @@ private static JarState provisionWithTransitives(boolean withTransitives, Collec return new JarState(mavenCoordinates, fileSignature); } - /** Wraps the given collection of a files as a JarState. */ - public static JarState forFiles(Collection jars) throws IOException { - FileSignature fileSignature = FileSignature.signAsSet(jars); + /** Wraps the given collection of a files as a JarState, maintaining the order in the Collection. */ + public static JarState preserveOrder(Collection jars) throws IOException { + FileSignature fileSignature = FileSignature.signAsList(jars); return new JarState(Collections.emptySet(), fileSignature); } From 67530b04146b8ca5f479082a13e8132f9f645974 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Mar 2023 17:30:42 -0800 Subject: [PATCH 0592/1120] We can remove Jvm.Support for Java 8 since we don't run there anymore. --- .../spotless/extra/java/EclipseJdtFormatterStep.java | 2 +- .../spotless/extra/java/EclipseJdtFormatterStepTest.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java index f618750b4e..50654899bd 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java @@ -31,7 +31,7 @@ public final class EclipseJdtFormatterStep { private EclipseJdtFormatterStep() {} private static final String NAME = "eclipse jdt formatter"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "4.16").add(11, "4.26"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26"); public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java index e73f51fa2f..91bc8740ab 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepTest.java @@ -23,13 +23,11 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import com.diffplug.spotless.Jvm; import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.extra.EquoBasedStepBuilder; import com.diffplug.spotless.extra.eclipse.EquoResourceHarness; class EclipseJdtFormatterStepTest extends EquoResourceHarness { - private final static Jvm.Support OLDEST_FOR_JVM = Jvm. support("Oldest Version").add(8, "4.8").add(11, "4.17"); private final static String INPUT = "package p; class C{}"; private final static String EXPECTED = "package p;\nclass C {\n}"; @@ -48,7 +46,7 @@ void formatWithVersion(String version) throws Exception { } private static Stream formatWithVersion() { - return Stream.of(OLDEST_FOR_JVM.getRecommendedFormatterVersion(), EclipseJdtFormatterStep.defaultVersion()); + return Stream.of("4.9", EclipseJdtFormatterStep.defaultVersion()); } /** New format interface requires source file information to distinguish module-info from compilation unit */ @@ -61,7 +59,7 @@ public NewFormatInterface() { @Test void formatModuleInfo() throws Exception { File settingsFile = createTestFile("java/eclipse/ModuleInfo.prefs"); - assertFormatted(OLDEST_FOR_JVM.getRecommendedFormatterVersion(), settingsFile); + assertFormatted("4.11", settingsFile); } } } From 0591e499b3981f09a290d24de9db5358d9976d6c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Mar 2023 17:31:29 -0800 Subject: [PATCH 0593/1120] Bump the oldest supported JDT to 4.9. --- CHANGES.md | 2 +- .../com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 3 +-- .../com/diffplug/spotless/maven/MavenProvisionerTest.java | 4 ++-- .../com/diffplug/spotless/maven/MultiModuleProjectTest.java | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 64c3726e9f..c09f3a0cdd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,7 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * We are now opting in to Gradle's new stable configuration cache. ([#1591](https://github.com/diffplug/spotless/pull/1591)) * Adopt [Equo Solstice OSGi and p2 shim](https://github.com/equodev/equo-ide/tree/main/solstice) to update all Eclipse-based plugins. ([#1524](https://github.com/diffplug/spotless/pull/1524)) - * Eclipse JDT now supports `4.8` through `4.26`. Also we now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. + * Eclipse JDT now supports `4.9` through `4.26`. Also we now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. ## [2.36.0] - 2023-02-27 ### Added diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index e3b8b37129..28aec41232 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.extra; -import dev.equo.solstice.NestedJars; - import java.io.File; import java.io.Serializable; import java.util.ArrayList; @@ -30,6 +28,7 @@ import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.ThrowingEx; +import dev.equo.solstice.NestedJars; import dev.equo.solstice.p2.P2ClientCache; import dev.equo.solstice.p2.P2Model; import dev.equo.solstice.p2.P2QueryCache; diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java index 3e769d7705..cabbf7c5c0 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.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. @@ -23,7 +23,7 @@ class MavenProvisionerTest extends MavenIntegrationHarness { void testMultipleDependenciesExcludingTransitives() throws Exception { writePomWithJavaSteps( "", - " 4.8.0", + " 4.9", ""); setFile("formatter.xml").toResource("java/eclipse/formatter.xml"); assertResolveDependenciesWorks(); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java index f7ce7cd0d9..0ed6c7c9fe 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java @@ -70,7 +70,7 @@ void testConfigurationDependency() throws Exception { "", " ", " configs/eclipse-formatter.xml", - " 4.8", + " 4.9", " ", "", "", From 2673e9117fd888890811a7550ee09a6d2148c7f6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 10 Mar 2023 17:32:01 -0800 Subject: [PATCH 0594/1120] We have a working GrEclipse! --- .../groovy/GrEclipseFormatterStepImpl.java | 8 +++ .../extra/groovy/GrEclipseFormatterStep.java | 71 +++++++++++++------ .../groovy/GrEclipseFormatterStepTest.java | 4 +- .../spotless/maven/groovy/GrEclipseTest.java | 4 +- 4 files changed, 59 insertions(+), 28 deletions(-) diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index 1077eeaaf6..ea51b637c5 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Properties; import org.codehaus.groovy.eclipse.core.GroovyCoreActivator; @@ -36,6 +37,8 @@ import org.eclipse.jface.text.TextSelection; import org.eclipse.text.edits.TextEdit; +import dev.equo.solstice.Solstice; + /** Spotless-Formatter step which calls out to the Groovy-Eclipse formatter. */ public class GrEclipseFormatterStepImpl { /** @@ -50,6 +53,11 @@ public class GrEclipseFormatterStepImpl { private final boolean ignoreFormatterProblems; public GrEclipseFormatterStepImpl(final Properties properties) throws Exception { + var solstice = Solstice.findBundlesOnClasspath(); + solstice.warnAndModifyManifestsToFix(); + solstice.openShim(Map.of()); + solstice.startAllWithLazy(false); + solstice.startWithoutTransitives("org.codehaus.groovy.eclipse.core"); PreferenceStore preferences = createPreferences(properties); preferencesStore = new FormatterPreferencesOnStore(preferences); ignoreFormatterProblems = Boolean.parseBoolean(properties.getProperty(IGNORE_FORMATTER_PROBLEMS, "false")); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java index 013f5b5c2c..312f9a786f 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.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. @@ -16,14 +16,15 @@ package com.diffplug.spotless.extra.groovy; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.util.List; import java.util.Properties; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.Jvm; import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder.State; +import com.diffplug.spotless.extra.EquoBasedStepBuilder; + +import dev.equo.solstice.p2.P2Model; /** Formatter step which calls out to the Groovy-Eclipse formatter. */ public final class GrEclipseFormatterStep { @@ -31,26 +32,58 @@ public final class GrEclipseFormatterStep { private GrEclipseFormatterStep() {} private static final String NAME = "eclipse groovy formatter"; - private static final String FORMATTER_CLASS = "com.diffplug.spotless.extra.eclipse.groovy.GrEclipseFormatterStepImpl"; - private static final String FORMATTER_CLASS_OLD = "com.diffplug.gradle.spotless.groovy.eclipse.GrEclipseFormatterStepImpl"; - private static final String MAVEN_GROUP_ARTIFACT = "com.diffplug.spotless:spotless-eclipse-groovy"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "4.19.0").add(11, "4.21.0"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26"); private static final String FORMATTER_METHOD = "format"; public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); } - /** Provides default configuration */ - public static EclipseBasedStepBuilder createBuilder(Provisioner provisioner) { - return new EclipseBasedStepBuilder(NAME, provisioner, GrEclipseFormatterStep::apply); + public static EquoBasedStepBuilder createBuilder(Provisioner provisioner) { + return new EquoBasedStepBuilder(NAME, provisioner, GrEclipseFormatterStep::apply) { + @Override + protected P2Model model(String version) { + if (!version.startsWith("4.")) { + throw new IllegalArgumentException("Expected version 4.x"); + } + int eVersion = Integer.parseInt(version.substring("4.".length())); + if (eVersion < 8) { + throw new IllegalArgumentException("4.8 is the oldest version we support, this was " + version); + } + String greclipseVersion; + if (eVersion >= 18) { + greclipseVersion = "4." + (eVersion - 18) + ".0"; + } else { + greclipseVersion = "3." + (eVersion - 8) + ".0"; + } + var model = new P2Model(); + model.addP2Repo("https://download.eclipse.org/eclipse/updates/" + version + "/"); + model.addP2Repo("https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/" + greclipseVersion + "/e" + version + "/"); + model.getInstall().addAll(List.of( + "org.codehaus.groovy.eclipse.refactoring", + "org.codehaus.groovy.eclipse.core", + "org.eclipse.jdt.groovy.core", + "org.codehaus.groovy")); + return model; + } + + @Override + public void setVersion(String version) { + if (version.endsWith(".0")) { + String newVersion = version.substring(0, version.length() - 2); + System.err.println("Recommend replacing '" + version + "' with '" + newVersion + "' for eclipse JDT"); + version = newVersion; + } + super.setVersion(version); + } + }; } - private static FormatterFunc apply(EclipseBasedStepBuilder.State state) throws Exception { + private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exception { JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion()); - Class formatterClazz = getClass(state); - Object formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences()); - Method method = formatterClazz.getMethod(FORMATTER_METHOD, String.class); + Class formatterClazz = state.getJarState().getClassLoader().loadClass("com.diffplug.spotless.extra.glue.groovy.GrEclipseFormatterStepImpl"); + var formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences()); + var method = formatterClazz.getMethod(FORMATTER_METHOD, String.class); return JVM_SUPPORT.suggestLaterVersionOnError(state.getSemanticVersion(), input -> { try { @@ -62,12 +95,4 @@ private static FormatterFunc apply(EclipseBasedStepBuilder.State state) throws E } }); } - - private static Class getClass(State state) { - if (state.getMavenCoordinate(MAVEN_GROUP_ARTIFACT).isPresent()) { - return state.loadClass(FORMATTER_CLASS); - } - return state.loadClass(FORMATTER_CLASS_OLD); - } - } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java index d655008bbc..d72fc2e1a4 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java @@ -20,12 +20,10 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import com.diffplug.spotless.Jvm; import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.extra.eclipse.EquoResourceHarness; class GrEclipseFormatterStepTest extends EquoResourceHarness { - private final static Jvm.Support JVM_SUPPORT = Jvm. support("Oldest Version").add(8, "4.8").add(11, "4.18"); private final static String INPUT = "class F{ def m(){} }"; private final static String EXPECTED = "class F{\n\tdef m(){}\n}"; @@ -40,6 +38,6 @@ void formatWithVersion(String version) throws Exception { } private static Stream formatWithVersion() { - return Stream.of(JVM_SUPPORT.getRecommendedFormatterVersion(), GrEclipseFormatterStep.defaultVersion()); + return Stream.of("4.25", GrEclipseFormatterStep.defaultVersion()); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java index 8807f47cc9..34d95dc7d2 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/GrEclipseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,7 +60,7 @@ private void writePomWithGrEclipse() throws IOException { writePomWithGroovySteps( "", " ${basedir}/greclipse.properties", - " 4.19.0", + " 4.25", ""); setFile("greclipse.properties").toResource("groovy/greclipse/format/greclipse.properties"); } From d4d3814b770219681aa985cb5cc50b76cdfa17f8 Mon Sep 17 00:00:00 2001 From: Kenji Abe Date: Sat, 11 Mar 2023 11:51:05 +0900 Subject: [PATCH 0595/1120] Refactor LicenseHeaderStep --- .../spotless/generic/LicenseHeaderStep.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index ccc665bb0d..0b7d076e12 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -213,6 +213,7 @@ private static class Runtime implements Serializable { private final @Nullable String afterYear; private final boolean updateYearWithLatest; private final boolean licenseHeaderWithRange; + private final boolean hasFileToken; private static final Pattern FILENAME_PATTERN = Pattern.compile("\\$FILE"); @@ -228,6 +229,7 @@ private Runtime(String licenseHeader, String delimiter, String yearSeparator, bo } this.delimiterPattern = Pattern.compile('^' + delimiter, Pattern.UNIX_LINES | Pattern.MULTILINE); this.skipLinesMatching = skipLinesMatching == null ? null : Pattern.compile(skipLinesMatching); + this.hasFileToken = FILENAME_PATTERN.matcher(licenseHeader).find(); Optional yearToken = getYearToken(licenseHeader); if (yearToken.isPresent()) { @@ -294,6 +296,12 @@ private String format(String raw, File file) { } private String addOrUpdateLicenseHeader(String raw, File file) { + raw = replaceYear(raw); + raw = replaceFileName(raw, file); + return raw; + } + + private String replaceYear(String raw) { Matcher contentMatcher = delimiterPattern.matcher(raw); if (!contentMatcher.find()) { throw new IllegalArgumentException("Unable to find delimiter regex " + delimiterPattern); @@ -307,14 +315,13 @@ private String addOrUpdateLicenseHeader(String raw, File file) { return raw; } else { // otherwise we'll have to add the header - return replaceFileName(yearSepOrFull, file) + content; + return yearSepOrFull + content; } } else { // the yes year case is a bit harder int beforeYearIdx = raw.indexOf(beforeYear); int afterYearIdx = raw.indexOf(afterYear, beforeYearIdx + beforeYear.length() + 1); - String header; if (beforeYearIdx >= 0 && afterYearIdx >= 0 && afterYearIdx + afterYear.length() <= contentMatcher.start()) { // and also ends with exactly the right header, so it's easy to parse the existing year String existingYear = raw.substring(beforeYearIdx + beforeYear.length(), afterYearIdx); @@ -323,16 +330,15 @@ private String addOrUpdateLicenseHeader(String raw, File file) { // fastpath where we don't need to make any changes at all boolean noPadding = beforeYearIdx == 0 && afterYearIdx + afterYear.length() == contentMatcher.start(); // allows fastpath return raw if (noPadding) { - return replaceFileName(raw.substring(0, contentMatcher.start()), file) + content; + return raw; } } - header = beforeYear + newYear + afterYear; + return beforeYear + newYear + afterYear + content; } else { String newYear = calculateYearBySearching(raw.substring(0, contentMatcher.start())); // at worst, we just say that it was made today - header = beforeYear + newYear + afterYear; + return beforeYear + newYear + afterYear + content; } - return replaceFileName(header, file) + content; } } } @@ -425,8 +431,17 @@ private String setLicenseHeaderYearsFromGitHistory(String raw, File file) throws return beforeYear + yearRange + afterYear + raw.substring(contentMatcher.start()); } - private String replaceFileName(String header, File file) { - return FILENAME_PATTERN.matcher(header).replaceAll(file.getName()); + private String replaceFileName(String raw, File file) { + if (!hasFileToken) { + return raw; + } + Matcher contentMatcher = delimiterPattern.matcher(raw); + if (!contentMatcher.find()) { + throw new IllegalArgumentException("Unable to find delimiter regex " + delimiterPattern); + } + String header = raw.substring(0, contentMatcher.start()); + String content = raw.substring(contentMatcher.start()); + return FILENAME_PATTERN.matcher(header).replaceAll(file.getName()) + content; } private static String parseYear(String cmd, File file) throws IOException { From 91977a1a71a0a81a1be2324d30eb0746150b2027 Mon Sep 17 00:00:00 2001 From: Kenji Abe Date: Sat, 11 Mar 2023 11:55:45 +0900 Subject: [PATCH 0596/1120] Add tests --- .../spotless/generic/LicenseHeaderStepTest.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java index 7d2e018028..760725229f 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java @@ -268,7 +268,18 @@ void should_preserve_year_for_license_with_address() throws Throwable { void should_apply_license_containing_filename_token() throws Exception { FormatterStep step = LicenseHeaderStep.headerDelimiter(header(HEADER_WITH_$FILE), package_).build(); StepHarnessWithFile.forStep(this, step) - .test(new File("Test.java"), getTestResource(FILE_NO_LICENSE), hasHeaderFileName(HEADER_WITH_$FILE, "Test.java")); + .test(new File("Test.java"), getTestResource(FILE_NO_LICENSE), hasHeaderFileName(HEADER_WITH_$FILE, "Test.java")) + .testUnaffected(new File("Test.java"), hasHeaderFileName(HEADER_WITH_$FILE, "Test.java")); + } + + @Test + void should_update_license_containing_filename_token() throws Exception { + FormatterStep step = LicenseHeaderStep.headerDelimiter(header(HEADER_WITH_$FILE), package_).build(); + StepHarnessWithFile.forStep(this, step) + .test( + new File("After.java"), + hasHeaderFileName(HEADER_WITH_$FILE, "Before.java"), + hasHeaderFileName(HEADER_WITH_$FILE, "After.java")); } @Test @@ -278,6 +289,9 @@ void should_apply_license_containing_YEAR_filename_token() throws Exception { .test( new File("Test.java"), getTestResource(FILE_NO_LICENSE), + hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java")) + .testUnaffected( + new File("Test.java"), hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java")); } } From 40488be7041de75d8bbfedeaf5cff20058202145 Mon Sep 17 00:00:00 2001 From: Kenji Abe Date: Sat, 11 Mar 2023 12:02:45 +0900 Subject: [PATCH 0597/1120] Run spotlessApply --- .../spotless/generic/LicenseHeaderStepTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java index ba65cdbafc..92c6794643 100644 --- a/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/generic/LicenseHeaderStepTest.java @@ -286,13 +286,13 @@ void should_update_license_containing_filename_token() throws Exception { void should_apply_license_containing_YEAR_filename_token() throws Exception { FormatterStep step = LicenseHeaderStep.headerDelimiter(header(HEADER_WITH_$YEAR_$FILE), package_).build(); StepHarnessWithFile.forStep(this, step) - .test( - new File("Test.java"), - getTestResource(FILE_NO_LICENSE), - hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java")) - .testUnaffected( - new File("Test.java"), - hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java")); + .test( + new File("Test.java"), + getTestResource(FILE_NO_LICENSE), + hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java")) + .testUnaffected( + new File("Test.java"), + hasHeaderYearFileName(HEADER_WITH_$YEAR_$FILE, currentYear(), "Test.java")); } void noPackage() throws Throwable { From f1ce2a0acf7819a392d811c608b355a207794e54 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 12 Mar 2023 09:52:12 -0700 Subject: [PATCH 0598/1120] Restore the more complex GrEclipse log manager. --- build.gradle | 2 +- lib-extra/build.gradle | 6 +-- .../groovy/GrEclipseFormatterStepImpl.java | 39 +++++++++++++++++-- .../spotless/extra/EquoBasedStepBuilder.java | 5 +-- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 312f84727d..6755d486c0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md - id 'dev.equo.ide' version '0.16.0' + id 'dev.equo.ide' version '0.17.1' } equoIde { branding().title('Spotless').icon(file('_images/spotless_logo.png')) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index a5a35fbde4..f3b4b7c4b5 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -7,7 +7,7 @@ version = rootProject.spotlessChangelog.versionNext apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') -String VER_SOLSTICE = '0.18.0' +String VER_SOLSTICE = '0.19.1' dependencies { api project(':lib') // misc useful utilities @@ -72,8 +72,8 @@ p2deps { install 'org.eclipse.jdt.core' } into 'groovyCompileOnly', { - p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' - p2repo 'https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/4.8.0/e4.26/' + p2repo 'https://download.eclipse.org/eclipse/updates/4.23/' + p2repo 'https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/4.8.0/e4.23/' install 'org.codehaus.groovy.eclipse.refactoring' install 'org.codehaus.groovy.eclipse.core' install 'org.eclipse.jdt.groovy.core' diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index ea51b637c5..18aed57aeb 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -24,6 +24,9 @@ import java.util.Map; import java.util.Properties; +import org.codehaus.groovy.eclipse.GroovyLogManager; +import org.codehaus.groovy.eclipse.IGroovyLogger; +import org.codehaus.groovy.eclipse.TraceCategory; import org.codehaus.groovy.eclipse.core.GroovyCoreActivator; import org.codehaus.groovy.eclipse.refactoring.formatter.DefaultGroovyFormatter; import org.codehaus.groovy.eclipse.refactoring.formatter.FormatterPreferencesOnStore; @@ -37,7 +40,10 @@ import org.eclipse.jface.text.TextSelection; import org.eclipse.text.edits.TextEdit; +import dev.equo.solstice.NestedJars; +import dev.equo.solstice.ShimIdeBootstrapServices; import dev.equo.solstice.Solstice; +import dev.equo.solstice.p2.CacheLocations; /** Spotless-Formatter step which calls out to the Groovy-Eclipse formatter. */ public class GrEclipseFormatterStepImpl { @@ -54,10 +60,15 @@ public class GrEclipseFormatterStepImpl { public GrEclipseFormatterStepImpl(final Properties properties) throws Exception { var solstice = Solstice.findBundlesOnClasspath(); + NestedJars.setToWarnOnly(); + NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.nestedJars()); solstice.warnAndModifyManifestsToFix(); - solstice.openShim(Map.of()); + var props = Map. of(); + solstice.openShim(props); + ShimIdeBootstrapServices.apply(props, solstice.getContext()); solstice.startAllWithLazy(false); solstice.startWithoutTransitives("org.codehaus.groovy.eclipse.core"); + PreferenceStore preferences = createPreferences(properties); preferencesStore = new FormatterPreferencesOnStore(preferences); ignoreFormatterProblems = Boolean.parseBoolean(properties.getProperty(IGNORE_FORMATTER_PROBLEMS, "false")); @@ -80,8 +91,7 @@ public String format(String raw) throws Exception { /** * Eclipse Groovy formatter does not signal problems by its return value, but by logging errors. */ - private static class GroovyErrorListener implements ILogListener { - + private static class GroovyErrorListener implements ILogListener, IGroovyLogger { private final List errors; public GroovyErrorListener() { @@ -92,6 +102,9 @@ public GroovyErrorListener() { errors = Collections.synchronizedList(new ArrayList()); ILog groovyLogger = GroovyCoreActivator.getDefault().getLog(); groovyLogger.addLogListener(this); + synchronized (GroovyLogManager.manager) { + GroovyLogManager.manager.addLogger(this); + } } @Override @@ -102,6 +115,9 @@ public void logging(final IStatus status, final String plugin) { public boolean errorsDetected() { ILog groovyLogger = GroovyCoreActivator.getDefault().getLog(); groovyLogger.removeLogListener(this); + synchronized (GroovyLogManager.manager) { + GroovyLogManager.manager.removeLogger(this); + } return 0 != errors.size(); } @@ -120,6 +136,22 @@ public String toString() { return string.toString(); } + + @Override + public boolean isCategoryEnabled(TraceCategory cat) { + /* + * Note that the compiler errors are just additionally caught here. + * They are also printed directly to System.err. + * See org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.recordProblems + * for details. + */ + return TraceCategory.COMPILER.equals(cat); + } + + @Override + public void log(TraceCategory arg0, String arg1) { + errors.add(arg1); + } } private static PreferenceStore createPreferences(final Properties properties) throws IOException { @@ -130,5 +162,4 @@ private static PreferenceStore createPreferences(final Properties properties) th preferences.load(input); return preferences; } - } diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 28aec41232..fb2ed88df7 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -70,12 +70,11 @@ EquoBasedStepBuilder.State get() throws Exception { var query = model(formatterVersion).query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW); var classpath = new ArrayList(); var mavenDeps = new ArrayList(); - mavenDeps.add("dev.equo.ide:solstice:0.18.0"); + mavenDeps.add("dev.equo.ide:solstice:0.19.1"); mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); classpath.addAll(query.getJarsNotOnMavenCentral()); - File nestedDir = new File("/Users/ntwigg/.equo/p2-blah"); - for (var nested : NestedJars.inFiles(query.getJarsNotOnMavenCentral()).extractAllNestedJars(nestedDir)) { + for (var nested : NestedJars.inFiles(query.getJarsNotOnMavenCentral()).extractAllNestedJars()) { classpath.add(nested.getValue()); } var jarState = JarState.preserveOrder(classpath); From 3ed28db594cfffd274174d68fe4ec4e33768c98f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 12 Mar 2023 13:24:29 -0700 Subject: [PATCH 0599/1120] Delete the Groovy lockfiles. --- .../eclipse_groovy_formatter/v2.3.0.lockfile | 5 ----- .../eclipse_groovy_formatter/v4.10.0.lockfile | 18 ----------------- .../eclipse_groovy_formatter/v4.12.0.lockfile | 18 ----------------- .../eclipse_groovy_formatter/v4.13.0.lockfile | 18 ----------------- .../eclipse_groovy_formatter/v4.14.0.lockfile | 18 ----------------- .../eclipse_groovy_formatter/v4.15.0.lockfile | 18 ----------------- .../eclipse_groovy_formatter/v4.16.0.lockfile | 18 ----------------- .../eclipse_groovy_formatter/v4.17.0.lockfile | 19 ------------------ .../eclipse_groovy_formatter/v4.18.0.lockfile | 19 ------------------ .../eclipse_groovy_formatter/v4.19.0.lockfile | 19 ------------------ .../eclipse_groovy_formatter/v4.20.0.lockfile | 20 ------------------- .../eclipse_groovy_formatter/v4.21.0.lockfile | 20 ------------------- .../eclipse_groovy_formatter/v4.6.3.lockfile | 2 -- .../eclipse_groovy_formatter/v4.8.0.lockfile | 18 ----------------- .../eclipse_groovy_formatter/v4.8.1.lockfile | 18 ----------------- 15 files changed, 248 deletions(-) delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v2.3.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.10.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.12.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.13.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.14.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.15.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.16.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.17.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.18.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.19.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.20.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.21.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.6.3.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.8.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.8.1.lockfile diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v2.3.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v2.3.0.lockfile deleted file mode 100644 index 878ddbe76a..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v2.3.0.lockfile +++ /dev/null @@ -1,5 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 2.3.0 (see https://github.com/groovy/groovy-eclipse/wiki) -# -# This version is deprecated since the new version system is based on the Eclipse versioning. -# Use the corresponding Eclipse version 4.6.3 instead. -com.diffplug.spotless:spotless-ext-greclipse:2.3.0 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.10.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.10.0.lockfile deleted file mode 100644 index 33f672b306..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.10.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 3.0.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:3.2.0 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.300 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.300 -org.eclipse.platform:org.eclipse.core.jobs:3.10.300 -org.eclipse.platform:org.eclipse.core.resources:3.13.300 -org.eclipse.platform:org.eclipse.core.runtime:3.15.200 -org.eclipse.platform:org.eclipse.equinox.app:1.4.100 -org.eclipse.platform:org.eclipse.equinox.common:3.10.300 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.300 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.300 -org.eclipse.platform:org.eclipse.jface.text:3.15.100 -org.eclipse.platform:org.eclipse.jface:3.15.100 -org.eclipse.platform:org.eclipse.osgi:3.13.300 -org.eclipse.platform:org.eclipse.text:3.8.100 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.12.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.12.0.lockfile deleted file mode 100644 index a60e5e8fb0..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.12.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 3.4.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:3.4.0 -com.diffplug.spotless:spotless-eclipse-base:3.2.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.400 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.300 -org.eclipse.platform:org.eclipse.core.jobs:3.10.400 -org.eclipse.platform:org.eclipse.core.resources:3.13.400 -org.eclipse.platform:org.eclipse.core.runtime:3.15.300 -org.eclipse.platform:org.eclipse.equinox.app:1.4.200 -org.eclipse.platform:org.eclipse.equinox.common:3.10.400 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.400 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.400 -org.eclipse.platform:org.eclipse.jface.text:3.15.200 -org.eclipse.platform:org.eclipse.jface:3.16.0 -org.eclipse.platform:org.eclipse.osgi:3.14.0 -org.eclipse.platform:org.eclipse.text:3.8.200 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.13.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.13.0.lockfile deleted file mode 100644 index aede5b0a76..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.13.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 3.5.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:3.5.0 -com.diffplug.spotless:spotless-eclipse-base:3.2.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.500 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.400 -org.eclipse.platform:org.eclipse.core.jobs:3.10.500 -org.eclipse.platform:org.eclipse.core.resources:3.13.500 -org.eclipse.platform:org.eclipse.core.runtime:3.16.0 -org.eclipse.platform:org.eclipse.equinox.app:1.4.300 -org.eclipse.platform:org.eclipse.equinox.common:3.10.500 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.500 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.500 -org.eclipse.platform:org.eclipse.jface.text:3.15.300 -org.eclipse.platform:org.eclipse.jface:3.17.0 -org.eclipse.platform:org.eclipse.osgi:3.15.0 -org.eclipse.platform:org.eclipse.text:3.9.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.14.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.14.0.lockfile deleted file mode 100644 index bca432c337..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.14.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 3.6.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:3.6.0 -com.diffplug.spotless:spotless-eclipse-base:3.3.0 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -org.eclipse.platform:org.eclipse.core.commands:3.9.600 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.500 -org.eclipse.platform:org.eclipse.core.jobs:3.10.600 -org.eclipse.platform:org.eclipse.core.resources:3.13.600 -org.eclipse.platform:org.eclipse.core.runtime:3.17.0 -org.eclipse.platform:org.eclipse.equinox.app:1.4.300 -org.eclipse.platform:org.eclipse.equinox.common:3.10.600 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.600 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.600 -org.eclipse.platform:org.eclipse.jface.text:3.16.100 -org.eclipse.platform:org.eclipse.jface:3.18.0 -org.eclipse.platform:org.eclipse.osgi:3.15.100 -org.eclipse.platform:org.eclipse.text:3.10.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.15.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.15.0.lockfile deleted file mode 100644 index fc91fae066..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.15.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 3.7.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:3.7.0 -com.diffplug.spotless:spotless-eclipse-base:3.3.0 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -org.eclipse.platform:org.eclipse.core.commands:3.9.700 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.600 -org.eclipse.platform:org.eclipse.core.jobs:3.10.700 -org.eclipse.platform:org.eclipse.core.resources:3.13.700 -org.eclipse.platform:org.eclipse.core.runtime:3.17.100 -org.eclipse.platform:org.eclipse.equinox.app:1.4.400 -org.eclipse.platform:org.eclipse.equinox.common:3.11.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.700 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.700 -org.eclipse.platform:org.eclipse.jface.text:3.16.200 -org.eclipse.platform:org.eclipse.jface:3.19.0 -org.eclipse.platform:org.eclipse.osgi:3.15.200 -org.eclipse.platform:org.eclipse.text:3.10.100 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.16.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.16.0.lockfile deleted file mode 100644 index 2c5f4ccd03..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.16.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 3.8.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:3.8.0 -com.diffplug.spotless:spotless-eclipse-base:3.3.0 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -org.eclipse.platform:org.eclipse.core.commands:3.9.700 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.700 -org.eclipse.platform:org.eclipse.core.jobs:3.10.800 -org.eclipse.platform:org.eclipse.core.resources:3.13.700 -org.eclipse.platform:org.eclipse.core.runtime:3.18.0 -org.eclipse.platform:org.eclipse.equinox.app:1.4.500 -org.eclipse.platform:org.eclipse.equinox.common:3.12.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.0 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.800 -org.eclipse.platform:org.eclipse.jface.text:3.16.300 -org.eclipse.platform:org.eclipse.jface:3.20.0 -org.eclipse.platform:org.eclipse.osgi:3.15.300 -org.eclipse.platform:org.eclipse.text:3.10.200 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.17.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.17.0.lockfile deleted file mode 100644 index 5242d0da8c..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.17.0.lockfile +++ /dev/null @@ -1,19 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 3.9.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:3.9.0 -com.diffplug.spotless:spotless-eclipse-base:3.4.1 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.700 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.800 -org.eclipse.platform:org.eclipse.core.jobs:3.10.800 -org.eclipse.platform:org.eclipse.core.resources:3.13.800 -org.eclipse.platform:org.eclipse.core.runtime:3.19.0 -org.eclipse.platform:org.eclipse.equinox.app:1.5.0 -org.eclipse.platform:org.eclipse.equinox.common:3.13.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.0 -org.eclipse.platform:org.eclipse.equinox.registry:3.9.0 -org.eclipse.platform:org.eclipse.jface.text:3.16.400 -org.eclipse.platform:org.eclipse.jface:3.21.0 -org.eclipse.platform:org.eclipse.osgi:3.16.0 -org.eclipse.platform:org.eclipse.text:3.10.300 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.18.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.18.0.lockfile deleted file mode 100644 index 6bfec53756..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.18.0.lockfile +++ /dev/null @@ -1,19 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 4.0.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:4.0.0 -com.diffplug.spotless:spotless-eclipse-base:3.4.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.800 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.800 -org.eclipse.platform:org.eclipse.core.jobs:3.10.1000 -org.eclipse.platform:org.eclipse.core.resources:3.13.900 -org.eclipse.platform:org.eclipse.core.runtime:3.20.0 -org.eclipse.platform:org.eclipse.equinox.app:1.5.0 -org.eclipse.platform:org.eclipse.equinox.common:3.14.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.10.0 -org.eclipse.platform:org.eclipse.jface.text:3.16.500 -org.eclipse.platform:org.eclipse.jface:3.22.0 -org.eclipse.platform:org.eclipse.osgi:3.16.100 -org.eclipse.platform:org.eclipse.text:3.10.400 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.19.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.19.0.lockfile deleted file mode 100644 index 880d55ac8d..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.19.0.lockfile +++ /dev/null @@ -1,19 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 4.1.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:4.1.0 -com.diffplug.spotless:spotless-eclipse-base:3.4.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.800 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.900 -org.eclipse.platform:org.eclipse.core.jobs:3.10.1100 -org.eclipse.platform:org.eclipse.core.resources:3.14.0 -org.eclipse.platform:org.eclipse.core.runtime:3.20.100 -org.eclipse.platform:org.eclipse.equinox.app:1.5.100 -org.eclipse.platform:org.eclipse.equinox.common:3.14.100 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.200 -org.eclipse.platform:org.eclipse.equinox.registry:3.10.100 -org.eclipse.platform:org.eclipse.jface.text:3.17.0 -org.eclipse.platform:org.eclipse.jface:3.22.100 -org.eclipse.platform:org.eclipse.osgi:3.16.200 -org.eclipse.platform:org.eclipse.text:3.11.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.20.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.20.0.lockfile deleted file mode 100644 index 2836c05982..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.20.0.lockfile +++ /dev/null @@ -1,20 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 4.2.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:4.2.0 -com.diffplug.spotless:spotless-eclipse-base:3.5.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.10.0 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.1000 -org.eclipse.platform:org.eclipse.core.filesystem:1.9.0 -org.eclipse.platform:org.eclipse.core.jobs:3.11.0 -org.eclipse.platform:org.eclipse.core.resources:3.15.0 -org.eclipse.platform:org.eclipse.core.runtime:3.22.0 -org.eclipse.platform:org.eclipse.equinox.app:1.5.100 -org.eclipse.platform:org.eclipse.equinox.common:3.15.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.200 -org.eclipse.platform:org.eclipse.equinox.registry:3.10.200 -org.eclipse.platform:org.eclipse.jface.text:3.18.0 -org.eclipse.platform:org.eclipse.jface:3.22.200 -org.eclipse.platform:org.eclipse.osgi:3.16.300 -org.eclipse.platform:org.eclipse.text:3.12.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.21.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.21.0.lockfile deleted file mode 100644 index 38376d1b32..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.21.0.lockfile +++ /dev/null @@ -1,20 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 4.3.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:4.3.0 -com.diffplug.spotless:spotless-eclipse-base:3.5.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.10.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.8.0 -org.eclipse.platform:org.eclipse.core.filesystem:1.9.100 -org.eclipse.platform:org.eclipse.core.jobs:3.12.0 -org.eclipse.platform:org.eclipse.core.resources:3.15.100 -org.eclipse.platform:org.eclipse.core.runtime:3.23.0 -org.eclipse.platform:org.eclipse.equinox.app:1.6.0 -org.eclipse.platform:org.eclipse.equinox.common:3.15.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.9.0 -org.eclipse.platform:org.eclipse.equinox.registry:3.11.0 -org.eclipse.platform:org.eclipse.jface.text:3.18.100 -org.eclipse.platform:org.eclipse.jface:3.23.0 -org.eclipse.platform:org.eclipse.osgi:3.17.0 -org.eclipse.platform:org.eclipse.text:3.12.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.6.3.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.6.3.lockfile deleted file mode 100644 index a6299ec57d..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.6.3.lockfile +++ /dev/null @@ -1,2 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 2.3.0 (see https://github.com/groovy/groovy-eclipse/wiki) -com.diffplug.spotless:spotless-ext-greclipse:2.3.0 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.8.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.8.0.lockfile deleted file mode 100644 index bb95c71104..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.8.0.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 2.9.2 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:2.9.2 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.0 -org.eclipse.platform:org.eclipse.core.jobs:3.10.0 -org.eclipse.platform:org.eclipse.core.resources:3.13.0 -org.eclipse.platform:org.eclipse.core.runtime:3.14.0 -org.eclipse.platform:org.eclipse.equinox.app:1.3.500 -org.eclipse.platform:org.eclipse.equinox.common:3.10.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.0 -org.eclipse.platform:org.eclipse.jface.text:3.13.0 -org.eclipse.platform:org.eclipse.jface:3.14.0 -org.eclipse.platform:org.eclipse.osgi:3.13.0 -org.eclipse.platform:org.eclipse.text:3.6.300 \ No newline at end of file diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.8.1.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.8.1.lockfile deleted file mode 100644 index 9198eaccb9..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_groovy_formatter/v4.8.1.lockfile +++ /dev/null @@ -1,18 +0,0 @@ -# Spotless formatter based on Groovy-Eclipse version 3.0.0 (see https://github.com/groovy/groovy-eclipse/releases) -com.diffplug.spotless:spotless-eclipse-groovy:3.0.1 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.0 -org.eclipse.platform:org.eclipse.core.jobs:3.10.0 -org.eclipse.platform:org.eclipse.core.resources:3.13.0 -org.eclipse.platform:org.eclipse.core.runtime:3.14.0 -org.eclipse.platform:org.eclipse.equinox.app:1.3.500 -org.eclipse.platform:org.eclipse.equinox.common:3.10.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.0 -org.eclipse.platform:org.eclipse.jface.text:3.13.0 -org.eclipse.platform:org.eclipse.jface:3.14.0 -org.eclipse.platform:org.eclipse.osgi:3.13.0 -org.eclipse.platform:org.eclipse.text:3.6.300 \ No newline at end of file From 24abb541e5df9c69acc9333ffec1137099494eef Mon Sep 17 00:00:00 2001 From: Kostiantyn Liutovych Date: Sun, 12 Mar 2023 21:05:16 +0100 Subject: [PATCH 0600/1120] Enable up-to-date checking in Maven plugin by default Up-to-date checking has been supported for a long time. We haven't received any negative feedback about it. Neo4j is an example project that has up-to-date checking enabled to improve performance and haven't had problems with it: https://github.com/neo4j/neo4j/blob/6ebc409772cea13354adb6a11aab4ed38da9d53e/pom.xml#L745-L747. It should be safe to enable up-to-date checking for all users of the Spotless Maven plugin. This commit also fixes the problem where plugin execution would fail on a parent of a multimodule Maven project with up-to-date checking enabled. A parent project can configure Spotless as: ```xml com.diffplug.spotless spotless-maven-plugin ... ``` It allows child projects to inherit plugin's version and configuration but the plugin is not enables by default. PluginFingerprint did not handle such configuration correctly. It could only handle a simple configuration like: ```xml com.diffplug.spotless spotless-maven-plugin ... ``` And failed with "Spotless plugin absent from the project" error for a multimodule parent project with Spotless in ``. --- plugin-maven/CHANGES.md | 2 + plugin-maven/README.md | 2 +- .../spotless/maven/AbstractSpotlessMojo.java | 4 +- .../maven/incremental/PluginFingerprint.java | 24 +++++- .../maven/incremental/UpToDateChecking.java | 8 +- .../maven/MultiModuleProjectTest.java | 34 ++++----- .../incremental/PluginFingerprintTest.java | 36 ++++++++- .../incremental/UpToDateCheckingTest.java | 75 +++++++++---------- 8 files changed, 121 insertions(+), 64 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 73eb026796..f65f5e61d4 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * You can now put the filename into a license header template with `$FILE`. ([#1605](https://github.com/diffplug/spotless/pull/1605) fixes [#1147](https://github.com/diffplug/spotless/issues/1147)) ### Fixed * `licenseHeader` default pattern for Java files is updated to `(package|import|public|class|module) `. ([#1614](https://github.com/diffplug/spotless/pull/1614)) +### Changes +* Enable incremental up-to-date checking by default. ([#1621](https://github.com/diffplug/spotless/pull/1621)) ## [2.34.0] - 2023-02-27 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 426b00184e..4af6308b89 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1262,7 +1262,7 @@ To define what lines to skip at the beginning of such files, fill the `skipLines ## Incremental up-to-date checking and formatting -**This feature is turned off by default.** +**This feature is enabled by default starting from version 2.35.0.** Execution of `spotless:check` and `spotless:apply` for large projects can take time. By default, Spotless Maven plugin needs to read and format each source file. 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 f6aab0eabb..2c0d6e35e6 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 @@ -187,7 +187,7 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { private String setLicenseHeaderYearsFromGitHistory; @Parameter - private UpToDateChecking upToDateChecking; + private UpToDateChecking upToDateChecking = UpToDateChecking.enabled(); protected abstract void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException; @@ -373,9 +373,9 @@ private UpToDateChecker createUpToDateChecker(Iterable formatters) { } final UpToDateChecker checker; if (upToDateChecking != null && upToDateChecking.isEnabled()) { - getLog().info("Up-to-date checking enabled"); checker = UpToDateChecker.forProject(project, indexFile, formatters, getLog()); } else { + getLog().info("Up-to-date checking disabled"); checker = UpToDateChecker.noop(project, indexFile, getLog()); } return UpToDateChecker.wrapWithBuildContext(checker, buildContext); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/PluginFingerprint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/PluginFingerprint.java index 9efd6f2586..34a01e235a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/PluginFingerprint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/PluginFingerprint.java @@ -21,6 +21,7 @@ import java.util.Objects; import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; import org.apache.maven.project.MavenProject; import com.diffplug.spotless.Formatter; @@ -43,10 +44,7 @@ private PluginFingerprint(String value) { } static PluginFingerprint from(MavenProject project, Iterable formatters) { - Plugin spotlessPlugin = project.getPlugin(SPOTLESS_PLUGIN_KEY); - if (spotlessPlugin == null) { - throw new IllegalArgumentException("Spotless plugin absent from the project: " + project); - } + Plugin spotlessPlugin = findSpotlessPlugin(project); byte[] digest = digest(spotlessPlugin, formatters); String value = Base64.getEncoder().encodeToString(digest); return new PluginFingerprint(value); @@ -86,6 +84,24 @@ public String toString() { return "PluginFingerprint[" + value + "]"; } + private static Plugin findSpotlessPlugin(MavenProject project) { + // Try to find the plugin instance from XML element + Plugin plugin = project.getPlugin(SPOTLESS_PLUGIN_KEY); + if (plugin == null) { + // Try to find the plugin instance from XML element. Useful when + // the current module is a parent of a multimodule project + PluginManagement pluginManagement = project.getPluginManagement(); + if (pluginManagement != null) { + plugin = pluginManagement.getPluginsAsMap().get(SPOTLESS_PLUGIN_KEY); + } + } + + if (plugin == null) { + throw new IllegalArgumentException("Spotless plugin absent from the project: " + project); + } + return plugin; + } + private static byte[] digest(Plugin plugin, Iterable formatters) { try (ObjectDigestOutputStream out = ObjectDigestOutputStream.create()) { out.writeObject(plugin.getVersion()); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecking.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecking.java index d5eb6aa941..f044b847c9 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecking.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecking.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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. @@ -38,4 +38,10 @@ public boolean isEnabled() { public Path getIndexFile() { return indexFile == null ? null : new File(indexFile).toPath(); } + + public static UpToDateChecking enabled() { + UpToDateChecking upToDateChecking = new UpToDateChecking(); + upToDateChecking.enabled = true; + return upToDateChecking; + } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java index 1c9521c402..a93b4ffdd0 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MultiModuleProjectTest.java @@ -32,31 +32,31 @@ class MultiModuleProjectTest extends MavenIntegrationHarness { @Test void testConfigurationDependency() throws Exception { /* - create a multi-module project with the following stucture: + create a multi-module project with the following structure: /junit-tmp-dir ├── config - │   ├── pom.xml - │   └── src/main/resources/configs - │   ├── eclipse-formatter.xml - │   └── scalafmt.conf + │ ├── pom.xml + │ └── src/main/resources/configs + │ ├── eclipse-formatter.xml + │ └── scalafmt.conf ├── mvnw ├── mvnw.cmd ├── one - │   ├── pom.xml - │   └── src - │   ├── main/java/test1.java - │   └── test/java/test2.java + │ ├── pom.xml + │ └── src + │ ├── main/java/test1.java + │ └── test/java/test2.java ├── two - │   ├── pom.xml - │   └── src - │   ├── main/java/test1.java - │   └── test/java/test2.java + │ ├── pom.xml + │ └── src + │ ├── main/java/test1.java + │ └── test/java/test2.java ├── three - │   ├── pom.xml - │   └── src - │   ├── main/scala/test1.scala - │   └── test/scala/test2.scala + │ ├── pom.xml + │ └── src + │ ├── main/scala/test1.scala + │ └── test/scala/test2.scala ├── pom.xml ├── .mvn ├── mvnw diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/PluginFingerprintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/PluginFingerprintTest.java index c344580d37..ae61dec331 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/PluginFingerprintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/PluginFingerprintTest.java @@ -23,9 +23,12 @@ import java.io.ByteArrayInputStream; import java.nio.file.Paths; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.ReaderFactory; @@ -106,7 +109,7 @@ void emptyFingerprint() { } @Test - void failsWhenProjectDoesNotContainSpotlessPlugin() { + void failsForProjectWithoutSpotlessPlugin() { MavenProject projectWithoutSpotless = new MavenProject(); assertThatThrownBy(() -> PluginFingerprint.from(projectWithoutSpotless, FORMATTERS)) @@ -114,6 +117,37 @@ void failsWhenProjectDoesNotContainSpotlessPlugin() { .hasMessageContaining("Spotless plugin absent from the project"); } + @Test + void buildsFingerprintForProjectWithSpotlessPluginInBuildPlugins() { + MavenProject project = new MavenProject(); + Plugin spotlessPlugin = new Plugin(); + spotlessPlugin.setGroupId("com.diffplug.spotless"); + spotlessPlugin.setArtifactId("spotless-maven-plugin"); + spotlessPlugin.setVersion("1.2.3"); + project.getBuild().addPlugin(spotlessPlugin); + + PluginFingerprint fingerprint = PluginFingerprint.from(project, Collections.emptyList()); + + assertThat(fingerprint).isNotNull(); + } + + @Test + void buildsFingerprintForProjectWithSpotlessPluginInPluginManagement() { + MavenProject project = new MavenProject(); + Plugin spotlessPlugin = new Plugin(); + spotlessPlugin.setGroupId("com.diffplug.spotless"); + spotlessPlugin.setArtifactId("spotless-maven-plugin"); + spotlessPlugin.setVersion("1.2.3"); + project.getBuild().addPlugin(spotlessPlugin); + PluginManagement pluginManagement = new PluginManagement(); + pluginManagement.addPlugin(spotlessPlugin); + project.getBuild().setPluginManagement(pluginManagement); + + PluginFingerprint fingerprint = PluginFingerprint.from(project, Collections.emptyList()); + + assertThat(fingerprint).isNotNull(); + } + private MavenProject mavenProject(String spotlessVersion) throws Exception { String xml = createPomXmlContent(spotlessVersion, new String[0], new String[0]); return new MavenProject(readPom(xml)); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java index 0a9fe8f2d4..cfc17594ca 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/incremental/UpToDateCheckingTest.java @@ -31,8 +31,10 @@ class UpToDateCheckingTest extends MavenIntegrationHarness { + private static final String DISABLED_MESSAGE = "Up-to-date checking disabled"; + @Test - void upToDateCheckingDisabledByDefault() throws Exception { + void upToDateCheckingEnabledByDefault() throws Exception { writePom( "", " ", @@ -41,75 +43,53 @@ void upToDateCheckingDisabledByDefault() throws Exception { List files = writeUnformattedFiles(1); String output = runSpotlessApply(); - assertThat(output).doesNotContain("Up-to-date checking enabled"); + assertThat(output).doesNotContain(DISABLED_MESSAGE); assertFormatted(files); } @Test - void enableUpToDateChecking() throws Exception { + void explicitlyEnableUpToDateChecking() throws Exception { writePomWithUpToDateCheckingEnabled(true); List files = writeUnformattedFiles(1); String output = runSpotlessApply(); - assertThat(output).contains("Up-to-date checking enabled"); + assertThat(output).doesNotContain(DISABLED_MESSAGE); assertFormatted(files); } @Test - void enableUpToDateCheckingWithPluginDependencies() throws Exception { - writePomWithPluginManagementAndDependency(); + void explicitlyDisableUpToDateChecking() throws Exception { + writePomWithUpToDateCheckingEnabled(false); List files = writeUnformattedFiles(1); String output = runSpotlessApply(); - assertThat(output).contains("Up-to-date checking enabled"); + assertThat(output).contains(DISABLED_MESSAGE); assertFormatted(files); } @Test - void enableUpToDateCheckingWithPluginDependenciesMaven3_6_3() throws Exception { + void enableUpToDateCheckingWithPluginDependencies() throws Exception { writePomWithPluginManagementAndDependency(); - setFile(".mvn/wrapper/maven-wrapper.properties").toContent("distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip\n"); - List files = writeUnformattedFiles(1); String output = runSpotlessApply(); - assertThat(output).contains("Up-to-date checking enabled"); + assertThat(output).doesNotContain(DISABLED_MESSAGE); assertFormatted(files); } - private void writePomWithPluginManagementAndDependency() throws IOException { - setFile("pom.xml").toContent(createPomXmlContent("/pom-test-management.xml.mustache", - null, - null, - new String[]{ - "", - " ", - "", - "", - " true", - ""}, - new String[]{ - "", - " ", - " javax.inject", - " javax.inject", - " 1", - " ", - ""}, - null)); - } - @Test - void disableUpToDateChecking() throws Exception { - writePomWithUpToDateCheckingEnabled(false); + void enableUpToDateCheckingWithPluginDependenciesMaven3_6_3() throws Exception { + writePomWithPluginManagementAndDependency(); + + setFile(".mvn/wrapper/maven-wrapper.properties").toContent("distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip\n"); List files = writeUnformattedFiles(1); String output = runSpotlessApply(); - assertThat(output).doesNotContain("Up-to-date checking enabled"); + assertThat(output).doesNotContain(DISABLED_MESSAGE); assertFormatted(files); } @@ -124,7 +104,7 @@ void enableUpToDateCheckingCustomIndexFile() throws Exception { List files = writeUnformattedFiles(1); String output = runSpotlessApply(); - assertThat(output).contains("Up-to-date checking enabled"); + assertThat(output).doesNotContain(DISABLED_MESSAGE); assertFormatted(files); assertThat(indexFile.getParent()).exists(); assertThat(indexFile).exists(); @@ -143,7 +123,7 @@ void disableUpToDateCheckingCustomIndexFile() throws Exception { List files = writeUnformattedFiles(1); String output = runSpotlessApply(); - assertThat(output).doesNotContain("Up-to-date checking enabled"); + assertThat(output).contains(DISABLED_MESSAGE); assertFormatted(files); assertThat(indexFile.getParent()).exists(); assertThat(indexFile).doesNotExist(); @@ -215,6 +195,25 @@ void spotlessCheckRecordsUnformattedFiles() throws Exception { assertSpotlessCheckSkipped(files, checkOutput3); } + private void writePomWithPluginManagementAndDependency() throws IOException { + setFile("pom.xml").toContent(createPomXmlContent("/pom-test-management.xml.mustache", + null, + null, + new String[]{ + "", + " ", + ""}, + new String[]{ + "", + " ", + " javax.inject", + " javax.inject", + " 1", + " ", + ""}, + null)); + } + private void writePomWithUpToDateCheckingEnabled(boolean enabled) throws IOException { writePom( "", From 657e0bc1f29da5a9a57bf2c2ab11f27809fbda52 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 12 Mar 2023 21:18:57 -0700 Subject: [PATCH 0601/1120] Added EquoBasedStepBuilder.addPlatformRepo which handles how the core platform IUs change with different versions. --- .../groovy/GrEclipseFormatterStepImpl.java | 28 ++++++++++++------- .../spotless/extra/EquoBasedStepBuilder.java | 20 +++++++++++++ .../extra/groovy/GrEclipseFormatterStep.java | 5 +++- .../extra/java/EclipseJdtFormatterStep.java | 4 +-- .../groovy/GrEclipseFormatterStepTest.java | 2 +- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index 18aed57aeb..dd3348a5a0 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -39,6 +39,7 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.TextSelection; import org.eclipse.text.edits.TextEdit; +import org.osgi.framework.Constants; import dev.equo.solstice.NestedJars; import dev.equo.solstice.ShimIdeBootstrapServices; @@ -47,6 +48,23 @@ /** Spotless-Formatter step which calls out to the Groovy-Eclipse formatter. */ public class GrEclipseFormatterStepImpl { + static { + System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); + NestedJars.setToWarnOnly(); + NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.nestedJars()); + + var solstice = Solstice.findBundlesOnClasspath(); + solstice.warnAndModifyManifestsToFix(); + var props = Map.of("osgi.nl", "en_US", + Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); + solstice.openShim(props); + ShimIdeBootstrapServices.apply(props, solstice.getContext()); + solstice.start("org.apache.felix.scr"); + solstice.startAllWithLazy(false); + // solstice.start("org.eclipse.core.resources"); + solstice.start("org.codehaus.groovy.eclipse.core"); + } + /** * Groovy compiler problems can be ignored. *

@@ -59,16 +77,6 @@ public class GrEclipseFormatterStepImpl { private final boolean ignoreFormatterProblems; public GrEclipseFormatterStepImpl(final Properties properties) throws Exception { - var solstice = Solstice.findBundlesOnClasspath(); - NestedJars.setToWarnOnly(); - NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.nestedJars()); - solstice.warnAndModifyManifestsToFix(); - var props = Map. of(); - solstice.openShim(props); - ShimIdeBootstrapServices.apply(props, solstice.getContext()); - solstice.startAllWithLazy(false); - solstice.startWithoutTransitives("org.codehaus.groovy.eclipse.core"); - PreferenceStore preferences = createPreferences(properties); preferencesStore = new FormatterPreferencesOnStore(preferences); ignoreFormatterProblems = Boolean.parseBoolean(properties.getProperty(IGNORE_FORMATTER_PROBLEMS, "false")); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index fb2ed88df7..885d3bfbc6 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.Serializable; import java.util.ArrayList; +import java.util.List; import java.util.Properties; import com.diffplug.spotless.FileSignature; @@ -65,12 +66,31 @@ public FormatterStep build() { protected abstract P2Model model(String version); + protected void addPlatformRepo(P2Model model, String version) { + if (!version.startsWith("4.")) { + throw new IllegalArgumentException("Expected 4.x"); + } + int minorVersion = Integer.parseInt(version.substring("4.".length())); + + model.addP2Repo("https://download.eclipse.org/eclipse/updates/" + version + "/"); + model.getInstall().addAll(List.of( + "org.apache.felix.scr", + "org.eclipse.equinox.event")); + if (minorVersion >= 25) { + model.getInstall().addAll(List.of( + "org.osgi.service.cm", + "org.osgi.service.metatype")); + } + } + /** Creates the state of the configuration. */ EquoBasedStepBuilder.State get() throws Exception { var query = model(formatterVersion).query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW); var classpath = new ArrayList(); var mavenDeps = new ArrayList(); mavenDeps.add("dev.equo.ide:solstice:0.19.1"); + mavenDeps.add("com.diffplug.durian:durian-swt.os:4.1.1"); + mavenDeps.add("org.slf4j:slf4j-simple:1.7.36"); mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); classpath.addAll(query.getJarsNotOnMavenCentral()); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java index 312f9a786f..657399ffa2 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java @@ -57,13 +57,16 @@ protected P2Model model(String version) { greclipseVersion = "3." + (eVersion - 8) + ".0"; } var model = new P2Model(); - model.addP2Repo("https://download.eclipse.org/eclipse/updates/" + version + "/"); + addPlatformRepo(model, version); model.addP2Repo("https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/" + greclipseVersion + "/e" + version + "/"); model.getInstall().addAll(List.of( "org.codehaus.groovy.eclipse.refactoring", "org.codehaus.groovy.eclipse.core", "org.eclipse.jdt.groovy.core", "org.codehaus.groovy")); + model.addFilterAndValidate("no-debug", filter -> { + filter.exclude("org.eclipse.jdt.debug"); + }); return model; } diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java index 50654899bd..cd9314406f 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java @@ -42,7 +42,7 @@ public static EquoBasedStepBuilder createBuilder(Provisioner provisioner) { @Override protected P2Model model(String version) { var model = new P2Model(); - model.addP2Repo("https://download.eclipse.org/eclipse/updates/" + version + "/"); + addPlatformRepo(model, version); model.getInstall().add("org.eclipse.jdt.core"); return model; } @@ -51,7 +51,7 @@ protected P2Model model(String version) { public void setVersion(String version) { if (version.endsWith(".0")) { String newVersion = version.substring(0, version.length() - 2); - System.err.println("Recommend replacing '" + version + "' with '" + newVersion + "' for eclipse JDT"); + System.err.println("Recommend replacing '" + version + "' with '" + newVersion + "' for Eclipse JDT"); version = newVersion; } super.setVersion(version); diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java index d72fc2e1a4..f4e47cd798 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java @@ -38,6 +38,6 @@ void formatWithVersion(String version) throws Exception { } private static Stream formatWithVersion() { - return Stream.of("4.25", GrEclipseFormatterStep.defaultVersion()); + return Stream.of("4.21", GrEclipseFormatterStep.defaultVersion()); } } From 3d12662be876c5fd9de2f05f3c7a230ecfb06b76 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 12 Mar 2023 23:44:28 -0700 Subject: [PATCH 0602/1120] Fix GrEclipse for 4.18 through 4.26 --- lib-extra/build.gradle | 2 +- .../groovy/GrEclipseFormatterStepImpl.java | 29 +++++++++++-------- .../spotless/extra/EquoBasedStepBuilder.java | 2 +- .../groovy/GrEclipseFormatterStepTest.java | 5 ++-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index f3b4b7c4b5..9506f9a2ad 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -7,7 +7,7 @@ version = rootProject.spotlessChangelog.versionNext apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') -String VER_SOLSTICE = '0.19.1' +String VER_SOLSTICE = '0.19.2' dependencies { api project(':lib') // misc useful utilities diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index dd3348a5a0..ded0ef56bd 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -18,6 +18,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -38,8 +39,10 @@ import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.TextSelection; +import org.eclipse.osgi.internal.location.EquinoxLocations; import org.eclipse.text.edits.TextEdit; import org.osgi.framework.Constants; +import org.slf4j.LoggerFactory; import dev.equo.solstice.NestedJars; import dev.equo.solstice.ShimIdeBootstrapServices; @@ -49,20 +52,22 @@ /** Spotless-Formatter step which calls out to the Groovy-Eclipse formatter. */ public class GrEclipseFormatterStepImpl { static { - System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); NestedJars.setToWarnOnly(); NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.nestedJars()); - - var solstice = Solstice.findBundlesOnClasspath(); - solstice.warnAndModifyManifestsToFix(); - var props = Map.of("osgi.nl", "en_US", - Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); - solstice.openShim(props); - ShimIdeBootstrapServices.apply(props, solstice.getContext()); - solstice.start("org.apache.felix.scr"); - solstice.startAllWithLazy(false); - // solstice.start("org.eclipse.core.resources"); - solstice.start("org.codehaus.groovy.eclipse.core"); + try { + var solstice = Solstice.findBundlesOnClasspath(); + solstice.warnAndModifyManifestsToFix(); + var props = Map.of("osgi.nl", "en_US", + Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT, + EquinoxLocations.PROP_INSTANCE_AREA, Files.createTempDirectory("spotless-groovy").toAbsolutePath().toString()); + solstice.openShim(props); + ShimIdeBootstrapServices.apply(props, solstice.getContext()); + solstice.start("org.apache.felix.scr"); + solstice.startAllWithLazy(false); + solstice.start("org.codehaus.groovy.eclipse.core"); + } catch (IOException e) { + throw new RuntimeException(e); + } } /** diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 885d3bfbc6..f4cea50275 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -88,7 +88,7 @@ EquoBasedStepBuilder.State get() throws Exception { var query = model(formatterVersion).query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW); var classpath = new ArrayList(); var mavenDeps = new ArrayList(); - mavenDeps.add("dev.equo.ide:solstice:0.19.1"); + mavenDeps.add("dev.equo.ide:solstice:0.19.2"); mavenDeps.add("com.diffplug.durian:durian-swt.os:4.1.1"); mavenDeps.add("org.slf4j:slf4j-simple:1.7.36"); mavenDeps.addAll(query.getJarsOnMavenCentral()); diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java index f4e47cd798..4121d49497 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java @@ -23,12 +23,13 @@ import com.diffplug.spotless.TestProvisioner; import com.diffplug.spotless.extra.eclipse.EquoResourceHarness; -class GrEclipseFormatterStepTest extends EquoResourceHarness { +public class GrEclipseFormatterStepTest extends EquoResourceHarness { private final static String INPUT = "class F{ def m(){} }"; private final static String EXPECTED = "class F{\n\tdef m(){}\n}"; public GrEclipseFormatterStepTest() { super(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral()), INPUT, EXPECTED); + System.setProperty("org.gradle.logging.level", "info"); } @ParameterizedTest @@ -38,6 +39,6 @@ void formatWithVersion(String version) throws Exception { } private static Stream formatWithVersion() { - return Stream.of("4.21", GrEclipseFormatterStep.defaultVersion()); + return Stream.of("4.18", GrEclipseFormatterStep.defaultVersion()); } } From 52a1d2450db8138e91cfa8cc160e6a1aee1fe72e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 12 Mar 2023 23:44:37 -0700 Subject: [PATCH 0603/1120] Update changelog for Groovy. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index c09f3a0cdd..3295ef5013 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * We are now opting in to Gradle's new stable configuration cache. ([#1591](https://github.com/diffplug/spotless/pull/1591)) * Adopt [Equo Solstice OSGi and p2 shim](https://github.com/equodev/equo-ide/tree/main/solstice) to update all Eclipse-based plugins. ([#1524](https://github.com/diffplug/spotless/pull/1524)) * Eclipse JDT now supports `4.9` through `4.26`. Also we now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. + * Eclipse Groovy now supports `4.18` through `4.26`. Also we now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. ## [2.36.0] - 2023-02-27 ### Added From 1d5888d58cc6e18ed69893948f7ce4befc3359fe Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 12 Mar 2023 23:45:50 -0700 Subject: [PATCH 0604/1120] Fix logging nonsense. --- .../spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java | 1 - .../java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 1 - .../diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java | 3 +-- .../spotless/extra/groovy/GrEclipseFormatterStepTest.java | 1 - 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index ded0ef56bd..0beb363b5a 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -42,7 +42,6 @@ import org.eclipse.osgi.internal.location.EquinoxLocations; import org.eclipse.text.edits.TextEdit; import org.osgi.framework.Constants; -import org.slf4j.LoggerFactory; import dev.equo.solstice.NestedJars; import dev.equo.solstice.ShimIdeBootstrapServices; diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index f4cea50275..2c3d083b1b 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -90,7 +90,6 @@ EquoBasedStepBuilder.State get() throws Exception { var mavenDeps = new ArrayList(); mavenDeps.add("dev.equo.ide:solstice:0.19.2"); mavenDeps.add("com.diffplug.durian:durian-swt.os:4.1.1"); - mavenDeps.add("org.slf4j:slf4j-simple:1.7.36"); mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); classpath.addAll(query.getJarsNotOnMavenCentral()); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java index 657399ffa2..08c28889f9 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java @@ -33,7 +33,6 @@ private GrEclipseFormatterStep() {} private static final String NAME = "eclipse groovy formatter"; private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26"); - private static final String FORMATTER_METHOD = "format"; public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); @@ -86,7 +85,7 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion()); Class formatterClazz = state.getJarState().getClassLoader().loadClass("com.diffplug.spotless.extra.glue.groovy.GrEclipseFormatterStepImpl"); var formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences()); - var method = formatterClazz.getMethod(FORMATTER_METHOD, String.class); + var method = formatterClazz.getMethod("format", String.class); return JVM_SUPPORT.suggestLaterVersionOnError(state.getSemanticVersion(), input -> { try { diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java index 4121d49497..2bd68d0281 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java @@ -29,7 +29,6 @@ public class GrEclipseFormatterStepTest extends EquoResourceHarness { public GrEclipseFormatterStepTest() { super(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral()), INPUT, EXPECTED); - System.setProperty("org.gradle.logging.level", "info"); } @ParameterizedTest From a8db32b61ae6b3f760598c6dd1f97fdea1cf7d27 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 12 Mar 2023 23:57:55 -0700 Subject: [PATCH 0605/1120] Remove _ext/eclipse-cdt --- _ext/eclipse-cdt/CHANGES.md | 63 ------------ _ext/eclipse-cdt/LICENSE.txt | 70 ------------- _ext/eclipse-cdt/README.md | 10 -- _ext/eclipse-cdt/build.gradle | 40 -------- _ext/eclipse-cdt/gradle.properties | 12 --- .../cdt/EclipseCdtFormatterStepImpl.java | 74 -------------- .../extra/eclipse/cdt/package-info.java | 20 ---- .../cdt/EclipseCdtFormatterStepImplTest.java | 99 ------------------- 8 files changed, 388 deletions(-) delete mode 100644 _ext/eclipse-cdt/CHANGES.md delete mode 100644 _ext/eclipse-cdt/LICENSE.txt delete mode 100644 _ext/eclipse-cdt/README.md delete mode 100644 _ext/eclipse-cdt/build.gradle delete mode 100644 _ext/eclipse-cdt/gradle.properties delete mode 100644 _ext/eclipse-cdt/src/main/java/com/diffplug/spotless/extra/eclipse/cdt/EclipseCdtFormatterStepImpl.java delete mode 100644 _ext/eclipse-cdt/src/main/java/com/diffplug/spotless/extra/eclipse/cdt/package-info.java delete mode 100644 _ext/eclipse-cdt/src/test/java/com/diffplug/spotless/extra/eclipse/cdt/EclipseCdtFormatterStepImplTest.java diff --git a/_ext/eclipse-cdt/CHANGES.md b/_ext/eclipse-cdt/CHANGES.md deleted file mode 100644 index cda212bd3d..0000000000 --- a/_ext/eclipse-cdt/CHANGES.md +++ /dev/null @@ -1,63 +0,0 @@ -# spotless-eclipse-cdt - -We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `9.9.0`). - -## [Unreleased] -### Fixed -* Fix typo in gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) - -## [10.5.0] - 2021-12-13 -### Added -* Switch to Eclipse CDT release 10.5 for Eclipse 2021-12. - -## [10.4.0] - 2021-09-23 -### Added -* Switch to Eclipse CDT release 10.4 for Eclipse 4.21. - -## [10.3.0] - 2021-06-27 -### Added -* Switch to Eclipse CDT release 10.3 for Eclipse 4.20. - -## [10.2.0] - 2021-06-07 -### Added -* Switch to Eclipse CDT release 10.2 for Eclipse 4.19. - -## [10.1.0] - 2020-12-26 -### Added -* Switch to Eclipse CDT release 10.1 for Eclipse 4.18. - -## [10.0.0] - 2020-10-17 -### Added -* Switch to Eclipse CDT release 10.0 for Eclipse 4.17. -* **BREAKING** Minimum required Java version changed from 8 to 11. - -## [9.11.0] - 2020-10-03 -### Added -* Switch to Eclipse CDT release 9.11.1 for Eclipse 4.16. - -## [9.10.0] - 2020-09-25 -### Added -* Switch to Eclipse CDT release 9.10 for Eclipse 4.14. - -## [9.9.0] - 2019-11-01 -* Switch to Eclipse CDT release 9.9 for Eclipse 4.13 ([#480](https://github.com/diffplug/spotless/issues/480)). - -## [9.8.1] - 2019-10-31 -* Really publish Eclipse CDT release 9.8 for Eclipse 4.12 ([#482](https://github.com/diffplug/spotless/pull/482)). - -## [9.8.0] - 2019-07-24 -* **Known bug** - we actually published Eclipse CDT 9.7 instead of 9.8 - fixed in 9.8.1 -* Switch to Eclipse CDT release 9.8 for Eclipse 4.12 ([#423](https://github.com/diffplug/spotless/pull/423)). - -## [9.7.0] - 2019-03-31 -* Switch to Eclipse CDT release 9.7 for Eclipse 4.11 ([#389](https://github.com/diffplug/spotless/pull/389)). -* Include Eclipse logging allowing formatter warnings/errors to be logged via SLF4J ([#236](https://github.com/diffplug/spotless/issues/236)). - -## [9.4.5] - 2019-02-25 -* Replaced `http` update-site with `https` ([#360](https://github.com/diffplug/spotless/issues/360)). - -## [9.4.4] - 2018-09-04 -* Added missing log service, which caused exceptions on AST warnings ([#286](https://github.com/diffplug/spotless/pull/286)). - -## [9.4.3] - 2018-08-08 -* Initial release! diff --git a/_ext/eclipse-cdt/LICENSE.txt b/_ext/eclipse-cdt/LICENSE.txt deleted file mode 100644 index 3d967aee74..0000000000 --- a/_ext/eclipse-cdt/LICENSE.txt +++ /dev/null @@ -1,70 +0,0 @@ -Eclipse Public License - v 1.0 - -THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. - -1. DEFINITIONS - -"Contribution" means: - -a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and -b) in the case of each subsequent Contributor: -i) changes to the Program, and -ii) additions to the Program; -where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. -"Contributor" means any person or entity that distributes the Program. - -"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. - -"Program" means the Contributions distributed in accordance with this Agreement. - -"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. - -2. GRANT OF RIGHTS - -a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. -b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. -c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. -d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. -3. REQUIREMENTS - -A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: - -a) it complies with the terms and conditions of this Agreement; and -b) its license agreement: -i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; -ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; -iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and -iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. -When the Program is made available in source code form: - -a) it must be made available under this Agreement; and -b) a copy of this Agreement must be included with each copy of the Program. -Contributors may not remove or alter any copyright notices contained within the Program. - -Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. - -4. COMMERCIAL DISTRIBUTION - -Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. - -For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. - -5. NO WARRANTY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. - -6. DISCLAIMER OF LIABILITY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -7. GENERAL - -If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. - -If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. - -All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. - -Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. - -This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. \ No newline at end of file diff --git a/_ext/eclipse-cdt/README.md b/_ext/eclipse-cdt/README.md deleted file mode 100644 index 842fbad606..0000000000 --- a/_ext/eclipse-cdt/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# spotless-eclipse-cdt - -Eclipse CDT is not available in a form which can be easily consumed by maven or gradle. To fix this, we publish Eclipse's formatter and all its dependencies, along with a small amount of glue code, into the `com.diffplug.gradle.spotless:spotless-eclipse-cdt` artifact. - -To publish a new version, update the `_ext/eclipse-cdt/gradle.properties` appropriately and see [CONTRIBUTING.md](../../CONTRIBUTING.md) how to enable -`_ext` projects. - -## License - -Spotless at large is under the Apache 2.0 license, but this jar is under the EPL v1. diff --git a/_ext/eclipse-cdt/build.gradle b/_ext/eclipse-cdt/build.gradle deleted file mode 100644 index 0982b7d555..0000000000 --- a/_ext/eclipse-cdt/build.gradle +++ /dev/null @@ -1,40 +0,0 @@ -ext { - developers = [ - fvgh: [ name: 'Frank Vennemeyer', email: 'frankgh@zoho.com' ], - ] - - p2Repository = "https://download.eclipse.org/tools/cdt/releases/${VER_ECLIPSE_CDT}" - - p2Dependencies = [ - 'org.eclipse.cdt.core':'+', // CodeFormatter and related - ] - -} - -apply from: rootProject.file('_ext/gradle/update-lockfile.gradle') -apply from: rootProject.file('_ext/gradle/p2-fat-jar-setup.gradle') -apply from: rootProject.file('gradle/java-publish.gradle') - - -dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" - // Provides text partitioners for formatters - implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { - exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' - } - // Required to by CCorePlugin calling CDTLogWriter - implementation "com.ibm.icu:icu4j:${VER_IBM_ICU}" - // Required to by CCorePlugin calling PositionTrackerManager - implementation "org.eclipse.platform:org.eclipse.core.filebuffers:${VER_ECLIPSE_EFS}" - - testImplementation("org.slf4j:slf4j-simple:${VER_SLF4J}") -} - - -////////// -// Test // -////////// -sourceSets { - // Use JAR file with all resources for Eclipse-CDT integration-tests - test.runtimeClasspath = jar.outputs.files + sourceSets.test.output + sourceSets.test.compileClasspath -} diff --git a/_ext/eclipse-cdt/gradle.properties b/_ext/eclipse-cdt/gradle.properties deleted file mode 100644 index 821ceea4d1..0000000000 --- a/_ext/eclipse-cdt/gradle.properties +++ /dev/null @@ -1,12 +0,0 @@ -artifactId=spotless-eclipse-cdt -description=Eclipse's CDT C/C++ formatter bundled for Spotless - -# Build requirements -VER_JAVA=11 - -# Compile dependencies -VER_ECLIPSE_CDT=10.5 -VER_SPOTLESS_ECLIPSE_BASE=[3.5.0,4.0.0[ -VER_ECLIPSE_JFACE=[3.18.0,4.0.0[ -VER_ECLIPSE_EFS=[3.7.0,4.0.0[ -VER_IBM_ICU=[67.1,68[ diff --git a/_ext/eclipse-cdt/src/main/java/com/diffplug/spotless/extra/eclipse/cdt/EclipseCdtFormatterStepImpl.java b/_ext/eclipse-cdt/src/main/java/com/diffplug/spotless/extra/eclipse/cdt/EclipseCdtFormatterStepImpl.java deleted file mode 100644 index 4482f3e752..0000000000 --- a/_ext/eclipse-cdt/src/main/java/com/diffplug/spotless/extra/eclipse/cdt/EclipseCdtFormatterStepImpl.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2016-2020 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.extra.eclipse.cdt; - -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.formatter.CodeFormatter; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.text.edits.TextEdit; - -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; - -/** Formatter step which calls out to the Eclipse CDT formatter. */ -public class EclipseCdtFormatterStepImpl { - private final CodeFormatter codeFormatter; - - public EclipseCdtFormatterStepImpl(Properties settings) throws Exception { - SpotlessEclipseFramework.setup(new FrameworkConfig()); - Stream> stream = settings.entrySet().stream(); - Map settingsMap = stream.collect(Collectors.toMap( - e -> String.valueOf(e.getKey()), - e -> String.valueOf(e.getValue()))); - codeFormatter = org.eclipse.cdt.core.ToolFactory.createDefaultCodeFormatter(settingsMap); - } - - private static class FrameworkConfig implements SpotlessEclipseConfig { - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - config.useSlf4J(EclipseCdtFormatterStepImpl.class.getPackage().getName()); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - config.add(new CCorePlugin()); - } - } - - /** Formatting C/C++ string */ - public String format(String raw) throws Exception { - //The 'kind' can be set to CodeFormatter.K_UNKNOWN, since it is anyway ignored by the internal formatter - TextEdit edit = codeFormatter.format(CodeFormatter.K_UNKNOWN, raw, 0, raw.length(), 0, SpotlessEclipseFramework.LINE_DELIMITER); - if (edit == null) { - throw new IllegalArgumentException("Invalid C/C++ syntax for formatting."); - } else { - IDocument doc = new Document(raw); - edit.apply(doc); - return doc.get(); - } - } -} diff --git a/_ext/eclipse-cdt/src/main/java/com/diffplug/spotless/extra/eclipse/cdt/package-info.java b/_ext/eclipse-cdt/src/main/java/com/diffplug/spotless/extra/eclipse/cdt/package-info.java deleted file mode 100644 index 831ab2b427..0000000000 --- a/_ext/eclipse-cdt/src/main/java/com/diffplug/spotless/extra/eclipse/cdt/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2016 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. - */ -/** Eclipse CDT based Spotless formatter */ -@ParametersAreNonnullByDefault -package com.diffplug.spotless.extra.eclipse.cdt; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/_ext/eclipse-cdt/src/test/java/com/diffplug/spotless/extra/eclipse/cdt/EclipseCdtFormatterStepImplTest.java b/_ext/eclipse-cdt/src/test/java/com/diffplug/spotless/extra/eclipse/cdt/EclipseCdtFormatterStepImplTest.java deleted file mode 100644 index 05637a4e22..0000000000 --- a/_ext/eclipse-cdt/src/test/java/com/diffplug/spotless/extra/eclipse/cdt/EclipseCdtFormatterStepImplTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.spotless.extra.eclipse.cdt; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Properties; -import java.util.function.Consumer; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; -import org.junit.jupiter.api.Test; - -/** Eclipse CDT wrapper integration tests */ -class EclipseCdtFormatterStepImplTest { - - private final static String CPP_UNFORMATTED = "#include \n" + - "using namespace std;\n" + - "int main()\n{\n" + - " cout <<\n\"Hello, World!\";\n" + - " return 0;\n" + - "}".replaceAll("\n", LINE_DELIMITER); - private final static String CPP_FORMATTED = "#include \n" + - "using namespace std;\n" + - "int main() {\n" + - "\tcout << \"Hello, World!\";\n" + - "\treturn 0;\n" + - "}\n".replaceAll("\n", LINE_DELIMITER); - - private final static String DOXYGEN_HTML = "/**\n *

void f() {int a =1;} 
\n */\n".replaceAll("\n", LINE_DELIMITER); - - private final static String ILLEGAL_CHAR = Character.toString((char) 254); - - private final static String FUNCT_PTR_UNFORMATTED = "void (*getFunc(void)) (int);"; - private final static String FUNCT_PTR_FORMATTED = "void (* getFunc(void)) (int);"; - - @Test - void defaultFormat() throws Throwable { - String output = format(CPP_UNFORMATTED, config -> {}); - assertEquals(CPP_FORMATTED, - output, "Unexpected formatting with default preferences."); - } - - @Test - void invalidFormat() throws Throwable { - String output = format(CPP_FORMATTED.replace("int main() {", "int main() "), config -> {}); - assertTrue(output.contains("int main()" + LINE_DELIMITER), "Incomplete CPP not formatted on best effort basis."); - } - - @Test - void invalidCharater() throws Throwable { - String output = format(CPP_FORMATTED.replace("int main() {", "int main()" + ILLEGAL_CHAR + " {"), config -> {}); - assertTrue(output.contains("int main()" + LINE_DELIMITER), "Invalid charater not formatted on best effort basis."); - } - - @Test - void invalidConfiguration() throws Throwable { - String output = format(CPP_FORMATTED, config -> { - config.setProperty(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); - config.setProperty(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "noInteger"); - }); - assertEquals(CPP_FORMATTED.replace("\t", " "), - output, "Invalid indentation configuration not replaced by default value (4 spaces)"); - } - - @Test - void htmlCommentFormat() throws Throwable { - String output = format(DOXYGEN_HTML + CPP_FORMATTED, config -> {}); - assertEquals(DOXYGEN_HTML + CPP_FORMATTED, - output, "HTML comments not ignored by formatter."); - } - - @Test - void regionWarning() throws Throwable { - String output = format(FUNCT_PTR_UNFORMATTED, config -> {}); - assertEquals(FUNCT_PTR_FORMATTED, output, "Code not formatted at all due to regional error."); - } - - private static String format(final String input, final Consumer config) throws Exception { - Properties properties = new Properties(); - config.accept(properties); - EclipseCdtFormatterStepImpl formatter = new EclipseCdtFormatterStepImpl(properties); - return formatter.format(input); - } -} From 96a9017a6a68fdfdb48a7703f06816ca9d162e46 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 12 Mar 2023 23:58:08 -0700 Subject: [PATCH 0606/1120] Remove the cdt lockfiles. --- .../eclipse_cdt_formatter/v4.11.0.lockfile | 21 ------------------ .../eclipse_cdt_formatter/v4.12.0.lockfile | 21 ------------------ .../eclipse_cdt_formatter/v4.13.0.lockfile | 21 ------------------ .../eclipse_cdt_formatter/v4.14.0.lockfile | 22 ------------------- .../eclipse_cdt_formatter/v4.16.0.lockfile | 22 ------------------- .../eclipse_cdt_formatter/v4.17.0.lockfile | 22 ------------------- .../eclipse_cdt_formatter/v4.18.0.lockfile | 22 ------------------- .../eclipse_cdt_formatter/v4.19.0.lockfile | 22 ------------------- .../eclipse_cdt_formatter/v4.20.0.lockfile | 22 ------------------- .../eclipse_cdt_formatter/v4.21.0.lockfile | 22 ------------------- .../eclipse_cdt_formatter/v4.7.3a.lockfile | 21 ------------------ 11 files changed, 238 deletions(-) delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.11.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.12.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.13.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.14.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.16.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.17.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.18.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.19.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.20.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.21.0.lockfile delete mode 100644 lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.7.3a.lockfile diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.11.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.11.0.lockfile deleted file mode 100644 index 7cad5634fe..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.11.0.lockfile +++ /dev/null @@ -1,21 +0,0 @@ -# Spotless formatter based on CDT version 9.7.0 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:9.7.0 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -com.ibm.icu:icu4j:61.1 -org.eclipse.platform:org.eclipse.core.commands:3.9.300 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.300 -org.eclipse.platform:org.eclipse.core.filebuffers:3.6.500 -org.eclipse.platform:org.eclipse.core.filesystem:1.7.300 -org.eclipse.platform:org.eclipse.core.jobs:3.10.300 -org.eclipse.platform:org.eclipse.core.resources:3.13.300 -org.eclipse.platform:org.eclipse.core.runtime:3.15.200 -org.eclipse.platform:org.eclipse.equinox.app:1.4.100 -org.eclipse.platform:org.eclipse.equinox.common:3.10.300 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.300 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.300 -org.eclipse.platform:org.eclipse.jface.text:3.15.100 -org.eclipse.platform:org.eclipse.jface:3.15.100 -org.eclipse.platform:org.eclipse.osgi:3.13.300 -org.eclipse.platform:org.eclipse.text:3.8.100 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.12.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.12.0.lockfile deleted file mode 100644 index 6fd639528a..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.12.0.lockfile +++ /dev/null @@ -1,21 +0,0 @@ -# Spotless formatter based on CDT version 9.8.0 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:9.8.1 -com.diffplug.spotless:spotless-eclipse-base:3.2.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -com.ibm.icu:icu4j:61.2 -org.eclipse.platform:org.eclipse.core.commands:3.9.400 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.300 -org.eclipse.platform:org.eclipse.core.filebuffers:3.6.600 -org.eclipse.platform:org.eclipse.core.filesystem:1.7.400 -org.eclipse.platform:org.eclipse.core.jobs:3.10.400 -org.eclipse.platform:org.eclipse.core.resources:3.13.400 -org.eclipse.platform:org.eclipse.core.runtime:3.15.300 -org.eclipse.platform:org.eclipse.equinox.app:1.4.200 -org.eclipse.platform:org.eclipse.equinox.common:3.10.400 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.400 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.400 -org.eclipse.platform:org.eclipse.jface.text:3.15.200 -org.eclipse.platform:org.eclipse.jface:3.16.0 -org.eclipse.platform:org.eclipse.osgi:3.14.0 -org.eclipse.platform:org.eclipse.text:3.8.200 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.13.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.13.0.lockfile deleted file mode 100644 index 1d169ff087..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.13.0.lockfile +++ /dev/null @@ -1,21 +0,0 @@ -# Spotless formatter based on CDT version 9.9.0 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:9.9.0 -com.diffplug.spotless:spotless-eclipse-base:3.2.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -com.ibm.icu:icu4j:61.2 -org.eclipse.platform:org.eclipse.core.commands:3.9.500 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.400 -org.eclipse.platform:org.eclipse.core.filebuffers:3.6.700 -org.eclipse.platform:org.eclipse.core.filesystem:1.7.500 -org.eclipse.platform:org.eclipse.core.jobs:3.10.500 -org.eclipse.platform:org.eclipse.core.resources:3.13.500 -org.eclipse.platform:org.eclipse.core.runtime:3.16.0 -org.eclipse.platform:org.eclipse.equinox.app:1.4.300 -org.eclipse.platform:org.eclipse.equinox.common:3.10.500 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.500 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.500 -org.eclipse.platform:org.eclipse.jface.text:3.15.300 -org.eclipse.platform:org.eclipse.jface:3.17.0 -org.eclipse.platform:org.eclipse.osgi:3.15.0 -org.eclipse.platform:org.eclipse.text:3.9.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.14.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.14.0.lockfile deleted file mode 100644 index 43cb98774d..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.14.0.lockfile +++ /dev/null @@ -1,22 +0,0 @@ -# Spotless formatter based on CDT version 9.10.0 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:9.10.0 -com.diffplug.spotless:spotless-eclipse-base:3.3.0 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -com.ibm.icu:icu4j:64.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.600 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.500 -org.eclipse.platform:org.eclipse.core.filebuffers:3.6.800 -org.eclipse.platform:org.eclipse.core.filesystem:1.7.600 -org.eclipse.platform:org.eclipse.core.jobs:3.10.600 -org.eclipse.platform:org.eclipse.core.resources:3.13.600 -org.eclipse.platform:org.eclipse.core.runtime:3.17.0 -org.eclipse.platform:org.eclipse.equinox.app:1.4.300 -org.eclipse.platform:org.eclipse.equinox.common:3.10.600 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.600 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.600 -org.eclipse.platform:org.eclipse.jface.text:3.16.100 -org.eclipse.platform:org.eclipse.jface:3.18.0 -org.eclipse.platform:org.eclipse.osgi:3.15.100 -org.eclipse.platform:org.eclipse.text:3.10.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.16.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.16.0.lockfile deleted file mode 100644 index 3bf6b1ca01..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.16.0.lockfile +++ /dev/null @@ -1,22 +0,0 @@ -# Spotless formatter based on CDT version 9.11.1 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:9.11.0 -com.diffplug.spotless:spotless-eclipse-base:3.3.0 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -com.google.j2objc:j2objc-annotations:1.3 -com.ibm.icu:icu4j:64.2 -org.eclipse.platform:org.eclipse.core.commands:3.9.700 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.700 -org.eclipse.platform:org.eclipse.core.filebuffers:3.6.1000 -org.eclipse.platform:org.eclipse.core.filesystem:1.7.700 -org.eclipse.platform:org.eclipse.core.jobs:3.10.800 -org.eclipse.platform:org.eclipse.core.resources:3.13.700 -org.eclipse.platform:org.eclipse.core.runtime:3.18.0 -org.eclipse.platform:org.eclipse.equinox.app:1.4.500 -org.eclipse.platform:org.eclipse.equinox.common:3.12.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.0 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.800 -org.eclipse.platform:org.eclipse.jface.text:3.16.300 -org.eclipse.platform:org.eclipse.jface:3.20.0 -org.eclipse.platform:org.eclipse.osgi:3.15.300 -org.eclipse.platform:org.eclipse.text:3.10.200 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.17.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.17.0.lockfile deleted file mode 100644 index 78a6db147f..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.17.0.lockfile +++ /dev/null @@ -1,22 +0,0 @@ -# Spotless formatter based on CDT version 10.0 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:10.0.0 -com.diffplug.spotless:spotless-eclipse-base:3.4.1 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -com.ibm.icu:icu4j:64.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.700 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.800 -org.eclipse.platform:org.eclipse.core.filebuffers:3.6.1000 -org.eclipse.platform:org.eclipse.core.filesystem:1.7.700 -org.eclipse.platform:org.eclipse.core.jobs:3.10.800 -org.eclipse.platform:org.eclipse.core.resources:3.13.800 -org.eclipse.platform:org.eclipse.core.runtime:3.19.0 -org.eclipse.platform:org.eclipse.equinox.app:1.5.0 -org.eclipse.platform:org.eclipse.equinox.common:3.13.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.0 -org.eclipse.platform:org.eclipse.equinox.registry:3.9.0 -org.eclipse.platform:org.eclipse.jface.text:3.16.400 -org.eclipse.platform:org.eclipse.jface:3.21.0 -org.eclipse.platform:org.eclipse.osgi:3.16.0 -org.eclipse.platform:org.eclipse.text:3.10.300 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.18.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.18.0.lockfile deleted file mode 100644 index 7135a6826d..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.18.0.lockfile +++ /dev/null @@ -1,22 +0,0 @@ -# Spotless formatter based on CDT version 10.1 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:10.1.0 -com.diffplug.spotless:spotless-eclipse-base:3.4.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -com.ibm.icu:icu4j:64.2 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.800 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.800 -org.eclipse.platform:org.eclipse.core.filebuffers:3.6.1100 -org.eclipse.platform:org.eclipse.core.filesystem:1.7.700 -org.eclipse.platform:org.eclipse.core.jobs:3.10.1000 -org.eclipse.platform:org.eclipse.core.resources:3.13.900 -org.eclipse.platform:org.eclipse.core.runtime:3.20.0 -org.eclipse.platform:org.eclipse.equinox.app:1.5.0 -org.eclipse.platform:org.eclipse.equinox.common:3.14.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.10.0 -org.eclipse.platform:org.eclipse.jface.text:3.16.500 -org.eclipse.platform:org.eclipse.jface:3.22.0 -org.eclipse.platform:org.eclipse.osgi:3.16.100 -org.eclipse.platform:org.eclipse.text:3.10.400 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.19.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.19.0.lockfile deleted file mode 100644 index 7c508e64bd..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.19.0.lockfile +++ /dev/null @@ -1,22 +0,0 @@ -# Spotless formatter based on CDT version 10.2 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:10.2.0 -com.diffplug.spotless:spotless-eclipse-base:3.4.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -com.ibm.icu:icu4j:67.1 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.9.800 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.900 -org.eclipse.platform:org.eclipse.core.filebuffers:3.6.1100 -org.eclipse.platform:org.eclipse.core.filesystem:1.7.700 -org.eclipse.platform:org.eclipse.core.jobs:3.10.1100 -org.eclipse.platform:org.eclipse.core.resources:3.14.0 -org.eclipse.platform:org.eclipse.core.runtime:3.20.100 -org.eclipse.platform:org.eclipse.equinox.app:1.5.100 -org.eclipse.platform:org.eclipse.equinox.common:3.14.100 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.200 -org.eclipse.platform:org.eclipse.equinox.registry:3.10.100 -org.eclipse.platform:org.eclipse.jface.text:3.17.0 -org.eclipse.platform:org.eclipse.jface:3.22.100 -org.eclipse.platform:org.eclipse.osgi:3.16.200 -org.eclipse.platform:org.eclipse.text:3.11.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.20.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.20.0.lockfile deleted file mode 100644 index 6cdb507d00..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.20.0.lockfile +++ /dev/null @@ -1,22 +0,0 @@ -# Spotless formatter based on CDT version 10.3 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:10.3.0 -com.diffplug.spotless:spotless-eclipse-base:3.5.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -com.ibm.icu:icu4j:67.1 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.10.0 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.1000 -org.eclipse.platform:org.eclipse.core.filebuffers:3.7.0 -org.eclipse.platform:org.eclipse.core.filesystem:1.9.0 -org.eclipse.platform:org.eclipse.core.jobs:3.11.0 -org.eclipse.platform:org.eclipse.core.resources:3.15.0 -org.eclipse.platform:org.eclipse.core.runtime:3.22.0 -org.eclipse.platform:org.eclipse.equinox.app:1.5.100 -org.eclipse.platform:org.eclipse.equinox.common:3.15.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.8.200 -org.eclipse.platform:org.eclipse.equinox.registry:3.10.200 -org.eclipse.platform:org.eclipse.jface.text:3.18.0 -org.eclipse.platform:org.eclipse.jface:3.22.200 -org.eclipse.platform:org.eclipse.osgi:3.16.300 -org.eclipse.platform:org.eclipse.text:3.12.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.21.0.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.21.0.lockfile deleted file mode 100644 index 4acd5a98ca..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.21.0.lockfile +++ /dev/null @@ -1,22 +0,0 @@ -# Spotless formatter based on CDT version 10.4 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:10.4.0 -com.diffplug.spotless:spotless-eclipse-base:3.5.2 -com.github.spotbugs:spotbugs-annotations:4.0.2 -com.google.code.findbugs:jsr305:3.0.2 -com.ibm.icu:icu4j:67.1 -net.jcip:jcip-annotations:1.0 -org.eclipse.platform:org.eclipse.core.commands:3.10.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.8.0 -org.eclipse.platform:org.eclipse.core.filebuffers:3.7.0 -org.eclipse.platform:org.eclipse.core.filesystem:1.9.100 -org.eclipse.platform:org.eclipse.core.jobs:3.12.0 -org.eclipse.platform:org.eclipse.core.resources:3.15.100 -org.eclipse.platform:org.eclipse.core.runtime:3.23.0 -org.eclipse.platform:org.eclipse.equinox.app:1.6.0 -org.eclipse.platform:org.eclipse.equinox.common:3.15.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.9.0 -org.eclipse.platform:org.eclipse.equinox.registry:3.11.0 -org.eclipse.platform:org.eclipse.jface.text:3.18.100 -org.eclipse.platform:org.eclipse.jface:3.23.0 -org.eclipse.platform:org.eclipse.osgi:3.17.0 -org.eclipse.platform:org.eclipse.text:3.12.0 diff --git a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.7.3a.lockfile b/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.7.3a.lockfile deleted file mode 100644 index 92a0d32cc7..0000000000 --- a/lib-extra/src/main/resources/com/diffplug/spotless/extra/eclipse_cdt_formatter/v4.7.3a.lockfile +++ /dev/null @@ -1,21 +0,0 @@ -# Spotless formatter based on CDT version 9.4.3 (see https://www.eclipse.org/cdt/) -com.diffplug.spotless:spotless-eclipse-cdt:9.4.5 -com.diffplug.spotless:spotless-eclipse-base:3.1.1 -com.google.code.findbugs:annotations:3.0.0 -com.google.code.findbugs:jsr305:3.0.0 -com.ibm.icu:icu4j:61.1 -org.eclipse.platform:org.eclipse.core.commands:3.9.100 -org.eclipse.platform:org.eclipse.core.contenttype:3.7.0 -org.eclipse.platform:org.eclipse.core.filebuffers:3.6.200 -org.eclipse.platform:org.eclipse.core.filesystem:1.7.100 -org.eclipse.platform:org.eclipse.core.jobs:3.10.0 -org.eclipse.platform:org.eclipse.core.resources:3.13.0 -org.eclipse.platform:org.eclipse.core.runtime:3.14.0 -org.eclipse.platform:org.eclipse.equinox.app:1.3.500 -org.eclipse.platform:org.eclipse.equinox.common:3.10.0 -org.eclipse.platform:org.eclipse.equinox.preferences:3.7.100 -org.eclipse.platform:org.eclipse.equinox.registry:3.8.0 -org.eclipse.platform:org.eclipse.jface.text:3.13.0 -org.eclipse.platform:org.eclipse.jface:3.14.0 -org.eclipse.platform:org.eclipse.osgi:3.13.0 -org.eclipse.platform:org.eclipse.text:3.6.300 From 4b0e1fb865d7025b310941ae97416362eb421724 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 00:10:06 -0700 Subject: [PATCH 0607/1120] Update EclipseCdtFormatterStep to Equo. --- lib-extra/build.gradle | 12 +++-- .../glue/cdt/EclipseCdtFormatterStepImpl.java | 53 +++++++++++++++++++ .../extra/cpp/EclipseCdtFormatterStep.java | 46 ++++++++++------ .../cpp/EclipseCdtFormatterStepTest.java | 10 ++-- 4 files changed, 97 insertions(+), 24 deletions(-) create mode 100644 lib-extra/src/cdt/java/com/diffplug/spotless/extra/glue/cdt/EclipseCdtFormatterStepImpl.java diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 9506f9a2ad..73890dcdd1 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -41,7 +41,8 @@ tasks.withType(Test).configureEach { def NEEDS_P2_DEPS = [ 'jdt', - 'groovy' + 'groovy', + 'cdt' ] for (needsP2 in NEEDS_P2_DEPS) { sourceSets.register(needsP2) { @@ -72,13 +73,18 @@ p2deps { install 'org.eclipse.jdt.core' } into 'groovyCompileOnly', { - p2repo 'https://download.eclipse.org/eclipse/updates/4.23/' - p2repo 'https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/4.8.0/e4.23/' + p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' + p2repo 'https://groovy.jfrog.io/artifactory/plugins-release/org/codehaus/groovy/groovy-eclipse-integration/4.8.0/e4.26/' install 'org.codehaus.groovy.eclipse.refactoring' install 'org.codehaus.groovy.eclipse.core' install 'org.eclipse.jdt.groovy.core' install 'org.codehaus.groovy' } + into 'cdtCompileOnly', { + p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' + p2repo 'https://download.eclipse.org/tools/cdt/releases/11.0/' + install 'org.eclipse.cdt.core' + } } // we'll hold the core lib to a high standard diff --git a/lib-extra/src/cdt/java/com/diffplug/spotless/extra/glue/cdt/EclipseCdtFormatterStepImpl.java b/lib-extra/src/cdt/java/com/diffplug/spotless/extra/glue/cdt/EclipseCdtFormatterStepImpl.java new file mode 100644 index 0000000000..045860f535 --- /dev/null +++ b/lib-extra/src/cdt/java/com/diffplug/spotless/extra/glue/cdt/EclipseCdtFormatterStepImpl.java @@ -0,0 +1,53 @@ +/* + * 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. + * 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.extra.glue.cdt; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.eclipse.cdt.core.formatter.CodeFormatter; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.text.edits.TextEdit; + +/** Formatter step which calls out to the Eclipse CDT formatter. */ +public class EclipseCdtFormatterStepImpl { + private final CodeFormatter codeFormatter; + + public EclipseCdtFormatterStepImpl(Properties settings) throws Exception { + Stream> stream = settings.entrySet().stream(); + Map settingsMap = stream.collect(Collectors.toMap( + e -> String.valueOf(e.getKey()), + e -> String.valueOf(e.getValue()))); + codeFormatter = org.eclipse.cdt.core.ToolFactory.createDefaultCodeFormatter(settingsMap); + } + + /** Formatting C/C++ string */ + public String format(String raw) throws Exception { + //The 'kind' can be set to CodeFormatter.K_UNKNOWN, since it is anyway ignored by the internal formatter + TextEdit edit = codeFormatter.format(CodeFormatter.K_UNKNOWN, raw, 0, raw.length(), 0, "\n"); + if (edit == null) { + throw new IllegalArgumentException("Invalid C/C++ syntax for formatting."); + } else { + IDocument doc = new Document(raw); + edit.apply(doc); + return doc.get(); + } + } +} diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java index 4c2b06fc9a..003e438324 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.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. @@ -15,14 +15,15 @@ */ package com.diffplug.spotless.extra.cpp; -import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; import java.util.Properties; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.Jvm; import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder.State; +import com.diffplug.spotless.extra.EquoBasedStepBuilder; + +import dev.equo.solstice.p2.P2Model; /** * Formatter step which calls out to the Eclipse CDT formatter. @@ -36,25 +37,40 @@ public final class EclipseCdtFormatterStep { private EclipseCdtFormatterStep() {} private static final String NAME = "eclipse cdt formatter"; - private static final String FORMATTER_CLASS = "com.diffplug.spotless.extra.eclipse.cdt.EclipseCdtFormatterStepImpl"; - private static final String FORMATTER_METHOD = "format"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "4.16.0").add(11, "4.21.0"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "11.0"); public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); } /** Provides default configuration */ - public static EclipseBasedStepBuilder createBuilder(Provisioner provisioner) { - return new EclipseBasedStepBuilder(NAME, provisioner, EclipseCdtFormatterStep::apply); + public static EquoBasedStepBuilder createBuilder(Provisioner provisioner) { + return new EquoBasedStepBuilder(NAME, provisioner, EclipseCdtFormatterStep::apply) { + @Override + protected P2Model model(String version) { + var model = new P2Model(); + addPlatformRepo(model, "4.26"); + model.addP2Repo("https://download.eclipse.org/tools/cdt/releases/" + version + "/"); + model.getInstall().add("org.eclipse.cdt.core"); + return model; + } + }; } - private static FormatterFunc apply(State state) throws Exception { + private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exception { JVM_SUPPORT.assertFormatterSupported(state.getSemanticVersion()); - Class formatterClazz = state.loadClass(FORMATTER_CLASS); - Object formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences()); - Method method = formatterClazz.getMethod(FORMATTER_METHOD, String.class); - return JVM_SUPPORT.suggestLaterVersionOnError(state.getSemanticVersion(), input -> (String) method.invoke(formatter, input)); + Class formatterClazz = state.getJarState().getClassLoader().loadClass("com.diffplug.spotless.extra.glue.cdt.EclipseCdtFormatterStepImpl"); + var formatter = formatterClazz.getConstructor(Properties.class).newInstance(state.getPreferences()); + var method = formatterClazz.getMethod("format", String.class); + return JVM_SUPPORT.suggestLaterVersionOnError(state.getSemanticVersion(), + input -> { + try { + return (String) method.invoke(formatter, input); + } catch (InvocationTargetException exceptionWrapper) { + Throwable throwable = exceptionWrapper.getTargetException(); + Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null; + throw (null == exception) ? exceptionWrapper : exception; + } + }); } - } diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStepTest.java index f39673cdc8..9ed9f2f227 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStepTest.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. @@ -20,12 +20,10 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import com.diffplug.spotless.Jvm; import com.diffplug.spotless.TestProvisioner; -import com.diffplug.spotless.extra.eclipse.EclipseResourceHarness; +import com.diffplug.spotless.extra.eclipse.EquoResourceHarness; -class EclipseCdtFormatterStepTest extends EclipseResourceHarness { - private final static Jvm.Support JVM_SUPPORT = Jvm. support("Oldest Version").add(8, "4.11.0"); +class EclipseCdtFormatterStepTest extends EquoResourceHarness { private final static String INPUT = "#include ;\nint main(int argc, \nchar *argv[]) {}"; private final static String EXPECTED = "#include ;\nint main(int argc, char *argv[]) {\n}\n"; @@ -40,6 +38,6 @@ void formatWithVersion(String version) throws Exception { } private static Stream formatWithVersion() { - return Stream.of(JVM_SUPPORT.getRecommendedFormatterVersion(), EclipseCdtFormatterStep.defaultVersion()); + return Stream.of("10.6", "10.7", EclipseCdtFormatterStep.defaultVersion()); } } From c534ed9f51611700217b01af1b384ffc71a55362 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 00:10:19 -0700 Subject: [PATCH 0608/1120] Update the plugins for EclipseCdt to Equo. --- .../java/com/diffplug/gradle/spotless/CppExtension.java | 6 +++--- .../java/com/diffplug/spotless/maven/cpp/EclipseCdt.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java index 64dabc9ca5..a08dc07d05 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -22,7 +22,7 @@ import org.gradle.api.Project; import com.diffplug.spotless.cpp.CppDefaults; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.EquoBasedStepBuilder; import com.diffplug.spotless.extra.cpp.EclipseCdtFormatterStep; public class CppExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { @@ -42,7 +42,7 @@ public EclipseConfig eclipseCdt(String version) { } public class EclipseConfig { - private final EclipseBasedStepBuilder builder; + private final EquoBasedStepBuilder builder; EclipseConfig(String version) { builder = EclipseCdtFormatterStep.createBuilder(provisioner()); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java index 78484abfba..a92e7b2423 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -21,7 +21,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.extra.EclipseBasedStepBuilder; +import com.diffplug.spotless.extra.EquoBasedStepBuilder; import com.diffplug.spotless.extra.cpp.EclipseCdtFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -36,7 +36,7 @@ public class EclipseCdt implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - EclipseBasedStepBuilder eclipseConfig = EclipseCdtFormatterStep.createBuilder(stepConfig.getProvisioner()); + EquoBasedStepBuilder eclipseConfig = EclipseCdtFormatterStep.createBuilder(stepConfig.getProvisioner()); eclipseConfig.setVersion(version == null ? EclipseCdtFormatterStep.defaultVersion() : version); if (null != file) { File settingsFile = stepConfig.getFileLocator().locateFile(file); From 9da4348bf152897549efdb7e6efdb10e718e5e01 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 00:15:25 -0700 Subject: [PATCH 0609/1120] Fix spotbugs. --- .../spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index 0beb363b5a..9549847d74 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -103,7 +103,7 @@ public String format(String raw) throws Exception { /** * Eclipse Groovy formatter does not signal problems by its return value, but by logging errors. */ - private static class GroovyErrorListener implements ILogListener, IGroovyLogger { + private static final class GroovyErrorListener implements ILogListener, IGroovyLogger { private final List errors; public GroovyErrorListener() { From b7610d79f64851509a880c5d68a74b5c5178b19c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 00:15:38 -0700 Subject: [PATCH 0610/1120] Add Eclipse CDT to the changelog. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 3295ef5013..8bf28910e2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Adopt [Equo Solstice OSGi and p2 shim](https://github.com/equodev/equo-ide/tree/main/solstice) to update all Eclipse-based plugins. ([#1524](https://github.com/diffplug/spotless/pull/1524)) * Eclipse JDT now supports `4.9` through `4.26`. Also we now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. * Eclipse Groovy now supports `4.18` through `4.26`. Also we now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. + * Eclipse CDT now supports `10.6` through `11.0`. ## [2.36.0] - 2023-02-27 ### Added From f93fccc9d05906adec452f1d521e4936f0db0789 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 00:26:10 -0700 Subject: [PATCH 0611/1120] Correct Eclipse CDT jvm requirements. --- lib-extra/build.gradle | 2 +- .../diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 73890dcdd1..d2d6542a52 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -82,7 +82,7 @@ p2deps { } into 'cdtCompileOnly', { p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' - p2repo 'https://download.eclipse.org/tools/cdt/releases/11.0/' + p2repo 'https://download.eclipse.org/tools/cdt/releases/10.7/' install 'org.eclipse.cdt.core' } } diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java index 003e438324..1a83389eaa 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java @@ -37,7 +37,7 @@ public final class EclipseCdtFormatterStep { private EclipseCdtFormatterStep() {} private static final String NAME = "eclipse cdt formatter"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "11.0"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "10.7").add(17, "11.0"); public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); From 25fc723a6a2585c0fcfe8edf7e95fdfcedb7ea6f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 01:45:48 -0700 Subject: [PATCH 0612/1120] Update readmes. --- plugin-gradle/README.md | 9 ++++----- plugin-maven/README.md | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 267136e4ac..aa312e76ed 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -213,7 +213,7 @@ spotless { java { eclipse() // optional: you can specify a specific version and/or config file - eclipse('4.17').configFile('eclipse-prefs.xml') + eclipse('4.26').configFile('eclipse-prefs.xml') ``` @@ -325,9 +325,8 @@ spotless { groovy { // Use the default version and Groovy-Eclipse default configuration greclipse() - // optional: you can specify a specific version or config file(s) - // compatible versions: https://github.com/diffplug/spotless/tree/main/lib-extra/src/main/resources/com/diffplug/spotless/extra/groovy_eclipse_formatter - greclipse('2.3.0').configFile('spotless.eclipseformat.xml', 'org.codehaus.groovy.eclipse.ui.prefs') + // optional: you can specify a specific version or config file(s), version matches the Eclipse Platform + greclipse('4.26').configFile('spotless.eclipseformat.xml', 'org.codehaus.groovy.eclipse.ui.prefs') ``` Groovy-Eclipse formatting errors/warnings lead per default to a build failure. This behavior can be changed by adding the property/key value `ignoreFormatterProblems=true` to a configuration file. In this scenario, files causing problems, will not be modified by this formatter step. @@ -993,7 +992,7 @@ spotless { format 'xml', { target 'src/**/*.xml' // must specify target eclipseWtp('xml') // must specify a type (table below) - eclipseWtp('xml', '4.13.0') // optional version + eclipseWtp('xml', '11.0') // optional version, others at https://download.eclipse.org/tools/cdt/releases/ // you can also specify an arbitrary number of config files eclipseWtp('xml').configFile('spotless.xml.prefs', 'spotless.common.properties' } diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 4af6308b89..340da9ae9f 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -237,7 +237,7 @@ any other maven phase (i.e. compile) then it can be configured as below; ```xml - 4.21.0 + 4.26 ${project.basedir}/eclipse-formatter.xml ``` @@ -331,7 +331,7 @@ These mechanisms already exist for the Gradle plugin. ```xml - 4.21.0 + 4.26 ${project.basedir}/greclipse.properties ``` @@ -481,7 +481,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```xml - 4.21.0 + 11.0 ${project.basedir}/eclipse-cdt.xml ``` From 3ab4c97e36a056638ad8a4966bd1f1d727aa106f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 01:46:12 -0700 Subject: [PATCH 0613/1120] Update changelog to reflect that WTP is still in-progress. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 478b6cbde0..580a3b0d76 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Eclipse JDT now supports `4.9` through `4.26`. Also we now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. * Eclipse Groovy now supports `4.18` through `4.26`. Also we now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. * Eclipse CDT now supports `10.6` through `11.0`. + * Eclipse WTP is still WIP at [#1622](https://github.com/diffplug/spotless/pull/1622). ## [2.36.0] - 2023-02-27 ### Added From 73d7ed2a2bfe9eebb0f5ea06be13c37e4f9fc925 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 01:52:51 -0700 Subject: [PATCH 0614/1120] Update plugin changelogs. --- plugin-gradle/CHANGES.md | 7 +++++++ plugin-maven/CHANGES.md | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f3e5276d53..76fc2a9de9 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,6 +6,13 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * You can now put the filename into a license header template with `$FILE`. ([#1605](https://github.com/diffplug/spotless/pull/1605) fixes [#1147](https://github.com/diffplug/spotless/issues/1147)) * `licenseHeader` default pattern for Java files is updated to `(package|import|public|class|module) `. ([#1614](https://github.com/diffplug/spotless/pull/1614)) +### Changes +* All Eclipse formatters are now based on [Equo Solstice OSGi and p2 shim](https://github.com/equodev/equo-ide/tree/main/solstice). ([#1524](https://github.com/diffplug/spotless/pull/1524)) + * Eclipse JDT bumped default to `4.26` from `4.21`, oldest supported is `4.9`. + * We now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. + * Eclipse Groovy bumped default to `4.26` from `4.21`, oldest supported is `4.18`. + * Eclipse CDT bumped default to `11.0` from `4.21`, oldest supported is `10.6`. + * Eclipse WTP is still WIP at [#1622](https://github.com/diffplug/spotless/pull/1622). ## [6.16.0] - 2023-02-27 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f65f5e61d4..f324dda349 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -9,6 +9,12 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `licenseHeader` default pattern for Java files is updated to `(package|import|public|class|module) `. ([#1614](https://github.com/diffplug/spotless/pull/1614)) ### Changes * Enable incremental up-to-date checking by default. ([#1621](https://github.com/diffplug/spotless/pull/1621)) +* All Eclipse formatters are now based on [Equo Solstice OSGi and p2 shim](https://github.com/equodev/equo-ide/tree/main/solstice). ([#1524](https://github.com/diffplug/spotless/pull/1524)) + * Eclipse JDT bumped default to `4.26` from `4.21`, oldest supported is `4.9`. + * We now recommend dropping the last `.0`, e.g. `4.26` instead of `4.26.0`, you'll get warnings to help you switch. + * Eclipse Groovy bumped default to `4.26` from `4.21`, oldest supported is `4.18`. + * Eclipse CDT bumped default to `11.0` from `4.21`, oldest supported is `10.6`. + * Eclipse WTP is still WIP at [#1622](https://github.com/diffplug/spotless/pull/1622). ## [2.34.0] - 2023-02-27 ### Added From cd2faeb0f70580a011972b052f174bf50cc9743c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 02:22:44 -0700 Subject: [PATCH 0615/1120] Bump Solstice to 1.0 --- lib-extra/build.gradle | 2 +- .../java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index d2d6542a52..491531f0c7 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -7,7 +7,7 @@ version = rootProject.spotlessChangelog.versionNext apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') -String VER_SOLSTICE = '0.19.2' +String VER_SOLSTICE = '1.0.0' dependencies { api project(':lib') // misc useful utilities diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 2c3d083b1b..5283321cec 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -88,7 +88,7 @@ EquoBasedStepBuilder.State get() throws Exception { var query = model(formatterVersion).query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW); var classpath = new ArrayList(); var mavenDeps = new ArrayList(); - mavenDeps.add("dev.equo.ide:solstice:0.19.2"); + mavenDeps.add("dev.equo.ide:solstice:1.0.0"); mavenDeps.add("com.diffplug.durian:durian-swt.os:4.1.1"); mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); From d807cf7a60b78f4d23de89128239e5e281aef6f1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 02:22:53 -0700 Subject: [PATCH 0616/1120] Bump build plugins to latest. --- build.gradle | 5 +---- settings.gradle | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 6755d486c0..c51f73751c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,4 @@ -plugins { - // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md - id 'dev.equo.ide' version '0.17.1' -} +apply plugin: 'dev.equo.ide' equoIde { branding().title('Spotless').icon(file('_images/spotless_logo.png')) welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') diff --git a/settings.gradle b/settings.gradle index cf200a94f6..683692b6ec 100644 --- a/settings.gradle +++ b/settings.gradle @@ -24,6 +24,8 @@ plugins { id 'io.github.davidburstrom.version-compatibility' version '0.4.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise id 'com.gradle.enterprise' version '3.12.4' + // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md + id 'dev.equo.ide' version '0.17.2' apply false } dependencyResolutionManagement { From a16b3a94c1fe85901267c7bb999115cc8cafcd24 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 13 Mar 2023 02:38:49 -0700 Subject: [PATCH 0617/1120] Try to fix publishing. --- .github/workflows/deploy.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e692fe8735..f139032cf6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -51,18 +51,18 @@ jobs: - name: publish all if: "${{ github.event.inputs.to_publish == 'all' }}" run: | - ./gradlew :changelogPush -Prelease=true --stacktrace --warning-mode all - ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_SECRET }} --stacktrace --warning-mode all - ./gradlew :plugin-maven:changelogPush -Prelease=true --stacktrace --warning-mode all + ./gradlew :changelogPush -Prelease=true --stacktrace --warning-mode all --no-configuration-cache + ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_SECRET }} --stacktrace --warning-mode all --no-configuration-cache + ./gradlew :plugin-maven:changelogPush -Prelease=true --stacktrace --warning-mode all --no-configuration-cache - name: publish just plugin-gradle if: "${{ github.event.inputs.to_publish == 'plugin-gradle' }}" run: | - ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_SECRET }} --stacktrace --warning-mode all + ./gradlew :plugin-gradle:changelogPush -Prelease=true -Pgradle.publish.key=${{ secrets.GRADLE_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_SECRET }} --stacktrace --warning-mode all --no-configuration-cache - name: publish just plugin-maven if: "${{ github.event.inputs.to_publish == 'plugin-maven' }}" run: | - ./gradlew :plugin-maven:changelogPush -Prelease=true --stacktrace --warning-mode all + ./gradlew :plugin-maven:changelogPush -Prelease=true --stacktrace --warning-mode all --no-configuration-cache - name: publish just lib if: "${{ github.event.inputs.to_publish == 'lib' }}" run: | - ./gradlew :changelogPush -Prelease=true --stacktrace --warning-mode all + ./gradlew :changelogPush -Prelease=true --stacktrace --warning-mode all --no-configuration-cache From b7eacad78e4a480b6900a4a65e5ddc0f7b609f1b Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 13 Mar 2023 09:42:07 +0000 Subject: [PATCH 0618/1120] Published lib/2.37.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 580a3b0d76..c0deba72dc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.37.0] - 2023-03-13 ### Added * You can now put the filename into a license header template with `$FILE`. ([#1605](https://github.com/diffplug/spotless/pull/1605) fixes [#1147](https://github.com/diffplug/spotless/issues/1147)) ### Changes From b39508f378f12213e8cca95b38db02c4bf37e17d Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 13 Mar 2023 09:43:41 +0000 Subject: [PATCH 0619/1120] Published gradle/6.17.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 50 ++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 76fc2a9de9..2c85978621 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.17.0] - 2023-03-13 ### Added * You can now put the filename into a license header template with `$FILE`. ([#1605](https://github.com/diffplug/spotless/pull/1605) fixes [#1147](https://github.com/diffplug/spotless/issues/1147)) * `licenseHeader` default pattern for Java files is updated to `(package|import|public|class|module) `. ([#1614](https://github.com/diffplug/spotless/pull/1614)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index aa312e76ed..fffdb38518 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.16.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.17.0-blue.svg)](CHANGES.md) [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -123,10 +123,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -138,7 +138,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -282,8 +282,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -333,8 +333,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -405,7 +405,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -437,7 +437,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -469,7 +469,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -503,7 +503,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -524,7 +524,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -549,7 +549,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -589,7 +589,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -682,7 +682,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -746,7 +746,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -821,7 +821,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -1048,7 +1048,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1121,9 +1121,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1156,11 +1156,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.16.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 124487befbe70f15cd52a2fab5fb4c40d7e0ae1a Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 13 Mar 2023 09:45:25 +0000 Subject: [PATCH 0620/1120] Published maven/2.35.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f324dda349..33e85b9f26 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.35.0] - 2023-03-13 ### Added * You can now put the filename into a license header template with `$FILE`. ([#1605](https://github.com/diffplug/spotless/pull/1605) fixes [#1147](https://github.com/diffplug/spotless/issues/1147)) ### Fixed diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 340da9ae9f..6d13bc87f3 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.34.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.34.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.35.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.35.0/index.html) + 1.8 - true + true com.google.googlejavaformat:google-java-format
From 94eaa5efc87e1a1d34d5b89d9b8db28ed1b45c65 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 17 Mar 2023 09:45:01 +0100 Subject: [PATCH 0632/1120] adapt to actual PR number --- CHANGES.md | 4 ++-- plugin-gradle/CHANGES.md | 4 ++-- plugin-maven/CHANGES.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f25f24ac3a..ec06be1db5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,8 +11,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* **POTENTIALLY BREAKING** Converted `googleJavaFormat` to a compile-only dependency and drop support for versions < `1.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) -* Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) +* **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)) ## [2.37.0] - 2023-03-13 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index eeb68f2cc5..ef7b1b8dae 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,8 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) -* Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) +* **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)) ## [6.17.0] - 2023-03-13 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ac39f49d27..421b5e56e7 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,8 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) -* Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#9999](https://github.com/diffplug/spotless/pull/9999)) +* **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)) ## [2.35.0] - 2023-03-13 ### Added From cb0fd38fa4c8f2446a4832b70c3d9abee37b52ca Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 17 Mar 2023 11:06:17 +0100 Subject: [PATCH 0633/1120] adaptions to min-required gjf version --- .../gradle/spotless/ConfigAvoidanceTest.java | 4 ++-- .../gradle/spotless/ConfigurationCacheTest.java | 8 ++++---- .../gradle/spotless/FilePermissionsTest.java | 4 ++-- .../gradle/spotless/IndependentTaskTest.java | 4 ++-- .../gradle/spotless/JavaDefaultTargetTest.java | 4 ++-- .../gradle/spotless/MultiProjectTest.java | 16 ++++++++-------- .../spotless/RegisterDependenciesTaskTest.java | 6 +++--- .../gradle/spotless/WithinBlockTest.java | 6 +++--- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigAvoidanceTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigAvoidanceTest.java index d5422a3631..bd521bd864 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigAvoidanceTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigAvoidanceTest.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. @@ -31,7 +31,7 @@ void noConfigOnHelp() throws IOException { "apply plugin: 'java'", "spotless {", " java {", - " googleJavaFormat('1.2')", + " googleJavaFormat()", " }", "}", "", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java index 4006752af2..396a884cc5 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ public void helpConfigures() throws IOException { "apply plugin: 'java'", "spotless {", " java {", - " googleJavaFormat('1.2')", + " googleJavaFormat()", " }", "}"); gradleRunner().withArguments("help").build(); @@ -55,7 +55,7 @@ public void helpConfiguresIfTasksAreCreated() throws IOException { "apply plugin: 'java'", "spotless {", " java {", - " googleJavaFormat('1.2')", + " googleJavaFormat()", " }", "}", "tasks.named('spotlessJavaApply').get()"); @@ -72,7 +72,7 @@ public void jvmLocalCache() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.2')", + " googleJavaFormat()", " }", "}"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FilePermissionsTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FilePermissionsTest.java index a5ce2d11cd..d342348a5b 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FilePermissionsTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FilePermissionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ void spotlessApplyShouldPreservePermissions() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.2')", + " googleJavaFormat()", " }", "}"); setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/IndependentTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/IndependentTaskTest.java index 459b871b94..4062aae51d 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/IndependentTaskTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/IndependentTaskTest.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. @@ -32,7 +32,7 @@ void independent() throws IOException { "", "def underTest = new JavaExtension(spotless)", "underTest.target file('test.java')", - "underTest.googleJavaFormat('1.2')", + "underTest.googleJavaFormat()", "", "def independent = underTest.createIndependentApplyTask('independent')"); setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java index 898008c27a..e6569b2647 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JavaDefaultTargetTest.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. @@ -32,7 +32,7 @@ void integration() throws IOException { "", "spotless {", " java {", - " googleJavaFormat('1.2')", + " googleJavaFormat()", " }", "}"); setFile("src/main/java/test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java index 086a2ddb1d..98761b472a 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.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. @@ -47,7 +47,7 @@ void createSubproject(String name) throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.2')", + " googleJavaFormat('1.16.0')", " }", "}"); setFile(name + "/test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); @@ -71,7 +71,7 @@ public void hasRootSpotless() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.2')", + " googleJavaFormat('1.16.0')", " }", "}"); setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); @@ -88,7 +88,7 @@ public void predeclaredFails() throws IOException { "spotless { predeclareDeps() }"); createNSubprojects(); Assertions.assertThat(gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput()) - .contains("Add a step with [com.google.googlejavaformat:google-java-format:1.2] into the `spotlessPredeclare` block in the root project."); + .contains("Add a step with [com.google.googlejavaformat:google-java-format:1.16.0] into the `spotlessPredeclare` block in the root project."); } @Test @@ -100,7 +100,7 @@ public void predeclaredSucceeds() throws IOException { "repositories { mavenCentral() }", "spotless { predeclareDeps() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.2') }", + " java { googleJavaFormat('1.16.0') }", "}"); createNSubprojects(); gradleRunner().withArguments("spotlessApply").build(); @@ -115,7 +115,7 @@ public void predeclaredFromBuildscriptSucceeds() throws IOException { "repositories { mavenCentral() }", "spotless { predeclareDepsFromBuildscript() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.2') }", + " java { googleJavaFormat('1.16.0') }", "}"); createNSubprojects(); gradleRunner().withArguments("spotlessApply").build(); @@ -129,7 +129,7 @@ public void predeclaredOrdering() throws IOException { "}", "repositories { mavenCentral() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.2') }", + " java { googleJavaFormat('1.16.0') }", "}", "spotless { predeclareDepsFromBuildscript() }"); createNSubprojects(); @@ -145,7 +145,7 @@ public void predeclaredUndeclared() throws IOException { "}", "repositories { mavenCentral() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.2') }", + " java { googleJavaFormat('1.16.0') }", "}"); createNSubprojects(); Assertions.assertThat(gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput()) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RegisterDependenciesTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RegisterDependenciesTaskTest.java index 480de4f01b..76d0449060 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RegisterDependenciesTaskTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RegisterDependenciesTaskTest.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. @@ -32,11 +32,11 @@ void duplicateConfigs() throws IOException { "spotless {", " java {", " target 'src/main/java/**/*.java'", - " googleJavaFormat('1.2')", + " googleJavaFormat()", " }", " format 'javaDupe', com.diffplug.gradle.spotless.JavaExtension, {", " target 'src/boop/java/**/*.java'", - " googleJavaFormat('1.2')", + " googleJavaFormat()", " }", "}"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/WithinBlockTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/WithinBlockTest.java index 01fb048b66..d1df8b5f96 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/WithinBlockTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/WithinBlockTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ void genericFormatTest() throws IOException { "spotless {", " format 'customJava', JavaExtension, {", " target '*.java'", - " googleJavaFormat('1.2')", + " googleJavaFormat()", " }", "}"); setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); @@ -53,7 +53,7 @@ void withinBlocksTourDeForce() throws IOException { " custom 'lowercase', { str -> str.toLowerCase() }", " }", " withinBlocks 'java only', '\\n```java\\n', '\\n```\\n', JavaExtension, {", - " googleJavaFormat('1.2')", + " googleJavaFormat()", " }", " }", "}"); From 048947b20ef8ad7111efea8c11b94482b05a4548 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 17 Mar 2023 13:40:45 +0100 Subject: [PATCH 0634/1120] adapt more gjf format specifications --- .../spotless/java/GoogleJavaFormatStep.java | 1 + .../spotless/maven/MavenProvisionerTest.java | 2 +- .../spotless/maven/SpecificFilesTest.java | 4 ++-- .../maven/java/GoogleJavaFormatTest.java | 6 +++--- .../java/GoogleJavaFormatStepTest.java | 20 ++++++++++++++----- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java index 9f41175ab8..d7ba26f384 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java @@ -71,6 +71,7 @@ public static FormatterStep create(String groupArtifact, String version, String static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME) .addMin(11, "1.8") // we only support google-java-format >= 1.8 due to api changes + .addMin(16, "1.10.0") // java 16 requires at least 1.10.0 due to jdk api changes in JavaTokenizer .add(11, "1.16.0"); // default version public static String defaultGroupArtifact() { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java index cabbf7c5c0..5af146c736 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java @@ -33,7 +33,7 @@ void testMultipleDependenciesExcludingTransitives() throws Exception { void testSingleDependencyIncludingTransitives() throws Exception { writePomWithJavaSteps( "", - " 1.2", + " 1.10.0", ""); assertResolveDependenciesWorks(); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java index 55cd586582..11cca5994a 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.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. @@ -58,7 +58,7 @@ private void integration(String patterns, boolean firstFormatted, boolean second " src/**/java/**/*.java", "
", "", - " 1.2", + " 1.10.0", ""); setFile(testFile(1)).toResource(fixture(false)); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java index 98a83d612c..407d089999 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java @@ -24,7 +24,7 @@ class GoogleJavaFormatTest extends MavenIntegrationHarness { void specificVersionDefaultStyle() throws Exception { writePomWithJavaSteps( "", - " 1.2", + " 1.10.0", ""); runTest("java/googlejavaformat/JavaCodeFormatted.test"); @@ -34,7 +34,7 @@ void specificVersionDefaultStyle() throws Exception { void specificVersionSpecificStyle() throws Exception { writePomWithJavaSteps( "", - " 1.2", + " 1.10.0", " ", ""); @@ -45,7 +45,7 @@ void specificVersionSpecificStyle() throws Exception { void specificVersionReflowLongStrings() throws Exception { writePomWithJavaSteps( "", - " 1.8", + " 1.10.0", " true", ""); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java index 2cac245adc..694e390727 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java @@ -17,6 +17,7 @@ import static org.junit.jupiter.api.condition.JRE.JAVA_13; import static org.junit.jupiter.api.condition.JRE.JAVA_15; +import static org.junit.jupiter.api.condition.JRE.JAVA_16; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledForJreRange; @@ -51,7 +52,7 @@ void behavior18() throws Exception { @Test void behavior() throws Exception { - FormatterStep step = GoogleJavaFormatStep.create("1.8", TestProvisioner.mavenCentral()); + FormatterStep step = GoogleJavaFormatStep.create("1.10.0", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormatted.test") .testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormatted.test") @@ -67,9 +68,18 @@ void versionBelowMinimumRequiredVersionIsNotAllowed() throws Exception { .contains("you are using 1.2"); } + @Test + @EnabledForJreRange(min = JAVA_16) + void versionBelowOneDotTenIsNotAllowed() throws Exception { + FormatterStep step = GoogleJavaFormatStep.create("1.9", "AOSP", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResourceExceptionMsg("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test") + .contains("you are using 1.9"); + } + @Test void behaviorWithAospStyle() throws Exception { - FormatterStep step = GoogleJavaFormatStep.create("1.8", "AOSP", TestProvisioner.mavenCentral()); + FormatterStep step = GoogleJavaFormatStep.create("1.10.0", "AOSP", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormattedAOSP.test") .testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormattedAOSP.test") @@ -91,7 +101,7 @@ void behaviorWithReflowLongStrings() throws Exception { @Test void behaviorWithCustomGroupArtifact() throws Exception { - FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), "1.8", GoogleJavaFormatStep.defaultStyle(), TestProvisioner.mavenCentral(), false); + FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), "1.10.0", GoogleJavaFormatStep.defaultStyle(), TestProvisioner.mavenCentral(), false); StepHarness.forStep(step) .testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormatted.test") .testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormatted.test") @@ -102,7 +112,7 @@ void behaviorWithCustomGroupArtifact() throws Exception { @Test void equality() throws Exception { new SerializableEqualityTester() { - String version = "1.8"; + String version = "1.10.0"; String style = ""; boolean reflowLongStrings = false; @@ -111,7 +121,7 @@ protected void setupTest(API api) { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "1.9"; + version = "1.11.0"; api.areDifferentThan(); // change the style, and it's different style = "AOSP"; From b0adcfaadeaf96d11266c36187720dc0f87cea94 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 17 Mar 2023 13:42:52 +0100 Subject: [PATCH 0635/1120] clarify comment --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index e939f7249e..19bc98f710 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -81,7 +81,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm - googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.8' // minimum required version for jdk 11 + googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.8' // minimum required version due to api changes before then testGoogleJavaFormatImplementation "com.diffplug.durian:durian-core:$VER_DURIAN" // used jackson-based formatters From ab982d2480d36a29d32ae0b2ed6063153295ad5e Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Fri, 17 Mar 2023 14:01:17 +0100 Subject: [PATCH 0636/1120] another pinned version to be upgraded --- .../gradle/spotless/GoogleJavaFormatIntegrationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java index 468ba527df..5c7fe54f59 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java @@ -31,7 +31,7 @@ void integration() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.8')", + " googleJavaFormat('1.10.0')", " }", "}"); @@ -41,8 +41,8 @@ void integration() throws IOException { checkRunsThenUpToDate(); replace("build.gradle", - "googleJavaFormat('1.8')", - "googleJavaFormat('1.9')"); + "googleJavaFormat('1.10.0')", + "googleJavaFormat()"); checkRunsThenUpToDate(); } } From abe30b897345fd973f0506e8c77e8849f99c37fa Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sat, 18 Mar 2023 09:36:49 +0100 Subject: [PATCH 0637/1120] remove obsolete fix code PR Feedback: this version is no longer supported anyway --- .../java/GoogleJavaFormatFormatterFunc.java | 5 +- ...rmatRemoveUnusedImporterFormatterFunc.java | 5 +- .../glue/java/GoogleJavaFormatUtils.java | 54 ---------------- .../glue/java/GoogleJavaFormatUtilsTest.java | 63 ------------------- 4 files changed, 2 insertions(+), 125 deletions(-) delete mode 100644 lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatUtils.java delete mode 100644 lib/src/testGoogleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatUtilsTest.java diff --git a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java index a326cf1f69..97d31da268 100644 --- a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java +++ b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.glue.java; -import static com.diffplug.spotless.glue.java.GoogleJavaFormatUtils.fixWindowsBug; - import java.util.Objects; import javax.annotation.Nonnull; @@ -57,8 +55,7 @@ public String apply(@Nonnull String input) throws Exception { String formatted = formatter.formatSource(input); String removedUnused = RemoveUnusedImports.removeUnusedImports(formatted); String sortedImports = ImportOrderer.reorderImports(removedUnused, formatterStyle); - String reflowedLongStrings = reflowLongStrings(sortedImports); - return fixWindowsBug(reflowedLongStrings, version); + return reflowLongStrings(sortedImports); } private String reflowLongStrings(String input) throws FormatterException { diff --git a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatRemoveUnusedImporterFormatterFunc.java b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatRemoveUnusedImporterFormatterFunc.java index 0073ce9dc9..de21a18795 100644 --- a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatRemoveUnusedImporterFormatterFunc.java +++ b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatRemoveUnusedImporterFormatterFunc.java @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.glue.java; -import static com.diffplug.spotless.glue.java.GoogleJavaFormatUtils.fixWindowsBug; - import java.util.Objects; import javax.annotation.Nonnull; @@ -37,7 +35,6 @@ public GoogleJavaFormatRemoveUnusedImporterFormatterFunc(@Nonnull String version @Override @Nonnull public String apply(@Nonnull String input) throws Exception { - String removedUnused = RemoveUnusedImports.removeUnusedImports(input); - return fixWindowsBug(removedUnused, version); + return RemoveUnusedImports.removeUnusedImports(input); } } diff --git a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatUtils.java b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatUtils.java deleted file mode 100644 index 98f47a6097..0000000000 --- a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.java; - -import com.diffplug.spotless.LineEnding; - -public class GoogleJavaFormatUtils { - - private static final boolean IS_WINDOWS = LineEnding.PLATFORM_NATIVE.str().equals("\r\n"); - - /** - * google-java-format-1.1's removeUnusedImports does *wacky* stuff on Windows. - * The beauty of normalizing all line endings to unix! - */ - static String fixWindowsBug(String input, String version) { - if (IS_WINDOWS && version.equals("1.1")) { - int firstImport = input.indexOf("\nimport "); - if (firstImport == 0) { - return input; - } else if (firstImport > 0) { - int numToTrim = 0; - char prevChar; - do { - ++numToTrim; - prevChar = input.charAt(firstImport - numToTrim); - } while (Character.isWhitespace(prevChar) && (firstImport - numToTrim) > 0); - if (firstImport - numToTrim == 0) { - // import was the very first line, and we'd like to maintain a one-line gap - ++numToTrim; - } else if (prevChar == ';' || prevChar == '/') { - // import came after either license or a package declaration - --numToTrim; - } - if (numToTrim > 0) { - return input.substring(0, firstImport - numToTrim + 2) + input.substring(firstImport + 1); - } - } - } - return input; - } -} diff --git a/lib/src/testGoogleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatUtilsTest.java b/lib/src/testGoogleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatUtilsTest.java deleted file mode 100644 index a6403c18a0..0000000000 --- a/lib/src/testGoogleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatUtilsTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.java; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import com.diffplug.common.base.StringPrinter; - -public class GoogleJavaFormatUtilsTest { - - @Test - void fixWindowsBugForGfj1Point1() { - fixWindowsBugTestcase(""); - fixWindowsBugTestcase( - "", - "import somepackage;", - ""); - fixWindowsBugTestcase( - "import somepackage;", - "", - "public class SomeClass {}"); - fixWindowsBugTestcase( - "/** Some license */", - "import somepackage;", - "", - "public class SomeClass {}"); - fixWindowsBugTestcase( - "package thispackage;", - "", - "import somepackage;", - "", - "public class SomeClass {}"); - fixWindowsBugTestcase( - "/*", - " * A License.", - " */", - "", - "package thispackage;", - "", - "import somepackage;", - "", - "public class SomeClass {}"); - } - - private void fixWindowsBugTestcase(String... lines) { - String input = StringPrinter.buildStringFromLines(lines); - Assertions.assertEquals(input, GoogleJavaFormatUtils.fixWindowsBug(input, "1.1")); - } -} From c65a0cfc7f5034b5b1cb2d64f968f7dbf6802fcc Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Sat, 18 Mar 2023 09:39:57 +0100 Subject: [PATCH 0638/1120] revert testGlue as it is no longer needed --- lib/build.gradle | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 19bc98f710..e712df9850 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -21,21 +21,11 @@ def NEEDS_GLUE = [ 'cleanthat' ] for (glue in NEEDS_GLUE) { - // main glue - def mainGlue = sourceSets.register(glue) { + sourceSets.register(glue) { compileClasspath += sourceSets.main.output runtimeClasspath += sourceSets.main.output java {} } - // test glue - sourceSets.register("test${glue.capitalize()}") { - compileClasspath += mainGlue.get().compileClasspath + mainGlue.get().output + sourceSets.test.output - runtimeClasspath += mainGlue.get().compileClasspath + mainGlue.get().output + sourceSets.test.output - java {} - } - configurations.named("test${glue.capitalize()}Implementation").configure { - extendsFrom(configurations.named("testImplementation").get()) - } } versionCompatibility { @@ -82,7 +72,6 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.8' // minimum required version due to api changes before then - testGoogleJavaFormatImplementation "com.diffplug.durian:durian-core:$VER_DURIAN" // used jackson-based formatters jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.2' From 3aea790f1d8ff54854c36ae6e192144ce1626e41 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Mon, 20 Mar 2023 09:38:13 +0100 Subject: [PATCH 0639/1120] formatting cleanup --- .../spotless/glue/java/GoogleJavaFormatFormatterFunc.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java index 97d31da268..f45394979a 100644 --- a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java +++ b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java @@ -35,8 +35,10 @@ public class GoogleJavaFormatFormatterFunc implements FormatterFunc { @Nonnull private final String version; + @Nonnull private final JavaFormatterOptions.Style formatterStyle; + private final boolean reflowStrings; public GoogleJavaFormatFormatterFunc(@Nonnull String version, @Nonnull String style, boolean reflowStrings) { From 316006fda17a341cc15dcf4bf7176dcf091d17a8 Mon Sep 17 00:00:00 2001 From: "Honnen, Julian" Date: Tue, 21 Mar 2023 09:17:22 +0100 Subject: [PATCH 0640/1120] Support configuration of P2 mirrors --- .../spotless/extra/EquoBasedStepBuilder.java | 31 ++++++++++++++++++- plugin-gradle/CHANGES.md | 10 ++++++ .../gradle/spotless/CppExtension.java | 8 +++++ .../gradle/spotless/GroovyExtension.java | 7 +++++ .../gradle/spotless/JavaExtension.java | 7 +++++ 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 5283321cec..ab20d27d88 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -19,6 +19,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Properties; import com.diffplug.spotless.FileSignature; @@ -43,6 +44,7 @@ public abstract class EquoBasedStepBuilder { private final ThrowingEx.Function stateToFormatter; private String formatterVersion; private Iterable settingsFiles = new ArrayList<>(); + private Map p2Mirrors = Map.of(); /** Initialize valid default configuration, taking latest version */ public EquoBasedStepBuilder(String formatterName, Provisioner mavenProvisioner, ThrowingEx.Function stateToFormatter) { @@ -59,6 +61,10 @@ public void setPreferences(Iterable settingsFiles) { this.settingsFiles = settingsFiles; } + public void setP2Mirrors(Map p2Mirrors) { + this.p2Mirrors = Map.copyOf(p2Mirrors); + } + /** Returns the FormatterStep (whose state will be calculated lazily). */ public FormatterStep build() { return FormatterStep.createLazy(formatterName, this::get, stateToFormatter); @@ -85,7 +91,7 @@ protected void addPlatformRepo(P2Model model, String version) { /** Creates the state of the configuration. */ EquoBasedStepBuilder.State get() throws Exception { - var query = model(formatterVersion).query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW); + var query = createModelWithMirrors().query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW); var classpath = new ArrayList(); var mavenDeps = new ArrayList(); mavenDeps.add("dev.equo.ide:solstice:1.0.0"); @@ -100,6 +106,29 @@ EquoBasedStepBuilder.State get() throws Exception { return new State(formatterVersion, jarState, FileSignature.signAsList(settingsFiles)); } + private P2Model createModelWithMirrors() { + P2Model model = model(formatterVersion); + if (p2Mirrors.isEmpty()) { + return model; + } + + ArrayList p2Repos = new ArrayList<>(model.getP2repo()); + p2Repos.replaceAll(url -> { + for (Map.Entry mirror : p2Mirrors.entrySet()) { + String prefix = mirror.getKey(); + if (url.startsWith(prefix)) { + return mirror.getValue() + url.substring(prefix.length()); + } + } + + throw new IllegalStateException("no mirror configured for P2 repository: " + url); + }); + + model.getP2repo().clear(); + model.getP2repo().addAll(p2Repos); + return model; + } + /** * State of Eclipse configuration items, providing functionality to derived information * based on the state. diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 2c85978621..2bd6e4d39e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Support configuration of mirrors for P2 repositories: + ``` + spotless { + java { + eclipse().withP2Mirrors(['https://download.eclipse.org/', 'https://some.internal.mirror/eclipse']) + } + } + ``` + The same configuration exists for `greclipse` and `eclipseCdt`. ## [6.17.0] - 2023-03-13 ### Added diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java index a08dc07d05..6a08946c48 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java @@ -17,6 +17,8 @@ import static com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull; +import java.util.Map; + import javax.inject.Inject; import org.gradle.api.Project; @@ -56,6 +58,12 @@ public void configFile(Object... configFiles) { builder.setPreferences(project.files(configFiles).getFiles()); replaceStep(builder.build()); } + + public EclipseConfig withP2Mirrors(Map mirrors) { + builder.setP2Mirrors(mirrors); + replaceStep(builder.build()); + return this; + } } @Override diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java index 2062946b32..d25433293d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java @@ -17,6 +17,7 @@ import static com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull; +import java.util.Map; import java.util.Objects; import javax.inject.Inject; @@ -99,6 +100,12 @@ public void configFile(Object... configFiles) { builder.setPreferences(project.files(configFiles).getFiles()); extension.replaceStep(builder.build()); } + + public GrEclipseConfig withP2Mirrors(Map mirrors) { + builder.setP2Mirrors(mirrors); + extension.replaceStep(builder.build()); + return this; + } } /** If the user hasn't specified the files yet, we'll assume he/she means all of the groovy files. */ diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index 8dd514ab37..e67bb6d076 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Objects; import javax.inject.Inject; @@ -232,6 +233,12 @@ public void configFile(Object... configFiles) { replaceStep(builder.build()); } + public EclipseConfig withP2Mirrors(Map mirrors) { + builder.setP2Mirrors(mirrors); + replaceStep(builder.build()); + return this; + } + } /** Removes newlines between type annotations and types. */ From 377d497eb0547fd51e6645da1a39ee959e20cfa0 Mon Sep 17 00:00:00 2001 From: "Honnen, Julian" Date: Tue, 21 Mar 2023 09:27:56 +0100 Subject: [PATCH 0641/1120] changelog improvements --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c0deba72dc..756e86ae4c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Support configuration of mirrors for P2 repositories in `EquoBasedStepBuilder` ([#1629](https://github.com/diffplug/spotless/issues/1629)). ## [2.37.0] - 2023-03-13 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 2bd6e4d39e..20668ea85c 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Support configuration of mirrors for P2 repositories: +* Support configuration of mirrors for P2 repositories ([#1629](https://github.com/diffplug/spotless/issues/1629)): ``` spotless { java { @@ -12,6 +12,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`. ## [6.17.0] - 2023-03-13 From 451854f25e5700929c1d3b0ba979cc6225a694cc Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 22 Mar 2023 04:26:37 +0000 Subject: [PATCH 0642/1120] chore(deps): update plugin com.github.spotbugs to v5.0.14 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 51c338b188..715d3ad112 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ plugins { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.0.13' apply false + id 'com.github.spotbugs' version '5.0.14' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md id 'com.diffplug.spotless-changelog' version '3.0.1' apply false // https://github.com/diffplug/goomph/blob/main/CHANGES.md From f94582da771811f6ff9250b7a9e0b6d1e947d3bb Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:00:36 +0000 Subject: [PATCH 0643/1120] chore(deps): update plugin com.gradle.enterprise to v3.12.6 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 51c338b188..17d1154699 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,7 +23,7 @@ plugins { // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.4.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise - id 'com.gradle.enterprise' version '3.12.4' + id 'com.gradle.enterprise' version '3.12.6' // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md id 'dev.equo.ide' version '1.0.1' apply false } From ce3c7daec169c567b6a682ca3e813dff788aed24 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 25 Mar 2023 19:42:40 +0800 Subject: [PATCH 0644/1120] Remove unused Jvm args --- lib/build.gradle | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 9a6e7913d5..9d50dee71c 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -119,19 +119,10 @@ spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even min apply from: rootProject.file('gradle/special-tests.gradle') tasks.withType(Test).configureEach { - def args = [] if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) { // https://docs.gradle.org/7.5/userguide/upgrading_version_7.html#removes_implicit_add_opens_for_test_workers - args += [ - "--add-opens=java.base/java.lang=ALL-UNNAMED", - "--add-opens=java.base/java.util=ALL-UNNAMED", - ] + jvmArgs "--add-opens=java.base/java.lang=ALL-UNNAMED" } - if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_18)) { - // https://openjdk.org/jeps/411 - args += "-Djava.security.manager=allow" - } - jvmArgs(args) } jar { From 0c79d980d5fa64f159791a8a5046bf7f79826f51 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 27 Mar 2023 22:40:51 +0000 Subject: [PATCH 0645/1120] fix(deps): update dependency com.google.googlejavaformat:google-java-format to v1.16.0 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 5480320889..a8eca18a57 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -71,7 +71,7 @@ dependencies { palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm - googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.8' // minimum required version due to api changes before then + googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.16.0' // minimum required version due to api changes before then // used jackson-based formatters jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.2' From b636ebeb01d057d9e1c15195f9c9b6ea8460cbb0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 27 Mar 2023 18:31:18 -0700 Subject: [PATCH 0646/1120] spotlessApply --- .../java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index ab20d27d88..cc12a938ad 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -94,7 +94,7 @@ EquoBasedStepBuilder.State get() throws Exception { var query = createModelWithMirrors().query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW); var classpath = new ArrayList(); var mavenDeps = new ArrayList(); - mavenDeps.add("dev.equo.ide:solstice:1.0.0"); + mavenDeps.add("dev.equo.ide:solstice:1.0.3"); mavenDeps.add("com.diffplug.durian:durian-swt.os:4.1.1"); mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); From 939d45f05687448b92d66f10f18dcfe0d49615ad Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 28 Mar 2023 20:33:58 +0000 Subject: [PATCH 0647/1120] fix(deps): update dependency org.scalameta:scalafmt-core_2.13 to v3.7.3 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 5480320889..3bd48adb11 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -102,7 +102,7 @@ dependencies { compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' - String VER_SCALAFMT="3.7.1" + String VER_SCALAFMT="3.7.3" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" String VER_DIKTAT = "1.2.4.2" From 0f65045a35b41dcac39b6c312b117448db64cb05 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 28 Mar 2023 22:58:00 +0200 Subject: [PATCH 0648/1120] Make sure the order of formatters is deterministic, fixes #1642 --- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 3 ++- .../java/com/diffplug/spotless/maven/FormattersHolder.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) 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 2c0d6e35e6..d68387bb27 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 @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -211,7 +212,7 @@ public final void execute() throws MojoExecutionException { List formatterFactories = getFormatterFactories(); FormatterConfig config = getFormatterConfig(); - Map>> formatterFactoryToFiles = new HashMap<>(); + Map>> formatterFactoryToFiles = new LinkedHashMap<>(); for (FormatterFactory formatterFactory : formatterFactories) { Supplier> filesToFormat = () -> collectFiles(formatterFactory, config); formatterFactoryToFiles.put(formatterFactory, filesToFormat); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormattersHolder.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormattersHolder.java index 1c226423f6..ff3e1c81fe 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormattersHolder.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormattersHolder.java @@ -17,6 +17,7 @@ import java.io.File; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -33,7 +34,7 @@ class FormattersHolder implements AutoCloseable { } static FormattersHolder create(Map>> formatterFactoryToFiles, FormatterConfig config) { - Map>> formatterToFiles = new HashMap<>(); + Map>> formatterToFiles = new LinkedHashMap<>(); try { for (Entry>> entry : formatterFactoryToFiles.entrySet()) { FormatterFactory formatterFactory = entry.getKey(); From a6b9f6ac4cb5c55c18605458c33547e91b34aec4 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 28 Mar 2023 23:08:16 +0200 Subject: [PATCH 0649/1120] Add change --- plugin-maven/CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 421b5e56e7..589a7a3d91 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)) +* Fix non deterministic computation of cache fingerprint when using multiple formatters. ([#1643](https://github.com/diffplug/spotless/pull/1643) fixes [#1642](https://github.com/diffplug/spotless/pull/1642)) ## [2.35.0] - 2023-03-13 ### Added From 39e40957bc26e5ac05b60e8678770590c9af61ee Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sat, 1 Apr 2023 22:23:01 +0400 Subject: [PATCH 0650/1120] 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 1c19210c40..4042d549fd 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 5480320889..4d95cfe84f 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 0000000000..f46f7da32a --- /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 0000000000..ba0d63763f --- /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 1f41835c04..10954f2bb1 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 de2ca7bdd5..62df3eac83 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 6eb5bced6c..fde7c55b8f 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 59ff16805f..f6f4c5a5c3 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 4b1fdc7efe..1be4f1f585 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 421b5e56e7..f865ae4ea1 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 5971721e24..84ca19f58d 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 2c0d6e35e6..b864a28f4c 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 0000000000..614e5026a0 --- /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 0000000000..e74bca929d --- /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 e7998a203a..9c0eb7e303 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 44467df367..9a62d86f80 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 1210bf21dd..2c85d72069 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 0651/1120] 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 3911e67cd9..31860d3bde 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 62df3eac83..1d95606ab9 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 f865ae4ea1..1557fe3966 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 0652/1120] 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 f6f4c5a5c3..ca2fcfbce6 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 1be4f1f585..a89d0ae03a 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 2891ee3b2c..216502bc07 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 0000000000..314c4a58d9 --- /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 0653/1120] 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 a89d0ae03a..915322830b 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 314c4a58d9..f4928da3d6 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 0654/1120] 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 ba0d63763f..6c718e0382 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 eb4d4de89a..5a9553d98d 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 504f8c62eccde68a5a5f5b2847ca01899b1b4562 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 2 Apr 2023 08:26:12 -0700 Subject: [PATCH 0655/1120] Create SECURITY.md --- SECURITY.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000000..56294d0a51 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1 @@ +For security disclosures, please send an email to spotless-security@diffplug.com From 5fd904e534dd8133cd49d989bc06a0c82a07b3dc Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sun, 2 Apr 2023 21:01:58 +0100 Subject: [PATCH 0656/1120] POC: Basic support for rome --- .../com/diffplug/spotless/Architecture.java | 39 ++ .../main/java/com/diffplug/spotless/OS.java | 21 + .../java/com/diffplug/spotless/Platform.java | 87 ++++ .../spotless/javascript/RomeStep.java | 121 ++++++ .../rome/RomeExecutableDownloader.java | 398 ++++++++++++++++++ .../spotless/maven/javascript/Javascript.java | 4 + .../spotless/maven/javascript/RomeJs.java | 61 +++ .../spotless/maven/typescript/Typescript.java | 5 + 8 files changed, 736 insertions(+) create mode 100644 lib/src/main/java/com/diffplug/spotless/Architecture.java create mode 100644 lib/src/main/java/com/diffplug/spotless/OS.java create mode 100644 lib/src/main/java/com/diffplug/spotless/Platform.java create mode 100644 lib/src/main/java/com/diffplug/spotless/javascript/RomeStep.java create mode 100644 lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java diff --git a/lib/src/main/java/com/diffplug/spotless/Architecture.java b/lib/src/main/java/com/diffplug/spotless/Architecture.java new file mode 100644 index 0000000000..211a5cb699 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/Architecture.java @@ -0,0 +1,39 @@ +package com.diffplug.spotless; + +/** + * Enumeration of possible computer architectures. + * + */ +public enum Architecture { + x86, x64, ppc64le, s390x, arm64, armv7l, ppc, ppc64; + + /** + * Attempts to guess the architecture of the environment running the JVM. + * + * @return The best guess for the architecture. + */ + public static Architecture guess() { + var arch = System.getProperty("os.arch"); + var version = System.getProperty("os.version"); + + if (arch.equals("ppc64le")) { + throw new IllegalArgumentException(); + } else if (arch.equals("aarch64")) { + return arm64; + } else if (arch.equals("s390x")) { + return s390x; + } else if (arch.equals("arm")) { + if (version.contains("v7")) { + return armv7l; + } else { + return arm64; + } + } else if (arch.equals("ppc64")) { + return ppc64; + } else if (arch.equals("ppc")) { + return ppc; + } else { + return arch.contains("64") ? x64 : x86; + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/OS.java b/lib/src/main/java/com/diffplug/spotless/OS.java new file mode 100644 index 0000000000..0e05c948de --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/OS.java @@ -0,0 +1,21 @@ +package com.diffplug.spotless; + +/** + * Enumeration of possible computer operation systems. + */ +public enum OS { + Windows, Mac, Linux, SunOS, AIX; + + /** + * Attempts to guess the OS of the environment running the JVM. + * + * @return The best guess for the architecture. + */ + public static OS guess() { + var osName = System.getProperty("os.name"); + return osName.contains("Windows") ? OS.Windows + : osName.contains("Mac") ? OS.Mac + : osName.contains("SunOS") ? OS.SunOS + : osName.toUpperCase().contains("AIX") ? OS.AIX : OS.Linux; + } +} \ No newline at end of file diff --git a/lib/src/main/java/com/diffplug/spotless/Platform.java b/lib/src/main/java/com/diffplug/spotless/Platform.java new file mode 100644 index 0000000000..c57932a7c6 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/Platform.java @@ -0,0 +1,87 @@ +package com.diffplug.spotless; + +/** + * Represents a platform where code is run, consisting of an operating system + * and an architecture. + */ +public class Platform { + /** + * Attempts to guess the platform of the hosting environment running the JVM + * machine. + * + * @return The best guess for the current OS and architecture. + */ + public static Platform guess() { + var os = OS.guess(); + var architecture = Architecture.guess(); + return new Platform(os, architecture); + } + + private final Architecture architecture; + + private final OS os; + + /** + * Creates a new Platform descriptor for the given OS and architecture. + * @param os Operating system of the platform. + * @param architecture Architecture of the platform. + */ + public Platform(OS os, Architecture architecture) { + this.os = os; + this.architecture = architecture; + } + + /** + * @return The architecture of this platform. + */ + public Architecture getArchitecture() { + return architecture; + } + + /** + * @return The operating system of this platform. + */ + public OS getOs() { + return os; + } + + /** + * @return Whether the operating system is Aix. + */ + public boolean isAix() { + return os == OS.AIX; + } + + /** + * @return Whether the operating system is Linux. + */ + public boolean isLinux() { + return os == OS.Linux; + } + + /** + * @return Whether the operating system is Mac. + */ + public boolean isMac() { + return os == OS.Mac; + } + + /** + * @return Whether the operating system is SunOS. + */ + public boolean isSunos() { + return os == OS.SunOS; + } + + /** + * @return Whether the operating system is Windows. + */ + public boolean isWindows() { + return os == OS.Windows; + } + + @Override + public String toString() { + return String.format("Platform[os=%s,architecture=%s]", os, architecture); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/javascript/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/javascript/RomeStep.java new file mode 100644 index 0000000000..4c8a487456 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/javascript/RomeStep.java @@ -0,0 +1,121 @@ +package com.diffplug.spotless.javascript; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.PosixFilePermission; +import java.util.HashSet; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.Platform; +import com.diffplug.spotless.ProcessRunner; +import com.diffplug.spotless.rome.RomeExecutableDownloader; + +/** + * formatter step that formats JavaScript and TypeScript code with Rome: + * https://github.com/rome/tools. + * It delegates to the Rome executable. + */ +public class RomeStep { + public static String name() { + return "rome"; + } + + private final String version; + + private final String pathToExe; + + private final String pathToExeDownloadDir; + + private RomeStep(String version, String pathToExe, String pathToExeDownloadDir) { + this.version = version != null && !version.isBlank() ? version : RomeStep.defaultVersion(); + this.pathToExe = pathToExe; + this.pathToExeDownloadDir = pathToExeDownloadDir; + } + + public FormatterStep create() { + return FormatterStep.createLazy(name(), this::createState, State::toFunc); + } + + private State createState() throws IOException, InterruptedException { + var resolvedPathToExe = resolveExe(); + makeExecutable(resolvedPathToExe); + return new State(this, resolvedPathToExe); + } + + private String resolveExe() throws IOException, InterruptedException { + if (pathToExe != null) { + return pathToExe; + } else { + var downloader = new RomeExecutableDownloader(Paths.get(pathToExeDownloadDir)); + var platform = Platform.guess(); + if (!downloader.isSupported(platform)) { + throw new IllegalStateException( + "Unsupported platform " + platform + ", please specifiy the Rome executable directly"); + } + var downloaded = downloader.ensureDownloaded(version, platform).toString(); + makeExecutable(downloaded); + return downloaded; + } + } + + public static RomeStep withVersionAndExe(String version, String pathToExe) { + return new RomeStep(version, pathToExe, null); + } + + public static RomeStep withVersionAndExeDownload(String version, String pathToExeDownloadDir) { + return new RomeStep(version, null, pathToExeDownloadDir); + } + + private static String defaultVersion() { + return "12.0.0"; + } + + private static void makeExecutable(String exe) { + var exePath = Paths.get(exe); + addPosixPermission(exePath, PosixFilePermission.GROUP_EXECUTE); + addPosixPermission(exePath, PosixFilePermission.OTHERS_EXECUTE); + addPosixPermission(exePath, PosixFilePermission.OWNER_EXECUTE); + } + + private static boolean addPosixPermission(Path file, PosixFilePermission permission) { + try { + var newPermissions = new HashSet<>(Files.getPosixFilePermissions(file)); + newPermissions.add(permission); + Files.setPosixFilePermissions(file, newPermissions); + return true; + } catch (final Exception e) { + return false; + } + } + + static class State implements Serializable { + private static final long serialVersionUID = -1825662356883926318L; + + // used for up-to-date checks and caching + final String version; + + final String pathToExe; + + State(RomeStep step, String exe) { + this.version = step.version; + this.pathToExe = exe; + } + + String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException { + var stdin = input.getBytes(StandardCharsets.UTF_8); + var args = new String[] { pathToExe, "format", "--stdin-file-path", file.getName() }; + return runner.exec(stdin, args).assertExitZero(StandardCharsets.UTF_8); + } + + FormatterFunc.Closeable toFunc() { + var runner = new ProcessRunner(); + return FormatterFunc.Closeable.of(runner, this::format); + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java new file mode 100644 index 0000000000..5df807003d --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java @@ -0,0 +1,398 @@ +package com.diffplug.spotless.rome; + +import java.io.IOException; +import java.math.BigInteger; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpClient.Redirect; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse.BodyHandlers; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.OpenOption; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Objects; +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.Architecture; +import com.diffplug.spotless.OS; +import com.diffplug.spotless.Platform; + +/** + * Downloader for the Rome executable: + * https://github.com/rome/tools. + */ +public class RomeExecutableDownloader { + private static final Logger logger = LoggerFactory.getLogger(RomeExecutableDownloader.class); + + /** + * The checksum algorithm to use for checking the integrity of downloaded files. + */ + private static final String CHECKSUM_ALGORITHM = "MD5"; + + /** + * The pattern for {@link String#format(String, Object...) String.format()} for + * the file name of a Rome executable for a certain version and architecure. The + * first parameter is the platform, the second is the OS, the third is the + * architecture. + */ + private static final String DOWNLOAD_FILE_PATTERN = "rome-%s-%s-%s"; + + /** + * The pattern for {@link String#format(String, Object...) String.format()} for + * the platform part of the Rome executable download URL. First parameter is the + * OS, second parameter the architecture, the third the file extension. + */ + private static final String PLATFORM_PATTERN = "%s-%s%s"; + + /** + * {@link OpenOption Open options} for reading an existing file without write + * access. + */ + private static final OpenOption[] READ_OPTIONS = { StandardOpenOption.READ }; + + /** + * The pattern for {@link String#format(String, Object...) String.format()} for + * the URL where the Rome executables can be downloaded. The first parameter is + * the version, the second parameter is the OS / platform. + */ + private static final String URL_PATTERN = "https://github.com/rome/tools/releases/download/cli%%2Fv%s/rome-%s"; + + /** + * {@link OpenOption Open options} for creating a new file, overwriting the + * existing file if present. + */ + private static final OpenOption[] WRITE_OPTIONS = { StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, + StandardOpenOption.WRITE }; + + private Path downloadDir; + + /** + * Creates a new downloader for the Rome executable. The executable files are + * stored in the given download directory. + * + * @param downloadDir Directory where + */ + public RomeExecutableDownloader(Path downloadDir) { + this.downloadDir = downloadDir; + } + + /** + * Downloads the Rome executable for the current platform from the network to + * the download directory. When the executable exists already, it is + * overwritten. + * + * @param version Desired Rome version. + * @param platform Desired platform. + * @return The path to the Rome executable. + * @throws IOException When the executable cannot be downloaded from + * the network or the file system could not be + * accessed. + * @throws InterruptedException When this thread was interrupted while + * downloading the file. + */ + public Path download(String version, Platform platform) throws IOException, InterruptedException { + var url = getDownloadUrl(version, platform); + var executablePath = getExecutablePath(version, platform); + var checksumPath = getChecksumPath(executablePath); + Files.createDirectories(executablePath.getParent()); + logger.info("Attempting to download Rome from '{}' to '{}'", url, executablePath); + var request = HttpRequest.newBuilder(URI.create(url)).GET().build(); + var handler = BodyHandlers.ofFile(executablePath, WRITE_OPTIONS); + var response = HttpClient.newBuilder().followRedirects(Redirect.NORMAL).build().send(request, handler); + if (response.statusCode() != 200) { + throw new IOException("Failed to download file from " + url + ", server returned " + response.statusCode()); + } + var downloadedFile = response.body(); + if (!Files.exists(downloadedFile) || Files.size(downloadedFile) == 0) { + throw new IOException("Failed to download file from " + url + ", file is empty or does not exist"); + } + writeChecksumFile(downloadedFile, checksumPath); + logger.debug("Rome was downloaded successfully to '{}'", downloadedFile); + return downloadedFile; + } + + /** + * Ensures that the Rome executable for the current platform exists in the + * download directory. When the executable does not exist in the download + * directory, an attempt is made to download the Rome executable from the + * network. When the executable exists already, no attempt to download it again + * is made. + * + * @param version Desired Rome version. + * @return The path to the Rome executable. + * @throws IOException When the executable cannot be downloaded from + * the network or the file system could not be + * accessed. + * @throws InterruptedException When this thread was interrupted while + * downloading the file. + */ + public Path ensureDownloaded(String version, Platform platform) throws IOException, InterruptedException { + logger.debug("Ensuring that Rome for platform '{}' is downloaded", platform); + var existing = findDownloaded(version, platform); + if (existing.isPresent()) { + logger.info("Rome was already downloaded, using executable at '{}'", existing.get()); + return existing.get(); + } else { + logger.debug("Rome was not yet downloaded, attempting to download executable"); + return download(version, platform); + } + } + + /** + * Attempts to find the Rome executable for the current platform in the download + * directory. No attempt is made to download the executable from the network. + * + * @param version Desired Rome version. + * @param platform Desired platform. + * @return The path to the Rome executable. + * @throws IOException When the executable does not exists in the download + * directory, or when the file system could not be accessed. + */ + public Optional findDownloaded(String version, Platform platform) throws IOException { + var executablePath = getExecutablePath(version, platform); + logger.debug("Checking rome executable at {}", executablePath); + return checkFileWithChecksum(executablePath) ? Optional.ofNullable(executablePath) : Optional.empty(); + } + + /** + * @param platform Platform to check. + * @return true if Rome officially supports the given platform, + * false otherwise. + */ + public boolean isSupported(Platform platform) { + var architecture = platform.getArchitecture(); + switch (platform.getOs()) { + case AIX: + return false; + case Linux: + return architecture == Architecture.x64 || architecture == Architecture.arm64; + case Mac: + return architecture == Architecture.x64 || architecture == Architecture.arm64; + case SunOS: + return false; + case Windows: + return architecture == Architecture.x64 || architecture == Architecture.arm64; + default: + return false; + } + } + + /** + * Checks whether the given file exists and matches the checksum. The checksum + * must be contained in a file next to the file to check. + * + * @param filePath File to check. + * @return true if the file exists and matches the checksum, + * false otherwise. + */ + private boolean checkFileWithChecksum(Path filePath) { + if (!Files.exists(filePath)) { + logger.debug("File '{}' does not exist yet", filePath); + return false; + } + if (Files.isDirectory(filePath)) { + logger.debug("File '{}' exists, but is a directory", filePath); + return false; + } + var checksumPath = getChecksumPath(filePath); + if (!Files.exists(checksumPath)) { + logger.debug("File '{}' exists, but checksum file '{}' does not", filePath, checksumPath); + return false; + } + if (Files.isDirectory(checksumPath)) { + logger.debug("Checksum file '{}' exists, but is a directory", checksumPath); + return false; + } + try { + var actualChecksum = computeChecksum(filePath, CHECKSUM_ALGORITHM); + var expectedChecksum = readTextFile(checksumPath, StandardCharsets.ISO_8859_1); + logger.debug("Expected checksum: {}, actual checksum: {}", expectedChecksum, actualChecksum); + return Objects.equals(expectedChecksum, actualChecksum); + } catch (final IOException ignored) { + return false; + } + } + + /** + * Computes the checksum of the given file. + * + * @param file File to process. + * @param algorithm The checksum algorithm to use. + * @return The MD5 checksum of the given file. + * @throws IOException When the file does not exist or could not be read. + */ + private String computeChecksum(Path file, String algorithm) throws IOException { + var buffer = new byte[4192]; + try (var in = Files.newInputStream(file, READ_OPTIONS)) { + var digest = MessageDigest.getInstance(algorithm); + int result; + while ((result = in.read(buffer, 0, buffer.length)) != -1) { + digest.update(buffer, 0, result); + } + var bytes = digest.digest(); + return String.format("%0" + (bytes.length * 2) + "X", new BigInteger(1, bytes)); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } + + /** + * Finds the code name for the given operating system used by the Rome + * executable download URL. + * + * @param os Desired operating system. + * @return Code name for the Rome download URL. + * @throws IOException When the given OS is not supported by Rome. + */ + private String getArchitectureCodeName(Architecture architecture) throws IOException { + switch (architecture) { + case arm64: + return "arm64"; + case armv7l: + throw new IOException("Unsupported architecture: " + architecture); + case ppc: + throw new IOException("Unsupported architecture: " + architecture); + case ppc64: + throw new IOException("Unsupported architecture: " + architecture); + case ppc64le: + throw new IOException("Unsupported architecture: " + architecture); + case s390x: + throw new IOException("Unsupported architecture: " + architecture); + case x64: + return "x64"; + case x86: + throw new IOException("Unsupported architecture: " + architecture); + default: + throw new IOException("Unsupported architecture: " + architecture); + } + } + + /** + * Derives a path for the file which contains the checksum of the given file. + * + * @param file A file for which to derive the checksum file path. + * @return The path with the checksum for the given file. + */ + private Path getChecksumPath(Path file) { + return file.getParent().resolve(file.getFileName().toString() + ".md5"); + } + + /** + * Finds the URL from which the Rome executable can be downloaded. + * + * @param version Desired Rome version. + * @param platform Desired platform. + * @return The URL for the Rome executable. + * @throws IOException When the platform is not supported by Rome. + */ + private String getDownloadUrl(String version, Platform platform) throws IOException { + if (!isSupported(platform)) { + throw new IOException("Unsupported platform: " + platform); + } + var osCodeName = getOsCodeName(platform.getOs()); + var architectureCodeName = getArchitectureCodeName(platform.getArchitecture()); + var extension = getDownloadUrlExtension(platform.getOs()); + var platformString = String.format(PLATFORM_PATTERN, osCodeName, architectureCodeName, extension); + return String.format(URL_PATTERN, version, platformString); + } + + /** + * Finds the file extension of the Rome download URL for the given operating + * system. + * + * @param os Desired operating system. + * @return Extension for the Rome download URL. + * @throws IOException When the given OS is not supported by Rome. + */ + private String getDownloadUrlExtension(OS os) throws IOException { + switch (os) { + case AIX: + throw new IOException("Unsupported OS: " + os); + case Linux: + return ""; + case Mac: + return ""; + case SunOS: + throw new IOException("Unsupported OS: " + os); + case Windows: + return ".exe"; + default: + throw new IOException("Unsupported OS: " + os); + } + } + + /** + * Finds the path on the file system for the Rome executable with a given + * version and platform. + * + * @param version Desired Rome version. + * @param platform Desired platform. + * @return The path for the Rome executable. + */ + private Path getExecutablePath(String version, Platform platform) { + var fileName = String.format(DOWNLOAD_FILE_PATTERN, platform.getOs(), platform.getArchitecture(), version); + return downloadDir.resolve(fileName); + } + + /** + * Finds the code name for the given operating system used by the Rome + * executable download URL. + * + * @param os Desired operating system. + * @return Code name for the Rome download URL. + * @throws IOException When the given OS is not supported by Rome. + */ + private String getOsCodeName(OS os) throws IOException { + switch (os) { + case AIX: + throw new IOException("Unsupported OS: " + os); + case Linux: + return "linux"; + case Mac: + return "darwin"; + case SunOS: + throw new IOException("Unsupported OS: " + os); + case Windows: + return "win32"; + default: + throw new IOException("Unsupported OS: " + os); + } + } + + /** + * Reads a plain text file with the given encoding into a string. + * + * @param file File to read. + * @param charset Encoding to use. + * @return The contents of the file as a string. + * @throws IOException When the file could not be read. + */ + private String readTextFile(Path file, Charset charset) throws IOException { + try (var in = Files.newInputStream(file, READ_OPTIONS)) { + return new String(in.readAllBytes(), charset); + } + } + + /** + * Computes the checksum of the given file and writes it to the target checksum + * file, using the {@code ISO_8859_1} encoding. + * + * @param file + * @param checksumPath + * @throws IOException + */ + private void writeChecksumFile(Path file, Path checksumPath) throws IOException { + var checksum = computeChecksum(file, CHECKSUM_ALGORITHM); + try (var out = Files.newOutputStream(checksumPath, WRITE_OPTIONS)) { + out.write(checksum.getBytes(StandardCharsets.ISO_8859_1)); + } + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java index 31a5917e06..b254110486 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java @@ -41,4 +41,8 @@ public String licenseHeaderDelimiter() { public void addEslint(EslintJs eslint) { addStepFactory(eslint); } + + public void addRome(RomeJs rome) { + addStepFactory(rome); + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java new file mode 100644 index 0000000000..337b05bebf --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java @@ -0,0 +1,61 @@ +package com.diffplug.spotless.maven.javascript; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.javascript.RomeStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +/** + * Factory for creating the Rome formatter step that formats JavaScript and + * TypeScript code with Rome: + * https://github.com/rome/tools. + * It delegates to the Rome executable. + */ +public class RomeJs implements FormatterStepFactory { + /** + * Optional directory where the downloaded Rome executable is placed. This + * defaults to ${project.buildDir}/spotless/rome. You may want to + * change this to a directory outside the build directory to preserve downloaded + * files even when cleaning the project. + */ + @Parameter + private String downloadDir; + + /** + * Optional path to the Rome executable. When not given, an attempt is made to + * download the executable for the given version from the network. + */ + @Parameter + private String pathToExe; + + /** + * Rome version. When not given, a default known version is used. For stable + * builds, it is recommended that you always set the version explicitly. This + * parameter is ignored when you specify a pathToExe explicitly. + */ + @Parameter + private String version; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig config) { + RomeStep rome; + if (pathToExe != null) { + rome = RomeStep.withVersionAndExe(version, pathToExe); + } else { + var downloadDir = resolveDownloadDir(config); + rome = RomeStep.withVersionAndExeDownload(version, downloadDir); + } + return rome.create(); + } + + private String resolveDownloadDir(FormatterStepConfig config) { + // e.g. /home/user/.m2/repository/com/diffplug/spotless/spotless-maven-plugin/2.35.1-SNAPSHOT/spotless-maven-plugin-2.35.1-SNAPSHOT.jar + // var self = config.getProvisioner().provisionWithTransitives(false, "com.diffplug.spotless:spotless-maven-plugin:2.35.1-SNAPSHOT"); + // e.g. /home/user/.m2/repository/com/diffplug/spotless/spotless-maven-plugin + // return self.iterator().next().getParentFile().getParent(); + var buildDir = config.getFileLocator().getBuildDir().toPath(); + return buildDir.resolve("spotless").resolve("rome").toAbsolutePath().toString(); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index 6ba45ab719..929ea334b1 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -21,6 +21,7 @@ import org.apache.maven.project.MavenProject; import com.diffplug.spotless.maven.FormatterFactory; +import com.diffplug.spotless.maven.javascript.RomeJs; /** * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. @@ -45,4 +46,8 @@ public void addTsfmt(Tsfmt tsfmt) { public void addEslint(EslintTs eslint) { addStepFactory(eslint); } + + public void addRome(RomeJs rome) { + addStepFactory(rome); + } } From c4920d92d77266fe5e2f9aa9aace6e4715bce87d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 11:41:09 +0000 Subject: [PATCH 0657/1120] fix(deps): update dependency org.cqfn.diktat:diktat-rules to v1.2.5 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 5480320889..7891235c8d 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -105,7 +105,7 @@ dependencies { String VER_SCALAFMT="3.7.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" - String VER_DIKTAT = "1.2.4.2" + String VER_DIKTAT = "1.2.5" diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" // used for markdown formatting From 58c2737d95fd3c1835b7539e31f25b7e4c32b0a6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 11:46:31 +0000 Subject: [PATCH 0658/1120] fix(deps): update dependency com.vladsch.flexmark:flexmark-all to v0.64.0 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 5480320889..5cfa14d907 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -109,7 +109,7 @@ dependencies { diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" // used for markdown formatting - flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' + flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.64.0' gsonCompileOnly 'com.google.code.gson:gson:2.10.1' From 4cd9cc1dc50a7c39bfeb9b5ebb5c3872afcf4600 Mon Sep 17 00:00:00 2001 From: Chao-Yue Lai Date: Mon, 3 Apr 2023 18:07:32 -0400 Subject: [PATCH 0659/1120] Adding back the "style" option in Palantir Java Format --- .../spotless/java/PalantirJavaFormatStep.java | 26 ++++++++++++++++--- .../pjf/PalantirJavaFormatFormatterFunc.java | 11 +++++--- plugin-gradle/README.md | 4 +-- .../gradle/spotless/JavaExtension.java | 10 ++++++- plugin-maven/README.md | 1 + .../JavaCodeFormattedGoogle.test | 11 ++++++++ .../JavaCodeWithLicenseFormattedGoogle.test | 16 ++++++++++++ .../JavaCodeWithPackageFormattedGoogle.test | 13 ++++++++++ .../java/PalantirJavaFormatStepTest.java | 15 ++++++++++- 9 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 testlib/src/main/resources/java/palantirjavaformat/JavaCodeFormattedGoogle.test create mode 100644 testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithLicenseFormattedGoogle.test create mode 100644 testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithPackageFormattedGoogle.test diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java index 67c55c2e86..f769ad09ec 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -27,6 +27,7 @@ public class PalantirJavaFormatStep { // prevent direct instantiation private PalantirJavaFormatStep() {} + private static final String DEFAULT_STYLE = "PALANTIR"; private static final String NAME = "palantir-java-format"; private static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:"; private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.1.0").add(11, "2.28.0"); @@ -38,11 +39,17 @@ public static FormatterStep create(Provisioner provisioner) { /** Creates a step which formats everything - code, import order, and unused imports. */ public static FormatterStep create(String version, Provisioner provisioner) { + return create(version, defaultStyle(), provisioner); + } + + /** Creates a step which formats everything - code, import order, and unused imports. And with the style input. */ + public static FormatterStep create(String version, String style, Provisioner provisioner) { Objects.requireNonNull(version, "version"); + Objects.requireNonNull(style, "style"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(JarState.from(MAVEN_COORDINATE + version, provisioner), version), + () -> new State(JarState.from(MAVEN_COORDINATE + version, provisioner), version, style), State::createFormat); } @@ -51,6 +58,11 @@ public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); } + /** Get default style */ + public static String defaultStyle() { + return DEFAULT_STYLE; + } + private static final class State implements Serializable { private static final long serialVersionUID = 1L; @@ -58,18 +70,24 @@ private static final class State implements Serializable { private final JarState jarState; /** Version of the formatter jar. */ private final String formatterVersion; + private final String style; State(JarState jarState, String formatterVersion) { + this(jarState, formatterVersion, DEFAULT_STYLE); + } + + State(JarState jarState, String formatterVersion, String style) { ModuleHelper.doOpenInternalPackagesIfRequired(); this.jarState = jarState; this.formatterVersion = formatterVersion; + this.style = style; } FormatterFunc createFormat() throws Exception { final ClassLoader classLoader = jarState.getClassLoader(); final Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.pjf.PalantirJavaFormatFormatterFunc"); - final Constructor constructor = formatterFunc.getConstructor(); - return JVM_SUPPORT.suggestLaterVersionOnError(formatterVersion, (FormatterFunc) constructor.newInstance()); + final Constructor constructor = formatterFunc.getConstructor(String.class); // style + return JVM_SUPPORT.suggestLaterVersionOnError(formatterVersion, (FormatterFunc) constructor.newInstance(style)); } } } diff --git a/lib/src/palantirJavaFormat/java/com/diffplug/spotless/glue/pjf/PalantirJavaFormatFormatterFunc.java b/lib/src/palantirJavaFormat/java/com/diffplug/spotless/glue/pjf/PalantirJavaFormatFormatterFunc.java index 6824cdbc48..189bbb54be 100644 --- a/lib/src/palantirJavaFormat/java/com/diffplug/spotless/glue/pjf/PalantirJavaFormatFormatterFunc.java +++ b/lib/src/palantirJavaFormat/java/com/diffplug/spotless/glue/pjf/PalantirJavaFormatFormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,16 +26,19 @@ public class PalantirJavaFormatFormatterFunc implements FormatterFunc { private final Formatter formatter; - public PalantirJavaFormatFormatterFunc() { + private final JavaFormatterOptions.Style formatterStyle; + + public PalantirJavaFormatFormatterFunc(String style) { + this.formatterStyle = JavaFormatterOptions.Style.valueOf(style); formatter = Formatter.createFormatter(JavaFormatterOptions.builder() - .style(JavaFormatterOptions.Style.PALANTIR) + .style(formatterStyle) .build()); } @Override public String apply(String input) throws Exception { String source = input; - source = ImportOrderer.reorderImports(source, JavaFormatterOptions.Style.PALANTIR); + source = ImportOrderer.reorderImports(source, formatterStyle); source = RemoveUnusedImports.removeUnusedImports(source); return formatter.formatSource(source); } diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 616aacdb1f..95ca3af5ff 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -200,8 +200,8 @@ spotless { spotless { java { palantirJavaFormat() - // optional: you can specify a specific version - palantirJavaFormat('2.9.0') + // optional: you can specify a specific version and/or switch to AOSP/GOOGLE style + palantirJavaFormat('2.9.0').style("GOOGLE") ``` ### eclipse jdt diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index e67bb6d076..d85cb8de5e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -198,14 +198,22 @@ public PalantirJavaFormatConfig palantirJavaFormat(String version) { public class PalantirJavaFormatConfig { final String version; + String style; PalantirJavaFormatConfig(String version) { this.version = Objects.requireNonNull(version); + this.style = PalantirJavaFormatStep.defaultStyle(); addStep(createStep()); } + public PalantirJavaFormatConfig style(String style) { + this.style = Objects.requireNonNull(style); + replaceStep(createStep()); + return this; + } + private FormatterStep createStep() { - return PalantirJavaFormatStep.create(version, provisioner()); + return PalantirJavaFormatStep.create(version, style, provisioner()); } } diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 5971721e24..12ade2ccf5 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -228,6 +228,7 @@ any other maven phase (i.e. compile) then it can be configured as below; ```xml 2.10.0 + ``` diff --git a/testlib/src/main/resources/java/palantirjavaformat/JavaCodeFormattedGoogle.test b/testlib/src/main/resources/java/palantirjavaformat/JavaCodeFormattedGoogle.test new file mode 100644 index 0000000000..7a83a0a12c --- /dev/null +++ b/testlib/src/main/resources/java/palantirjavaformat/JavaCodeFormattedGoogle.test @@ -0,0 +1,11 @@ +import mylib.UsedA; +import mylib.UsedB; + +public class Java { + public static void main(String[] args) { + System.out.println( + "A very very very very very very very very very very very very very very very very very very very very very long string that goes beyond the 100-character line length."); + UsedB.someMethod(); + UsedA.someMethod(); + } +} diff --git a/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithLicenseFormattedGoogle.test b/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithLicenseFormattedGoogle.test new file mode 100644 index 0000000000..9ee9bcbad6 --- /dev/null +++ b/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithLicenseFormattedGoogle.test @@ -0,0 +1,16 @@ +/* + * Some license stuff. + * Very official. + */ + +import mylib.UsedA; +import mylib.UsedB; + +public class Java { + public static void main(String[] args) { + System.out.println( + "A very very very very very very very very very very very very very very very very very very very very very long string that goes beyond the 100-character line length."); + UsedB.someMethod(); + UsedA.someMethod(); + } +} diff --git a/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithPackageFormattedGoogle.test b/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithPackageFormattedGoogle.test new file mode 100644 index 0000000000..4992ade147 --- /dev/null +++ b/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithPackageFormattedGoogle.test @@ -0,0 +1,13 @@ +package hello.world; + +import mylib.UsedA; +import mylib.UsedB; + +public class Java { + public static void main(String[] args) { + System.out.println( + "A very very very very very very very very very very very very very very very very very very very very very long string that goes beyond the 100-character line length."); + UsedB.someMethod(); + UsedA.someMethod(); + } +} diff --git a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java index dfd59c2655..81d03b6c32 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java @@ -54,10 +54,20 @@ void behavior() throws Exception { .testResource("java/palantirjavaformat/JavaCodeWithPackageUnformatted.test", "java/palantirjavaformat/JavaCodeWithPackageFormatted.test"); } + @Test + void behaviorWithGoogleStyle() throws Exception { + FormatterStep step = PalantirJavaFormatStep.create("1.1.0", "GOOGLE", TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("java/palantirjavaformat/JavaCodeUnformatted.test", "java/palantirjavaformat/JavaCodeFormattedGoogle.test") + .testResource("java/palantirjavaformat/JavaCodeWithLicenseUnformatted.test", "java/palantirjavaformat/JavaCodeWithLicenseFormattedGoogle.test") + .testResource("java/palantirjavaformat/JavaCodeWithPackageUnformatted.test", "java/palantirjavaformat/JavaCodeWithPackageFormattedGoogle.test"); + } + @Test void equality() { new SerializableEqualityTester() { String version = "1.1.0"; + String style = ""; @Override protected void setupTest(API api) { @@ -66,12 +76,15 @@ protected void setupTest(API api) { // change the version, and it's different version = "1.0.0"; api.areDifferentThan(); + // change the style, and it's different + style = "AOSP"; + api.areDifferentThan(); } @Override protected FormatterStep create() { String finalVersion = this.version; - return PalantirJavaFormatStep.create(finalVersion, TestProvisioner.mavenCentral()); + return PalantirJavaFormatStep.create(finalVersion, style, TestProvisioner.mavenCentral()); } }.testEquals(); } From e12973a37a648a9e84806dfd94ccbe30073b1d5f Mon Sep 17 00:00:00 2001 From: Chao-Yue Lai Date: Mon, 3 Apr 2023 18:45:28 -0400 Subject: [PATCH 0660/1120] Adding the commit in CHANGES.md's --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 2 ++ 3 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 77c49efe2a..89c99b7841 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)). +* The `style` option in Palantir Java Format ([#1654](https://github.com/diffplug/spotless/pull/1654)). ### 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 0a0cabcca0..15ee39e1f8 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`. +* The `style` option in Palantir Java Format ([#1654](https://github.com/diffplug/spotless/pull/1654)). ### 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 421b5e56e7..72d235a38a 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* The `style` option in Palantir Java Format ([#1654](https://github.com/diffplug/spotless/pull/1654)). ### 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)) From cb9433fe36025accd94a16f5fda1c94326e6c841 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 11 Mar 2023 19:01:09 +0800 Subject: [PATCH 0661/1120] Prefer using plugin extensions over deprecated conventions https://docs.gradle.org/current/userguide/upgrading_version_7.html#all_convention_deprecation --- .../gradle/spotless/GroovyExtension.java | 52 ++++++++++++++----- .../gradle/spotless/JavaExtension.java | 30 ++++++++--- .../gradle/spotless/KotlinExtension.java | 39 ++++++++++---- .../gradle/spotless/ScalaExtension.java | 41 ++++++++++----- 4 files changed, 117 insertions(+), 45 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java index d25433293d..8d20cd3036 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java @@ -28,8 +28,11 @@ import org.gradle.api.internal.plugins.DslObject; import org.gradle.api.plugins.GroovyBasePlugin; import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; +import org.gradle.api.tasks.GroovySourceDirectorySet; import org.gradle.api.tasks.GroovySourceSet; import org.gradle.api.tasks.SourceSet; +import org.gradle.util.GradleVersion; import com.diffplug.spotless.extra.EquoBasedStepBuilder; import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; @@ -112,22 +115,43 @@ public GrEclipseConfig withP2Mirrors(Map mirrors) { @Override protected void setupTask(SpotlessTask task) { if (target == null) { - JavaPluginConvention convention = getProject().getConvention().getPlugin(JavaPluginConvention.class); - if (convention == null || !getProject().getPlugins().hasPlugin(GroovyBasePlugin.class)) { - throw new GradleException("You must apply the groovy plugin before the spotless plugin if you are using the groovy extension."); - } - //Add all Groovy files (may contain Java files as well) - - FileCollection union = getProject().files(); - for (SourceSet sourceSet : convention.getSourceSets()) { - GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class); - if (excludeJava) { - union = union.plus(groovySourceSet.getAllGroovy()); - } else { - union = union.plus(groovySourceSet.getGroovy()); + if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { + JavaPluginExtension javaPluginExtension = getProject().getExtensions().findByType(JavaPluginExtension.class); + if (javaPluginExtension == null || !getProject().getPlugins().hasPlugin(GroovyBasePlugin.class)) { + throw new GradleException("You must apply the groovy plugin before the spotless plugin if you are using the groovy extension."); + } + //Add all Groovy files (may contain Java files as well) + + FileCollection union = getProject().files(); + for (SourceSet sourceSet : javaPluginExtension.getSourceSets()) { + union = union.plus(sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class).filter(file -> { + String name = file.getName(); + if (excludeJava) { + return name.endsWith(".groovy"); + } else { + return name.endsWith(".groovy") || name.endsWith(".java"); + } + })); + } + target = union; + } else { + JavaPluginConvention convention = getProject().getConvention().getPlugin(JavaPluginConvention.class); + if (convention == null || !getProject().getPlugins().hasPlugin(GroovyBasePlugin.class)) { + throw new GradleException("You must apply the groovy plugin before the spotless plugin if you are using the groovy extension."); + } + //Add all Groovy files (may contain Java files as well) + + FileCollection union = getProject().files(); + for (SourceSet sourceSet : convention.getSourceSets()) { + GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class); + if (excludeJava) { + union = union.plus(groovySourceSet.getAllGroovy()); + } else { + union = union.plus(groovySourceSet.getGroovy()); + } } + target = union; } - target = union; } else if (excludeJava) { throw new IllegalArgumentException("'excludeJava' is not supported in combination with a custom 'target'."); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index e67bb6d076..f511e9cebd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -30,7 +30,9 @@ import org.gradle.api.Project; import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSet; +import org.gradle.util.GradleVersion; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; @@ -366,15 +368,27 @@ private FormatterStep createStep() { @Override protected void setupTask(SpotlessTask task) { if (target == null) { - JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); - if (javaPlugin == null) { - throw new GradleException("You must either specify 'target' manually or apply the 'java' plugin."); - } - FileCollection union = getProject().files(); - for (SourceSet sourceSet : javaPlugin.getSourceSets()) { - union = union.plus(sourceSet.getAllJava()); + if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { + JavaPluginExtension javaPluginExtension = getProject().getExtensions().findByType(JavaPluginExtension.class); + if (javaPluginExtension == null) { + throw new GradleException("You must either specify 'target' manually or apply the 'java' plugin."); + } + FileCollection union = getProject().files(); + for (SourceSet sourceSet : javaPluginExtension.getSourceSets()) { + union = union.plus(sourceSet.getAllJava()); + } + target = union; + } else { + JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); + if (javaPlugin == null) { + throw new GradleException("You must either specify 'target' manually or apply the 'java' plugin."); + } + FileCollection union = getProject().files(); + for (SourceSet sourceSet : javaPlugin.getSourceSets()) { + union = union.plus(sourceSet.getAllJava()); + } + target = union; } - target = union; } steps.replaceAll(step -> { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 5a7419f68d..f6cab3c28b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -30,7 +30,9 @@ import org.gradle.api.GradleException; import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSet; +import org.gradle.util.GradleVersion; import com.diffplug.common.collect.ImmutableSortedMap; import com.diffplug.spotless.FileSignature; @@ -230,18 +232,33 @@ private FormatterStep createStep() { @Override protected void setupTask(SpotlessTask task) { if (target == null) { - JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); - if (javaPlugin == null) { - throw new GradleException("You must either specify 'target' manually or apply a kotlin plugin."); - } - FileCollection union = getProject().files(); - for (SourceSet sourceSet : javaPlugin.getSourceSets()) { - union = union.plus(sourceSet.getAllSource().filter(file -> { - String name = file.getName(); - return name.endsWith(".kt") || name.endsWith(".kts"); - })); + if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { + JavaPluginExtension javaPluginExtension = getProject().getExtensions().findByType(JavaPluginExtension.class); + if (javaPluginExtension == null) { + throw new GradleException("You must either specify 'target' manually or apply a kotlin plugin."); + } + FileCollection union = getProject().files(); + for (SourceSet sourceSet : javaPluginExtension.getSourceSets()) { + union = union.plus(sourceSet.getAllSource().filter(file -> { + String name = file.getName(); + return name.endsWith(".kt") || name.endsWith(".kts"); + })); + } + target = union; + } else { + JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); + if (javaPlugin == null) { + throw new GradleException("You must either specify 'target' manually or apply a kotlin plugin."); + } + FileCollection union = getProject().files(); + for (SourceSet sourceSet : javaPlugin.getSourceSets()) { + union = union.plus(sourceSet.getAllSource().filter(file -> { + String name = file.getName(); + return name.endsWith(".kt") || name.endsWith(".kts"); + })); + } + target = union; } - target = union; } super.setupTask(task); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java index 8a8765b539..9d710a1ba9 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -24,7 +24,9 @@ import org.gradle.api.GradleException; import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSet; +import org.gradle.util.GradleVersion; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.scala.ScalaFmtStep; @@ -79,18 +81,33 @@ private FormatterStep createStep() { @Override protected void setupTask(SpotlessTask task) { if (target == null) { - JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); - if (javaPlugin == null) { - throw new GradleException("You must either specify 'target' manually or apply the 'scala' plugin."); + if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { + JavaPluginExtension javaPluginExtension = getProject().getExtensions().findByType(JavaPluginExtension.class); + if (javaPluginExtension == null) { + throw new GradleException("You must either specify 'target' manually or apply the 'scala' plugin."); + } + FileCollection union = getProject().files(); + for (SourceSet sourceSet : javaPluginExtension.getSourceSets()) { + union = union.plus(sourceSet.getAllSource().filter(file -> { + String name = file.getName(); + return name.endsWith(".scala") || name.endsWith(".sc"); + })); + } + target = union; + } else { + JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); + if (javaPlugin == null) { + throw new GradleException("You must either specify 'target' manually or apply the 'scala' plugin."); + } + FileCollection union = getProject().files(); + for (SourceSet sourceSet : javaPlugin.getSourceSets()) { + union = union.plus(sourceSet.getAllSource().filter(file -> { + String name = file.getName(); + return name.endsWith(".scala") || name.endsWith(".sc"); + })); + } + target = union; } - FileCollection union = getProject().files(); - for (SourceSet sourceSet : javaPlugin.getSourceSets()) { - union = union.plus(sourceSet.getAllSource().filter(file -> { - String name = file.getName(); - return name.endsWith(".scala") || name.endsWith(".sc"); - })); - } - target = union; } super.setupTask(task); } From 4410531a75e26788114b627d804d263afc791de7 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 11 Mar 2023 10:29:23 +0800 Subject: [PATCH 0662/1120] Reuse getSources logic for Jvm languages --- .../gradle/spotless/GroovyExtension.java | 55 ++++++------------- .../gradle/spotless/JavaExtension.java | 32 ++--------- .../com/diffplug/gradle/spotless/JvmLang.java | 55 +++++++++++++++++++ .../gradle/spotless/KotlinExtension.java | 39 +++---------- .../gradle/spotless/ScalaExtension.java | 39 +++---------- 5 files changed, 92 insertions(+), 128 deletions(-) create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java index 8d20cd3036..17a57f6301 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java @@ -24,14 +24,10 @@ import org.gradle.api.GradleException; import org.gradle.api.Project; -import org.gradle.api.file.FileCollection; import org.gradle.api.internal.plugins.DslObject; import org.gradle.api.plugins.GroovyBasePlugin; -import org.gradle.api.plugins.JavaPluginConvention; -import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.GroovySourceDirectorySet; import org.gradle.api.tasks.GroovySourceSet; -import org.gradle.api.tasks.SourceSet; import org.gradle.util.GradleVersion; import com.diffplug.spotless.extra.EquoBasedStepBuilder; @@ -39,7 +35,7 @@ import com.diffplug.spotless.generic.LicenseHeaderStep; import com.diffplug.spotless.java.ImportOrderStep; -public class GroovyExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { +public class GroovyExtension extends FormatExtension implements HasBuiltinDelimiterForLicense, JvmLang { static final String NAME = "groovy"; @Inject @@ -115,43 +111,28 @@ public GrEclipseConfig withP2Mirrors(Map mirrors) { @Override protected void setupTask(SpotlessTask task) { if (target == null) { - if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { - JavaPluginExtension javaPluginExtension = getProject().getExtensions().findByType(JavaPluginExtension.class); - if (javaPluginExtension == null || !getProject().getPlugins().hasPlugin(GroovyBasePlugin.class)) { - throw new GradleException("You must apply the groovy plugin before the spotless plugin if you are using the groovy extension."); - } - //Add all Groovy files (may contain Java files as well) - - FileCollection union = getProject().files(); - for (SourceSet sourceSet : javaPluginExtension.getSourceSets()) { - union = union.plus(sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class).filter(file -> { - String name = file.getName(); + final String message = "You must apply the groovy plugin before the spotless plugin if you are using the groovy extension."; + if (!getProject().getPlugins().hasPlugin(GroovyBasePlugin.class)) { + throw new GradleException(message); + } + target = getSources(getProject(), + message, + sourceSet -> { + if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { + return sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class); + } else { + final GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class); + return groovySourceSet.getGroovy(); + } + }, + file -> { + final String name = file.getName(); if (excludeJava) { return name.endsWith(".groovy"); } else { return name.endsWith(".groovy") || name.endsWith(".java"); } - })); - } - target = union; - } else { - JavaPluginConvention convention = getProject().getConvention().getPlugin(JavaPluginConvention.class); - if (convention == null || !getProject().getPlugins().hasPlugin(GroovyBasePlugin.class)) { - throw new GradleException("You must apply the groovy plugin before the spotless plugin if you are using the groovy extension."); - } - //Add all Groovy files (may contain Java files as well) - - FileCollection union = getProject().files(); - for (SourceSet sourceSet : convention.getSourceSets()) { - GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class); - if (excludeJava) { - union = union.plus(groovySourceSet.getAllGroovy()); - } else { - union = union.plus(groovySourceSet.getGroovy()); - } - } - target = union; - } + }); } else if (excludeJava) { throw new IllegalArgumentException("'excludeJava' is not supported in combination with a custom 'target'."); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index f511e9cebd..8634e9b6b3 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -26,13 +26,8 @@ import javax.inject.Inject; -import org.gradle.api.GradleException; import org.gradle.api.Project; -import org.gradle.api.file.FileCollection; -import org.gradle.api.plugins.JavaPluginConvention; -import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSet; -import org.gradle.util.GradleVersion; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; @@ -45,7 +40,7 @@ import com.diffplug.spotless.java.PalantirJavaFormatStep; import com.diffplug.spotless.java.RemoveUnusedImportsStep; -public class JavaExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { +public class JavaExtension extends FormatExtension implements HasBuiltinDelimiterForLicense, JvmLang { static final String NAME = "java"; @Inject @@ -368,27 +363,10 @@ private FormatterStep createStep() { @Override protected void setupTask(SpotlessTask task) { if (target == null) { - if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { - JavaPluginExtension javaPluginExtension = getProject().getExtensions().findByType(JavaPluginExtension.class); - if (javaPluginExtension == null) { - throw new GradleException("You must either specify 'target' manually or apply the 'java' plugin."); - } - FileCollection union = getProject().files(); - for (SourceSet sourceSet : javaPluginExtension.getSourceSets()) { - union = union.plus(sourceSet.getAllJava()); - } - target = union; - } else { - JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); - if (javaPlugin == null) { - throw new GradleException("You must either specify 'target' manually or apply the 'java' plugin."); - } - FileCollection union = getProject().files(); - for (SourceSet sourceSet : javaPlugin.getSourceSets()) { - union = union.plus(sourceSet.getAllJava()); - } - target = union; - } + target = getSources(getProject(), + "You must either specify 'target' manually or apply the 'java' plugin.", + SourceSet::getAllJava, + file -> file.getName().endsWith(".java")); } steps.replaceAll(step -> { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java new file mode 100644 index 0000000000..6e30674c6c --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java @@ -0,0 +1,55 @@ +/* + * 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.gradle.spotless; + +import java.io.File; +import java.util.function.Function; + +import org.gradle.api.GradleException; +import org.gradle.api.Project; +import org.gradle.api.file.FileCollection; +import org.gradle.api.file.SourceDirectorySet; +import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.plugins.JavaPluginExtension; +import org.gradle.api.specs.Spec; +import org.gradle.api.tasks.SourceSet; +import org.gradle.api.tasks.SourceSetContainer; +import org.gradle.util.GradleVersion; + +interface JvmLang { + + default FileCollection getSources(Project project, String message, Function sourceSetSourceDirectory, Spec filterSpec) { + final SourceSetContainer sourceSets; + FileCollection union = project.files(); + if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { + final JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class); + if (javaPluginExtension == null) { + throw new GradleException(message); + } + sourceSets = javaPluginExtension.getSourceSets(); + } else { + final JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class); + if (javaPluginConvention == null) { + throw new GradleException(message); + } + sourceSets = javaPluginConvention.getSourceSets(); + } + for (SourceSet sourceSet : sourceSets) { + union = union.plus(sourceSetSourceDirectory.apply(sourceSet).filter(filterSpec)); + } + return union; + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index f6cab3c28b..363a9cac6f 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -27,12 +27,7 @@ import javax.annotation.Nullable; import javax.inject.Inject; -import org.gradle.api.GradleException; -import org.gradle.api.file.FileCollection; -import org.gradle.api.plugins.JavaPluginConvention; -import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSet; -import org.gradle.util.GradleVersion; import com.diffplug.common.collect.ImmutableSortedMap; import com.diffplug.spotless.FileSignature; @@ -43,7 +38,7 @@ import com.diffplug.spotless.kotlin.KtfmtStep.KtfmtFormattingOptions; import com.diffplug.spotless.kotlin.KtfmtStep.Style; -public class KotlinExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { +public class KotlinExtension extends FormatExtension implements HasBuiltinDelimiterForLicense, JvmLang { static final String NAME = "kotlin"; @Inject @@ -232,33 +227,13 @@ private FormatterStep createStep() { @Override protected void setupTask(SpotlessTask task) { if (target == null) { - if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { - JavaPluginExtension javaPluginExtension = getProject().getExtensions().findByType(JavaPluginExtension.class); - if (javaPluginExtension == null) { - throw new GradleException("You must either specify 'target' manually or apply a kotlin plugin."); - } - FileCollection union = getProject().files(); - for (SourceSet sourceSet : javaPluginExtension.getSourceSets()) { - union = union.plus(sourceSet.getAllSource().filter(file -> { - String name = file.getName(); + target = getSources(getProject(), + "You must either specify 'target' manually or apply a kotlin plugin.", + SourceSet::getAllSource, + file -> { + final String name = file.getName(); return name.endsWith(".kt") || name.endsWith(".kts"); - })); - } - target = union; - } else { - JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); - if (javaPlugin == null) { - throw new GradleException("You must either specify 'target' manually or apply a kotlin plugin."); - } - FileCollection union = getProject().files(); - for (SourceSet sourceSet : javaPlugin.getSourceSets()) { - union = union.plus(sourceSet.getAllSource().filter(file -> { - String name = file.getName(); - return name.endsWith(".kt") || name.endsWith(".kts"); - })); - } - target = union; - } + }); } super.setupTask(task); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java index 9d710a1ba9..1639f3473c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java @@ -21,17 +21,12 @@ import javax.annotation.Nullable; import javax.inject.Inject; -import org.gradle.api.GradleException; -import org.gradle.api.file.FileCollection; -import org.gradle.api.plugins.JavaPluginConvention; -import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.SourceSet; -import org.gradle.util.GradleVersion; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.scala.ScalaFmtStep; -public class ScalaExtension extends FormatExtension { +public class ScalaExtension extends FormatExtension implements JvmLang { static final String NAME = "scala"; @Inject @@ -81,33 +76,13 @@ private FormatterStep createStep() { @Override protected void setupTask(SpotlessTask task) { if (target == null) { - if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { - JavaPluginExtension javaPluginExtension = getProject().getExtensions().findByType(JavaPluginExtension.class); - if (javaPluginExtension == null) { - throw new GradleException("You must either specify 'target' manually or apply the 'scala' plugin."); - } - FileCollection union = getProject().files(); - for (SourceSet sourceSet : javaPluginExtension.getSourceSets()) { - union = union.plus(sourceSet.getAllSource().filter(file -> { - String name = file.getName(); + target = getSources(getProject(), + "You must either specify 'target' manually or apply the 'scala' plugin.", + SourceSet::getAllSource, + file -> { + final String name = file.getName(); return name.endsWith(".scala") || name.endsWith(".sc"); - })); - } - target = union; - } else { - JavaPluginConvention javaPlugin = getProject().getConvention().findPlugin(JavaPluginConvention.class); - if (javaPlugin == null) { - throw new GradleException("You must either specify 'target' manually or apply the 'scala' plugin."); - } - FileCollection union = getProject().files(); - for (SourceSet sourceSet : javaPlugin.getSourceSets()) { - union = union.plus(sourceSet.getAllSource().filter(file -> { - String name = file.getName(); - return name.endsWith(".scala") || name.endsWith(".sc"); - })); - } - target = union; - } + }); } super.setupTask(task); } From 1c21d12ebc7e1dabdb6d2001df18fff8d84c1fe4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 27 Mar 2023 18:37:25 -0700 Subject: [PATCH 0663/1120] Centralize gradle versions so we can remove version-specific workarounds as soon as possible. --- .../src/main/java/com/diffplug/gradle/spotless/JvmLang.java | 2 +- .../java/com/diffplug/gradle/spotless/SpotlessPlugin.java | 5 +++-- .../diffplug/gradle/spotless/SpotlessPluginRedirect.java | 6 +++--- .../diffplug/gradle/spotless/GradleIntegrationHarness.java | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java index 6e30674c6c..1a9a06b986 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JvmLang.java @@ -34,7 +34,7 @@ interface JvmLang { default FileCollection getSources(Project project, String message, Function sourceSetSourceDirectory, Spec filterSpec) { final SourceSetContainer sourceSets; FileCollection union = project.files(); - if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { + if (GradleVersion.current().compareTo(GradleVersion.version(SpotlessPlugin.VER_GRADLE_javaPluginExtension)) >= 0) { final JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class); if (javaPluginExtension == null) { throw new GradleException(message); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java index 91847af0cf..0043e2b274 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java @@ -26,13 +26,14 @@ public class SpotlessPlugin implements Plugin { static final String SPOTLESS_MODERN = "spotlessModern"; - static final String MINIMUM_GRADLE = "6.1.1"; + static final String VER_GRADLE_min = "6.1.1"; + static final String VER_GRADLE_javaPluginExtension = "7.1"; private static final int MINIMUM_JRE = 11; @Override public void apply(Project project) { if (SpotlessPluginRedirect.gradleIsTooOld(project)) { - throw new GradleException("Spotless requires Gradle " + MINIMUM_GRADLE + " or newer, this was " + project.getGradle().getGradleVersion()); + throw new GradleException("Spotless requires Gradle " + VER_GRADLE_min + " or newer, this was " + project.getGradle().getGradleVersion()); } if (Jvm.version() < MINIMUM_JRE) { throw new GradleException("Spotless requires JRE " + MINIMUM_JRE + " or newer, this was " + JavaVersion.current() + ".\n" diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java index da4d3dcd8b..975ec5576e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ private static int badSemver(int major, int minor) { static boolean gradleIsTooOld(Project project) { if (gradleIsTooOld == null) { - gradleIsTooOld = badSemver(project.getGradle().getGradleVersion()) < badSemver(SpotlessPlugin.MINIMUM_GRADLE); + gradleIsTooOld = badSemver(project.getGradle().getGradleVersion()) < badSemver(SpotlessPlugin.VER_GRADLE_min); } return gradleIsTooOld.booleanValue(); } @@ -73,7 +73,7 @@ public void apply(Project project) { "If you like the idea behind 'ratchetFrom', you should checkout spotless-changelog", "https://github.com/diffplug/spotless-changelog"); if (gradleIsTooOld(project)) { - errorMsg = errorMsg.replace("To migrate:\n", "To migrate:\n- Upgrade gradle to " + SpotlessPlugin.MINIMUM_GRADLE + " or newer (you're on " + project.getGradle().getGradleVersion() + ")\n"); + errorMsg = errorMsg.replace("To migrate:\n", "To migrate:\n- Upgrade gradle to " + SpotlessPlugin.VER_GRADLE_min + " or newer (you're on " + project.getGradle().getGradleVersion() + ")\n"); } throw new GradleException(errorMsg); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java index 1763fd088f..61d191bab1 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java @@ -43,7 +43,7 @@ public class GradleIntegrationHarness extends ResourceHarness { public enum GradleVersionSupport { - JRE_11("5.0"), MINIMUM(SpotlessPlugin.MINIMUM_GRADLE), + JRE_11("5.0"), MINIMUM(SpotlessPlugin.VER_GRADLE_min), // technically, this API exists in 6.5, but the flags for it change in 6.6, so we build to that CONFIGURATION_CACHE("6.6"), // https://docs.gradle.org/7.5/userguide/configuration_cache.html#config_cache:stable From 86fc942a75e37c6ad0dea9348bbe858d382a91ae Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 5 Apr 2023 23:06:05 +0400 Subject: [PATCH 0664/1120] 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 2caf22809f..7a4673ccdc 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 ca2fcfbce6..ab28e2213f 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 915322830b..b78094cf18 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 2464527426..35caa4771b 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 614e5026a0..60181d048a 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 e74bca929d..885d701874 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 f4928da3d6..95a60097d0 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 0665/1120] 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 0905c13857..70200b092f 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 61dca9cca9..903064e2b1 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 7a4673ccdc..5ae9d2bd95 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 8fc3886d99..69877ce03e 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 35caa4771b..da7cc6ad07 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 0666/1120] 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 f46f7da32a..4b79347b29 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 6c718e0382..d7962c6543 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 10954f2bb1..78f5eacd32 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 ab28e2213f..6305289818 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 885d701874..2eeabb9ab5 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 2c85d72069..56cad1273a 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 0667/1120] 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 da7cc6ad07..b12d777b29 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 0668/1120] Update the root README table. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 662c624bdf..52628574d9 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 1470666c83588149ba1e0bc2178099343abc39d9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:21:19 -0700 Subject: [PATCH 0669/1120] More version centralizing. --- .../main/java/com/diffplug/gradle/spotless/GroovyExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java index 17a57f6301..f20137f047 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java @@ -118,7 +118,7 @@ protected void setupTask(SpotlessTask task) { target = getSources(getProject(), message, sourceSet -> { - if (GradleVersion.current().compareTo(GradleVersion.version("7.1")) >= 0) { + if (GradleVersion.current().compareTo(GradleVersion.version(SpotlessPlugin.VER_GRADLE_javaPluginExtension)) >= 0) { return sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class); } else { final GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class); From 9f490688151ae0d858df59b5c923efbeba8fffe0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:25:02 -0700 Subject: [PATCH 0670/1120] Improve the GroovyExtension error message when there is no target and no `groovy` plugin. --- .../main/java/com/diffplug/gradle/spotless/GroovyExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java index f20137f047..a7f3d98ce4 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java @@ -111,7 +111,7 @@ public GrEclipseConfig withP2Mirrors(Map mirrors) { @Override protected void setupTask(SpotlessTask task) { if (target == null) { - final String message = "You must apply the groovy plugin before the spotless plugin if you are using the groovy extension."; + final String message = "You must either specify 'target' manually or apply the 'groovy' plugin."; if (!getProject().getPlugins().hasPlugin(GroovyBasePlugin.class)) { throw new GradleException(message); } From 45e078d3540660c97f07319134d524086519a920 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:26:34 -0700 Subject: [PATCH 0671/1120] Update changelog. --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 0a0cabcca0..831182d900 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -17,6 +17,8 @@ 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)) +### Fixed +* Stop using deprecated conventions when used in Gradle >= `7.1`. ([#1618](https://github.com/diffplug/spotless/pull/1618)) ## [6.17.0] - 2023-03-13 ### Added From aeb6098e4a21f37c10d0146325c00552c8ba265f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:30:26 -0700 Subject: [PATCH 0672/1120] spotlessApply --- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 1 - .../java/com/diffplug/spotless/maven/FormattersHolder.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) 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 d68387bb27..0c49a32ab2 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 @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormattersHolder.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormattersHolder.java index ff3e1c81fe..873321f9df 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormattersHolder.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FormattersHolder.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. @@ -16,7 +16,6 @@ package com.diffplug.spotless.maven; import java.io.File; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; From 051454677897ed410bb6287cfda7cba33852844e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:40:01 -0700 Subject: [PATCH 0673/1120] 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 56cad1273a..6bc478027b 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 0674/1120] 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 eb4d4de89a..5a9553d98d 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 d7ca743c187b868d2ba58d93027d3a61ac8950e0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:44:04 -0700 Subject: [PATCH 0675/1120] Fix groovy test for new error message. --- .../java/com/diffplug/gradle/spotless/GroovyExtensionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java index b9c7d2f66e..8ca432ebf6 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java @@ -103,7 +103,7 @@ void groovyPluginMissingCheck() throws IOException { Throwable error = assertThrows(Throwable.class, () -> gradleRunner().withArguments("spotlessApply").build()); - assertThat(error).hasMessageContaining("must apply the groovy plugin before"); + assertThat(error).hasMessageContaining("You must either specify 'target' manually or apply the 'groovy' plugin."); } } From 350d37ca96cb4d193e3c148a6de1dfed3290a8be Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:48:43 -0700 Subject: [PATCH 0676/1120] Update FlexmarkStep version to latest. --- .../java/com/diffplug/spotless/markdown/FlexmarkStep.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java index 19550b6e44..263931693e 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.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. @@ -29,7 +29,7 @@ public class FlexmarkStep { // prevent direct instantiation private FlexmarkStep() {} - private static final String DEFAULT_VERSION = "0.62.2"; + private static final String DEFAULT_VERSION = "0.64.0"; private static final String NAME = "flexmark-java"; private static final String MAVEN_COORDINATE = "com.vladsch.flexmark:flexmark-all:"; From 101b435f44e8d40fa9895bd617efb490248492a5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:48:53 -0700 Subject: [PATCH 0677/1120] Add test for earliest and latest versions. --- .../spotless/markdown/FlexmarkStepTest.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/markdown/FlexmarkStepTest.java b/testlib/src/test/java/com/diffplug/spotless/markdown/FlexmarkStepTest.java index 191ffa4cb5..0406c05678 100644 --- a/testlib/src/test/java/com/diffplug/spotless/markdown/FlexmarkStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/markdown/FlexmarkStepTest.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. @@ -21,9 +21,18 @@ import com.diffplug.spotless.TestProvisioner; class FlexmarkStepTest { + private static final String oldestSupported = "0.62.2"; @Test - void behavior() throws Exception { + void behaviorOldest() { + StepHarness.forStep(FlexmarkStep.create(oldestSupported, TestProvisioner.mavenCentral())) + .testResource( + "markdown/flexmark/FlexmarkUnformatted.md", + "markdown/flexmark/FlexmarkFormatted.md"); + } + + @Test + void behaviorLatest() { StepHarness.forStep(FlexmarkStep.create(TestProvisioner.mavenCentral())) .testResource( "markdown/flexmark/FlexmarkUnformatted.md", From 91439e5c7300e4ee2253e404a72e92963863f7e2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:50:14 -0700 Subject: [PATCH 0678/1120] spotlessApply --- .../java/com/diffplug/gradle/spotless/GroovyExtensionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java index 8ca432ebf6..c38df40d54 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.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. From 64b8183793497522a58d07ee49ac578f930a5c04 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 15:06:52 -0700 Subject: [PATCH 0679/1120] The equo-based steps ought to be initialized with a version. --- .../diffplug/spotless/extra/EquoBasedStepBuilder.java | 9 ++++++++- .../spotless/extra/cpp/EclipseCdtFormatterStep.java | 2 +- .../spotless/extra/groovy/GrEclipseFormatterStep.java | 2 +- .../spotless/extra/java/EclipseJdtFormatterStep.java | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index cc12a938ad..66993e2f6c 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -46,10 +46,17 @@ public abstract class EquoBasedStepBuilder { private Iterable settingsFiles = new ArrayList<>(); private Map p2Mirrors = Map.of(); - /** Initialize valid default configuration, taking latest version */ + /** @deprecated if you use this constructor you *must* call {@link #setVersion(String)} before calling {@link #build()} */ + @Deprecated public EquoBasedStepBuilder(String formatterName, Provisioner mavenProvisioner, ThrowingEx.Function stateToFormatter) { + this(formatterName, mavenProvisioner, null, stateToFormatter); + } + + /** Initialize valid default configuration, taking latest version */ + public EquoBasedStepBuilder(String formatterName, Provisioner mavenProvisioner, String defaultVersion, ThrowingEx.Function stateToFormatter) { this.formatterName = formatterName; this.mavenProvisioner = mavenProvisioner; + this.formatterVersion = defaultVersion; this.stateToFormatter = stateToFormatter; } diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java index 1a83389eaa..9f9d591c3c 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java @@ -45,7 +45,7 @@ public static String defaultVersion() { /** Provides default configuration */ public static EquoBasedStepBuilder createBuilder(Provisioner provisioner) { - return new EquoBasedStepBuilder(NAME, provisioner, EclipseCdtFormatterStep::apply) { + return new EquoBasedStepBuilder(NAME, provisioner, defaultVersion(), EclipseCdtFormatterStep::apply) { @Override protected P2Model model(String version) { var model = new P2Model(); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java index 08c28889f9..fd3c8b7d8b 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java @@ -39,7 +39,7 @@ public static String defaultVersion() { } public static EquoBasedStepBuilder createBuilder(Provisioner provisioner) { - return new EquoBasedStepBuilder(NAME, provisioner, GrEclipseFormatterStep::apply) { + return new EquoBasedStepBuilder(NAME, provisioner, defaultVersion(), GrEclipseFormatterStep::apply) { @Override protected P2Model model(String version) { if (!version.startsWith("4.")) { diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java index cd9314406f..4a90a40832 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java @@ -38,7 +38,7 @@ public static String defaultVersion() { } public static EquoBasedStepBuilder createBuilder(Provisioner provisioner) { - return new EquoBasedStepBuilder(NAME, provisioner, EclipseJdtFormatterStep::apply) { + return new EquoBasedStepBuilder(NAME, provisioner, defaultVersion(), EclipseJdtFormatterStep::apply) { @Override protected P2Model model(String version) { var model = new P2Model(); From c802a1e797ae8f31fdfb927f9e9f7abd06b34b88 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 5 Apr 2023 22:37:35 +0000 Subject: [PATCH 0680/1120] chore(deps): update plugin io.github.davidburstrom.version-compatibility to v0.5.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index a9ed9373ef..a35dab8e40 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,7 +21,7 @@ plugins { // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' apply false // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags - id 'io.github.davidburstrom.version-compatibility' version '0.4.0' apply false + id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise id 'com.gradle.enterprise' version '3.12.6' // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md From 97b5cc4031eb59134569390ae46644b0bd42820e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 16:15:16 -0700 Subject: [PATCH 0681/1120] Failed attempt to reproduce #1638 (I think we need spotless-format23.xml) --- ...clipseJdtFormatterStepSpecialCaseTest.java | 30 +++++++++++ .../resources/java/eclipse/AbstractType.clean | 38 +++++++++++++ .../resources/java/eclipse/AbstractType.test | 54 +++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepSpecialCaseTest.java create mode 100644 testlib/src/main/resources/java/eclipse/AbstractType.clean create mode 100644 testlib/src/main/resources/java/eclipse/AbstractType.test diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepSpecialCaseTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepSpecialCaseTest.java new file mode 100644 index 0000000000..eb93cf1f09 --- /dev/null +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepSpecialCaseTest.java @@ -0,0 +1,30 @@ +/* + * 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. + * 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.extra.java; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.TestProvisioner; + +public class EclipseJdtFormatterStepSpecialCaseTest { + /** https://github.com/diffplug/spotless/issues/1638 */ + @Test + public void issue_1638() { + StepHarness.forStep(EclipseJdtFormatterStep.createBuilder(TestProvisioner.mavenCentral()).build()) + .testResource("java/eclipse/AbstractType.test", "java/eclipse/AbstractType.clean"); + } +} diff --git a/testlib/src/main/resources/java/eclipse/AbstractType.clean b/testlib/src/main/resources/java/eclipse/AbstractType.clean new file mode 100644 index 0000000000..475b1186fd --- /dev/null +++ b/testlib/src/main/resources/java/eclipse/AbstractType.clean @@ -0,0 +1,38 @@ +package test; + +public abstract class AbstractType { + + private String _typeName; + + AbstractType(String typeName) { + _typeName = typeName; + } + + private String _type() { + String name = getClass().getSimpleName(); + return name.endsWith("Type") ? name.substring(0, getClass().getSimpleName().length() - 4) : name; + } + + AbstractType argument() { + throw new UnsupportedOperationException(getClass().getSimpleName()); + } + + @Override + public boolean equals(Object another) { + if (this == another) { + return true; + } + return another instanceof AbstractType t && _typeName.equals(t._typeName); + } + + @Override + public int hashCode() { + return _typeName.hashCode(); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "(typeName)"; + } + +} diff --git a/testlib/src/main/resources/java/eclipse/AbstractType.test b/testlib/src/main/resources/java/eclipse/AbstractType.test new file mode 100644 index 0000000000..d4753b2cfc --- /dev/null +++ b/testlib/src/main/resources/java/eclipse/AbstractType.test @@ -0,0 +1,54 @@ +package test; + + + + +public abstract class AbstractType { + + + private String _typeName; + + AbstractType(String typeName) { + _typeName = typeName; + } + + + + private String _type() { + String name = getClass().getSimpleName(); + return name.endsWith("Type") + ? name.substring(0, getClass().getSimpleName().length() - 4) + : name; + } + + AbstractType argument() { + throw new UnsupportedOperationException(getClass().getSimpleName()); + } + + + @Override + public boolean equals(Object another) { + if (this == another) { + return true; + } + return another instanceof AbstractType t + && _typeName.equals(t._typeName); + } + + + + @Override + public int hashCode() { + return _typeName.hashCode(); + } + + + + + @Override + public String toString() { + return getClass().getSimpleName() + "(typeName)"; + } + + +} From fea35e65b6c49fccdbcb917f12688ec476b8430a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 16:52:11 -0700 Subject: [PATCH 0682/1120] Add a testcase to reproduce #1657. --- ...GrEclipseFormatterStepSpecialCaseTest.java | 30 +++++++++++++++++++ .../groovy/greclipse/format/SomeClass.test | 12 ++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java create mode 100644 testlib/src/main/resources/groovy/greclipse/format/SomeClass.test diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java new file mode 100644 index 0000000000..768e939dfb --- /dev/null +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java @@ -0,0 +1,30 @@ +/* + * 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.extra.groovy; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.TestProvisioner; + +public class GrEclipseFormatterStepSpecialCaseTest { + /** https://github.com/diffplug/spotless/issues/1657 */ + @Test + public void issue_1657() { + StepHarness.forStep(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral()).build()) + .testResourceUnaffected("groovy/greclipse/format/SomeClass.test"); + } +} diff --git a/testlib/src/main/resources/groovy/greclipse/format/SomeClass.test b/testlib/src/main/resources/groovy/greclipse/format/SomeClass.test new file mode 100644 index 0000000000..09ea835cca --- /dev/null +++ b/testlib/src/main/resources/groovy/greclipse/format/SomeClass.test @@ -0,0 +1,12 @@ +package com.somepackage + +class SomeClass { + + def func(parm) { + """ + ${parm == null ? "" : "$parm"} + ${parm == null ? "" : "$parm"} + + """ + } +} From 4a9e26984368003a4e50b79684d2e4028d0f58be Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 16:57:39 -0700 Subject: [PATCH 0683/1120] Improve error reporting within the GrEclipse step. --- .../glue/groovy/GrEclipseFormatterStepImpl.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index 9549847d74..7c29209157 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -104,14 +104,14 @@ public String format(String raw) throws Exception { * Eclipse Groovy formatter does not signal problems by its return value, but by logging errors. */ private static final class GroovyErrorListener implements ILogListener, IGroovyLogger { - private final List errors; + private final List errors; public GroovyErrorListener() { /* * We need a synchronized list here, in case multiple instantiations * run in parallel. */ - errors = Collections.synchronizedList(new ArrayList()); + errors = Collections.synchronizedList(new ArrayList<>()); ILog groovyLogger = GroovyCoreActivator.getDefault().getLog(); groovyLogger.addLogListener(this); synchronized (GroovyLogManager.manager) { @@ -121,7 +121,7 @@ public GroovyErrorListener() { @Override public void logging(final IStatus status, final String plugin) { - errors.add(status.getMessage()); + errors.add(status.getException()); } public boolean errorsDetected() { @@ -141,9 +141,10 @@ public String toString() { } else if (0 == errors.size()) { string.append("Step sucesfully executed."); } - for (String error : errors) { + for (Throwable error : errors) { + error.printStackTrace(); string.append(System.lineSeparator()); - string.append(error); + string.append(error.getMessage()); } return string.toString(); @@ -162,7 +163,11 @@ public boolean isCategoryEnabled(TraceCategory cat) { @Override public void log(TraceCategory arg0, String arg1) { - errors.add(arg1); + try { + throw new RuntimeException(arg1); + } catch (RuntimeException e) { + errors.add(e); + } } } From a8d5db8d3921ff3b9f8863c7f1d48e0c3907ccfc Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 16:57:54 -0700 Subject: [PATCH 0684/1120] Use the new error reporting to figure out exactly what was wrong. --- .../GrEclipseFormatterStepSpecialCaseTest.java | 18 ++++++++++++++++-- .../groovy/greclipse/format/SomeClass.fixed | 12 ++++++++++++ .../groovy/greclipse/format/SomeClass.test | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 testlib/src/main/resources/groovy/greclipse/format/SomeClass.fixed diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java index 768e939dfb..8f832b89f0 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java @@ -15,16 +15,30 @@ */ package com.diffplug.spotless.extra.groovy; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.TestProvisioner; public class GrEclipseFormatterStepSpecialCaseTest { - /** https://github.com/diffplug/spotless/issues/1657 */ + /** + * https://github.com/diffplug/spotless/issues/1657 + * + * broken: ${parm == null ? "" : "$parm"} + * works: ${parm == null ? "" : "parm"} + */ @Test public void issue_1657() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + StepHarness.forStep(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral()).build()) + .testResourceUnaffected("groovy/greclipse/format/SomeClass.test"); + }); + } + + @Test + public void issue_1657_fixed() { StepHarness.forStep(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral()).build()) - .testResourceUnaffected("groovy/greclipse/format/SomeClass.test"); + .testResourceUnaffected("groovy/greclipse/format/SomeClass.fixed"); } } diff --git a/testlib/src/main/resources/groovy/greclipse/format/SomeClass.fixed b/testlib/src/main/resources/groovy/greclipse/format/SomeClass.fixed new file mode 100644 index 0000000000..8c93ca4ad0 --- /dev/null +++ b/testlib/src/main/resources/groovy/greclipse/format/SomeClass.fixed @@ -0,0 +1,12 @@ +package com.somepackage + +class SomeClass { + + def func(parm) { + """ + ${parm == null ? "" : "parm"} + ${parm == null ? "" : "parm"} + + """ + } +} diff --git a/testlib/src/main/resources/groovy/greclipse/format/SomeClass.test b/testlib/src/main/resources/groovy/greclipse/format/SomeClass.test index 09ea835cca..62d4df0fc5 100644 --- a/testlib/src/main/resources/groovy/greclipse/format/SomeClass.test +++ b/testlib/src/main/resources/groovy/greclipse/format/SomeClass.test @@ -6,7 +6,7 @@ class SomeClass { """ ${parm == null ? "" : "$parm"} ${parm == null ? "" : "$parm"} - + """ } } From aea5e4107cb79e83474c85bde9e75457fb75cacc Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 6 Apr 2023 00:08:19 +0000 Subject: [PATCH 0685/1120] fix(deps): update dependency io.github.solven-eu.cleanthat:java to v2.13 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 876aa9e4a1..4c04ea42c1 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -114,7 +114,7 @@ dependencies { gsonCompileOnly 'com.google.code.gson:gson:2.10.1' - String VER_CLEANTHAT="2.8" + String VER_CLEANTHAT="2.13" cleanthatCompileOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT" compatCleanthat2Dot1CompileAndTestOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT" From 1475663ad839af05437e726fd54442ad20505f13 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:08:41 -0700 Subject: [PATCH 0686/1120] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 11 ++++++----- plugin-maven/CHANGES.md | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 70200b092f..a62ee49c3b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### 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)) +* Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) ## [2.37.0] - 2023-03-13 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d4256b15b4..d165e265fb 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,8 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `removeUnusedImport` can be configured to rely on `cleanthat-javaparser-unnecessaryimport`. Default remains `google-java-format`. ([#1589](https://github.com/diffplug/spotless/pull/1589)) -### Changes -* Bump default `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) +* Added formatter for Gherkin feature files ([#1649](https://github.com/diffplug/spotless/issues/1649)). * Support configuration of mirrors for P2 repositories ([#1629](https://github.com/diffplug/spotless/issues/1629)): ``` spotless { @@ -18,12 +17,14 @@ 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)). +### Fixed +* Stop using deprecated conventions when used in Gradle >= `7.1`. ([#1618](https://github.com/diffplug/spotless/pull/1618)) ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) +* Bump default `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) -### Fixed -* Stop using deprecated conventions when used in Gradle >= `7.1`. ([#1618](https://github.com/diffplug/spotless/pull/1618)) +* Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) + ## [6.17.0] - 2023-03-13 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index dfd5677031..1b905dcc77 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,13 +6,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * `removeUnusedImport` can be configured to rely on `cleanthat-javaparser-unnecessaryimport`. Default remains `google-java-format`. ([#1589](https://github.com/diffplug/spotless/pull/1589)) * 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 formatter for Gherkin feature files ([#1649](https://github.com/diffplug/spotless/issues/1649)). ### Fixed * Fix non deterministic computation of cache fingerprint when using multiple formatters. ([#1643](https://github.com/diffplug/spotless/pull/1643) fixes [#1642](https://github.com/diffplug/spotless/pull/1642)) ### Changes * Bump default `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) * **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)) +* Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) ## [2.35.0] - 2023-03-13 ### Added From f708c53325b92b7b9f7f3d45de42b93328cba145 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:11:37 -0700 Subject: [PATCH 0687/1120] Bump default diktat `1.2.4.2` -> `1.2.5`. --- .../main/java/com/diffplug/spotless/kotlin/DiktatStep.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index 9fb5bd634f..fefda39784 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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. @@ -32,7 +32,7 @@ private DiktatStep() {} private static final String MIN_SUPPORTED_VERSION = "1.2.1"; - private static final String DEFAULT_VERSION = "1.2.4.2"; + private static final String DEFAULT_VERSION = "1.2.5"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; From 73d0553497822671c5d6e6da08abd8801069b010 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:14:01 -0700 Subject: [PATCH 0688/1120] Bump changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a62ee49c3b..418320062d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,8 +16,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * 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 `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) +* Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) ## [2.37.0] - 2023-03-13 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d165e265fb..be0a426056 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -24,7 +24,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) - +* Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) ## [6.17.0] - 2023-03-13 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1b905dcc77..a29cd7b217 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,10 +10,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Fix non deterministic computation of cache fingerprint when using multiple formatters. ([#1643](https://github.com/diffplug/spotless/pull/1643) fixes [#1642](https://github.com/diffplug/spotless/pull/1642)) ### Changes -* Bump default `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) +* Bump default `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) +* Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) ## [2.35.0] - 2023-03-13 ### Added From 9568a97b190f9b378feaf01283b8720d7a848a4f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:15:23 -0700 Subject: [PATCH 0689/1120] Typo double-* --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 418320062d..17da08f52d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,7 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * 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 `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) +* Bump default `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) From 1df679a544a2f0d5ca58152201a3bb78bfe51368 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:17:52 -0700 Subject: [PATCH 0690/1120] Bump default scalafmt 3.7.1 -> 3.7.3 --- lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java | 2 +- testlib/src/main/resources/scala/scalafmt/scalafmt.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java index 264ca679db..114f4a9f1a 100644 --- a/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java @@ -34,7 +34,7 @@ public class ScalaFmtStep { // prevent direct instantiation private ScalaFmtStep() {} - static final String DEFAULT_VERSION = "3.7.1"; + static final String DEFAULT_VERSION = "3.7.3"; private static final String DEFAULT_SCALA_MAJOR_VERSION = "2.13"; static final String NAME = "scalafmt"; diff --git a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf index f3cfb3a031..edea864af1 100644 --- a/testlib/src/main/resources/scala/scalafmt/scalafmt.conf +++ b/testlib/src/main/resources/scala/scalafmt/scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.7.1 +version = 3.7.3 runner.dialect = scala213 style = defaultWithAlign # For pretty alignment. maxColumn = 20 # For my teensy narrow display From 25571abe9f17428afdff6fee607458c4368302f3 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:20:11 -0700 Subject: [PATCH 0691/1120] Update changelogs. --- CHANGES.md | 5 +++-- plugin-gradle/CHANGES.md | 5 +++-- plugin-maven/CHANGES.md | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 17da08f52d..d316c0a268 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,9 +17,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### 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 `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) -* Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) -* Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) +* Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) +* Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) +* Bump default `scalafmt` version `3.7.1` -> `3.7.3`. ([#1584](https://github.com/diffplug/spotless/pull/1584)) ## [2.37.0] - 2023-03-13 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index be0a426056..9ce2dbd752 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -22,9 +22,10 @@ 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 `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) -* Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) -* Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) +* Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) +* Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) +* Bump default `scalafmt` version `3.7.1` -> `3.7.3`. ([#1584](https://github.com/diffplug/spotless/pull/1584)) ## [6.17.0] - 2023-03-13 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a29cd7b217..6239d8a48b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -12,9 +12,10 @@ 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 `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) -* Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) -* Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) +* Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) +* Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) +* Bump default `scalafmt` version `3.7.1` -> `3.7.3`. ([#1584](https://github.com/diffplug/spotless/pull/1584)) ## [2.35.0] - 2023-03-13 ### Added From c745519d0c2ae927429044f01b0e99e9b9bfcce1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:25:24 -0700 Subject: [PATCH 0692/1120] Bump default cleanthat `2.8` -> `2.13`. --- .../main/java/com/diffplug/spotless/java/CleanthatJavaStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 0377af8bc5..92b7daa5f6 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -40,7 +40,7 @@ public final class CleanthatJavaStep { private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java"; // CleanThat changelog is available at https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.8"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.13"); // prevent direct instantiation private CleanthatJavaStep() {} From 579e9f18c9e96a8d9674b678d6a6aba7e5d9b1ce Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:25:31 -0700 Subject: [PATCH 0693/1120] Update changelogs. --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d316c0a268..cc6b21e399 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,7 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * 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 `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) +* Bump default `cleanthat` version to latest `2.6` -> `2.13`. ([#1589](https://github.com/diffplug/spotless/pull/1589) and [#1661](https://github.com/diffplug/spotless/pull/1661)) * Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * 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 9ce2dbd752..7ad64c04b2 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -21,7 +21,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Stop using deprecated conventions when used in Gradle >= `7.1`. ([#1618](https://github.com/diffplug/spotless/pull/1618)) ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) -* Bump default `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) +* Bump default `cleanthat` version to latest `2.6` -> `2.13`. ([#1589](https://github.com/diffplug/spotless/pull/1589) and [#1661](https://github.com/diffplug/spotless/pull/1661)) * Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * 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 6239d8a48b..2f89316bf2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Fix non deterministic computation of cache fingerprint when using multiple formatters. ([#1643](https://github.com/diffplug/spotless/pull/1643) fixes [#1642](https://github.com/diffplug/spotless/pull/1642)) ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) -* Bump default `cleanthat` version to latest `2.6` -> `2.8`. ([#1589](https://github.com/diffplug/spotless/pull/1589) +* Bump default `cleanthat` version to latest `2.6` -> `2.13`. ([#1589](https://github.com/diffplug/spotless/pull/1589) and [#1661](https://github.com/diffplug/spotless/pull/1661)) * Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) From c19d3c06f90e8e3ab1572434bf272cf0777d7208 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:37:20 -0700 Subject: [PATCH 0694/1120] Fix spotbugs warning. --- .../com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 66993e2f6c..db2e6674db 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -22,6 +22,8 @@ import java.util.Map; import java.util.Properties; +import javax.annotation.Nullable; + import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterProperties; @@ -53,7 +55,7 @@ public EquoBasedStepBuilder(String formatterName, Provisioner mavenProvisioner, } /** Initialize valid default configuration, taking latest version */ - public EquoBasedStepBuilder(String formatterName, Provisioner mavenProvisioner, String defaultVersion, ThrowingEx.Function stateToFormatter) { + public EquoBasedStepBuilder(String formatterName, Provisioner mavenProvisioner, @Nullable String defaultVersion, ThrowingEx.Function stateToFormatter) { this.formatterName = formatterName; this.mavenProvisioner = mavenProvisioner; this.formatterVersion = defaultVersion; From 7ca11bf0b795c49ab0d7f84f2b61d1557289e99b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:31:17 -0700 Subject: [PATCH 0695/1120] Bump default Eclipse JDT to 4.27 (for java 17). --- .../diffplug/spotless/extra/java/EclipseJdtFormatterStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java index 4a90a40832..cd766fc8c8 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java @@ -31,7 +31,7 @@ public final class EclipseJdtFormatterStep { private EclipseJdtFormatterStep() {} private static final String NAME = "eclipse jdt formatter"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26").add(17, "4.27"); public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); From 9238bfd7a6ed5e7c7d0a903cbc6d380936d6db1d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:31:27 -0700 Subject: [PATCH 0696/1120] Bump default Eclipse Groovy to 4.27 (for java 17). --- .../diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java index fd3c8b7d8b..3b57df889b 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java @@ -32,7 +32,7 @@ public final class GrEclipseFormatterStep { private GrEclipseFormatterStep() {} private static final String NAME = "eclipse groovy formatter"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26").add(17, "4.27"); public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); From cfe9084169b59cca568c5728a1b9d1afda1b5b63 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 17:31:44 -0700 Subject: [PATCH 0697/1120] Bump default Eclipse CDT to 4.27 (for java 17). --- .../diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java index 9f9d591c3c..bcbb58c0f6 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java @@ -37,7 +37,7 @@ public final class EclipseCdtFormatterStep { private EclipseCdtFormatterStep() {} private static final String NAME = "eclipse cdt formatter"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "10.7").add(17, "11.0"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "10.7").add(17, "11.1"); public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); From ddc82c17830eb61c93aa10928694d685832360e4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 18:45:12 -0700 Subject: [PATCH 0698/1120] Update changelogs. --- CHANGES.md | 4 ++++ plugin-gradle/CHANGES.md | 4 ++++ plugin-maven/CHANGES.md | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index cc6b21e399..7e869a2e1b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `scalafmt` version `3.7.1` -> `3.7.3`. ([#1584](https://github.com/diffplug/spotless/pull/1584)) +* Bump default Eclipse formatters for the 2023-03 release. ([#1662](https://github.com/diffplug/spotless/pull/1662)) + * JDT and GrEclipse `4.26` -> `4.27` + * Improve GrEclipse error reporting. ([#1660](https://github.com/diffplug/spotless/pull/1660)) + * CDT `11.0` -> `11.1` ## [2.37.0] - 2023-03-13 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7ad64c04b2..6d96095bab 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -26,6 +26,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `scalafmt` version `3.7.1` -> `3.7.3`. ([#1584](https://github.com/diffplug/spotless/pull/1584)) +* Bump default Eclipse formatters for the 2023-03 release. ([#1662](https://github.com/diffplug/spotless/pull/1662)) + * JDT and GrEclipse `4.26` -> `4.27` + * Improve GrEclipse error reporting. ([#1660](https://github.com/diffplug/spotless/pull/1660)) + * CDT `11.0` -> `11.1` ## [6.17.0] - 2023-03-13 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 2f89316bf2..f311a22ccb 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -16,6 +16,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `scalafmt` version `3.7.1` -> `3.7.3`. ([#1584](https://github.com/diffplug/spotless/pull/1584)) +* Bump default Eclipse formatters for the 2023-03 release. ([#1662](https://github.com/diffplug/spotless/pull/1662)) + * JDT and GrEclipse `4.26` -> `4.27` + * Improve GrEclipse error reporting. ([#1660](https://github.com/diffplug/spotless/pull/1660)) + * CDT `11.0` -> `11.1` ## [2.35.0] - 2023-03-13 ### Added From 7f245a8892408e40ee72d801dc3ad47ab284295c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 18:48:39 -0700 Subject: [PATCH 0699/1120] Sort all the "glue" adaptors in the build. --- lib-extra/build.gradle | 16 ++++--- lib/build.gradle | 97 ++++++++++++++++++++---------------------- 2 files changed, 56 insertions(+), 57 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 8ed36bede6..5e491eaf20 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -40,9 +40,10 @@ tasks.withType(Test).configureEach { } def NEEDS_P2_DEPS = [ - 'jdt', + // (alphabetic order please) + 'cdt', 'groovy', - 'cdt' + 'jdt' ] for (needsP2 in NEEDS_P2_DEPS) { sourceSets.register(needsP2) { @@ -68,9 +69,11 @@ tasks.withType(Test).configureEach { apply plugin: 'dev.equo.p2deps' p2deps { - into 'jdtCompileOnly', { + // (alphabetic order please) + into 'cdtCompileOnly', { p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' - install 'org.eclipse.jdt.core' + p2repo 'https://download.eclipse.org/tools/cdt/releases/10.7/' + install 'org.eclipse.cdt.core' } into 'groovyCompileOnly', { p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' @@ -80,10 +83,9 @@ p2deps { install 'org.eclipse.jdt.groovy.core' install 'org.codehaus.groovy' } - into 'cdtCompileOnly', { + into 'jdtCompileOnly', { p2repo 'https://download.eclipse.org/eclipse/updates/4.26/' - p2repo 'https://download.eclipse.org/tools/cdt/releases/10.7/' - install 'org.eclipse.cdt.core' + install 'org.eclipse.jdt.core' } } diff --git a/lib/build.gradle b/lib/build.gradle index a0835a09e0..9e31bed698 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -8,18 +8,19 @@ apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') def NEEDS_GLUE = [ - 'sortPom', - 'palantirJavaFormat', + // (alphabetic order please) + 'cleanthat', + 'diktat', + 'flexmark', + 'gherkin', 'googleJavaFormat', + 'gson', + 'jackson', 'ktfmt', 'ktlint', - 'flexmark', - 'diktat', + 'palantirJavaFormat', 'scalafmt', - 'jackson', - 'gson', - 'cleanthat', - 'gherkin' + 'sortPom' ] for (glue in NEEDS_GLUE) { sourceSets.register(glue) { @@ -31,6 +32,13 @@ for (glue in NEEDS_GLUE) { versionCompatibility { adapters { + // (alphabetic order please) + namespaces.register('Cleanthat') { + versions = [ + '2.1', + ] + targetSourceSetName = 'cleanthat' + } namespaces.register('KtLint') { // as discussed at https://github.com/diffplug/spotless/pull/1475 // we will support no more than 2 breaking changes at a time = 3 incompatible versions @@ -42,12 +50,6 @@ versionCompatibility { ] targetSourceSetName = 'ktlint' } - namespaces.register('Cleanthat') { - versions = [ - '2.1', - ] - targetSourceSetName = 'cleanthat' - } } } @@ -66,33 +68,39 @@ dependencies { testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ" testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" - // used for pom sorting - sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' - sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' - - palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm - - googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.16.0' // minimum required version due to api changes before then - - // used jackson-based formatters - jacksonCompileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.2' - jacksonCompileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.14.2' - - String VER_KTFMT = '0.43' - ktfmtCompileOnly "com.facebook:ktfmt:$VER_KTFMT" - String VER_KTLINT_GOOGLE_JAVA_FORMAT = '1.7' // for JDK 8 compatibility + // GLUE CODE (alphabetic order please) + // cleanthat + String VER_CLEANTHAT='2.13' + cleanthatCompileOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT" + compatCleanthat2Dot1CompileAndTestOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT" + // diktat + diktatCompileOnly 'org.cqfn.diktat:diktat-rules:1.2.5' + // flexmark + flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.64.0' + // gherkin + gherkinCompileOnly 'io.cucumber:gherkin-utils:8.0.2' + gherkinCompileOnly 'org.slf4j:slf4j-api:2.0.0' + // googleJavaFormat + googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.16.0' + // gson + gsonCompileOnly 'com.google.code.gson:gson:2.10.1' + // jackson + String VER_JACKSON='2.14.2' + jacksonCompileOnly "com.fasterxml.jackson.core:jackson-databind:$VER_JACKSON" + jacksonCompileOnly "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$VER_JACKSON" + // ktfmt + ktfmtCompileOnly "com.facebook:ktfmt:0.43" ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") { version { - strictly VER_KTLINT_GOOGLE_JAVA_FORMAT + strictly '1.7' // for JDK 8 compatibility } } - + // ktlint String VER_KTLINT='0.46.1' ktlintCompileOnly "com.pinterest:ktlint:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-core:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" - compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.46.0' compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.46.0' compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.46.0' @@ -102,24 +110,13 @@ dependencies { compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' - - String VER_SCALAFMT="3.7.3" - scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" - - String VER_DIKTAT = "1.2.5" - diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" - - // used for markdown formatting - flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.64.0' - - gsonCompileOnly 'com.google.code.gson:gson:2.10.1' - - String VER_CLEANTHAT="2.13" - cleanthatCompileOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT" - compatCleanthat2Dot1CompileAndTestOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT" - - gherkinCompileOnly 'io.cucumber:gherkin-utils:8.0.2' - gherkinCompileOnly 'org.slf4j:slf4j-api:2.0.0' + // palantirJavaFormat + palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm + // scalafmt + scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:3.7.3" + // sortPom + sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' + sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' } // we'll hold the core lib to a high standard From 7e852e30ccb2e285028083f2b17e8717c62f6759 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 20:15:26 -0700 Subject: [PATCH 0700/1120] On JRE 11, users will get alert that they might fix the GrEclipse issue by bumping to JRE 17 and using the latest. --- .../extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java index 8f832b89f0..25a269834c 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepSpecialCaseTest.java @@ -30,7 +30,7 @@ public class GrEclipseFormatterStepSpecialCaseTest { */ @Test public void issue_1657() { - Assertions.assertThrows(IllegalArgumentException.class, () -> { + Assertions.assertThrows(RuntimeException.class, () -> { StepHarness.forStep(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral()).build()) .testResourceUnaffected("groovy/greclipse/format/SomeClass.test"); }); From e34d6773f8cc43adea0ad076a07d8241889698fa Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 6 Apr 2023 03:40:22 +0000 Subject: [PATCH 0701/1120] Published lib/2.38.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7e869a2e1b..50141ece9c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.38.0] - 2023-04-06 ### 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)). From 4895f3a35ee6b8613700eb270eba17bdd4c944ae Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 6 Apr 2023 03:41:31 +0000 Subject: [PATCH 0702/1120] Published gradle/6.18.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 52 ++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 6d96095bab..05f497d1e3 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.18.0] - 2023-04-06 ### Added * `removeUnusedImport` can be configured to rely on `cleanthat-javaparser-unnecessaryimport`. Default remains `google-java-format`. ([#1589](https://github.com/diffplug/spotless/pull/1589)) * Added formatter for Gherkin feature files ([#1649](https://github.com/diffplug/spotless/issues/1649)). diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 2bb824b3ee..cea45a049f 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.17.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.18.0-blue.svg)](CHANGES.md) [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -125,10 +125,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -140,7 +140,7 @@ If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -297,8 +297,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -348,8 +348,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -420,7 +420,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -452,7 +452,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -484,7 +484,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -518,7 +518,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -539,7 +539,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -564,7 +564,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -604,7 +604,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -697,7 +697,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -761,7 +761,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -836,7 +836,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -867,7 +867,7 @@ spotless { ## Gherkin -- `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) +- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.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 { @@ -1090,7 +1090,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1163,9 +1163,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1198,11 +1198,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From aee54d0fd94a09a0bd392893075e8bd7a666030e Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 6 Apr 2023 03:42:55 +0000 Subject: [PATCH 0703/1120] Published maven/2.36.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f311a22ccb..df994a2b44 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.36.0] - 2023-04-06 ### Added * `removeUnusedImport` can be configured to rely on `cleanthat-javaparser-unnecessaryimport`. Default remains `google-java-format`. ([#1589](https://github.com/diffplug/spotless/pull/1589)) * The `style` option in Palantir Java Format ([#1654](https://github.com/diffplug/spotless/pull/1654)). diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 9ffd6f10b8..b4d7393e21 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.35.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.35.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.36.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.36.0/index.html) ${project.basedir}/scalafmt.conf - 2.13 + 2.13 ``` From c562a976dfb1e1963fe7ad80613dd708867a09c9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 7 Apr 2023 16:22:34 +0000 Subject: [PATCH 0718/1120] chore(deps): update plugin com.gradle.plugin-publish to v1.2.0 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 7386b911eb..6d80b0b38a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,7 +8,7 @@ pluginManagement { plugins { id 'com.diffplug.spotless' version '6.18.0' apply false // https://plugins.gradle.org/plugin/com.gradle.plugin-publish - id 'com.gradle.plugin-publish' version '1.1.0' apply false + id 'com.gradle.plugin-publish' version '1.2.0' apply false // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases From cdb0ec62b99845b360281ae0d9284f1cbb072105 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 10:13:00 +0100 Subject: [PATCH 0719/1120] Fix changes.md + Architecture visibility --- CHANGES.md | 3 ++- .../main/java/com/diffplug/spotless/rome/Architecture.java | 2 +- plugin-gradle/CHANGES.md | 4 +++- plugin-maven/CHANGES.md | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 57b831b8ad..a5d783b64b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,12 +11,13 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +* * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. https://github.com/diffplug/spotless/pull/1663 + ## [2.38.0] - 2023-04-06 ### 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)). -* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. https://github.com/diffplug/spotless/pull/1663 ### 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 `cleanthat` version to latest `2.6` -> `2.13`. ([#1589](https://github.com/diffplug/spotless/pull/1589) and [#1661](https://github.com/diffplug/spotless/pull/1661)) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java b/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java index 064bd52b32..1207f2ddc7 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java @@ -3,7 +3,7 @@ /** * Enumeration of possible computer architectures. */ -public enum Architecture { +enum Architecture { /** The arm64 architecture */ ARM64, /** Either x64 or x64_32 architecture */ diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 4fb0d57e14..9fa9415dd9 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. https://github.com/diffplug/spotless/pull/1663 + ## [6.18.0] - 2023-04-06 ### Added * `removeUnusedImport` can be configured to rely on `cleanthat-javaparser-unnecessaryimport`. Default remains `google-java-format`. ([#1589](https://github.com/diffplug/spotless/pull/1589)) @@ -19,7 +21,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)). -* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. https://github.com/diffplug/spotless/pull/1663 + ### Fixed * Stop using deprecated conventions when used in Gradle >= `7.1`. ([#1618](https://github.com/diffplug/spotless/pull/1618)) ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f0134bc2f2..7d79f14784 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,13 +3,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. https://github.com/diffplug/spotless/pull/1663### Fixed ## [2.36.0] - 2023-04-06 ### Added * `removeUnusedImport` can be configured to rely on `cleanthat-javaparser-unnecessaryimport`. Default remains `google-java-format`. ([#1589](https://github.com/diffplug/spotless/pull/1589)) * 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)). -* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. https://github.com/diffplug/spotless/pull/1663### Fixed + * Fix non deterministic computation of cache fingerprint when using multiple formatters. ([#1643](https://github.com/diffplug/spotless/pull/1643) fixes [#1642](https://github.com/diffplug/spotless/pull/1642)) ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) From 404b80efde56dbd6f47ceb30c35e9fafe06b1f87 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sat, 8 Apr 2023 13:38:33 +0400 Subject: [PATCH 0720/1120] Accept -SNAPSHOT versions --- CHANGES.md | 1 + lib/src/main/java/com/diffplug/spotless/Jvm.java | 6 +++++- testlib/src/test/java/com/diffplug/spotless/JvmTest.java | 8 ++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8540a44851..ee53a0ac21 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] ### Changes * We are now opting in to Gradle's new stable configuration cache. ([#1591](https://github.com/diffplug/spotless/pull/1591)) +* `Jvm.Support` now accepts `-SNAPSHOT` versions, treated as the non`-SNAPSHOT`. ([#1583](https://github.com/diffplug/spotless/issues/1583)) ## [2.36.0] - 2023-02-27 ### Added diff --git a/lib/src/main/java/com/diffplug/spotless/Jvm.java b/lib/src/main/java/com/diffplug/spotless/Jvm.java index c9c71b72df..077dbb1366 100644 --- a/lib/src/main/java/com/diffplug/spotless/Jvm.java +++ b/lib/src/main/java/com/diffplug/spotless/Jvm.java @@ -243,7 +243,11 @@ public int compare(V version0, V version1) { private static int[] convert(V versionObject) { try { - return Arrays.asList(versionObject.toString().split("\\.")).stream().mapToInt(Integer::parseInt).toArray(); + String versionString = versionObject.toString(); + if (versionString.endsWith("-SNAPSHOT")) { + versionString = versionString.substring(0, versionString.length() - "-SNAPSHOT".length()); + } + return Arrays.asList(versionString.split("\\.")).stream().mapToInt(Integer::parseInt).toArray(); } catch (Exception e) { throw new IllegalArgumentException(String.format("Not a semantic version: %s", versionObject), e); } diff --git a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java index ca7fb71305..1c966c51f4 100644 --- a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java @@ -93,7 +93,7 @@ void supportListsMinimumJvmIfOnlyHigherJvmSupported() { assertNull(testSupport.getRecommendedFormatterVersion(), "No formatter version is supported"); - for (String fmtVersion : Arrays.asList("1.2", "1.2.3")) { + for (String fmtVersion : Arrays.asList("1.2", "1.2.3", "1.2-SNAPSHOT", "1.2.3-SNAPSHOT")) { String proposal = assertThrows(Exception.class, () -> { testSupport.assertFormatterSupported(fmtVersion); }).getMessage(); @@ -111,7 +111,7 @@ void supportListsMinimumJvmIfOnlyHigherJvmSupported() { assertThat(proposal).contains(String.format("try %s alternatives", TEST_NAME)); } - for (String fmtVersion : Arrays.asList("1.2.4", "2")) { + for (String fmtVersion : Arrays.asList("1.2.4", "2", "1.2.5-SNAPSHOT")) { String proposal = assertThrows(Exception.class, () -> { testSupport.assertFormatterSupported(fmtVersion); }).getMessage(); @@ -132,7 +132,7 @@ void supportProposesFormatterUpgrade() { testSupport.add(Jvm.version() - 2, "1"); testSupport.add(requiredJvm, "2"); testSupport.add(Jvm.version() + 1, "3"); - for (String fmtVersion : Arrays.asList("0", "1", "1.9")) { + for (String fmtVersion : Arrays.asList("0", "1", "1.9", "1.9-SNAPSHOT")) { testSupport.assertFormatterSupported(fmtVersion); String proposal = assertThrows(Exception.class, () -> { @@ -168,7 +168,7 @@ void supportProposesJvmUpgrade() { @Test void supportAllowsExperimentalVersions() { testSupport.add(Jvm.version(), "1.0"); - for (String fmtVersion : Arrays.asList("1", "2.0")) { + for (String fmtVersion : Arrays.asList("1", "2.0", "1.1-SNAPSHOT", "2.0-SNAPSHOT")) { testSupport.assertFormatterSupported(fmtVersion); Exception testException = new Exception("Some test exception"); From a15849312327fdb7947be704b227628041f2eb15 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 13:54:12 +0100 Subject: [PATCH 0721/1120] Support formatting JSON files with Rome --- README.md | 1 + .../com/diffplug/spotless/rome/RomeStep.java | 207 +++++++++++++++--- .../diffplug/spotless/maven/FileLocator.java | 4 +- .../spotless/maven/generic/Format.java | 4 + .../diffplug/spotless/maven/generic/Rome.java | 34 +++ .../spotless/maven/javascript/RomeJs.java | 132 +---------- .../diffplug/spotless/maven/json/Json.java | 3 + .../spotless/maven/json/RomeJson.java | 13 ++ .../spotless/maven/rome/AbstractRome.java | 173 +++++++++++++++ .../spotless/maven/typescript/RomeTs.java | 13 ++ .../spotless/maven/typescript/Typescript.java | 3 +- 11 files changed, 422 insertions(+), 165 deletions(-) create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java diff --git a/README.md b/README.md index 52628574d9..001b00b5e2 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('pom.SortPomStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', +lib('rome.RomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java index 1d67743f41..820d1af66e 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java @@ -37,18 +37,38 @@ public class RomeStep { */ private final String configPath; + /** + * The language (syntax) of the input files to format. When null or + * the empty string, the language is detected automatically from the file name. + * Currently the following languages are supported by Rome: + *
    + *
  • js (JavaScript)
  • + *
  • jsx (JavaScript + JSX)
  • + *
  • js? (JavaScript or JavaScript + JSX, depending on the file + * extension)
  • + *
  • ts (TypeScript)
  • + *
  • tsx (TypeScript + JSX)
  • + *
  • ts? (TypeScript or TypeScript + JSX, depending on the file + * extension)
  • + *
  • json (JSON)
  • + *
+ */ + private final String language; + /** * Path to the Rome executable. Can be null, but either a path to - * the executable of a download directory and version must be given. + * the executable of a download directory and version must be given. The path + * must be either an absolute path, or a file name without path separators. If + * the latter, it is interpreted as a command in the user's path. */ private final String pathToExe; /** - * Path to the download directory for storing the download Rome executable. Can - * be null, but either a path to the executable of a download - * directory and version must be given. + * Absolute path to the download directory for storing the download Rome + * executable. Can be null, but either a path to the executable of + * a download directory and version must be given. */ - private final String pathToExeDownloadDir; + private final String downloadDir; /** * Version of Rome to download. Can be null, but either a path to @@ -71,9 +91,8 @@ public static String name() { * @param downloadDir Directory where to place the downloaded executable. * @return A new Rome step that download the executable from the network. */ - public static RomeStep withExeDownload(String version, String downloadDir) { - version = version != null && !version.isBlank() ? version : defaultVersion(); - return new RomeStep(version, null, downloadDir, null); + public static RomeStep.Builder withExeDownload(String version, String downloadDir) { + return new RomeStep.Builder(version, null, downloadDir); } /** @@ -83,8 +102,8 @@ public static RomeStep withExeDownload(String version, String downloadDir) { * @param pathToExe Path to the Rome executable to use. * @return A new Rome step that format with the given executable. */ - public static RomeStep withExePath(String pathToExe) { - return new RomeStep(null, pathToExe, null, null); + public static RomeStep.Builder withExePath(String pathToExe) { + return new RomeStep.Builder(null, pathToExe, null); } /** @@ -180,14 +199,16 @@ private static void validateRomeExecutable(String resolvedPathToExe) { } /** - * Checks the Rome executable. When the executable path does not exist, an error - * is thrown. + * Creates a new Rome step with the configuration from the given builder. + * + * @param builder Builder with the configuration to use. */ - private RomeStep(String version, String pathToExe, String pathToExeDownloadDir, String configPath) { - this.version = version; - this.pathToExe = pathToExe; - this.pathToExeDownloadDir = pathToExeDownloadDir; - this.configPath = configPath; + private RomeStep(RomeStep.Builder builder) { + this.version = builder.version != null && !builder.version.isBlank() ? builder.version : defaultVersion(); + this.pathToExe = builder.pathToExe; + this.downloadDir = builder.downloadDir; + this.configPath = builder.configPath; + this.language = builder.language; } /** @@ -200,19 +221,6 @@ public FormatterStep create() { return FormatterStep.createLazy(name(), this::createState, State::toFunc); } - /** - * Derives a new Rome step from this step by replacing the config path with the - * given value. - * - * @param configPath Config path to use. Must point to a directory which contain - * a file named {@code rome.json}. - * @return A new Rome step with the same configuration as this step, but with - * the given config file instead. - */ - public RomeStep withConfigPath(String configPath) { - return new RomeStep(version, pathToExe, pathToExeDownloadDir, configPath); - } - /** * Resolves the Rome executable, possibly downloading it from the network, and * creates a new state instance with the resolved executable that can format @@ -234,7 +242,7 @@ private State createState() throws IOException, InterruptedException { logger.debug("Using Rome executable located at '{}'", resolvedPathToExe); var exeSignature = FileSignature.signAsList(Collections.singleton(new File(resolvedPathToExe))); makeExecutable(resolvedPathToExe); - return new State(resolvedPathToExe, exeSignature, configPath); + return new State(resolvedPathToExe, exeSignature, configPath, language); } /** @@ -261,13 +269,95 @@ private String resolveExe() throws IOException, InterruptedException { return pathToExe; } } else { - var downloader = new RomeExecutableDownloader(Paths.get(pathToExeDownloadDir)); + var downloader = new RomeExecutableDownloader(Paths.get(downloadDir)); var downloaded = downloader.ensureDownloaded(version).toString(); makeExecutable(downloaded); return downloaded; } } + public final static class Builder { + /** See {@link RomeStep#configPath} */ + private String configPath; + + /** See {@link RomeStep#downloadDir} */ + private final String downloadDir; + + /** See {@link RomeStep#language} */ + private String language; + + /** See {@link RomeStep#pathToExe} */ + private final String pathToExe; + + /** See {@link RomeStep#version} */ + private final String version; + + /** + * Creates a new builder for configuring a Rome step that can format code via + * Rome. Either a version and and downloadDir, or a pathToExe must be given. + * + * @param version The version of Rome to download, see + * {@link RomeStep#version}. + * @param pathToExe The path to the Rome executable to use, see + * {@link RomeStep#pathToExe}. + * @param downloadDir The path to the download directory when downloading Rome + * from the network, {@link RomeStep#downloadDir}. + */ + private Builder(String version, String pathToExe, String downloadDir) { + this.version = version; + this.pathToExe = pathToExe; + this.downloadDir = downloadDir; + } + + /** + * Creates a new Rome step for formatting code with Rome from the current + * configuration of this builder. + * + * @return A new Rome step with the current configuration. + */ + public RomeStep build() { + return new RomeStep(this); + } + + /** + * Sets the path to the directory with the {@code rome.json} config file. When + * no config path is set, the default configuration is used. + * + * @param configPath Config path to use. Must point to a directory which contain + * a file named {@code rome.json}. + * @return This builder instance for chaining method calls. + */ + public Builder withConfigPath(String configPath) { + this.configPath = configPath; + return this; + } + + /** + * Sets the language of the files to format When no language is set, it is + * determined automatically from the file name. The following languages are + * currently supported by Rome. + * + *
    + *
  • js (JavaScript)
  • + *
  • jsx (JavaScript + JSX)
  • + *
  • js? (JavaScript or JavaScript + JSX, depending on the file + * extension)
  • + *
  • ts (TypeScript)
  • + *
  • tsx (TypeScript + JSX)
  • + *
  • ts? (TypeScript or TypeScript + JSX, depending on the file + * extension)
  • + *
  • json (JSON)
  • + *
+ * + * @param language The language of the files to format. + * @return This builder instance for chaining method calls. + */ + public Builder withLanguage(String language) { + this.language = language; + return this; + } + } + /** * The internal state used by the Rome formatter. A state instance is created * when the spotless plugin for Maven or Gradle is executed, and reused for all @@ -293,6 +383,12 @@ private static class State implements Serializable { */ private final String configPath; + /** + * The language of the files to format. When null or the empty + * string, the language is detected from the file name. + */ + private final String language; + /** * Creates a new state for instance which can format code with the given Rome * executable. @@ -303,10 +399,11 @@ private static class State implements Serializable { * config file, can be null, in which case the * defaults are used. */ - private State(String exe, FileSignature exeSignature, String configPath) { + private State(String exe, FileSignature exeSignature, String configPath, String language) { this.pathToExe = exe; this.exeSignature = exeSignature; this.configPath = configPath; + this.language = language; } /** @@ -317,11 +414,12 @@ private State(String exe, FileSignature exeSignature, String configPath) { * @return The Rome command to use for formatting code. */ private String[] buildRomeCommand(File file) { + var fileName = resolveFileName(file); var argList = new ArrayList(); argList.add(pathToExe); argList.add("format"); argList.add("--stdin-file-path"); - argList.add(file.getName()); + argList.add(fileName); if (configPath != null) { argList.add("--config-path"); argList.add(configPath); @@ -352,6 +450,47 @@ private String format(ProcessRunner runner, String input, File file) throws IOEx return runner.exec(stdin, args).assertExitZero(StandardCharsets.UTF_8); } + /** + * The Rome executable currently does not have a parameter to specify the + * expected language / syntax. Rome always determined the language from the file + * extension. This method returns the file name for the desired language when a + * language was requested explicitly, or the file name of the input file for + * auto detection. + * + * @param file File to be formatted. + * @return The file name to pass to the Rome executable. + */ + private String resolveFileName(File file) { + var name = file.getName(); + if (language == null || language.isBlank()) { + return name; + } + var dot = name.lastIndexOf("."); + var ext = dot >= 0 ? name.substring(dot + 1) : name; + switch (language) { + case "js?": + return "jsx".equals(ext) || "js".equals(ext) || "mjs".equals(ext) || "cjs".equals(ext) ? name + : "file.js"; + case "ts?": + return "tsx".equals(ext) || "ts".equals(ext) || "tjs".equals(ext) || "tjs".equals(ext) ? name + : "file.js"; + case "js": + return "js".equals(ext) || "mjs".equals(ext) || "cjs".equals(ext) ? name : "file.js"; + case "jsx": + return "jsx".equals(ext) ? name : "file.jsx"; + case "ts": + return "ts".equals(ext) || "mts".equals(ext) || "cts".equals(ext) ? name : "file.ts"; + case "tsx": + return "tsx".equals(ext) ? name : "file.tsx"; + case "json": + return "json".equals(ext) ? name : "file.json"; + // so that we can support new languages such as css or yaml when Rome adds + // support for them without having to change the code + default: + return "file." + language; + } + } + /** * Creates a new formatter function for formatting a piece of code by delegating * to the Rome executable. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java index 3e6d4cfeae..7def4423f8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java @@ -30,7 +30,7 @@ import org.codehaus.plexus.resource.loader.ResourceNotFoundException; import org.codehaus.plexus.util.FileUtils; -import com.diffplug.spotless.maven.javascript.RomeJs; +import com.diffplug.spotless.maven.rome.AbstractRome; public class FileLocator { @@ -122,7 +122,7 @@ private static byte[] hash(String value) { private static File findDataDir() { // E.g. ~/.m2/repository/com/diffplug/spotless/spotless-plugin-maven/1.2.3/spotless-plugin-maven-1.2.3.jar - final var jarPath = Paths.get(RomeJs.class.getProtectionDomain().getCodeSource().getLocation().getPath()); + final var jarPath = Paths.get(AbstractRome.class.getProtectionDomain().getCodeSource().getLocation().getPath()); final var base = jarPath.getParent().getParent().getParent(); final var sub = base.resolve("spotless-data"); return sub.toAbsolutePath().toFile(); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java index a696e13ffb..6cf843255a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java @@ -40,4 +40,8 @@ public String licenseHeaderDelimiter() { // do not specify a default delimiter return null; } + + public void addRome(Rome rome) { + addStepFactory(rome); + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java new file mode 100644 index 0000000000..b3d645f9e6 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java @@ -0,0 +1,34 @@ +package com.diffplug.spotless.maven.generic; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.maven.rome.AbstractRome; + +/** + * Generic Rome formatter step that detects the language of the input file from + * the file name. It should be specified as a formatter step for a generic + * {@code }. + */ +public class Rome extends AbstractRome { + /** + * Gets the language (syntax) of the input files to format. When + * null or the empty string, the language is detected automatically + * from the file name. Currently the following languages are supported by Rome: + *
    + *
  • js (JavaScript)
  • + *
  • jsx (JavaScript + JSX)
  • + *
  • ts (TypeScript)
  • + *
  • tsx (TypeScript + JSX)
  • + *
  • json (JSON)
  • + *
+ * + * @return The language of the input files. + */ + @Parameter + private String language; + + @Override + protected String getLanguage() { + return language; + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java index 4a4a57c646..11467a2820 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java @@ -1,135 +1,13 @@ package com.diffplug.spotless.maven.javascript; -import java.nio.file.Paths; - -import org.apache.maven.plugins.annotations.Parameter; - -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.maven.FormatterStepConfig; -import com.diffplug.spotless.maven.FormatterStepFactory; -import com.diffplug.spotless.rome.RomeStep; +import com.diffplug.spotless.maven.rome.AbstractRome; /** - * Factory for creating the Rome formatter step that formats JavaScript and - * TypeScript code with Rome: - * https://github.com/rome/tools. - * It delegates to the Rome executable. + * Rome formatter step for JavaScript. */ -public class RomeJs implements FormatterStepFactory { - /** - * Optional path to the directory with configuration file for Rome. The file - * must be named {@code rome.json}. When none is given, the default - * configuration is used. If this is a relative path, it is resolved against the - * project's base directory. - */ - @Parameter - private String configPath; - - /** - * Optional directory where the downloaded Rome executable is placed. If this is - * a relative path, it is resolved against the project's base directory. - * Defaults to - * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. - *

- * You can use an expression like ${user.home}/rome if you want to - * use the home directory, or ${project.build.directory if you want - * to use the target directory of the current project. - */ - @Parameter - private String downloadDir; - - /** - * Optional path to the Rome executable. Either a version or a - * pathToExe should be specified. When not given, an attempt is - * made to download the executable for the given version from the network. When - * given, the executable is used and the version parameter is - * ignored. - *

- * When an absolute path is given, that path is used as-is. When a relative path - * is given, it is resolved against the project's base directory. When only a - * file name (i.e. without any slashes or back slash path separators such as - * {@code rome}) is given, this is interpreted as the name of a command with - * executable that is in your {@code path} environment variable. Use - * {@code ./executable-name} if you want to use an executable in the project's - * base directory. - */ - @Parameter - private String pathToExe; - - /** - * Rome version to download, applies only when no pathToExe is - * specified explicitly. Either a version or a - * pathToExe should be specified. When not given, a default known - * version is used. For stable builds, it is recommended that you always set the - * version explicitly. This parameter is ignored when you specify a - * pathToExe explicitly. - */ - @Parameter - private String version; - +public class RomeJs extends AbstractRome { @Override - public FormatterStep newFormatterStep(FormatterStepConfig config) { - RomeStep rome; - if (pathToExe != null) { - var resolvedExePath = resolveExePath(config); - rome = RomeStep.withExePath(resolvedExePath); - } else { - var downloadDir = resolveDownloadDir(config); - rome = RomeStep.withExeDownload(version, downloadDir); - } - if (configPath != null) { - var resolvedConfigFile = resolveConfigFile(config); - rome = rome.withConfigPath(resolvedConfigFile); - } - return rome.create(); - } - - /** - * Resolves the path to the configuration file for Rome. Relative paths are - * resolved against the project's base directory. - * - * @param config Configuration from the Maven Mojo execution with details about - * the currently executed project. - * @return The resolved path to the configuration file. - */ - private String resolveConfigFile(FormatterStepConfig config) { - return config.getFileLocator().getBaseDir().toPath().resolve(configPath).toAbsolutePath().toString(); - } - - /** - * Resolves the path to the Rome executable. When the path is only a file name, - * do not perform any resolution and interpret it as a command that must be on - * the user's path. Otherwise resolve the executable path against the project's - * base directory. - * - * @param config Configuration from the Maven Mojo execution with details about - * the currently executed project. - * @return The resolved path to the Rome executable. - */ - private String resolveExePath(FormatterStepConfig config) { - var path = Paths.get(pathToExe); - if (path.getNameCount() == 1) { - return path.toString(); - } else { - return config.getFileLocator().getBaseDir().toPath().resolve(path).toAbsolutePath().toString(); - } - } - - /** - * Resolves the directory to use for storing downloaded Rome executable. When a - * {@link #downloadDir} is given, use that directory, resolved against the - * current project's directory. Otherwise, use the {@code Rome} sub folder in - * the shared data directory. - * - * @param config Configuration for this step. - * @return The download directory for the Rome executable. - */ - private String resolveDownloadDir(FormatterStepConfig config) { - final var fileLocator = config.getFileLocator(); - if (downloadDir != null && !downloadDir.isBlank()) { - return fileLocator.getBaseDir().toPath().resolve(downloadDir).toAbsolutePath().toString(); - } else { - return fileLocator.getDataDir().toPath().resolve("rome").toString(); - } + protected String getLanguage() { + return "js?"; } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index 5bb7c17b3a..adbb2b7883 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -50,4 +50,7 @@ public void addJackson(JacksonJson jackson) { addStepFactory(jackson); } + public void addRome(RomeJson rome) { + addStepFactory(rome); + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java new file mode 100644 index 0000000000..df75b7ffbe --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java @@ -0,0 +1,13 @@ +package com.diffplug.spotless.maven.json; + +import com.diffplug.spotless.maven.rome.AbstractRome; + +/** + * Rome formatter step for JSON. + */ +public class RomeJson extends AbstractRome { + @Override + protected String getLanguage() { + return "json"; + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java new file mode 100644 index 0000000000..c9e28ea9b3 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java @@ -0,0 +1,173 @@ +package com.diffplug.spotless.maven.rome; + +import java.nio.file.Paths; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.rome.RomeStep; +import com.diffplug.spotless.rome.RomeStep.Builder; + +/** + * Factory for creating the Rome formatter step that can format format code in + * various types of language with Rome. Currently Rome support JavaScript, + * TypeScript, JSX, TSX, and JSON. See also + * https://github.com/rome/tools. + * It delegates to the Rome CLI executable. + */ +public abstract class AbstractRome implements FormatterStepFactory { + /** + * Optional path to the directory with configuration file for Rome. The file + * must be named {@code rome.json}. When none is given, the default + * configuration is used. If this is a relative path, it is resolved against the + * project's base directory. + */ + @Parameter + private String configPath; + + /** + * Optional directory where the downloaded Rome executable is placed. If this is + * a relative path, it is resolved against the project's base directory. + * Defaults to + * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + *

+ * You can use an expression like ${user.home}/rome if you want to + * use the home directory, or ${project.build.directory if you want + * to use the target directory of the current project. + */ + @Parameter + private String downloadDir; + + /** + * Optional path to the Rome executable. Either a version or a + * pathToExe should be specified. When not given, an attempt is + * made to download the executable for the given version from the network. When + * given, the executable is used and the version parameter is + * ignored. + *

+ * When an absolute path is given, that path is used as-is. When a relative path + * is given, it is resolved against the project's base directory. When only a + * file name (i.e. without any slashes or back slash path separators such as + * {@code rome}) is given, this is interpreted as the name of a command with + * executable that is in your {@code path} environment variable. Use + * {@code ./executable-name} if you want to use an executable in the project's + * base directory. + */ + @Parameter + private String pathToExe; + + /** + * Rome version to download, applies only when no pathToExe is + * specified explicitly. Either a version or a + * pathToExe should be specified. When not given, a default known + * version is used. For stable builds, it is recommended that you always set the + * version explicitly. This parameter is ignored when you specify a + * pathToExe explicitly. + */ + @Parameter + private String version; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig config) { + var builder = newBuilder(config); + if (configPath != null) { + var resolvedConfigFile = resolveConfigFile(config); + builder.withConfigPath(resolvedConfigFile); + } + if (getLanguage() != null) { + builder.withLanguage(getLanguage()); + } + var step = builder.build(); + return step.create(); + } + + /** + * Gets the language (syntax) of the input files to format. When + * null or the empty string, the language is detected automatically + * from the file name. Currently the following languages are supported by Rome: + *

    + *
  • js (JavaScript)
  • + *
  • jsx (JavaScript + JSX)
  • + *
  • js? (JavaScript or JavaScript + JSX, depending on the file + * extension)
  • + *
  • ts (TypeScript)
  • + *
  • tsx (TypeScript + JSX)
  • + *
  • ts? (TypeScript or TypeScript + JSX, depending on the file + * extension)
  • + *
  • json (JSON)
  • + *
+ * + * @return The language of the input files. + */ + protected abstract String getLanguage(); + + /** + * A new builder for configuring a Rome step that either downloads the Rome + * executable with the given version from the network, or uses the executable + * from the given path. + * + * @param config Configuration from the Maven Mojo execution with details about + * the currently executed project. + * @return A builder for a Rome step. + */ + private Builder newBuilder(FormatterStepConfig config) { + if (pathToExe != null) { + var resolvedExePath = resolveExePath(config); + return RomeStep.withExePath(resolvedExePath); + } else { + var downloadDir = resolveDownloadDir(config); + return RomeStep.withExeDownload(version, downloadDir); + } + } + + /** + * Resolves the path to the configuration file for Rome. Relative paths are + * resolved against the project's base directory. + * + * @param config Configuration from the Maven Mojo execution with details about + * the currently executed project. + * @return The resolved path to the configuration file. + */ + private String resolveConfigFile(FormatterStepConfig config) { + return config.getFileLocator().getBaseDir().toPath().resolve(configPath).toAbsolutePath().toString(); + } + + /** + * Resolves the path to the Rome executable. When the path is only a file name, + * do not perform any resolution and interpret it as a command that must be on + * the user's path. Otherwise resolve the executable path against the project's + * base directory. + * + * @param config Configuration from the Maven Mojo execution with details about + * the currently executed project. + * @return The resolved path to the Rome executable. + */ + private String resolveExePath(FormatterStepConfig config) { + var path = Paths.get(pathToExe); + if (path.getNameCount() == 1) { + return path.toString(); + } else { + return config.getFileLocator().getBaseDir().toPath().resolve(path).toAbsolutePath().toString(); + } + } + + /** + * Resolves the directory to use for storing downloaded Rome executable. When a + * {@link #downloadDir} is given, use that directory, resolved against the + * current project's directory. Otherwise, use the {@code Rome} sub folder in + * the shared data directory. + * + * @param config Configuration for this step. + * @return The download directory for the Rome executable. + */ + private String resolveDownloadDir(FormatterStepConfig config) { + final var fileLocator = config.getFileLocator(); + if (downloadDir != null && !downloadDir.isBlank()) { + return fileLocator.getBaseDir().toPath().resolve(downloadDir).toAbsolutePath().toString(); + } else { + return fileLocator.getDataDir().toPath().resolve("rome").toString(); + } + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java new file mode 100644 index 0000000000..dfc736dc2a --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java @@ -0,0 +1,13 @@ +package com.diffplug.spotless.maven.typescript; + +import com.diffplug.spotless.maven.rome.AbstractRome; + +/** + * Rome formatter step for TypeScript. + */ +public class RomeTs extends AbstractRome { + @Override + protected String getLanguage() { + return "ts?"; + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index 929ea334b1..ddae74db82 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -21,7 +21,6 @@ import org.apache.maven.project.MavenProject; import com.diffplug.spotless.maven.FormatterFactory; -import com.diffplug.spotless.maven.javascript.RomeJs; /** * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. @@ -47,7 +46,7 @@ public void addEslint(EslintTs eslint) { addStepFactory(eslint); } - public void addRome(RomeJs rome) { + public void addRome(RomeTs rome) { addStepFactory(rome); } } From 7461c040fb7d15ecbfdcfc9f8992538b9f8a452b Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 13:57:09 +0100 Subject: [PATCH 0722/1120] Add rome to feature matrix --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 001b00b5e2..1809fc5d5f 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | | [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | +| [`rome.RomeStep`](lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | From 17b05d70894adfb3953bad7e78f461deab7cb3ea Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 17:19:57 +0100 Subject: [PATCH 0723/1120] Add rome() step to generic format for Gradle plugin --- .../gradle/spotless/FormatExtension.java | 309 ++++++++++++++++++ .../diffplug/spotless/maven/generic/Rome.java | 6 + 2 files changed, 315 insertions(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index fd613e82e1..b7c8dc2d2b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -22,6 +22,7 @@ import java.io.Serializable; import java.nio.charset.Charset; import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -37,6 +38,7 @@ import org.gradle.api.Action; import org.gradle.api.GradleException; import org.gradle.api.Project; +import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import org.gradle.api.file.ConfigurableFileTree; import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.BasePlugin; @@ -63,6 +65,7 @@ import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; +import com.diffplug.spotless.rome.RomeStep; import groovy.lang.Closure; @@ -648,6 +651,296 @@ protected FormatterStep createStep() { this.prettierConfig)); } } + + public abstract static class RomeStepConfig> { + /** + * Optional path to the directory with configuration file for Rome. The file + * must be named {@code rome.json}. When none is given, the default + * configuration is used. If this is a relative path, it is resolved against the + * project's base directory. + */ + @Nullable + private Object configPath; + + /** + * Optional directory where the downloaded Rome executable is placed. If this is + * a relative path, it is resolved against the project's base directory. + * Defaults to + * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + */ + @Nullable + private Object downloadDir; + + /** + * Optional path to the Rome executable. Either a version or a + * pathToExe should be specified. When not given, an attempt is + * made to download the executable for the given version from the network. When + * given, the executable is used and the version parameter is + * ignored. + *

+ * When an absolute path is given, that path is used as-is. When a relative path + * is given, it is resolved against the project's base directory. When only a + * file name (i.e. without any slashes or back slash path separators such as + * {@code rome}) is given, this is interpreted as the name of a command with + * executable that is in your {@code path} environment variable. Use + * {@code ./executable-name} if you want to use an executable in the project's + * base directory. + */ + @Nullable + private Object pathToExe; + + /** A reference to the Gradle project for which spotless is executed. */ + private final Project project; + + /** Replaces the current Rome formatter step with the given step. */ + private final Consumer replaceStep; + + /** + * Rome version to download, applies only when no pathToExe is + * specified explicitly. Either a version or a + * pathToExe should be specified. When not given, a default known + * version is used. For stable builds, it is recommended that you always set the + * version explicitly. This parameter is ignored when you specify a + * pathToExe explicitly. + */ + @Nullable + private String version; + + protected RomeStepConfig(Project project, Consumer replaceStep, String version) { + this.project = requireNonNull(project); + this.replaceStep = requireNonNull(replaceStep); + this.version = version; + } + + /** + * Optional path to the directory with configuration file for Rome. The file + * must be named {@code rome.json}. When none is given, the default + * configuration is used. If this is a relative path, it is resolved against the + * project's base directory. + * @return This step for further configuration. + */ + public Self configPath(Object configPath) { + this.configPath = configPath; + replaceStep(); + return getThis(); + } + + /** + * Optional directory where the downloaded Rome executable is placed. If this is + * a relative path, it is resolved against the project's base directory. + * Defaults to + * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + * @return This step for further configuration. + */ + public Self downloadDir(Object downloadDir) { + this.downloadDir = downloadDir; + replaceStep(); + return getThis(); + } + + /** + * Optional path to the Rome executable. Overwrites the configured version. No + * attempt is made to download the Rome executable from the network. + *

+ * When an absolute path is given, that path is used as-is. When a relative path + * is given, it is resolved against the project's base directory. When only a + * file name (i.e. without any slashes or back slash path separators such as + * {@code rome}) is given, this is interpreted as the name of a command with + * executable that is in your {@code path} environment variable. Use + * {@code ./executable-name} if you want to use an executable in the project's + * base directory. + * @return This step for further configuration. + */ + public Self pathToExe(Object pathToExe) { + this.pathToExe = pathToExe; + replaceStep(); + return getThis(); + } + + /** + * Creates a new formatter step that formats code by calling the Rome + * executable, using the current configuration. + * + * @return A new formatter step for the Rome formatter. + */ + protected FormatterStep createStep() { + var builder = newBuilder(); + if (configPath != null) { + var resolvedConfigPath = project.file(configPath); + builder.withConfigPath(resolvedConfigPath.toString()); + } + builder.withLanguage(getLanguage()); + var rome = builder.build(); + return rome.create(); + } + + /** + * Gets the language (syntax) of the input files to format. When + * null or the empty string, the language is detected automatically + * from the file name. Currently the following languages are supported by Rome: + *

    + *
  • js (JavaScript)
  • + *
  • jsx (JavaScript + JSX)
  • + *
  • js? (JavaScript or JavaScript + JSX, depending on the file + * extension)
  • + *
  • ts (TypeScript)
  • + *
  • tsx (TypeScript + JSX)
  • + *
  • ts? (TypeScript or TypeScript + JSX, depending on the file + * extension)
  • + *
  • json (JSON)
  • + *
+ * + * @return The language of the input files. + */ + protected abstract String getLanguage(); + + /** + * @return This Rome config instance. + */ + protected abstract Self getThis(); + + /** + * Creates a new Rome step and replaces the existing Rome step in the list of + * format steps. + */ + protected void replaceStep() { + replaceStep.accept(createStep()); + } + + /** + * Finds the data directory that can be used for storing shared data such as + * Rome executable globally. This is a directory in the local repository, e.g. + * ~/.m2/repository/com/diffplus/spotless/spotless-data. + * + * @return The directory for storing shared data. + */ + private File findDataDir() { + var currentRepo = project.getRepositories().stream() + .filter(r -> r instanceof MavenArtifactRepository) + .map(r -> (MavenArtifactRepository) r) + .filter(r -> "file".equals(r.getUrl().getScheme())) + .findAny().orElse(null); + // Temporarily add mavenLocal() repository to get its file URL + var localRepo = currentRepo != null ? (MavenArtifactRepository)currentRepo : project.getRepositories().mavenLocal(); + try { + // e.g. ~/.m2/repository/ + var repoPath = Paths.get(localRepo.getUrl().getPath()); + var dataPath = repoPath.resolve("com").resolve("diffplus").resolve("spotless").resolve("spotless-data"); + return dataPath.toAbsolutePath().toFile(); + } + finally { + // Remove mavenLocal() repository again if it was not part of the project + if (currentRepo == null) { + project.getRepositories().remove(localRepo); + } + } + } + + /** + * A new builder for configuring a Rome step that either downloads the Rome + * executable with the given version from the network, or uses the executable + * from the given path. + * + * @return A builder for a Rome step. + */ + private RomeStep.Builder newBuilder() { + if (pathToExe != null) { + var resolvedPathToExe = resolvePathToExe(); + return RomeStep.withExePath(resolvedPathToExe); + } else { + var downloadDir = resolveDownloadDir(); + return RomeStep.withExeDownload(version, downloadDir); + } + } + + /** + * Resolves the path to the Rome executable. When the path is only a file name, + * do not perform any resolution and interpret it as a command that must be on + * the user's path. Otherwise resolve the executable path against the project's + * base directory. + * + * @param config Configuration from the Maven Mojo execution with details about + * the currently executed project. + * @return The resolved path to the Rome executable. + */ + private String resolvePathToExe() { + var fileNameOnly = pathToExe instanceof String && Paths.get(pathToExe.toString()).getNameCount() == 1; + if (fileNameOnly) { + return pathToExe.toString(); + } else { + return project.file(pathToExe).toString(); + } + } + + /** + * Resolves the directory to use for storing downloaded Rome executable. When a + * {@link #downloadDir} is given, use that directory, resolved against the + * current project's directory. Otherwise, use the {@code Rome} sub folder in + * the shared data directory. + * + * @param config Configuration for this step. + * @return The download directory for the Rome executable. + */ + private String resolveDownloadDir() { + if (downloadDir != null) { + return project.file(downloadDir).toString(); + } else { + return findDataDir().toPath().resolve("rome").toString(); + } + } + } + + /** + * Generic Rome formatter step that detects the language of the input file from + * the file name. It should be specified as a formatter step for a generic + * format{ ... }. + */ + public class RomeGeneric extends RomeStepConfig { + @Nullable + String language; + + /** + * Creates a new Rome config that downloads the Rome executable for the given version from the network. + * @param version Rome version to use. The default version is used when null. + */ + public RomeGeneric(String version) { + super(getProject(), FormatExtension.this::replaceStep, version); + } + + /** + * Sets the language (syntax) of the input files to format. When + * null or the empty string, the language is detected automatically + * from the file name. Currently the following languages are supported by Rome: + *
    + *
  • js (JavaScript)
  • + *
  • jsx (JavaScript + JSX)
  • + *
  • js? (JavaScript or JavaScript + JSX, depending on the file + * extension)
  • + *
  • ts (TypeScript)
  • + *
  • tsx (TypeScript + JSX)
  • + *
  • ts? (TypeScript or TypeScript + JSX, depending on the file + * extension)
  • + *
  • json (JSON)
  • + *
+ * @param language The language of the files to format. + * @return This step for further configuration. + */ + public RomeGeneric language(String language) { + this.language = language; + replaceStep(); + return this; + } + + @Override + protected String getLanguage() { + return language; + } + + @Override + protected RomeGeneric getThis() { + return this; + } + } /** Uses the default version of prettier. */ public PrettierConfig prettier() { @@ -665,6 +958,22 @@ public PrettierConfig prettier(Map devDependencies) { addStep(prettierConfig.createStep()); return prettierConfig; } + + /** + * Defaults to downloading the default Rome version from the network. To work + * offline, you can specify the path to the Rome executable via + * {@code rome().pathToExe(...)}. + */ + public RomeGeneric rome() { + return rome(null); + } + + /** Downloads the given Rome version from the network. */ + public RomeGeneric rome(String version) { + var romeConfig = new RomeGeneric(version); + addStep(romeConfig.createStep()); + return romeConfig; + } /** Uses the default version of clang-format. */ public ClangFormatConfig clangFormat() { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java index b3d645f9e6..c39bb5df3b 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java @@ -15,12 +15,18 @@ public class Rome extends AbstractRome { * null or the empty string, the language is detected automatically * from the file name. Currently the following languages are supported by Rome: *
    + *
      *
    • js (JavaScript)
    • *
    • jsx (JavaScript + JSX)
    • + *
    • js? (JavaScript or JavaScript + JSX, depending on the file + * extension)
    • *
    • ts (TypeScript)
    • *
    • tsx (TypeScript + JSX)
    • + *
    • ts? (TypeScript or TypeScript + JSX, depending on the file + * extension)
    • *
    • json (JSON)
    • *
    + *
* * @return The language of the input files. */ From 7481a9bb86655be6b01f668bdecb524bd051073f Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 17:27:20 +0100 Subject: [PATCH 0724/1120] Add license header --- .../com/diffplug/spotless/rome/Architecture.java | 15 +++++++++++++++ .../main/java/com/diffplug/spotless/rome/OS.java | 15 +++++++++++++++ .../java/com/diffplug/spotless/rome/Platform.java | 15 +++++++++++++++ .../spotless/rome/RomeExecutableDownloader.java | 15 +++++++++++++++ .../java/com/diffplug/spotless/rome/RomeStep.java | 15 +++++++++++++++ .../com/diffplug/spotless/maven/generic/Rome.java | 15 +++++++++++++++ .../spotless/maven/javascript/RomeJs.java | 15 +++++++++++++++ .../diffplug/spotless/maven/json/RomeJson.java | 15 +++++++++++++++ .../spotless/maven/rome/AbstractRome.java | 15 +++++++++++++++ .../spotless/maven/typescript/RomeTs.java | 15 +++++++++++++++ 10 files changed, 150 insertions(+) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java b/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java index 1207f2ddc7..835bf8367a 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.rome; /** diff --git a/lib/src/main/java/com/diffplug/spotless/rome/OS.java b/lib/src/main/java/com/diffplug/spotless/rome/OS.java index c7b874bb24..cc5338ba0e 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/OS.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/OS.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.rome; import java.util.Locale; diff --git a/lib/src/main/java/com/diffplug/spotless/rome/Platform.java b/lib/src/main/java/com/diffplug/spotless/rome/Platform.java index 2631cf3131..8a551d1810 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/Platform.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/Platform.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.rome; /** diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java index 72df92224f..35bb4966c3 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.rome; import java.io.IOException; diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java index 820d1af66e..8ede197a36 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.rome; import java.io.File; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java index c39bb5df3b..29b290a746 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.maven.generic; import org.apache.maven.plugins.annotations.Parameter; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java index 11467a2820..cf40f53f47 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.maven.javascript; import com.diffplug.spotless.maven.rome.AbstractRome; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java index df75b7ffbe..5b2eec6abb 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.maven.json; import com.diffplug.spotless.maven.rome.AbstractRome; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java index c9e28ea9b3..ccf253d770 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.maven.rome; import java.nio.file.Paths; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java index dfc736dc2a..21f182079b 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016-2022 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.maven.typescript; import com.diffplug.spotless.maven.rome.AbstractRome; From afd0edb6df7a708c39d6b5baab8d895c662306de Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 17:30:48 +0100 Subject: [PATCH 0725/1120] Run spotlessApply --- README.md | 2 +- .../diffplug/spotless/rome/Architecture.java | 4 +- .../java/com/diffplug/spotless/rome/OS.java | 6 +-- .../com/diffplug/spotless/rome/Platform.java | 6 +-- .../rome/RomeExecutableDownloader.java | 36 +++++++-------- .../com/diffplug/spotless/rome/RomeStep.java | 45 +++++++++---------- .../gradle/spotless/FormatExtension.java | 23 +++++----- .../diffplug/spotless/maven/FileLocator.java | 8 ++-- .../spotless/maven/generic/Format.java | 2 +- .../diffplug/spotless/maven/generic/Rome.java | 4 +- .../spotless/maven/javascript/RomeJs.java | 2 +- .../spotless/maven/json/RomeJson.java | 2 +- .../spotless/maven/rome/AbstractRome.java | 12 ++--- .../spotless/maven/typescript/RomeTs.java | 2 +- 14 files changed, 76 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 1809fc5d5f..aceb9c22e9 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`pom.SortPomStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | | [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | -| [`rome.RomeStep`](lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | +| [`rome.RomeStep`](lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | diff --git a/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java b/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java index 835bf8367a..64e0a94640 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -26,7 +26,7 @@ enum Architecture { /** * Attempts to guess the architecture of the environment running the JVM. - * + * * @return The best guess for the architecture. */ public static Architecture guess() { diff --git a/lib/src/main/java/com/diffplug/spotless/rome/OS.java b/lib/src/main/java/com/diffplug/spotless/rome/OS.java index cc5338ba0e..44c87d9ece 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/OS.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/OS.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -30,7 +30,7 @@ enum OS { /** * Attempts to guess the OS of the environment running the JVM. - * + * * @return The best guess for the architecture. * @throws IllegalStateException When the OS is either unsupported or no * information about the OS could be retrieved. @@ -53,4 +53,4 @@ public static OS guess() { return OS.LINUX; } } -} \ No newline at end of file +} diff --git a/lib/src/main/java/com/diffplug/spotless/rome/Platform.java b/lib/src/main/java/com/diffplug/spotless/rome/Platform.java index 8a551d1810..c50608830a 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/Platform.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/Platform.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -23,7 +23,7 @@ class Platform { /** * Attempts to guess the platform of the hosting environment running the JVM * machine. - * + * * @return The best guess for the current OS and architecture. * @throws IllegalStateException When no OS information is available, or when * the OS or architecture is unsupported. @@ -40,7 +40,7 @@ public static Platform guess() { /** * Creates a new Platform descriptor for the given OS and architecture. - * + * * @param os Operating system of the platform. * @param architecture Architecture of the platform. */ diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java index 35bb4966c3..c55a18f754 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -68,7 +68,7 @@ final class RomeExecutableDownloader { * {@link OpenOption Open options} for reading an existing file without write * access. */ - private static final OpenOption[] READ_OPTIONS = { StandardOpenOption.READ }; + private static final OpenOption[] READ_OPTIONS = {StandardOpenOption.READ}; /** * The pattern for {@link String#format(String, Object...) String.format()} for @@ -81,15 +81,15 @@ final class RomeExecutableDownloader { * {@link OpenOption Open options} for creating a new file, overwriting the * existing file if present. */ - private static final OpenOption[] WRITE_OPTIONS = { StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, - StandardOpenOption.WRITE }; + private static final OpenOption[] WRITE_OPTIONS = {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, + StandardOpenOption.WRITE}; private Path downloadDir; /** * Creates a new downloader for the Rome executable. The executable files are * stored in the given download directory. - * + * * @param downloadDir Directory where */ public RomeExecutableDownloader(Path downloadDir) { @@ -100,7 +100,7 @@ public RomeExecutableDownloader(Path downloadDir) { * Downloads the Rome executable for the current platform from the network to * the download directory. When the executable exists already, it is * overwritten. - * + * * @param version Desired Rome version. * @return The path to the Rome executable. * @throws IOException When the executable cannot be downloaded from @@ -140,7 +140,7 @@ public Path download(String version) throws IOException, InterruptedException { * directory, an attempt is made to download the Rome executable from the * network. When the executable exists already, no attempt to download it again * is made. - * + * * @param version Desired Rome version. * @return The path to the Rome executable. * @throws IOException When the executable cannot be downloaded from @@ -168,7 +168,7 @@ public Path ensureDownloaded(String version) throws IOException, InterruptedExce /** * Attempts to find the Rome executable for the current platform in the download * directory. No attempt is made to download the executable from the network. - * + * * @param version Desired Rome version. * @return The path to the Rome executable. * @throws IOException When the executable does not exists in the @@ -188,7 +188,7 @@ public Optional findDownloaded(String version) throws IOException { /** * Checks whether the given file exists and matches the checksum. The checksum * must be contained in a file next to the file to check. - * + * * @param filePath File to check. * @return true if the file exists and matches the checksum, * false otherwise. @@ -223,7 +223,7 @@ private boolean checkFileWithChecksum(Path filePath) { /** * Computes the checksum of the given file. - * + * * @param file File to process. * @param algorithm The checksum algorithm to use. * @return The MD5 checksum of the given file. @@ -247,7 +247,7 @@ private String computeChecksum(Path file, String algorithm) throws IOException { /** * Finds the code name for the given operating system used by the Rome * executable download URL. - * + * * @param os Desired operating system. * @return Code name for the Rome download URL. * @throws IOException When the given OS is not supported by Rome. @@ -265,7 +265,7 @@ private String getArchitectureCodeName(Architecture architecture) throws IOExcep /** * Derives a path for the file which contains the checksum of the given file. - * + * * @param file A file for which to derive the checksum file path. * @return The path with the checksum for the given file. */ @@ -275,7 +275,7 @@ private Path getChecksumPath(Path file) { /** * Finds the URL from which the Rome executable can be downloaded. - * + * * @param version Desired Rome version. * @param platform Desired platform. * @return The URL for the Rome executable. @@ -292,7 +292,7 @@ private String getDownloadUrl(String version, Platform platform) throws IOExcept /** * Finds the file extension of the Rome download URL for the given operating * system. - * + * * @param os Desired operating system. * @return Extension for the Rome download URL. * @throws IOException When the given OS is not supported by Rome. @@ -313,7 +313,7 @@ private String getDownloadUrlExtension(OS os) throws IOException { /** * Finds the path on the file system for the Rome executable with a given * version and platform. - * + * * @param version Desired Rome version. * @param platform Desired platform. * @return The path for the Rome executable. @@ -328,7 +328,7 @@ private Path getExecutablePath(String version, Platform platform) { /** * Finds the code name for the given operating system used by the Rome * executable download URL. - * + * * @param os Desired operating system. * @return Code name for the Rome download URL. * @throws IOException When the given OS is not supported by Rome. @@ -348,7 +348,7 @@ private String getOsCodeName(OS os) throws IOException { /** * Reads a plain text file with the given encoding into a string. - * + * * @param file File to read. * @param charset Encoding to use. * @return The contents of the file as a string. @@ -363,7 +363,7 @@ private String readTextFile(Path file, Charset charset) throws IOException { /** * Computes the checksum of the given file and writes it to the target checksum * file, using the {@code ISO_8859_1} encoding. - * + * * @param file * @param checksumPath * @throws IOException diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java index 8ede197a36..e48a78c2ba 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -101,7 +101,7 @@ public static String name() { /** * Creates a Rome step that format code by downloading to the given Rome * version. The executable is downloaded from the network. - * + * * @param version Version of the Rome executable to download. * @param downloadDir Directory where to place the downloaded executable. * @return A new Rome step that download the executable from the network. @@ -113,7 +113,7 @@ public static RomeStep.Builder withExeDownload(String version, String downloadDi /** * Creates a Rome step that formats code by delegating to the Rome executable * located at the given path. - * + * * @param pathToExe Path to the Rome executable to use. * @return A new Rome step that format with the given executable. */ @@ -125,7 +125,7 @@ public static RomeStep.Builder withExePath(String pathToExe) { * Attempts to add a POSIX permission to the given file, ignoring any errors. * All existing permissions on the file are preserved and the new permission is * added, if possible. - * + * * @param file File or directory to which to add a permission. * @param permission The POSIX permission to add. */ @@ -134,15 +134,14 @@ private static void attemptToAddPosixPermission(Path file, PosixFilePermission p var newPermissions = new HashSet<>(Files.getPosixFilePermissions(file)); newPermissions.add(permission); Files.setPosixFilePermissions(file, newPermissions); - } catch (final Exception ignore) { - } + } catch (final Exception ignore) {} } /** * Finds the default version for Rome when no version is specified explicitly. * Over time this will become outdated -- people should always specify the * version explicitly! - * + * * @return The default version for Rome. */ private static String defaultVersion() { @@ -154,7 +153,7 @@ private static String defaultVersion() { * any errors are swallowed. Depending on the OS, the file might still be * executable even if this method fails. The user will get a descriptive error * later when we attempt to execute the Rome executable. - * + * * @param filePath Path to the file to make executable. */ private static void makeExecutable(String filePath) { @@ -167,7 +166,7 @@ private static void makeExecutable(String filePath) { /** * Finds the absolute path of a command on the user's path. Uses {@code which} * for Linux and {@code where} for Windows. - * + * * @param name Name of the command to resolve. * @return The absolute path of the command's executable. * @throws IOException When the command could not be resolved. @@ -215,7 +214,7 @@ private static void validateRomeExecutable(String resolvedPathToExe) { /** * Creates a new Rome step with the configuration from the given builder. - * + * * @param builder Builder with the configuration to use. */ private RomeStep(RomeStep.Builder builder) { @@ -229,7 +228,7 @@ private RomeStep(RomeStep.Builder builder) { /** * Creates a formatter step with the current configuration, which formats code * by passing it to the Rome executable. - * + * * @return A new formatter step for formatting with Rome. */ public FormatterStep create() { @@ -240,7 +239,7 @@ public FormatterStep create() { * Resolves the Rome executable, possibly downloading it from the network, and * creates a new state instance with the resolved executable that can format * code via Rome. - * + * * @return The state instance for formatting code via Rome. * @throws IOException When any file system or network operations * failed, such as when the Rome executable could @@ -266,7 +265,7 @@ private State createState() throws IOException, InterruptedException { * used as-is. Otherwise, at attempt is made to download the Rome executable for * the configured version from the network, unless it was already downloaded and * is available in the cache. - * + * * @return The path to the resolved Rome executable. * @throws IOException When any file system or network operations * failed, such as when the Rome executable could @@ -310,7 +309,7 @@ public final static class Builder { /** * Creates a new builder for configuring a Rome step that can format code via * Rome. Either a version and and downloadDir, or a pathToExe must be given. - * + * * @param version The version of Rome to download, see * {@link RomeStep#version}. * @param pathToExe The path to the Rome executable to use, see @@ -327,7 +326,7 @@ private Builder(String version, String pathToExe, String downloadDir) { /** * Creates a new Rome step for formatting code with Rome from the current * configuration of this builder. - * + * * @return A new Rome step with the current configuration. */ public RomeStep build() { @@ -337,7 +336,7 @@ public RomeStep build() { /** * Sets the path to the directory with the {@code rome.json} config file. When * no config path is set, the default configuration is used. - * + * * @param configPath Config path to use. Must point to a directory which contain * a file named {@code rome.json}. * @return This builder instance for chaining method calls. @@ -351,7 +350,7 @@ public Builder withConfigPath(String configPath) { * Sets the language of the files to format When no language is set, it is * determined automatically from the file name. The following languages are * currently supported by Rome. - * + * *
    *
  • js (JavaScript)
  • *
  • jsx (JavaScript + JSX)
  • @@ -363,7 +362,7 @@ public Builder withConfigPath(String configPath) { * extension) *
  • json (JSON)
  • *
- * + * * @param language The language of the files to format. * @return This builder instance for chaining method calls. */ @@ -407,7 +406,7 @@ private static class State implements Serializable { /** * Creates a new state for instance which can format code with the given Rome * executable. - * + * * @param exe Path to the Rome executable. * @param exeSignature Signature (e.g. SHA-256 checksum) of the Rome executable. * @param configPath Path to the optional directory with the {@code rome.json} @@ -424,7 +423,7 @@ private State(String exe, FileSignature exeSignature, String configPath, String /** * Builds the list of arguments for the command that executes Rome to format a * piece of code passed via stdin. - * + * * @param file File to format. * @return The Rome command to use for formatting code. */ @@ -446,7 +445,7 @@ private String[] buildRomeCommand(File file) { * Formats the given piece of code by delegating to the Rome executable. The * code is passed to Rome via stdin, the file name is used by Rome only to * determine the code syntax (e.g. JavaScript or TypeScript). - * + * * @param runner Process runner for invoking the Rome executable. * @param input Code to format. * @param file File to format. @@ -471,7 +470,7 @@ private String format(ProcessRunner runner, String input, File file) throws IOEx * extension. This method returns the file name for the desired language when a * language was requested explicitly, or the file name of the input file for * auto detection. - * + * * @param file File to be formatted. * @return The file name to pass to the Rome executable. */ @@ -509,7 +508,7 @@ private String resolveFileName(File file) { /** * Creates a new formatter function for formatting a piece of code by delegating * to the Rome executable. - * + * * @return A formatter function for formatting code. */ private FormatterFunc.Closeable toFunc() { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index b7c8dc2d2b..c3c366f3ea 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -651,7 +651,7 @@ protected FormatterStep createStep() { this.prettierConfig)); } } - + public abstract static class RomeStepConfig> { /** * Optional path to the directory with configuration file for Rome. The file @@ -760,7 +760,7 @@ public Self pathToExe(Object pathToExe) { /** * Creates a new formatter step that formats code by calling the Rome * executable, using the current configuration. - * + * * @return A new formatter step for the Rome formatter. */ protected FormatterStep createStep() { @@ -789,7 +789,7 @@ protected FormatterStep createStep() { * extension) *
  • json (JSON)
  • * - * + * * @return The language of the input files. */ protected abstract String getLanguage(); @@ -806,12 +806,12 @@ protected FormatterStep createStep() { protected void replaceStep() { replaceStep.accept(createStep()); } - + /** * Finds the data directory that can be used for storing shared data such as * Rome executable globally. This is a directory in the local repository, e.g. * ~/.m2/repository/com/diffplus/spotless/spotless-data. - * + * * @return The directory for storing shared data. */ private File findDataDir() { @@ -821,14 +821,13 @@ private File findDataDir() { .filter(r -> "file".equals(r.getUrl().getScheme())) .findAny().orElse(null); // Temporarily add mavenLocal() repository to get its file URL - var localRepo = currentRepo != null ? (MavenArtifactRepository)currentRepo : project.getRepositories().mavenLocal(); + var localRepo = currentRepo != null ? (MavenArtifactRepository) currentRepo : project.getRepositories().mavenLocal(); try { // e.g. ~/.m2/repository/ var repoPath = Paths.get(localRepo.getUrl().getPath()); var dataPath = repoPath.resolve("com").resolve("diffplus").resolve("spotless").resolve("spotless-data"); return dataPath.toAbsolutePath().toFile(); - } - finally { + } finally { // Remove mavenLocal() repository again if it was not part of the project if (currentRepo == null) { project.getRepositories().remove(localRepo); @@ -840,7 +839,7 @@ private File findDataDir() { * A new builder for configuring a Rome step that either downloads the Rome * executable with the given version from the network, or uses the executable * from the given path. - * + * * @return A builder for a Rome step. */ private RomeStep.Builder newBuilder() { @@ -858,7 +857,7 @@ private RomeStep.Builder newBuilder() { * do not perform any resolution and interpret it as a command that must be on * the user's path. Otherwise resolve the executable path against the project's * base directory. - * + * * @param config Configuration from the Maven Mojo execution with details about * the currently executed project. * @return The resolved path to the Rome executable. @@ -877,7 +876,7 @@ private String resolvePathToExe() { * {@link #downloadDir} is given, use that directory, resolved against the * current project's directory. Otherwise, use the {@code Rome} sub folder in * the shared data directory. - * + * * @param config Configuration for this step. * @return The download directory for the Rome executable. */ @@ -958,7 +957,7 @@ public PrettierConfig prettier(Map devDependencies) { addStep(prettierConfig.createStep()); return prettierConfig; } - + /** * Defaults to downloading the default Rome version from the network. To work * offline, you can specify the path to the Rome executable via diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java index 7def4423f8..a8c3973dd3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -74,7 +74,7 @@ public File locateFile(String path) { /** * Finds the base directory of the Maven or Gradle project on which spotless is * currently being executed. - * + * * @return The base directory of the current Maven or Gradel project. */ public File getBaseDir() { @@ -84,7 +84,7 @@ public File getBaseDir() { /** * Finds the build directory (e.g. /target) of the Maven or Gradle * project on which spotless is currently being executed. - * + * * @return The project build directory of the current Maven or Gradle project. */ public File getBuildDir() { @@ -95,7 +95,7 @@ public File getBuildDir() { * Finds the data directory that can be used for storing shared data such as * downloaded files globally. This is a directory in the local repository, e.g. * ~/.m2/repository/com/diffplus/spotless/spotless-data. - * + * * @return The directory for storing shared data. */ public File getDataDir() { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java index 6cf843255a..ed08718c65 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java @@ -40,7 +40,7 @@ public String licenseHeaderDelimiter() { // do not specify a default delimiter return null; } - + public void addRome(Rome rome) { addStepFactory(rome); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java index 29b290a746..62d9d3fdec 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -42,7 +42,7 @@ public class Rome extends AbstractRome { *
  • json (JSON)
  • * * - * + * * @return The language of the input files. */ @Parameter diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java index cf40f53f47..60fb7077df 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java index 5b2eec6abb..1cd044b759 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java index ccf253d770..8af56c5a00 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -113,7 +113,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { * extension) *
  • json (JSON)
  • * - * + * * @return The language of the input files. */ protected abstract String getLanguage(); @@ -122,7 +122,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { * A new builder for configuring a Rome step that either downloads the Rome * executable with the given version from the network, or uses the executable * from the given path. - * + * * @param config Configuration from the Maven Mojo execution with details about * the currently executed project. * @return A builder for a Rome step. @@ -140,7 +140,7 @@ private Builder newBuilder(FormatterStepConfig config) { /** * Resolves the path to the configuration file for Rome. Relative paths are * resolved against the project's base directory. - * + * * @param config Configuration from the Maven Mojo execution with details about * the currently executed project. * @return The resolved path to the configuration file. @@ -154,7 +154,7 @@ private String resolveConfigFile(FormatterStepConfig config) { * do not perform any resolution and interpret it as a command that must be on * the user's path. Otherwise resolve the executable path against the project's * base directory. - * + * * @param config Configuration from the Maven Mojo execution with details about * the currently executed project. * @return The resolved path to the Rome executable. @@ -173,7 +173,7 @@ private String resolveExePath(FormatterStepConfig config) { * {@link #downloadDir} is given, use that directory, resolved against the * current project's directory. Otherwise, use the {@code Rome} sub folder in * the shared data directory. - * + * * @param config Configuration for this step. * @return The download directory for the Rome executable. */ diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java index 21f182079b..ccee83744a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. From 0afd327dd543cc343d8228877cc738a7d854e26f Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 17:51:11 +0100 Subject: [PATCH 0726/1120] Add rome format step to json/javascript/typescript languages --- .../gradle/spotless/FormatExtension.java | 6 +-- .../gradle/spotless/JavascriptExtension.java | 42 +++++++++++++++++++ .../gradle/spotless/JsonExtension.java | 41 ++++++++++++++++++ .../gradle/spotless/TypescriptExtension.java | 41 ++++++++++++++++++ 4 files changed, 127 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index c3c366f3ea..dbf45e87f1 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -232,7 +232,7 @@ protected final FileCollection parseTarget(Object target) { private final FileCollection parseTargetIsExclude(Object target, boolean isExclude) { if (target instanceof Collection) { - return parseTargetsIsExclude(((Collection) target).toArray(), isExclude); + return parseTargetsIsExclude(((Collection) target).toArray(), isExclude); } else if (target instanceof FileCollection) { return (FileCollection) target; } else if (target instanceof String) { @@ -963,12 +963,12 @@ public PrettierConfig prettier(Map devDependencies) { * offline, you can specify the path to the Rome executable via * {@code rome().pathToExe(...)}. */ - public RomeGeneric rome() { + public RomeStepConfig rome() { return rome(null); } /** Downloads the given Rome version from the network. */ - public RomeGeneric rome(String version) { + public RomeStepConfig rome(String version) { var romeConfig = new RomeGeneric(version); addStep(romeConfig.createStep()); return romeConfig; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index e8a76166bc..76ad5650ca 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -138,9 +138,51 @@ public PrettierConfig prettier(Map devDependencies) { return prettierConfig; } + /** + * Defaults to downloading the default Rome version from the network. To work + * offline, you can specify the path to the Rome executable via + * {@code rome().pathToExe(...)}. + */ + public RomeJs rome() { + return rome(null); + } + + /** Downloads the given Rome version from the network. */ + public RomeJs rome(String version) { + var romeConfig = new RomeJs(version); + addStep(romeConfig.createStep()); + return romeConfig; + } + private static final String DEFAULT_PRETTIER_JS_PARSER = "babel"; private static final ImmutableList PRETTIER_JS_PARSERS = ImmutableList.of(DEFAULT_PRETTIER_JS_PARSER, "babel-flow", "flow"); + /** + * Rome formatter step for JavaScript. + */ + public class RomeJs extends RomeStepConfig { + + /** + * Creates a new Rome formatter step config for formatting JavaScript files. Unless + * overwritten, the given Rome version is downloaded from the network. + * + * @param version Rome version to use. + */ + public RomeJs(String version) { + super(getProject(), JavascriptExtension.this::replaceStep, version); + } + + @Override + protected String getLanguage() { + return "js?"; + } + + @Override + protected RomeJs getThis() { + return this; + } + } + /** * Overrides the parser to be set to a js parser. */ diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 39b158ce1e..510ac529e8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -55,6 +55,22 @@ public JacksonJsonGradleConfig jackson() { return new JacksonJsonGradleConfig(this); } + /** + * Defaults to downloading the default Rome version from the network. To work + * offline, you can specify the path to the Rome executable via + * {@code rome().pathToExe(...)}. + */ + public RomeJson rome() { + return rome(null); + } + + /** Downloads the given Rome version from the network. */ + public RomeJson rome(String version) { + var romeConfig = new RomeJson(version); + addStep(romeConfig.createStep()); + return romeConfig; + } + public class SimpleConfig { private int indent; @@ -145,4 +161,29 @@ protected final FormatterStep createStep() { return JacksonJsonStep.create(jacksonConfig, version, formatExtension.provisioner()); } } + + /** + * Rome formatter step for JSON. + */ + public class RomeJson extends RomeStepConfig { + /** + * Creates a new Rome formatter step config for formatting JSON files. Unless + * overwritten, the given Rome version is downloaded from the network. + * + * @param version Rome version to use. + */ + public RomeJson(String version) { + super(getProject(), JsonExtension.this::replaceStep, version); + } + + @Override + protected String getLanguage() { + return "json"; + } + + @Override + protected RomeJson getThis() { + return this; + } + } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 9f1d04abfd..ddb7fbfc10 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -229,6 +229,47 @@ protected EslintConfig eslintConfig() { } } + /** + * Defaults to downloading the default Rome version from the network. To work + * offline, you can specify the path to the Rome executable via + * {@code rome().pathToExe(...)}. + */ + public RomeTs rome() { + return rome(null); + } + + /** Downloads the given Rome version from the network. */ + public RomeTs rome(String version) { + var romeConfig = new RomeTs(version); + addStep(romeConfig.createStep()); + return romeConfig; + } + + /** + * Rome formatter step for TypeScript. + */ + public class RomeTs extends RomeStepConfig { + /** + * Creates a new Rome formatter step config for formatting TypeScript files. Unless + * overwritten, the given Rome version is downloaded from the network. + * + * @param version Rome version to use. + */ + public RomeTs(String version) { + super(getProject(), TypescriptExtension.this::replaceStep, version); + } + + @Override + protected String getLanguage() { + return "ts?"; + } + + @Override + protected RomeTs getThis() { + return this; + } + } + @Override protected void setupTask(SpotlessTask task) { if (target == null) { From 8c71500b00aa0658ff92ca8b66601ea64649d31d Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 19:06:27 +0100 Subject: [PATCH 0727/1120] Add docs for Maven plugin --- plugin-maven/README.md | 151 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index b4d7393e21..b4c15f7fc2 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -57,6 +57,7 @@ user@machine repo % mvn spotless:check - 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) + - [Rome](#rome) ([binary detection](#rome-binary), [config file](#rome-configuration-file), [input language](#rome-input-language)) - **Language independent** - [Generic steps](#generic-steps) - [License header](#license-header) ([slurp year from git](#retroactively-slurp-years-from-git-history)) @@ -704,6 +705,7 @@ Currently, none of the available options can be configured yet. It uses only the + /* (C)$YEAR */ @@ -814,6 +816,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr + /* (C)$YEAR */ @@ -890,6 +893,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr +
    ``` @@ -1220,6 +1224,153 @@ to true. +## Rome + +[homepage](https://rome.tools/). [changelog](https://github.com/rome/tools/blob/main/CHANGELOG.md). Rome is a formatter that for the Frontend written in Rust, which has a native binary, +does not require Node.js and as such, is pretty fast. It can currently format +JavaScript, TypeScript, JSX, and JSON, and may support +[more frontend languages](https://docs.rome.tools/internals/language_support/) +such as CSS in the future. + +You can use rome in any language-specific format for supported languages, but +usually you will be creating a generic format. + +```xml + + + + + src/**/typescript/**/*.ts + + + + + 12.0.0 + + + ${project.basedir}/path/to/config/dir + + + + ts +
    + + + + +``` + +**Limitations:** +- The auto-discovery of config files (up the file tree) will not work when using + Rome within spotless. + +To apply Rome to more kinds of files, just add more formats + +```xml + + + src/**/*.ts + src/**/*.js +``` + +### Rome binary + +To format with Rome, spotless needs to find the Rome binary. By default, +spotless downloads the binary for the given version from the network. This +should be fine in most cases, but may not work e.g. when there is not connection +to the internet. + +To download the Rome binary from the network, just specify a version: + +```xml + + 12.0.0 + +``` + +Spotless uses a default version when you do not specfiy a version, but this +may change at any time, so we recommend that you always set the Rome version +you want to use. Optionally, you can also specify a directory for the downloaded +Rome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/rome`): + +```xml + + 12.0.0 + + ${user.home}/rome + +``` + +To use a fixed binary, omit the `version` and specify a `pathToExe`: + +```xml + + ${project.basedir}/bin/rome + +``` + +Absolute paths are used as-is. Relative paths are resolved against the project's +base directory. To use a pre-installed Rome binary on the user's path, specify +just a name without any slashes / backslashes: + + +```xml + + + rome + +``` + +### Rome configuration file + +Rome is a biased formatter and linter without many options, but there are a few +basic options. Rome uses a file named [rome.json](https://docs.rome.tools/configuration/) +for its configuration. When none is specified, the default configuration from +Rome is used. To use a custom configuration: + +```xml + + + + ${project.basedir} + +``` + +### Rome input Language + +By default, Rome detects the language / syntax of the files to format +automatically from the file extension. This may fail if your source code files +have unusual extensions for some reason. If you are using the generic format, +you can force a certain language like this: + +```xml + + + + + src/**/typescript/**/*.mjson + + + + 12.0.0 + json + + + + + +``` + +The following languages are currently recognized: + +* `js` -- JavaScript +* `jsx` -- JavaScript + JSX (React) +* `js?` -- JavaScript, with or without JSX, depending on the file extension +* `ts` -- TypeScript +* `tsx` -- TypeScript + JSX (React) +* `ts?` -- TypeScript, with or without JSX, depending on the file extension +* `json` -- JSON + ## Generic steps [Prettier](#prettier), [eclipse wtp](#eclipse-web-tools-platform), and [license header](#license-header) are available in every format, and they each have their own section. As mentioned in the [quickstart](#quickstart), there are a variety of simple generic steps which are also available in every format, here are examples of these: From 8fa9cdadfaf487ebba83d88fc522b6822433c2f0 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 19:30:16 +0100 Subject: [PATCH 0728/1120] Add docs for Gradle plugin --- plugin-gradle/README.md | 173 +++++++++++++++++++++++++++++++++++++++- plugin-maven/README.md | 8 +- 2 files changed, 176 insertions(+), 5 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index cea45a049f..f47c7a543f 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -75,6 +75,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - c, c++, c#, objective-c, protobuf, javascript, java - [eclipse web tools platform](#eclipse-web-tools-platform) - css, html, js, json, xml + - [Rome](#rome) ([binary detection](#rome-binary), [config file](#rome-configuration-file), [input language](#rome-input-language)) - **Language independent** - [Generic steps](#generic-steps) - [License header](#license-header) ([slurp year from git](#retroactively-slurp-years-from-git-history)) @@ -613,7 +614,8 @@ spotless { tsfmt() // has its own section below prettier() // has its own section below - eslint() // has its own section below + eslint() // has its own section below + rome() // has its own section below licenseHeader '/* (C) $YEAR */', '(import|const|declare|export|var) ' // or licenseHeaderFile // note the '(import|const|...' argument - this is a regex which identifies the top @@ -705,7 +707,8 @@ spotless { target 'src/**/*.js' // you have to set the target manually prettier() // has its own section below - eslint() // has its own section below + eslint() // has its own section below + rome() // has its own section below licenseHeader '/* (C) $YEAR */', 'REGEX_TO_DEFINE_TOP_OF_FILE' // or licenseHeaderFile } @@ -772,6 +775,7 @@ spotless { eclipseWtp('json') // see Eclipse web tools platform section gson() // has its own section below jackson() // has its own section below + rome() // has its own section below } } ``` @@ -1064,6 +1068,171 @@ Unlike Eclipse, Spotless WTP ignores per default external URIs in schema locatio external entities. To allow the access of external URIs, set the property `resolveExternalURI` to true. +## Rome + +[homepage](https://rome.tools/). [changelog](https://github.com/rome/tools/blob/main/CHANGELOG.md). Rome is a formatter that for the Frontend written in Rust, which has a native binary, +does not require Node.js and as such, is pretty fast. It can currently format +JavaScript, TypeScript, JSX, and JSON, and may support +[more frontend languages](https://docs.rome.tools/internals/language_support/) +such as CSS in the future. + +You can use rome in any language-specific format for supported languages, but +usually you will be creating a generic format. + +```gradle +spotless { + format 'styling', { + // you have to set the target manually + target 'src/*/webapp/**/*.js' + + // Download Rome from the network if not already downloaded, see below for more info + rome('12.0.0') + + // (optional) Path to the directory with the rome.json conig file + rome('12.0.0').configPath("path/config/dir") + + // (optional) Rome will auto detect the language based on the file extension. + // See below for possible values. + rome('12.0.0').language("js") + } +} +``` + +**Limitations:** +- The auto-discovery of config files (up the file tree) will not work when using + Rome within spotless. + +To apply Rome to more kinds of files with a different configuration, just add +more formats: + +```gradle +spotless { + format 'rome-js', { + target '**/*.js' + rome('12.0.0') + } + format 'rome-ts', { + target '**/*.ts' + rome('12.0.0') + } + format 'rome-json', { + target '**/*.json' + rome('12.0.0') + } +} +``` + +### Rome binary + +To format with Rome, spotless needs to find the Rome binary. By default, +spotless downloads the binary for the given version from the network. This +should be fine in most cases, but may not work e.g. when there is not connection +to the internet. + +To download the Rome binary from the network, just specify a version: + +```gradle +spotless { + format 'rome', { + target '**/*.js','**/*.ts','**/*.json' + rome('12.0.0') + } +} +``` + +Spotless uses a default version when you do not specfiy a version, but this +may change at any time, so we recommend that you always set the Rome version +you want to use. Optionally, you can also specify a directory for the downloaded +Rome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/rome`): + +```gradle +spotless { + format 'rome', { + target '**/*.js','**/*.ts','**/*.json' + // Relative paths are resolved against the project's base directory + rome('12.0.0').downloadDir("${project.gradle.gradleUserHomeDir}/rome") + } +} +``` + +To use a fixed binary, omit the `version` and specify a `pathToExe`: + +```gradle +spotless { + format 'rome', { + target '**/*.js','**/*.ts','**/*.json' + rome('12.0.0').pathToExe("${project.buildDir.absolutePath}/bin/rome") + } +} +``` + +Absolute paths are used as-is. Relative paths are resolved against the project's +base directory. To use a pre-installed Rome binary on the user's path, specify +just a name without any slashes / backslashes: + +```gradle +spotless { + format 'rome', { + target '**/*.js','**/*.ts','**/*.json' + // Uses the "rome" command, which must be on the user's path. --> + rome('12.0.0').pathToExe('rome') + } +} +``` + +### Rome configuration file + +Rome is a biased formatter and linter without many options, but there are a few +basic options. Rome uses a file named [rome.json](https://docs.rome.tools/configuration/) +for its configuration. When none is specified, the default configuration from +Rome is used. To use a custom configuration: + +```gradle +spotless { + format 'rome', { + target '**/*.js','**/*.ts','**/*.json' + // Must point to the directory with the "rome.json" config file --> + // Relative paths are resolved against the project's base directory --> + rome('12.0.0').configPath('./config') + } +} +``` + +### Rome input language + +By default, Rome detects the language / syntax of the files to format +automatically from the file extension. This may fail if your source code files +have unusual extensions for some reason. If you are using the generic format, +you can force a certain language like this: + +```xml + + + + + src/**/typescript/**/*.mjson + + + + 12.0.0 + json + + + + + +``` + +The following languages are currently recognized: + +* `js` -- JavaScript +* `jsx` -- JavaScript + JSX (React) +* `js?` -- JavaScript, with or without JSX, depending on the file extension +* `ts` -- TypeScript +* `tsx` -- TypeScript + JSX (React) +* `ts?` -- TypeScript, with or without JSX, depending on the file extension +* `json` -- JSON + ## Generic steps [Prettier](#prettier), [eclipse wtp](#eclipse-web-tools-platform), and [license header](#license-header) are available in every format, and they each have their own section. As mentioned in the [quickstart](#quickstart), there are a variety of simple generic steps which are also available in every format, here are examples of these: diff --git a/plugin-maven/README.md b/plugin-maven/README.md index b4c15f7fc2..03638278f5 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1250,7 +1250,7 @@ usually you will be creating a generic format. ${project.basedir}/path/to/config/dir - + ts @@ -1264,13 +1264,15 @@ usually you will be creating a generic format. - The auto-discovery of config files (up the file tree) will not work when using Rome within spotless. -To apply Rome to more kinds of files, just add more formats +To apply Rome to more kinds of files with a different configuration, just add +more formats ```xml src/**/*.ts src/**/*.js + ``` ### Rome binary @@ -1336,7 +1338,7 @@ Rome is used. To use a custom configuration: ``` -### Rome input Language +### Rome input language By default, Rome detects the language / syntax of the files to format automatically from the file extension. This may fail if your source code files From 23308740d17e28c03fa1e5902ff25a3810e7831b Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 19:32:51 +0100 Subject: [PATCH 0729/1120] Readme: Mention Rome in TOC for JS/TS --- plugin-gradle/README.md | 4 ++-- plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f47c7a543f..de0f9e5f31 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -63,8 +63,8 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript)) - - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Rome](#rome)) - [JSON](#json) - [YAML](#yaml) - [Gherkin](#gherkin) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 03638278f5..0d7ddeaf4f 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -49,8 +49,8 @@ user@machine repo % mvn spotless:check - [Sql](#sql) ([dbeaver](#dbeaver)) - [Maven Pom](#maven-pom) ([sortPom](#sortpom)) - [Markdown](#markdown) ([flexmark](#flexmark)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript)) - - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Rome](#rome)) - [JSON](#json) - [YAML](#yaml) - [Gherkin](#gherkin) From 850b2877342930354035ce1f4cbb5d103ceb274d Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 19:35:59 +0100 Subject: [PATCH 0730/1120] Fix readme for Gradle plugin with custom binary --- plugin-gradle/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index de0f9e5f31..3e409677a2 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -1161,7 +1161,7 @@ To use a fixed binary, omit the `version` and specify a `pathToExe`: spotless { format 'rome', { target '**/*.js','**/*.ts','**/*.json' - rome('12.0.0').pathToExe("${project.buildDir.absolutePath}/bin/rome") + rome().pathToExe("${project.buildDir.absolutePath}/bin/rome") } } ``` @@ -1175,7 +1175,7 @@ spotless { format 'rome', { target '**/*.js','**/*.ts','**/*.json' // Uses the "rome" command, which must be on the user's path. --> - rome('12.0.0').pathToExe('rome') + rome().pathToExe('rome') } } ``` From 7afe75b999002efed6e245ced92c02cc7326a130 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 19:58:17 +0100 Subject: [PATCH 0731/1120] Minor refactor, remove useless extra builder class --- .../com/diffplug/spotless/rome/RomeStep.java | 142 ++++++------------ .../gradle/spotless/FormatExtension.java | 5 +- .../spotless/maven/rome/AbstractRome.java | 6 +- 3 files changed, 52 insertions(+), 101 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java index e48a78c2ba..b0f17fafd6 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java @@ -50,7 +50,7 @@ public class RomeStep { * Path to the directory with the {@code rome.json} config file, can be * null, in which case the defaults are used. */ - private final String configPath; + private String configPath; /** * The language (syntax) of the input files to format. When null or @@ -68,7 +68,7 @@ public class RomeStep { *
  • json (JSON)
  • * */ - private final String language; + private String language; /** * Path to the Rome executable. Can be null, but either a path to @@ -106,8 +106,8 @@ public static String name() { * @param downloadDir Directory where to place the downloaded executable. * @return A new Rome step that download the executable from the network. */ - public static RomeStep.Builder withExeDownload(String version, String downloadDir) { - return new RomeStep.Builder(version, null, downloadDir); + public static RomeStep withExeDownload(String version, String downloadDir) { + return new RomeStep(version, null, downloadDir); } /** @@ -117,8 +117,8 @@ public static RomeStep.Builder withExeDownload(String version, String downloadDi * @param pathToExe Path to the Rome executable to use. * @return A new Rome step that format with the given executable. */ - public static RomeStep.Builder withExePath(String pathToExe) { - return new RomeStep.Builder(null, pathToExe, null); + public static RomeStep withExePath(String pathToExe) { + return new RomeStep(null, pathToExe, null); } /** @@ -217,12 +217,10 @@ private static void validateRomeExecutable(String resolvedPathToExe) { * * @param builder Builder with the configuration to use. */ - private RomeStep(RomeStep.Builder builder) { - this.version = builder.version != null && !builder.version.isBlank() ? builder.version : defaultVersion(); - this.pathToExe = builder.pathToExe; - this.downloadDir = builder.downloadDir; - this.configPath = builder.configPath; - this.language = builder.language; + private RomeStep(String version, String pathToExe, String downloadDir) { + this.version = version != null && !version.isBlank() ? version : defaultVersion(); + this.pathToExe = pathToExe; + this.downloadDir = downloadDir; } /** @@ -235,6 +233,44 @@ public FormatterStep create() { return FormatterStep.createLazy(name(), this::createState, State::toFunc); } + /** + * Sets the path to the directory with the {@code rome.json} config file. When + * no config path is set, the default configuration is used. + * + * @param configPath Config path to use. Must point to a directory which contain + * a file named {@code rome.json}. + * @return This builder instance for chaining method calls. + */ + public RomeStep withConfigPath(String configPath) { + this.configPath = configPath; + return this; + } + + /** + * Sets the language of the files to format When no language is set, it is + * determined automatically from the file name. The following languages are + * currently supported by Rome. + * + *
      + *
    • js (JavaScript)
    • + *
    • jsx (JavaScript + JSX)
    • + *
    • js? (JavaScript or JavaScript + JSX, depending on the file + * extension)
    • + *
    • ts (TypeScript)
    • + *
    • tsx (TypeScript + JSX)
    • + *
    • ts? (TypeScript or TypeScript + JSX, depending on the file + * extension)
    • + *
    • json (JSON)
    • + *
    + * + * @param language The language of the files to format. + * @return This builder instance for chaining method calls. + */ + public RomeStep withLanguage(String language) { + this.language = language; + return this; + } + /** * Resolves the Rome executable, possibly downloading it from the network, and * creates a new state instance with the resolved executable that can format @@ -290,88 +326,6 @@ private String resolveExe() throws IOException, InterruptedException { } } - public final static class Builder { - /** See {@link RomeStep#configPath} */ - private String configPath; - - /** See {@link RomeStep#downloadDir} */ - private final String downloadDir; - - /** See {@link RomeStep#language} */ - private String language; - - /** See {@link RomeStep#pathToExe} */ - private final String pathToExe; - - /** See {@link RomeStep#version} */ - private final String version; - - /** - * Creates a new builder for configuring a Rome step that can format code via - * Rome. Either a version and and downloadDir, or a pathToExe must be given. - * - * @param version The version of Rome to download, see - * {@link RomeStep#version}. - * @param pathToExe The path to the Rome executable to use, see - * {@link RomeStep#pathToExe}. - * @param downloadDir The path to the download directory when downloading Rome - * from the network, {@link RomeStep#downloadDir}. - */ - private Builder(String version, String pathToExe, String downloadDir) { - this.version = version; - this.pathToExe = pathToExe; - this.downloadDir = downloadDir; - } - - /** - * Creates a new Rome step for formatting code with Rome from the current - * configuration of this builder. - * - * @return A new Rome step with the current configuration. - */ - public RomeStep build() { - return new RomeStep(this); - } - - /** - * Sets the path to the directory with the {@code rome.json} config file. When - * no config path is set, the default configuration is used. - * - * @param configPath Config path to use. Must point to a directory which contain - * a file named {@code rome.json}. - * @return This builder instance for chaining method calls. - */ - public Builder withConfigPath(String configPath) { - this.configPath = configPath; - return this; - } - - /** - * Sets the language of the files to format When no language is set, it is - * determined automatically from the file name. The following languages are - * currently supported by Rome. - * - *
      - *
    • js (JavaScript)
    • - *
    • jsx (JavaScript + JSX)
    • - *
    • js? (JavaScript or JavaScript + JSX, depending on the file - * extension)
    • - *
    • ts (TypeScript)
    • - *
    • tsx (TypeScript + JSX)
    • - *
    • ts? (TypeScript or TypeScript + JSX, depending on the file - * extension)
    • - *
    • json (JSON)
    • - *
    - * - * @param language The language of the files to format. - * @return This builder instance for chaining method calls. - */ - public Builder withLanguage(String language) { - this.language = language; - return this; - } - } - /** * The internal state used by the Rome formatter. A state instance is created * when the spotless plugin for Maven or Gradle is executed, and reused for all diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index dbf45e87f1..ae7e792e9b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -770,8 +770,7 @@ protected FormatterStep createStep() { builder.withConfigPath(resolvedConfigPath.toString()); } builder.withLanguage(getLanguage()); - var rome = builder.build(); - return rome.create(); + return builder.create(); } /** @@ -842,7 +841,7 @@ private File findDataDir() { * * @return A builder for a Rome step. */ - private RomeStep.Builder newBuilder() { + private RomeStep newBuilder() { if (pathToExe != null) { var resolvedPathToExe = resolvePathToExe(); return RomeStep.withExePath(resolvedPathToExe); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java index 8af56c5a00..33567b0a20 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java @@ -23,7 +23,6 @@ import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; import com.diffplug.spotless.rome.RomeStep; -import com.diffplug.spotless.rome.RomeStep.Builder; /** * Factory for creating the Rome formatter step that can format format code in @@ -94,8 +93,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { if (getLanguage() != null) { builder.withLanguage(getLanguage()); } - var step = builder.build(); - return step.create(); + return builder.create(); } /** @@ -127,7 +125,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { * the currently executed project. * @return A builder for a Rome step. */ - private Builder newBuilder(FormatterStepConfig config) { + private RomeStep newBuilder(FormatterStepConfig config) { if (pathToExe != null) { var resolvedExePath = resolveExePath(config); return RomeStep.withExePath(resolvedExePath); From 57d36b4a4d7a2dce664b1f7c518c2d53d3e1697e Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 19:58:39 +0100 Subject: [PATCH 0732/1120] Fix default download dir path for Gradle plugin --- .../main/java/com/diffplug/gradle/spotless/FormatExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index ae7e792e9b..c429c469d2 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -824,7 +824,7 @@ private File findDataDir() { try { // e.g. ~/.m2/repository/ var repoPath = Paths.get(localRepo.getUrl().getPath()); - var dataPath = repoPath.resolve("com").resolve("diffplus").resolve("spotless").resolve("spotless-data"); + var dataPath = repoPath.resolve("com").resolve("diffplug").resolve("spotless").resolve("spotless-data"); return dataPath.toAbsolutePath().toFile(); } finally { // Remove mavenLocal() repository again if it was not part of the project From c483ed37e2e8bfdfe26c084a79801570600595cd Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 21:24:29 +0100 Subject: [PATCH 0733/1120] Add tests for RomeStep --- .../resources/rome/config/line-width-120.json | 11 + .../resources/rome/config/line-width-80.json | 11 + .../src/main/resources/rome/js/fileAfter.cjs | 3 + .../src/main/resources/rome/js/fileAfter.js | 3 + .../src/main/resources/rome/js/fileAfter.jsx | 3 + .../src/main/resources/rome/js/fileAfter.mjs | 3 + .../src/main/resources/rome/js/fileBefore.cjs | 3 + .../src/main/resources/rome/js/fileBefore.js | 3 + .../src/main/resources/rome/js/fileBefore.jsx | 4 + .../src/main/resources/rome/js/fileBefore.mjs | 3 + .../resources/rome/js/longLineAfter120.js | 1 + .../main/resources/rome/js/longLineAfter80.js | 13 + .../main/resources/rome/js/longLineBefore.js | 1 + .../main/resources/rome/json/fileAfter.json | 5 + .../main/resources/rome/json/fileBefore.json | 7 + .../src/main/resources/rome/ts/fileAfter.cts | 4 + .../src/main/resources/rome/ts/fileAfter.mts | 4 + .../src/main/resources/rome/ts/fileAfter.ts | 4 + .../src/main/resources/rome/ts/fileAfter.tsx | 7 + .../src/main/resources/rome/ts/fileBefore.cts | 4 + .../src/main/resources/rome/ts/fileBefore.mts | 5 + .../src/main/resources/rome/ts/fileBefore.ts | 5 + .../src/main/resources/rome/ts/fileBefore.tsx | 8 + .../diffplug/spotless/rome/RomeStepTest.java | 284 ++++++++++++++++++ 24 files changed, 399 insertions(+) create mode 100644 testlib/src/main/resources/rome/config/line-width-120.json create mode 100644 testlib/src/main/resources/rome/config/line-width-80.json create mode 100644 testlib/src/main/resources/rome/js/fileAfter.cjs create mode 100644 testlib/src/main/resources/rome/js/fileAfter.js create mode 100644 testlib/src/main/resources/rome/js/fileAfter.jsx create mode 100644 testlib/src/main/resources/rome/js/fileAfter.mjs create mode 100644 testlib/src/main/resources/rome/js/fileBefore.cjs create mode 100644 testlib/src/main/resources/rome/js/fileBefore.js create mode 100644 testlib/src/main/resources/rome/js/fileBefore.jsx create mode 100644 testlib/src/main/resources/rome/js/fileBefore.mjs create mode 100644 testlib/src/main/resources/rome/js/longLineAfter120.js create mode 100644 testlib/src/main/resources/rome/js/longLineAfter80.js create mode 100644 testlib/src/main/resources/rome/js/longLineBefore.js create mode 100644 testlib/src/main/resources/rome/json/fileAfter.json create mode 100644 testlib/src/main/resources/rome/json/fileBefore.json create mode 100644 testlib/src/main/resources/rome/ts/fileAfter.cts create mode 100644 testlib/src/main/resources/rome/ts/fileAfter.mts create mode 100644 testlib/src/main/resources/rome/ts/fileAfter.ts create mode 100644 testlib/src/main/resources/rome/ts/fileAfter.tsx create mode 100644 testlib/src/main/resources/rome/ts/fileBefore.cts create mode 100644 testlib/src/main/resources/rome/ts/fileBefore.mts create mode 100644 testlib/src/main/resources/rome/ts/fileBefore.ts create mode 100644 testlib/src/main/resources/rome/ts/fileBefore.tsx create mode 100644 testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java diff --git a/testlib/src/main/resources/rome/config/line-width-120.json b/testlib/src/main/resources/rome/config/line-width-120.json new file mode 100644 index 0000000000..8f14afa3f8 --- /dev/null +++ b/testlib/src/main/resources/rome/config/line-width-120.json @@ -0,0 +1,11 @@ +{ + "formatter": { + "enabled": true, + "indentStyle": "tab", + "lineWidth": 120, + "formatWithErrors": false + }, + "linter": { + "enabled": false + } + } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/config/line-width-80.json b/testlib/src/main/resources/rome/config/line-width-80.json new file mode 100644 index 0000000000..5ec998bd97 --- /dev/null +++ b/testlib/src/main/resources/rome/config/line-width-80.json @@ -0,0 +1,11 @@ +{ + "formatter": { + "enabled": true, + "indentStyle": "tab", + "lineWidth": 80, + "formatWithErrors": false + }, + "linter": { + "enabled": false + } + } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/js/fileAfter.cjs b/testlib/src/main/resources/rome/js/fileAfter.cjs new file mode 100644 index 0000000000..defc9c85eb --- /dev/null +++ b/testlib/src/main/resources/rome/js/fileAfter.cjs @@ -0,0 +1,3 @@ +function foo(name = "World") { + return "Hello " + name; +} diff --git a/testlib/src/main/resources/rome/js/fileAfter.js b/testlib/src/main/resources/rome/js/fileAfter.js new file mode 100644 index 0000000000..defc9c85eb --- /dev/null +++ b/testlib/src/main/resources/rome/js/fileAfter.js @@ -0,0 +1,3 @@ +function foo(name = "World") { + return "Hello " + name; +} diff --git a/testlib/src/main/resources/rome/js/fileAfter.jsx b/testlib/src/main/resources/rome/js/fileAfter.jsx new file mode 100644 index 0000000000..313aceb6ed --- /dev/null +++ b/testlib/src/main/resources/rome/js/fileAfter.jsx @@ -0,0 +1,3 @@ +export function Panel(cfg = {}) { + return
    {1 + 2}
    ; +} diff --git a/testlib/src/main/resources/rome/js/fileAfter.mjs b/testlib/src/main/resources/rome/js/fileAfter.mjs new file mode 100644 index 0000000000..defc9c85eb --- /dev/null +++ b/testlib/src/main/resources/rome/js/fileAfter.mjs @@ -0,0 +1,3 @@ +function foo(name = "World") { + return "Hello " + name; +} diff --git a/testlib/src/main/resources/rome/js/fileBefore.cjs b/testlib/src/main/resources/rome/js/fileBefore.cjs new file mode 100644 index 0000000000..92539ba751 --- /dev/null +++ b/testlib/src/main/resources/rome/js/fileBefore.cjs @@ -0,0 +1,3 @@ +function foo ( name="World"){ + return "Hello "+name ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/js/fileBefore.js b/testlib/src/main/resources/rome/js/fileBefore.js new file mode 100644 index 0000000000..92539ba751 --- /dev/null +++ b/testlib/src/main/resources/rome/js/fileBefore.js @@ -0,0 +1,3 @@ +function foo ( name="World"){ + return "Hello "+name ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/js/fileBefore.jsx b/testlib/src/main/resources/rome/js/fileBefore.jsx new file mode 100644 index 0000000000..8e5d9834bc --- /dev/null +++ b/testlib/src/main/resources/rome/js/fileBefore.jsx @@ -0,0 +1,4 @@ +export function Panel ( cfg={}){ + return (
    {1+2}
    + ) ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/js/fileBefore.mjs b/testlib/src/main/resources/rome/js/fileBefore.mjs new file mode 100644 index 0000000000..92539ba751 --- /dev/null +++ b/testlib/src/main/resources/rome/js/fileBefore.mjs @@ -0,0 +1,3 @@ +function foo ( name="World"){ + return "Hello "+name ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/js/longLineAfter120.js b/testlib/src/main/resources/rome/js/longLineAfter120.js new file mode 100644 index 0000000000..68addc4b65 --- /dev/null +++ b/testlib/src/main/resources/rome/js/longLineAfter120.js @@ -0,0 +1 @@ +const x = ["Hello", "World", "How", "Are", "You", "Doing", "Today", "Such", "A", "Wondrous", "Sunshine"]; diff --git a/testlib/src/main/resources/rome/js/longLineAfter80.js b/testlib/src/main/resources/rome/js/longLineAfter80.js new file mode 100644 index 0000000000..dbdbd157e9 --- /dev/null +++ b/testlib/src/main/resources/rome/js/longLineAfter80.js @@ -0,0 +1,13 @@ +const x = [ + "Hello", + "World", + "How", + "Are", + "You", + "Doing", + "Today", + "Such", + "A", + "Wondrous", + "Sunshine", +]; diff --git a/testlib/src/main/resources/rome/js/longLineBefore.js b/testlib/src/main/resources/rome/js/longLineBefore.js new file mode 100644 index 0000000000..fd59e429c2 --- /dev/null +++ b/testlib/src/main/resources/rome/js/longLineBefore.js @@ -0,0 +1 @@ +const x = ["Hello", "World", "How", "Are", "You", "Doing", "Today", "Such", "A", "Wondrous", "Sunshine"]; \ No newline at end of file diff --git a/testlib/src/main/resources/rome/json/fileAfter.json b/testlib/src/main/resources/rome/json/fileAfter.json new file mode 100644 index 0000000000..468dac3297 --- /dev/null +++ b/testlib/src/main/resources/rome/json/fileAfter.json @@ -0,0 +1,5 @@ +{ + "a": [1, 2, 3], + "b": 9, + "c": null +} diff --git a/testlib/src/main/resources/rome/json/fileBefore.json b/testlib/src/main/resources/rome/json/fileBefore.json new file mode 100644 index 0000000000..77182284c7 --- /dev/null +++ b/testlib/src/main/resources/rome/json/fileBefore.json @@ -0,0 +1,7 @@ + { + "a":[1,2,3 + +], + "b":9, + "c" : null + } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/ts/fileAfter.cts b/testlib/src/main/resources/rome/ts/fileAfter.cts new file mode 100644 index 0000000000..f854953234 --- /dev/null +++ b/testlib/src/main/resources/rome/ts/fileAfter.cts @@ -0,0 +1,4 @@ +type Name = "World" | "Maven" | "Gradle"; +const foo = (name: Name = "World", v: T): string => { + return "Hello " + name; +}; diff --git a/testlib/src/main/resources/rome/ts/fileAfter.mts b/testlib/src/main/resources/rome/ts/fileAfter.mts new file mode 100644 index 0000000000..e6563e3030 --- /dev/null +++ b/testlib/src/main/resources/rome/ts/fileAfter.mts @@ -0,0 +1,4 @@ +export type Name = "World" | "Maven" | "Gradle"; +export const foo = (name: Name = "World", v: T): string => { + return "Hello " + name; +}; diff --git a/testlib/src/main/resources/rome/ts/fileAfter.ts b/testlib/src/main/resources/rome/ts/fileAfter.ts new file mode 100644 index 0000000000..e6563e3030 --- /dev/null +++ b/testlib/src/main/resources/rome/ts/fileAfter.ts @@ -0,0 +1,4 @@ +export type Name = "World" | "Maven" | "Gradle"; +export const foo = (name: Name = "World", v: T): string => { + return "Hello " + name; +}; diff --git a/testlib/src/main/resources/rome/ts/fileAfter.tsx b/testlib/src/main/resources/rome/ts/fileAfter.tsx new file mode 100644 index 0000000000..15ef316142 --- /dev/null +++ b/testlib/src/main/resources/rome/ts/fileAfter.tsx @@ -0,0 +1,7 @@ +export interface Cfg { + classname: string; + message: T; +} +const Panel = (cfg: Cfg): JSX.Element => { + return
    {String(cfg.message)}
    ; +}; diff --git a/testlib/src/main/resources/rome/ts/fileBefore.cts b/testlib/src/main/resources/rome/ts/fileBefore.cts new file mode 100644 index 0000000000..d4304287c0 --- /dev/null +++ b/testlib/src/main/resources/rome/ts/fileBefore.cts @@ -0,0 +1,4 @@ +type Name = "World" | "Maven"|"Gradle"; +const foo = ( name: Name="World", v: T): string => { + return "Hello " + name; + } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/ts/fileBefore.mts b/testlib/src/main/resources/rome/ts/fileBefore.mts new file mode 100644 index 0000000000..96837762a3 --- /dev/null +++ b/testlib/src/main/resources/rome/ts/fileBefore.mts @@ -0,0 +1,5 @@ +export + type Name = "World" | "Maven"|"Gradle"; +export const foo = ( name: Name="World", v: T): string => { + return "Hello " + name; + } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/ts/fileBefore.ts b/testlib/src/main/resources/rome/ts/fileBefore.ts new file mode 100644 index 0000000000..96837762a3 --- /dev/null +++ b/testlib/src/main/resources/rome/ts/fileBefore.ts @@ -0,0 +1,5 @@ +export + type Name = "World" | "Maven"|"Gradle"; +export const foo = ( name: Name="World", v: T): string => { + return "Hello " + name; + } \ No newline at end of file diff --git a/testlib/src/main/resources/rome/ts/fileBefore.tsx b/testlib/src/main/resources/rome/ts/fileBefore.tsx new file mode 100644 index 0000000000..38f24f8440 --- /dev/null +++ b/testlib/src/main/resources/rome/ts/fileBefore.tsx @@ -0,0 +1,8 @@ +export interface Cfg{ +classname:string, +message:T, +} +const Panel = ( cfg:Cfg):JSX.Element =>{ + return (
    {String(cfg.message)}
    + ) ; + } \ No newline at end of file diff --git a/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java new file mode 100644 index 0000000000..5c4801d50a --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java @@ -0,0 +1,284 @@ +/* + * 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.rome; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import com.diffplug.common.base.StandardSystemProperty; +import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.StepHarnessWithFile; +import com.diffplug.spotless.ThrowingEx; + +class RomeStepTest extends ResourceHarness { + private static String downloadDir; + + @BeforeAll + static void createDownloadDir() throws IOException { + // We do not want to download Rome each time we execute a test + var userHome = Paths.get(StandardSystemProperty.USER_HOME.value()); + downloadDir = userHome.resolve(".gradle").resolve("rome-dl-test").toAbsolutePath().normalize().toString(); + } + + /** + * Tests that files can be formatted without setting the input language + * explicitly. + */ + @Nested + class AutoDetectLanguage { + /** + * Tests that a *.cjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); + } + + /** + * Tests that a *.cts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCts() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.cts", "rome/ts/fileAfter.cts"); + } + + /** + * Tests that a *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJs() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.js", "rome/js/fileAfter.js"); + } + + /** + * Tests that a *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJson() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/json/fileBefore.json", "rome/json/fileAfter.json"); + } + + /** + * Tests that a *.jsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJsx() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.jsx", "rome/js/fileAfter.jsx"); + } + + /** + * Tests that a *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.mjs", "rome/js/fileAfter.mjs"); + } + + /** + * Tests that a *.mts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMts() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.mts", "rome/ts/fileAfter.mts"); + } + + /** + * Tests that a *.ts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectTs() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.ts", "rome/ts/fileAfter.ts"); + } + + /** + * Tests that a *.tsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectTsx() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); + } + } + + @Nested + class ConfigFile { + /** + * Test formatting with the line width in the config file set to 120. + */ + @Test + void testLineWidth120() { + var path = createRomeConfig("rome/config/line-width-120.json"); + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withConfigPath(path).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/longLineBefore.js", "rome/js/longLineAfter120.js"); + } + + /** + * Test formatting with the line width in the config file set to 120. + */ + @Test + void testLineWidth80() { + var path = createRomeConfig("rome/config/line-width-80.json"); + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withConfigPath(path).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/longLineBefore.js", "rome/js/longLineAfter80.js"); + } + + private String createRomeConfig(String name) { + var config = createTestFile(name).toPath(); + var dir = config.getParent(); + var rome = dir.resolve("rome.json"); + ThrowingEx.run(() -> Files.copy(config, rome)); + return dir.toString(); + } + } + + /** + * Tests that files can be formatted when setting the input language explicitly. + */ + @Nested + class ExplicitLanguage { + /** + * Tests that a *.cjs file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); + } + + /** + * Tests that a *.cts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectCts() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.cts", "rome/ts/fileAfter.cts"); + } + + /** + * Tests that a *.js file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJs() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.js", "rome/js/fileAfter.js"); + } + + /** + * Tests that a *.json file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJson() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("json").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/json/fileBefore.json", "rome/json/fileAfter.json"); + } + + /** + * Tests that a *.jsx file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJsx() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("jsx").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.jsx", "rome/js/fileAfter.jsx"); + } + + /** + * Tests that a *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.mjs", "rome/js/fileAfter.mjs"); + } + + /** + * Tests that a *.mts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectMts() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.mts", "rome/ts/fileAfter.mts"); + } + + /** + * Tests that a *.ts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectTs() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.ts", "rome/ts/fileAfter.ts"); + } + + /** + * Tests that a *.tsx file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectTsx() { + var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("tsx").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); + } + } +} From 97198cb239589e8bc3688146ba7efd44170ac085 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 22:18:24 +0100 Subject: [PATCH 0734/1120] Add tests for Maven plugin --- plugin-maven/build.gradle | 1 + .../maven/MavenIntegrationHarness.java | 4 + .../spotless/maven/rome/RomeMavenTest.java | 187 ++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index a8604c6ed9..dda98ad79a 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -50,6 +50,7 @@ dependencies { testImplementation "org.mockito:mockito-core:${VER_MOCKITO}" testImplementation "com.diffplug.durian:durian-io:${VER_DURIAN}" testImplementation 'com.github.spullara.mustache.java:compiler:0.9.10' + testImplementation 'org.owasp.encoder:encoder:1.2.3' testImplementation "org.apache.maven:maven-plugin-api:${VER_MAVEN_API}" testImplementation "org.eclipse.aether:aether-api:${VER_ECLIPSE_AETHER}" testImplementation "org.codehaus.plexus:plexus-resources:${VER_PLEXUS_RESOURCES}" 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 216502bc07..398932dd19 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 @@ -154,6 +154,10 @@ protected void writePomWithPrettierSteps(String includes, String... steps) throw writePom(formats(groupWithSteps("format", including(includes), steps))); } + protected void writePomWithRomeSteps(String includes, String... steps) throws IOException { + writePom(formats(groupWithSteps("format", including(includes), steps))); + } + protected void writePomWithPrettierSteps(String[] plugins, String includes, String... steps) throws IOException { writePom(null, formats(groupWithSteps("format", including(includes), steps)), null, plugins); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java new file mode 100644 index 0000000000..76e297e704 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java @@ -0,0 +1,187 @@ +/* + * 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.rome; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.owasp.encoder.Encode.forXml; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +class RomeMavenTest extends MavenIntegrationHarness { + /** + * Tests that rome can be used as a generic formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testAsGenericStep() throws Exception { + writePomWithRomeSteps("**/*.js", "12.0.0"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); + } + + /** + * Tests that rome can be used as a JavaScript formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testAsJavaScriptStep() throws Exception { + writePomWithJavascriptSteps("**/*.js", "12.0.0"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); + } + + /** + * Tests that rome can be used as a JSON formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testAsJsonStep() throws Exception { + writePomWithJsonSteps("**/*.json", "12.0.0"); + setFile("rome_test.json").toResource("rome/json/fileBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("rome_test.json").sameAsResource("rome/json/fileAfter.json"); + } + + /** + * Tests that rome can be used as a TypeScript formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testAsTypeScriptStep() throws Exception { + writePomWithTypescriptSteps("**/*.ts", "12.0.0"); + setFile("rome_test.ts").toResource("rome/ts/fileBefore.ts"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("rome_test.ts").sameAsResource("rome/ts/fileAfter.ts"); + } + + /** + * Tests that the language can be specified for the generic format step. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testCanSetLanguageForGenericStep() throws Exception { + writePomWithRomeSteps("**/*.nosj", "12.0.0json"); + setFile("rome_test.nosj").toResource("rome/json/fileBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("rome_test.nosj").sameAsResource("rome/json/fileAfter.json"); + } + + /** + * Tests that an absolute config path can be specified. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testConfigPathAbsolute() throws Exception { + var path = newFile("configs").getAbsolutePath(); + writePomWithRomeSteps("**/*.js", + "12.0.0" + forXml(path) + ""); + setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); + setFile("configs/rome.json").toResource("rome/config/line-width-120.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the rome.json config file can be + * specified. Uses a config file with a line width of 120. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testConfigPathLineWidth120() throws Exception { + writePomWithRomeSteps("**/*.js", "12.0.0configs"); + setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); + setFile("configs/rome.json").toResource("rome/config/line-width-120.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the rome.json config file can be + * specified. Uses a config file with a line width of 80. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testConfigPathLineWidth80() throws Exception { + writePomWithRomeSteps("**/*.js", "12.0.0configs"); + setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); + setFile("configs/rome.json").toResource("rome/config/line-width-80.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter80.js"); + } + + /** + * Tests that the download directory can be an absolute path. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testDownloadDirAbsolute() throws Exception { + var path = newFile("target/bin/rome").getAbsoluteFile().toString(); + writePomWithRomeSteps("**/*.js", + "12.0.0" + forXml(path) + ""); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/rome").exists() || newFile("target/bin/rome").list().length == 0); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/rome").list().length); + } + + /** + * Tests that the download directory can be changed to a path relative to the + * project's base directory. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testDownloadDirRelative() throws Exception { + writePomWithRomeSteps("**/*.js", + "12.0.0target/bin/rome"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/rome").exists() || newFile("target/bin/rome").list().length == 0); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/rome").list().length); + } + + /** + * Tests that the build fails when the input file could not be parsed. + * + * @throws Exception When a test failure occurs. + */ + @Test + public void testFailureWhenNotParseable() throws Exception { + writePomWithRomeSteps("**/*.js", "12.0.0json"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + var result = mavenRunner().withArguments("spotless:apply").runHasError(); + assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); + assertTrue(result.stdOutUtf8().contains("Format with errors is disabled.")); + assertTrue(result.stdOutUtf8().contains("Unable to format file")); + assertTrue(result.stdOutUtf8().contains("Step 'rome' found problem in 'rome_test.js'")); + } +} From 77d302e60106f90dec7cf2252e4b3bedf21c8580 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 8 Apr 2023 22:56:57 +0100 Subject: [PATCH 0735/1120] Add tests for Gradle plugin --- plugin-gradle/build.gradle | 1 + .../gradle/spotless/RomeIntegrationTest.java | 343 ++++++++++++++++++ .../spotless/maven/rome/RomeMavenTest.java | 43 ++- 3 files changed, 373 insertions(+), 14 deletions(-) create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 9a725dbf5d..021155abfe 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -25,6 +25,7 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" + testImplementation 'org.owasp.encoder:encoder:1.2.3' } apply from: rootProject.file('gradle/special-tests.gradle') diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java new file mode 100644 index 0000000000..4464b1cec7 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java @@ -0,0 +1,343 @@ +/* + * 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.gradle.spotless; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; +import org.owasp.encoder.Encode; + +class RomeIntegrationTest extends GradleIntegrationHarness { + /** + * Tests that rome can be used as a generic formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asGenericStep() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'myrome', {", + " target '**/*.js'", + " rome('12.0.0')", + " }", + "}"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); + } + + /** + * Tests that rome can be used as a JavaScript formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asJavaScriptStep() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target '**/*.js'", + " rome('12.0.0')", + " }", + "}"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); + } + + /** + * Tests that rome can be used as a JSON formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asJsonStep() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target '**/*.json'", + " rome('12.0.0')", + " }", + "}"); + setFile("rome_test.json").toResource("rome/json/fileBefore.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("rome_test.json").sameAsResource("rome/json/fileAfter.json"); + } + + /** + * Tests that rome can be used as a TypeScript formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asTypeScriptStep() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target '**/*.ts'", + " rome('12.0.0')", + " }", + "}"); + setFile("rome_test.ts").toResource("rome/ts/fileBefore.ts"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("rome_test.ts").sameAsResource("rome/ts/fileAfter.ts"); + } + + /** + * Tests that the language can be specified for the generic format step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void canSetLanguageForGenericStep() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'myrome', {", + " target '**/*.nosj'", + " rome('12.0.0').language('json')", + " }", + "}"); + setFile("rome_test.nosj").toResource("rome/json/fileBefore.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("rome_test.nosj").sameAsResource("rome/json/fileAfter.json"); + } + + /** + * Tests that an absolute config path can be specified. + * + * @throws Exception When a test failure occurs. + */ + @Test + void configPathAbsolute() throws Exception { + var path = newFile("configs").getAbsolutePath(); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'myrome', {", + " target '**/*.js'", + " rome('12.0.0').configPath('" + Encode.forJava(path) + "')", + " }", + "}"); + setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); + setFile("configs/rome.json").toResource("rome/config/line-width-120.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the rome.json config file can be + * specified. Uses a config file with a line width of 120. + * + * @throws Exception When a test failure occurs. + */ + @Test + void configPathLineWidth120() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'myrome', {", + " target '**/*.js'", + " rome('12.0.0').configPath('configs')", + " }", + "}"); + setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); + setFile("configs/rome.json").toResource("rome/config/line-width-120.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the rome.json config file can be + * specified. Uses a config file with a line width of 80. + * + * @throws Exception When a test failure occurs. + */ + @Test + void configPathLineWidth80() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'myrome', {", + " target '**/*.js'", + " rome('12.0.0').configPath('configs')", + " }", + "}"); + setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); + setFile("configs/rome.json").toResource("rome/config/line-width-80.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("rome_test.js").sameAsResource("rome/js/longLineAfter80.js"); + } + + /** + * Tests that the download directory can be an absolute path. + * + * @throws Exception When a test failure occurs. + */ + @Test + void downloadDirAbsolute() throws Exception { + var path = newFile("target/bin/rome").getAbsoluteFile().toString(); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'myrome', {", + " target '**/*.js'", + " rome('12.0.0').downloadDir('" + Encode.forJava(path) + "')", + " }", + "}"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/rome").exists() || newFile("target/bin/rome").list().length == 0); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/rome").list().length); + } + + /** + * Tests that the download directory can be changed to a path relative to the + * project's base directory. + * + * @throws Exception When a test failure occurs. + */ + @Test + void downloadDirRelative() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'myrome', {", + " target '**/*.js'", + " rome('12.0.0').downloadDir('target/bin/rome')", + " }", + "}"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/rome").exists() || newFile("target/bin/rome").list().length == 0); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("rome_test.js").sameAsResource("rome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/rome").list().length); + } + + /** + * Tests that the build fails when given Rome executable does not exist. + * + * @throws Exception When a test failure occurs. + */ + @Test + void failureWhenExeNotFound() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'myrome', {", + " target '**/*.js'", + " rome('12.0.0').pathToExe('rome/is/missing')", + " }", + "}"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + assertThat(spotlessApply.getOutput()).contains("Build failed with an exception"); + assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); + assertThat(spotlessApply.getOutput()).contains("Could not create task ':spotlessMyromeApply'"); + assertThat(spotlessApply.getOutput()).contains("Rome executable does not exist"); + } + + /** + * Tests that the build fails when the input file could not be parsed. + * + * @throws Exception When a test failure occurs. + */ + @Test + void failureWhenNotParseable() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'myrome', {", + " target '**/*.js'", + " rome('12.0.0').language('json')", + " }", + "}"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + assertThat(spotlessApply.getOutput()).contains("spotlessMyrome FAILED"); + assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); + assertThat(spotlessApply.getOutput()).contains("Format with errors is disabled."); + assertThat(spotlessApply.getOutput()).contains("Step 'rome' found problem in 'rome_test.js'"); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java index 76e297e704..7ca3f7d981 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.maven.rome; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.owasp.encoder.Encode.forXml; @@ -30,7 +31,7 @@ class RomeMavenTest extends MavenIntegrationHarness { * @throws Exception When a test failure occurs. */ @Test - public void testAsGenericStep() throws Exception { + void asGenericStep() throws Exception { writePomWithRomeSteps("**/*.js", "12.0.0"); setFile("rome_test.js").toResource("rome/js/fileBefore.js"); mavenRunner().withArguments("spotless:apply").runNoError(); @@ -43,7 +44,7 @@ public void testAsGenericStep() throws Exception { * @throws Exception When a test failure occurs. */ @Test - public void testAsJavaScriptStep() throws Exception { + void asJavaScriptStep() throws Exception { writePomWithJavascriptSteps("**/*.js", "12.0.0"); setFile("rome_test.js").toResource("rome/js/fileBefore.js"); mavenRunner().withArguments("spotless:apply").runNoError(); @@ -56,7 +57,7 @@ public void testAsJavaScriptStep() throws Exception { * @throws Exception When a test failure occurs. */ @Test - public void testAsJsonStep() throws Exception { + void asJsonStep() throws Exception { writePomWithJsonSteps("**/*.json", "12.0.0"); setFile("rome_test.json").toResource("rome/json/fileBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError(); @@ -69,7 +70,7 @@ public void testAsJsonStep() throws Exception { * @throws Exception When a test failure occurs. */ @Test - public void testAsTypeScriptStep() throws Exception { + void asTypeScriptStep() throws Exception { writePomWithTypescriptSteps("**/*.ts", "12.0.0"); setFile("rome_test.ts").toResource("rome/ts/fileBefore.ts"); mavenRunner().withArguments("spotless:apply").runNoError(); @@ -82,7 +83,7 @@ public void testAsTypeScriptStep() throws Exception { * @throws Exception When a test failure occurs. */ @Test - public void testCanSetLanguageForGenericStep() throws Exception { + void canSetLanguageForGenericStep() throws Exception { writePomWithRomeSteps("**/*.nosj", "12.0.0json"); setFile("rome_test.nosj").toResource("rome/json/fileBefore.json"); mavenRunner().withArguments("spotless:apply").runNoError(); @@ -95,7 +96,7 @@ public void testCanSetLanguageForGenericStep() throws Exception { * @throws Exception When a test failure occurs. */ @Test - public void testConfigPathAbsolute() throws Exception { + void configPathAbsolute() throws Exception { var path = newFile("configs").getAbsolutePath(); writePomWithRomeSteps("**/*.js", "12.0.0" + forXml(path) + ""); @@ -112,7 +113,7 @@ public void testConfigPathAbsolute() throws Exception { * @throws Exception When a test failure occurs. */ @Test - public void testConfigPathLineWidth120() throws Exception { + void configPathLineWidth120() throws Exception { writePomWithRomeSteps("**/*.js", "12.0.0configs"); setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); setFile("configs/rome.json").toResource("rome/config/line-width-120.json"); @@ -127,7 +128,7 @@ public void testConfigPathLineWidth120() throws Exception { * @throws Exception When a test failure occurs. */ @Test - public void testConfigPathLineWidth80() throws Exception { + void configPathLineWidth80() throws Exception { writePomWithRomeSteps("**/*.js", "12.0.0configs"); setFile("rome_test.js").toResource("rome/js/longLineBefore.js"); setFile("configs/rome.json").toResource("rome/config/line-width-80.json"); @@ -141,7 +142,7 @@ public void testConfigPathLineWidth80() throws Exception { * @throws Exception When a test failure occurs. */ @Test - public void testDownloadDirAbsolute() throws Exception { + void downloadDirAbsolute() throws Exception { var path = newFile("target/bin/rome").getAbsoluteFile().toString(); writePomWithRomeSteps("**/*.js", "12.0.0" + forXml(path) + ""); @@ -159,7 +160,7 @@ public void testDownloadDirAbsolute() throws Exception { * @throws Exception When a test failure occurs. */ @Test - public void testDownloadDirRelative() throws Exception { + void downloadDirRelative() throws Exception { writePomWithRomeSteps("**/*.js", "12.0.0target/bin/rome"); setFile("rome_test.js").toResource("rome/js/fileBefore.js"); @@ -175,13 +176,27 @@ public void testDownloadDirRelative() throws Exception { * @throws Exception When a test failure occurs. */ @Test - public void testFailureWhenNotParseable() throws Exception { + void failureWhenExeNotFound() throws Exception { + writePomWithRomeSteps("**/*.js", "12.0.0rome/is/missing"); + setFile("rome_test.js").toResource("rome/js/fileBefore.js"); + var result = mavenRunner().withArguments("spotless:apply").runHasError(); + assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); + assertThat(result.stdOutUtf8()).contains("Rome executable does not exist"); + } + + /** + * Tests that the build fails when the input file could not be parsed. + * + * @throws Exception When a test failure occurs. + */ + @Test + void failureWhenNotParseable() throws Exception { writePomWithRomeSteps("**/*.js", "12.0.0json"); setFile("rome_test.js").toResource("rome/js/fileBefore.js"); var result = mavenRunner().withArguments("spotless:apply").runHasError(); assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); - assertTrue(result.stdOutUtf8().contains("Format with errors is disabled.")); - assertTrue(result.stdOutUtf8().contains("Unable to format file")); - assertTrue(result.stdOutUtf8().contains("Step 'rome' found problem in 'rome_test.js'")); + assertThat(result.stdOutUtf8()).contains("Format with errors is disabled."); + assertThat(result.stdOutUtf8()).contains("Unable to format file"); + assertThat(result.stdOutUtf8()).contains("Step 'rome' found problem in 'rome_test.js'"); } } From 99fa04935f93913cb28866a194826b09c15ce861 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 11 Apr 2023 20:44:40 +0000 Subject: [PATCH 0736/1120] fix(deps): update dependency org.mockito:mockito-core to v5.3.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1a72150dd6..c235d2ac5a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,4 +32,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.5.0.202303070854-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.2.0 +VER_MOCKITO=5.3.0 From 979fe80f7aea90ffd67960238e787dfb907b264e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 12 Apr 2023 16:37:30 +0000 Subject: [PATCH 0737/1120] chore(deps): update plugin com.gradle.enterprise to v3.13 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 6d80b0b38a..41c2a123e0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,7 +23,7 @@ plugins { // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise - id 'com.gradle.enterprise' version '3.12.6' + id 'com.gradle.enterprise' version '3.13' // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md id 'dev.equo.ide' version '1.0.1' apply false } From 971824d7677254bff75bcdf00a198da4b50040c3 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Thu, 13 Apr 2023 07:09:50 +0100 Subject: [PATCH 0738/1120] Fix spotbugs issues --- .../rome/RomeExecutableDownloader.java | 11 +++++++-- .../com/diffplug/spotless/rome/RomeStep.java | 6 +++-- .../diffplug/spotless/maven/FileLocator.java | 23 +++++++++++++++---- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java index c55a18f754..5f389f0342 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java @@ -117,7 +117,10 @@ public Path download(String version) throws IOException, InterruptedException { var url = getDownloadUrl(version, platform); var executablePath = getExecutablePath(version, platform); var checksumPath = getChecksumPath(executablePath); - Files.createDirectories(executablePath.getParent()); + var executableDir = executablePath.getParent(); + if (executableDir != null) { + Files.createDirectories(executableDir); + } logger.info("Attempting to download Rome from '{}' to '{}'", url, executablePath); var request = HttpRequest.newBuilder(URI.create(url)).GET().build(); var handler = BodyHandlers.ofFile(executablePath, WRITE_OPTIONS); @@ -270,7 +273,11 @@ private String getArchitectureCodeName(Architecture architecture) throws IOExcep * @return The path with the checksum for the given file. */ private Path getChecksumPath(Path file) { - return file.getParent().resolve(file.getFileName().toString() + ".md5"); + var parent = file.getParent(); + var base = parent != null ? parent : file; + var fileName = file.getFileName(); + var checksumName = fileName != null ? fileName.toString() + ".md5" : "checksum.md5"; + return base.resolve(checksumName); } /** diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java index b0f17fafd6..d6a3e62669 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java @@ -134,7 +134,9 @@ private static void attemptToAddPosixPermission(Path file, PosixFilePermission p var newPermissions = new HashSet<>(Files.getPosixFilePermissions(file)); newPermissions.add(permission); Files.setPosixFilePermissions(file, newPermissions); - } catch (final Exception ignore) {} + } catch (final Exception ignore) { + logger.debug("Unable to add POSIX permission '{}' to file '{}'", permission, file); + } } /** @@ -440,7 +442,7 @@ private String resolveFileName(File file) { return "jsx".equals(ext) || "js".equals(ext) || "mjs".equals(ext) || "cjs".equals(ext) ? name : "file.js"; case "ts?": - return "tsx".equals(ext) || "ts".equals(ext) || "tjs".equals(ext) || "tjs".equals(ext) ? name + return "tsx".equals(ext) || "ts".equals(ext) || "mts".equals(ext) || "cts".equals(ext) ? name : "file.js"; case "js": return "js".equals(ext) || "mjs".equals(ext) || "cjs".equals(ext) ? name : "file.js"; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java index a8c3973dd3..0c66fe29cb 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java @@ -24,6 +24,7 @@ import java.security.NoSuchAlgorithmException; import java.util.Base64; import java.util.Objects; +import java.util.Optional; import org.codehaus.plexus.resource.ResourceManager; import org.codehaus.plexus.resource.loader.FileResourceCreationException; @@ -121,10 +122,22 @@ private static byte[] hash(String value) { } private static File findDataDir() { - // E.g. ~/.m2/repository/com/diffplug/spotless/spotless-plugin-maven/1.2.3/spotless-plugin-maven-1.2.3.jar - final var jarPath = Paths.get(AbstractRome.class.getProtectionDomain().getCodeSource().getLocation().getPath()); - final var base = jarPath.getParent().getParent().getParent(); - final var sub = base.resolve("spotless-data"); - return sub.toAbsolutePath().toFile(); + // JAR path is e.g. + // ~/.m2/repository/com/diffplug/spotless/spotless-plugin-maven/1.2.3/spotless-plugin-maven-1.2.3.jar + var codeSource = FileLocator.class.getProtectionDomain().getCodeSource(); + var location = codeSource != null ? codeSource.getLocation() : null; + var path = location != null ? location.getPath() : null; + var jarPath = path != null && !path.isBlank() ? Paths.get(path) : null; + var parent1 = jarPath != null ? jarPath.getParent() : null; + var parent2 = parent1 != null ? parent1.getParent() : null; + var base = parent2 != null ? parent2.getParent() : null; + var sub = base != null ? base.resolve("spotless-data") : null; + if (sub != null) { + return sub.toAbsolutePath().toFile(); + } + else { + var home = Paths.get(System.getenv("user.home")); + return home.resolve(".rome").toAbsolutePath().toFile(); + } } } From 071df538360ea93fdaf3898de86f8d6d5008b63e Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Thu, 13 Apr 2023 07:16:43 +0100 Subject: [PATCH 0739/1120] Run spotlessApply again --- .../main/java/com/diffplug/spotless/maven/FileLocator.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java index 0c66fe29cb..fdf91ef68f 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java @@ -24,15 +24,12 @@ import java.security.NoSuchAlgorithmException; import java.util.Base64; import java.util.Objects; -import java.util.Optional; import org.codehaus.plexus.resource.ResourceManager; import org.codehaus.plexus.resource.loader.FileResourceCreationException; import org.codehaus.plexus.resource.loader.ResourceNotFoundException; import org.codehaus.plexus.util.FileUtils; -import com.diffplug.spotless.maven.rome.AbstractRome; - public class FileLocator { static final String TMP_RESOURCE_FILE_PREFIX = "spotless-resource-"; @@ -134,8 +131,7 @@ private static File findDataDir() { var sub = base != null ? base.resolve("spotless-data") : null; if (sub != null) { return sub.toAbsolutePath().toFile(); - } - else { + } else { var home = Paths.get(System.getenv("user.home")); return home.resolve(".rome").toAbsolutePath().toFile(); } From c40afe736c23c7ff55e0090784cf1663c02baff9 Mon Sep 17 00:00:00 2001 From: "Tyler B. Thrailkill" Date: Tue, 18 Apr 2023 16:09:07 -0600 Subject: [PATCH 0740/1120] Update sortpom plugin to newest version Update the sortpom plugin to add sortDependencyManagement element. Remove dependency on IOUtils --- lib/build.gradle | 2 +- .../com/diffplug/spotless/pom/SortPomCfg.java | 4 +++- .../diffplug/spotless/pom/SortPomStep.java | 4 ++-- .../glue/pom/SortPomFormatterFunc.java | 22 ++++++++++--------- .../diffplug/spotless/maven/pom/SortPom.java | 6 ++++- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 9e31bed698..8db911e33e 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -115,7 +115,7 @@ dependencies { // scalafmt scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:3.7.3" // sortPom - sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' + sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.2.1' sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' } diff --git a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java index 93c11e1e31..7c9f0f09a9 100644 --- a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java +++ b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.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. @@ -43,6 +43,8 @@ public class SortPomCfg implements Serializable { public String sortDependencies = null; + public String sortDependencyManagement = null; + public String sortDependencyExclusions = null; public String sortPlugins = null; diff --git a/lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java b/lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java index 69d833f8e7..7f672d5c05 100644 --- a/lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java +++ b/lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.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. @@ -42,7 +42,7 @@ static class State implements Serializable { public State(SortPomCfg cfg, Provisioner provisioner) throws IOException { this.cfg = cfg; - this.jarState = JarState.from("com.github.ekryd.sortpom:sortpom-sorter:3.0.0", provisioner); + this.jarState = JarState.from("com.github.ekryd.sortpom:sortpom-sorter:3.2.1", provisioner); } FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { diff --git a/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java b/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java index 22a0249634..4dcde62bae 100644 --- a/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java +++ b/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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. @@ -15,11 +15,10 @@ */ package com.diffplug.spotless.glue.pom; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import java.io.*; +import java.nio.charset.Charset; +import java.nio.file.Files; -import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,10 +39,12 @@ public SortPomFormatterFunc(SortPomCfg cfg) { @Override public String apply(String input) throws Exception { - // SortPom expects a file to sort, so we write the inpout into a temporary file + // SortPom expects a file to sort, so we write the input into a temporary file File pom = File.createTempFile("pom", ".xml"); pom.deleteOnExit(); - IOUtils.write(input, new FileOutputStream(pom), cfg.encoding); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(pom, Charset.forName(cfg.encoding)))) { + writer.write(input); + } SortPomImpl sortPom = new SortPomImpl(); sortPom.setup(new MySortPomLogger(), PluginParameters.builder() .setPomFile(pom) @@ -52,11 +53,12 @@ public String apply(String input) throws Exception { .setFormatting(cfg.lineSeparator, cfg.expandEmptyElements, cfg.spaceBeforeCloseEmptyElement, cfg.keepBlankLines) .setIndent(cfg.nrOfIndentSpace, cfg.indentBlankLines, cfg.indentSchemaLocation) .setSortOrder(cfg.sortOrderFile, cfg.predefinedSortOrder) - .setSortEntities(cfg.sortDependencies, cfg.sortDependencyExclusions, cfg.sortPlugins, cfg.sortProperties, cfg.sortModules, cfg.sortExecutions) - .setTriggers(false) + .setSortEntities(cfg.sortDependencies, cfg.sortDependencyExclusions, cfg.sortDependencyManagement, + cfg.sortPlugins, cfg.sortProperties, cfg.sortModules, cfg.sortExecutions) + .setIgnoreLineSeparators(false) .build()); sortPom.sortPom(); - return IOUtils.toString(new FileInputStream(pom), cfg.encoding); + return Files.readString(pom.toPath(), Charset.forName(cfg.encoding)); } private static class MySortPomLogger implements SortPomLogger { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java index f4fe8cb96b..a1706ee381 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.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. @@ -59,6 +59,9 @@ public class SortPom implements FormatterStepFactory { @Parameter String sortDependencies = defaultValues.sortDependencies; + @Parameter + String sortDependencyManagement = defaultValues.sortDependencyManagement; + @Parameter String sortDependencyExclusions = defaultValues.sortDependencyExclusions; @@ -88,6 +91,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { cfg.predefinedSortOrder = predefinedSortOrder; cfg.sortOrderFile = sortOrderFile; cfg.sortDependencies = sortDependencies; + cfg.sortDependencyManagement = sortDependencyManagement; cfg.sortDependencyExclusions = sortDependencyExclusions; cfg.sortPlugins = sortPlugins; cfg.sortProperties = sortProperties; From a4ddf9d85bf867b10037fa5c84fcafc0e4e92dd2 Mon Sep 17 00:00:00 2001 From: "Tyler B. Thrailkill" Date: Tue, 18 Apr 2023 16:09:12 -0600 Subject: [PATCH 0741/1120] Add sortpom change to changelog --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 50141ece9c..323912888b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Update sortpom plugin to the newest version ## [2.38.0] - 2023-04-06 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index becf2e5ac7..f64b54b65d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Added `@DisableCachingByDefault` to `RegisterDependenciesTask`. +* Update sortpom plugin to the newest version ## [6.18.0] - 2023-04-06 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index df994a2b44..96a7b5189f 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +* Update sortpom plugin to the newest version ## [2.36.0] - 2023-04-06 ### Added From 1028dd1689aa8cda1ac957d3d40c47153fe4b683 Mon Sep 17 00:00:00 2001 From: "Tyler B. Thrailkill" Date: Tue, 18 Apr 2023 16:09:15 -0600 Subject: [PATCH 0742/1120] Update changelog with pr reference --- CHANGES.md | 3 ++- plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 323912888b..6d5b4d9ead 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -* Update sortpom plugin to the newest version +### Changes +* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) ## [2.38.0] - 2023-04-06 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f64b54b65d..1e875dff9c 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,7 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Added `@DisableCachingByDefault` to `RegisterDependenciesTask`. -* Update sortpom plugin to the newest version +### Changes +* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) ## [6.18.0] - 2023-04-06 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 96a7b5189f..911ffc306c 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,7 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -* Update sortpom plugin to the newest version +### Changes +* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) ## [2.36.0] - 2023-04-06 ### Added From e686e4f58263b6a046c62b124404a032ebce9a35 Mon Sep 17 00:00:00 2001 From: "Tyler B. Thrailkill" Date: Tue, 18 Apr 2023 16:09:18 -0600 Subject: [PATCH 0743/1120] Make sortpom version configurable Add test for version config Update SortPomTest to use ResourceHarness --- .../com/diffplug/spotless/pom/SortPomCfg.java | 2 ++ .../diffplug/spotless/pom/SortPomStep.java | 4 +++- .../diffplug/spotless/maven/pom/SortPom.java | 4 ++++ .../diffplug/spotless/pom/SortPomTest.java | 21 ++++++++++++------- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java index 7c9f0f09a9..8315035dc7 100644 --- a/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java +++ b/lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java @@ -21,6 +21,8 @@ public class SortPomCfg implements Serializable { private static final long serialVersionUID = 1L; + public String version = "3.2.1"; + public String encoding = "UTF-8"; public String lineSeparator = System.getProperty("line.separator"); diff --git a/lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java b/lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java index 7f672d5c05..4325d16516 100644 --- a/lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java +++ b/lib/src/main/java/com/diffplug/spotless/pom/SortPomStep.java @@ -27,6 +27,8 @@ public class SortPomStep { public static final String NAME = "sortPom"; + static final String PACKAGE = "com.github.ekryd.sortpom"; + static final String MAVEN_COORDINATE = PACKAGE + ":sortpom-sorter:"; private SortPomStep() {} @@ -42,7 +44,7 @@ static class State implements Serializable { public State(SortPomCfg cfg, Provisioner provisioner) throws IOException { this.cfg = cfg; - this.jarState = JarState.from("com.github.ekryd.sortpom:sortpom-sorter:3.2.1", provisioner); + this.jarState = JarState.from(MAVEN_COORDINATE + cfg.version, provisioner); } FormatterFunc createFormat() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java index a1706ee381..8620427f79 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/pom/SortPom.java @@ -26,6 +26,9 @@ public class SortPom implements FormatterStepFactory { private final SortPomCfg defaultValues = new SortPomCfg(); + @Parameter + String version = defaultValues.version; + @Parameter String encoding = defaultValues.encoding; @@ -80,6 +83,7 @@ public class SortPom implements FormatterStepFactory { @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { SortPomCfg cfg = new SortPomCfg(); + cfg.version = version; cfg.encoding = encoding; cfg.lineSeparator = lineSeparator; cfg.expandEmptyElements = expandEmptyElements; diff --git a/testlib/src/test/java/com/diffplug/spotless/pom/SortPomTest.java b/testlib/src/test/java/com/diffplug/spotless/pom/SortPomTest.java index f397962086..c88918f505 100644 --- a/testlib/src/test/java/com/diffplug/spotless/pom/SortPomTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/pom/SortPomTest.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,16 +17,21 @@ import org.junit.jupiter.api.Test; -import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.StepHarness; -import com.diffplug.spotless.TestProvisioner; +import com.diffplug.spotless.*; -public class SortPomTest { +public class SortPomTest extends ResourceHarness { @Test public void testSortPomWithDefaultConfig() throws Exception { SortPomCfg cfg = new SortPomCfg(); - Provisioner provisioner = TestProvisioner.mavenCentral(); - StepHarness harness = StepHarness.forStep(SortPomStep.create(cfg, provisioner)); - harness.testResource("pom/pom_dirty.xml", "pom/pom_clean_default.xml"); + FormatterStep step = SortPomStep.create(cfg, TestProvisioner.mavenCentral()); + StepHarness.forStep(step).testResource("pom/pom_dirty.xml", "pom/pom_clean_default.xml"); + } + + @Test + public void testSortPomWithVersion() throws Exception { + SortPomCfg cfg = new SortPomCfg(); + cfg.version = "3.2.1"; + FormatterStep step = SortPomStep.create(cfg, TestProvisioner.mavenCentral()); + StepHarness.forStep(step).testResource("pom/pom_dirty.xml", "pom/pom_clean_default.xml"); } } From e0c01205759d19dc1861c4a850305f7fbbf8b53f Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 19 Apr 2023 08:45:26 +0200 Subject: [PATCH 0744/1120] reproducer for issue #1679 --- .../main/resources/combined/issue1679.clean | 106 ++++++++++++++++++ .../main/resources/combined/issue1679.dirty | 104 +++++++++++++++++ .../combined/CombinedJavaFormatStepTest.java | 56 +++++++++ 3 files changed, 266 insertions(+) create mode 100644 testlib/src/main/resources/combined/issue1679.clean create mode 100644 testlib/src/main/resources/combined/issue1679.dirty create mode 100644 testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java diff --git a/testlib/src/main/resources/combined/issue1679.clean b/testlib/src/main/resources/combined/issue1679.clean new file mode 100644 index 0000000000..af86db275e --- /dev/null +++ b/testlib/src/main/resources/combined/issue1679.clean @@ -0,0 +1,106 @@ +/* + * Copyright 2021-2022 Creek Contributors (https://github.com/creek-service) + * + * 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 io.github.creek.service.basic.kafka.streams.demo.services; + +// formatting:off +// begin-snippet: includes-1 +import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicConfigBuilder.withPartitions; +import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicDescriptors.inputTopic; +import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicDescriptors.outputTopic; +// end-snippet +import java.time.Duration; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +// begin-snippet: includes-2 +import org.creekservice.api.kafka.metadata.OwnedKafkaTopicInput; +import org.creekservice.api.kafka.metadata.OwnedKafkaTopicOutput; +// end-snippet +import org.creekservice.api.platform.metadata.ComponentInput; +import org.creekservice.api.platform.metadata.ComponentInternal; +import org.creekservice.api.platform.metadata.ComponentOutput; +import org.creekservice.api.platform.metadata.ServiceDescriptor; +// formatting:on + +// begin-snippet: class-name +public final class HandleOccurrenceServiceDescriptor implements ServiceDescriptor { + // end-snippet + private static final List INPUTS = new ArrayList<>(); + private static final List INTERNALS = new ArrayList<>(); + private static final List OUTPUTS = new ArrayList<>(); + + // formatting:off +// begin-snippet: topic-resources + // Define the tweet-text input topic, conceptually owned by this service: + public static final OwnedKafkaTopicInput TweetTextStream = + register( + inputTopic( + "twitter.tweet.text", // Topic name + Long.class, // Topic key: Tweet id + String.class, // Topic value: Tweet text + withPartitions(5))); // Topic config + + // Define the output topic, again conceptually owned by this service: + public static final OwnedKafkaTopicOutput TweetHandleUsageStream = + register(outputTopic( + "twitter.handle.usage", + String.class, // Twitter handle + Integer.class, // Usage count + withPartitions(6) + .withRetentionTime(Duration.ofHours(12)) + )); +// end-snippet +// formatting:on + + public HandleOccurrenceServiceDescriptor() {} + + @Override + public String dockerImage() { + return "ghcr.io/creek-service/basic-kafka-streams-demo-handle-occurrence-service"; + } + + @Override + public Collection inputs() { + return List.copyOf(INPUTS); + } + + @Override + public Collection internals() { + return List.copyOf(INTERNALS); + } + + @Override + public Collection outputs() { + return List.copyOf(OUTPUTS); + } + + private static T register(final T input) { + INPUTS.add(input); + return input; + } + + // Uncomment if needed: + // private static T register(final T internal) { + // INTERNALS.add(internal); + // return internal; + // } + + private static T register(final T output) { + OUTPUTS.add(output); + return output; + } +} diff --git a/testlib/src/main/resources/combined/issue1679.dirty b/testlib/src/main/resources/combined/issue1679.dirty new file mode 100644 index 0000000000..70754cef6c --- /dev/null +++ b/testlib/src/main/resources/combined/issue1679.dirty @@ -0,0 +1,104 @@ +/* + * Copyright 2021-2022 Creek Contributors (https://github.com/creek-service) + * + * 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 io.github.creek.service.basic.kafka.streams.demo.services; + +// formatting:off +// begin-snippet: includes-1 +import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicConfigBuilder.withPartitions; +import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicDescriptors.inputTopic; +import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicDescriptors.outputTopic; +// end-snippet +import java.time.Duration; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +// begin-snippet: includes-2 +import org.creekservice.api.kafka.metadata.OwnedKafkaTopicInput; +import org.creekservice.api.kafka.metadata.OwnedKafkaTopicOutput; +// end-snippet +import org.creekservice.api.platform.metadata.ComponentInput; +import org.creekservice.api.platform.metadata.ComponentInternal; +import org.creekservice.api.platform.metadata.ComponentOutput; +import org.creekservice.api.platform.metadata.ServiceDescriptor; +// formatting:on + +// begin-snippet: class-name +public final class HandleOccurrenceServiceDescriptor implements ServiceDescriptor { + // end-snippet + private static final List INPUTS = new ArrayList<>(); + private static final List INTERNALS = new ArrayList<>(); + private static final List OUTPUTS = new ArrayList<>(); + + // formatting:off +// begin-snippet: topic-resources + // Define the tweet-text input topic, conceptually owned by this service: + public static final OwnedKafkaTopicInput TweetTextStream = + register( + inputTopic( + "twitter.tweet.text", // Topic name + Long.class, // Topic key: Tweet id + String.class, // Topic value: Tweet text + withPartitions(5))); // Topic config + + // Define the output topic, again conceptually owned by this service: + public static final OwnedKafkaTopicOutput TweetHandleUsageStream = + register(outputTopic( + "twitter.handle.usage", + String.class, // Twitter handle + Integer.class, // Usage count + withPartitions(6) + .withRetentionTime(Duration.ofHours(12)) + )); +// end-snippet +// formatting:on + + public HandleOccurrenceServiceDescriptor() {} + + @Override + public String dockerImage() { + return "ghcr.io/creek-service/basic-kafka-streams-demo-handle-occurrence-service"; + } + + @Override + public Collection inputs() { return List.copyOf(INPUTS); } + + @Override + public Collection internals() { + return List.copyOf(INTERNALS); + } + + @Override + public Collection outputs() { + return List.copyOf(OUTPUTS); + } + + private static T register(final T input) { + INPUTS.add(input); + return input; + } + + // Uncomment if needed: + // private static T register(final T internal) { + // INTERNALS.add(internal); + // return internal; + // } + + private static T register(final T output) { + OUTPUTS.add(output); + return output; + } +} \ No newline at end of file diff --git a/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java new file mode 100644 index 0000000000..cc32281771 --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java @@ -0,0 +1,56 @@ +/* + * 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.combined; + +import static com.diffplug.spotless.TestProvisioner.mavenCentral; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ResourceHarness; +import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.generic.EndWithNewlineStep; +import com.diffplug.spotless.generic.IndentStep; +import com.diffplug.spotless.generic.PipeStepPair; +import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; +import com.diffplug.spotless.java.GoogleJavaFormatStep; +import com.diffplug.spotless.java.ImportOrderStep; +import com.diffplug.spotless.java.RemoveUnusedImportsStep; + +public class CombinedJavaFormatStepTest extends ResourceHarness { + + @Test + void checkIssue1679() { + FormatterStep gjf = GoogleJavaFormatStep.create("1.15.0", "AOSP", mavenCentral()); + FormatterStep indentWithSpaces = IndentStep.Type.SPACE.create(); + FormatterStep importOrder = ImportOrderStep.forJava().createFrom(); + FormatterStep removeUnused = RemoveUnusedImportsStep.create(mavenCentral()); + FormatterStep trimTrailing = TrimTrailingWhitespaceStep.create(); + FormatterStep endWithNewLine = EndWithNewlineStep.create(); + PipeStepPair toggleOffOnPair = PipeStepPair.named(PipeStepPair.defaultToggleName()).openClose("formatting:off", "formatting:on").buildPair(); + try (StepHarness formatter = StepHarness.forSteps( + toggleOffOnPair.in(), + gjf, + indentWithSpaces, + importOrder, + removeUnused, + trimTrailing, + endWithNewLine, + toggleOffOnPair.out())) { + formatter.testResource("combined/issue1679.dirty", "combined/issue1679.clean"); + } + } +} From 0183cc20385361775fac3eacc0b11f8a443f4c0f Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Wed, 19 Apr 2023 10:20:53 +0200 Subject: [PATCH 0745/1120] fix #1679 --- .../glue/java/GoogleJavaFormatFormatterFunc.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java index f45394979a..87e086b440 100644 --- a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java +++ b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java @@ -23,6 +23,7 @@ import com.google.googlejavaformat.java.FormatterException; import com.google.googlejavaformat.java.ImportOrderer; import com.google.googlejavaformat.java.JavaFormatterOptions; +import com.google.googlejavaformat.java.JavaFormatterOptions.Style; import com.google.googlejavaformat.java.RemoveUnusedImports; import com.google.googlejavaformat.java.StringWrapper; @@ -37,13 +38,13 @@ public class GoogleJavaFormatFormatterFunc implements FormatterFunc { private final String version; @Nonnull - private final JavaFormatterOptions.Style formatterStyle; + private final Style formatterStyle; private final boolean reflowStrings; public GoogleJavaFormatFormatterFunc(@Nonnull String version, @Nonnull String style, boolean reflowStrings) { this.version = Objects.requireNonNull(version); - this.formatterStyle = JavaFormatterOptions.Style.valueOf(Objects.requireNonNull(style)); + this.formatterStyle = Style.valueOf(Objects.requireNonNull(style)); this.reflowStrings = reflowStrings; this.formatter = new Formatter(JavaFormatterOptions.builder() @@ -56,7 +57,10 @@ public GoogleJavaFormatFormatterFunc(@Nonnull String version, @Nonnull String st public String apply(@Nonnull String input) throws Exception { String formatted = formatter.formatSource(input); String removedUnused = RemoveUnusedImports.removeUnusedImports(formatted); - String sortedImports = ImportOrderer.reorderImports(removedUnused, formatterStyle); + // Issue #1679: we used to call ImportOrderer.reorderImports(String) here, but that is deprecated. + // Replacing the call with (the correct) reorderImports(String, Style) causes issues for Style.AOSP, + // so we force the style to GOOGLE for now (which is what the deprecated method did) + String sortedImports = ImportOrderer.reorderImports(removedUnused, Style.GOOGLE); return reflowLongStrings(sortedImports); } From a4c53cf29e58d05ee52ba86b45ba3ee632ad9a9f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 21 Apr 2023 20:59:25 +0000 Subject: [PATCH 0746/1120] fix(deps): update dependency org.mockito:mockito-core to v5.3.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index c235d2ac5a..a22e891679 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,4 +32,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.5.0.202303070854-r VER_JUNIT=5.9.2 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.3.0 +VER_MOCKITO=5.3.1 From 20729b8272c211f21f241037c307090356044135 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 22 Apr 2023 10:59:18 +0100 Subject: [PATCH 0747/1120] Fix conversion of file URL to Path, improve exception handling --- .../diffplug/spotless/maven/FileLocator.java | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java index fdf91ef68f..91aae3a055 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java @@ -19,6 +19,9 @@ import static java.nio.charset.StandardCharsets.UTF_8; import java.io.File; +import java.net.URISyntaxException; +import java.nio.file.FileSystemNotFoundException; +import java.nio.file.Path; import java.nio.file.Paths; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -119,21 +122,31 @@ private static byte[] hash(String value) { } private static File findDataDir() { - // JAR path is e.g. - // ~/.m2/repository/com/diffplug/spotless/spotless-plugin-maven/1.2.3/spotless-plugin-maven-1.2.3.jar - var codeSource = FileLocator.class.getProtectionDomain().getCodeSource(); - var location = codeSource != null ? codeSource.getLocation() : null; - var path = location != null ? location.getPath() : null; - var jarPath = path != null && !path.isBlank() ? Paths.get(path) : null; - var parent1 = jarPath != null ? jarPath.getParent() : null; - var parent2 = parent1 != null ? parent1.getParent() : null; - var base = parent2 != null ? parent2.getParent() : null; - var sub = base != null ? base.resolve("spotless-data") : null; - if (sub != null) { - return sub.toAbsolutePath().toFile(); - } else { - var home = Paths.get(System.getenv("user.home")); - return home.resolve(".rome").toAbsolutePath().toFile(); + try { + // JAR path is e.g. + // ~/.m2/repository/com/diffplug/spotless/spotless-plugin-maven/1.2.3/spotless-plugin-maven-1.2.3.jar + var codeSource = FileLocator.class.getProtectionDomain().getCodeSource(); + var location = codeSource != null ? codeSource.getLocation() : null; + var locationUri = location != null ? location.toURI() : null; + var jarPath = locationUri != null && "file".equals(locationUri.getScheme()) ? Path.of(locationUri) : null; + var parent1 = jarPath != null ? jarPath.getParent() : null; + var parent2 = parent1 != null ? parent1.getParent() : null; + var base = parent2 != null ? parent2.getParent() : null; + var sub = base != null ? base.resolve("spotless-data") : null; + if (sub != null) { + return sub.toAbsolutePath().toFile(); + } else { + return findUserHome(); + } + } catch (final SecurityException e) { + return findUserHome(); + } catch (final URISyntaxException | FileSystemNotFoundException | IllegalArgumentException e) { + throw new RuntimeException("Unable to determine data directory in local Maven repository", e); } } + + private static File findUserHome() { + var home = Paths.get(System.getenv("user.home")); + return home.resolve(".rome").toAbsolutePath().toFile(); + } } From bc3261ba30de82db7f81adc79da684837fdc8f3a Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 22 Apr 2023 11:13:22 +0100 Subject: [PATCH 0748/1120] use sha-256 for downloaded rome binary checksum --- .../diffplug/spotless/rome/RomeExecutableDownloader.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java index 5f389f0342..1307655e63 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java @@ -47,7 +47,7 @@ final class RomeExecutableDownloader { /** * The checksum algorithm to use for checking the integrity of downloaded files. */ - private static final String CHECKSUM_ALGORITHM = "MD5"; + private static final String CHECKSUM_ALGORITHM = "SHA256"; /** * The pattern for {@link String#format(String, Object...) String.format()} for @@ -229,7 +229,7 @@ private boolean checkFileWithChecksum(Path filePath) { * * @param file File to process. * @param algorithm The checksum algorithm to use. - * @return The MD5 checksum of the given file. + * @return The checksum of the given file. * @throws IOException When the file does not exist or could not be read. */ private String computeChecksum(Path file, String algorithm) throws IOException { @@ -276,7 +276,7 @@ private Path getChecksumPath(Path file) { var parent = file.getParent(); var base = parent != null ? parent : file; var fileName = file.getFileName(); - var checksumName = fileName != null ? fileName.toString() + ".md5" : "checksum.md5"; + var checksumName = fileName != null ? fileName.toString() + ".sha256" : "checksum.sha256"; return base.resolve(checksumName); } From 3456be2d5325d793a708b9c7bd31ccefea263d94 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 26 Apr 2023 09:15:48 +0000 Subject: [PATCH 0749/1120] fix(deps): update dependency org.junit.jupiter:junit-jupiter to v5.9.3 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a22e891679..31bed9971d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,6 +30,6 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 VER_JGIT=6.5.0.202303070854-r -VER_JUNIT=5.9.2 +VER_JUNIT=5.9.3 VER_ASSERTJ=3.24.2 VER_MOCKITO=5.3.1 From 82390aed00ff8491f55edc62ef7dc809ab0242e8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 18:48:51 +0000 Subject: [PATCH 0750/1120] fix(deps): update dependency com.facebook:ktfmt to v0.44 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 9e31bed698..2df76a2864 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -89,7 +89,7 @@ dependencies { jacksonCompileOnly "com.fasterxml.jackson.core:jackson-databind:$VER_JACKSON" jacksonCompileOnly "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$VER_JACKSON" // ktfmt - ktfmtCompileOnly "com.facebook:ktfmt:0.43" + ktfmtCompileOnly "com.facebook:ktfmt:0.44" ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") { version { strictly '1.7' // for JDK 8 compatibility From 5e75cb166ed97abc32d2337099465828e5797602 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 29 Apr 2023 12:03:50 -0700 Subject: [PATCH 0751/1120] Update README to reflect that we require Java 11 (fixes #1690). --- plugin-gradle/README.md | 5 +++-- plugin-maven/README.md | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index cea45a049f..d84645e51d 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -132,9 +132,10 @@ All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.dif ### Requirements -Spotless requires JRE 8+, and Gradle 6.1.1+. Some steps require JRE 11+, `Unsupported major.minor version` means you're using a step that needs a newer JRE. +Spotless requires JRE 11+ and Gradle 6.1.1 or newer. -If you're stuck on an older version of Gradle, `id 'com.diffplug.gradle.spotless' version '4.5.1'` supports all the way back to Gradle 2.x. +- If you're stuck on JRE 8, use [`id 'com.diffplug.spotless' version '6.13.0'` or older](https://github.com/diffplug/spotless/blob/main/plugin-gradle/CHANGES.md#6130---2023-01-14). +- If you're stuck on an older version of Gradle, [`id 'com.diffplug.gradle.spotless' version '4.5.1'` supports all the way back to Gradle 2.x](https://github.com/diffplug/spotless/blob/main/plugin-gradle/CHANGES.md#451---2020-07-04). diff --git a/plugin-maven/README.md b/plugin-maven/README.md index ba687a06c9..505eafeedd 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -137,7 +137,7 @@ Spotless consists of a list of formats (in the example above, `misc` and `java`) ### Requirements -Spotless requires Maven to be running on JRE 8+. +Spotless requires Maven to be running on JRE 11+. To use JRE 8, go back to [`2.30.0` or older](https://github.com/diffplug/spotless/blob/main/plugin-maven/CHANGES.md#2300---2023-01-13). From 8b2afb90b502d3134f6c75ff7ec252a05e2d753f Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 6 May 2023 23:31:01 +0800 Subject: [PATCH 0752/1120] PalantirJavaFormat in plugin-maven should take style parameter It's on the document, but we don't actually have such a parameter. --- .../diffplug/spotless/maven/java/PalantirJavaFormat.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java index df58764c1d..c8962aa07a 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java @@ -27,9 +27,13 @@ public class PalantirJavaFormat implements FormatterStepFactory { @Parameter private String version; + @Parameter + private String style; + @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { String version = this.version != null ? this.version : PalantirJavaFormatStep.defaultVersion(); - return PalantirJavaFormatStep.create(version, config.getProvisioner()); + String style = this.style != null ? this.style : PalantirJavaFormatStep.defaultStyle(); + return PalantirJavaFormatStep.create(version, style, config.getProvisioner()); } } From 0f6b1c1de6d6d6a0db6d2a959b363b4e50a927f8 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 6 May 2023 23:33:07 +0800 Subject: [PATCH 0753/1120] Update PalantirJavaFormat.java --- .../com/diffplug/spotless/maven/java/PalantirJavaFormat.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java index c8962aa07a..192588d85d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. From 22ad0b6414cdbd1da5705bd796e7560968f2cc77 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 10 May 2023 00:26:03 -0700 Subject: [PATCH 0754/1120] Update changelog. --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index df994a2b44..c00aeda138 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `palantir` step now accepts a `style` parameter, which is documentation had already claimed to do. ([#1694](https://github.com/diffplug/spotless/pull/1694)) ## [2.36.0] - 2023-04-06 ### Added From 0e9355773af3245cbb6142fe94eaf253e85460ee Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 10 May 2023 08:03:05 -0400 Subject: [PATCH 0755/1120] If `EquoBasedStepBuilder.get` fails, indicate the formatter --- .../diffplug/spotless/extra/EquoBasedStepBuilder.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index db2e6674db..7f0e181837 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -16,6 +16,7 @@ package com.diffplug.spotless.extra; import java.io.File; +import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -36,6 +37,7 @@ import dev.equo.solstice.p2.P2ClientCache; import dev.equo.solstice.p2.P2Model; import dev.equo.solstice.p2.P2QueryCache; +import dev.equo.solstice.p2.P2QueryResult; /** * Generic Eclipse based formatter step {@link State} builder. @@ -100,7 +102,12 @@ protected void addPlatformRepo(P2Model model, String version) { /** Creates the state of the configuration. */ EquoBasedStepBuilder.State get() throws Exception { - var query = createModelWithMirrors().query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW); + P2QueryResult query; + try { + query = createModelWithMirrors().query(P2ClientCache.PREFER_OFFLINE, P2QueryCache.ALLOW); + } catch (Exception x) { + throw new IOException("Failed to load " + formatterName + ": " + x, x); + } var classpath = new ArrayList(); var mavenDeps = new ArrayList(); mavenDeps.add("dev.equo.ide:solstice:1.0.3"); From fab850fd469674f963ebe6fa63dc9708573501aa Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 10 May 2023 08:08:45 -0400 Subject: [PATCH 0756/1120] changelog --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5ec89d7173..0ddf4511b0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * `Jvm.Support` now accepts `-SNAPSHOT` versions, treated as the non`-SNAPSHOT`. ([#1583](https://github.com/diffplug/spotless/issues/1583)) +### Fixed +* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) ## [2.38.0] - 2023-04-06 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index becf2e5ac7..56afb7c34f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Added `@DisableCachingByDefault` to `RegisterDependenciesTask`. +* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) ## [6.18.0] - 2023-04-06 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c00aeda138..06bf3c86bf 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * `palantir` step now accepts a `style` parameter, which is documentation had already claimed to do. ([#1694](https://github.com/diffplug/spotless/pull/1694)) +* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) ## [2.36.0] - 2023-04-06 ### Added From b516c65d267afa387a53d06c48f11a1d8603c70f Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Tue, 16 May 2023 06:32:17 +0100 Subject: [PATCH 0757/1120] Remove whitespace on empty line --- .../src/main/java/com/diffplug/spotless/maven/FileLocator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java index 91aae3a055..088c35a3d0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java @@ -144,7 +144,7 @@ private static File findDataDir() { throw new RuntimeException("Unable to determine data directory in local Maven repository", e); } } - + private static File findUserHome() { var home = Paths.get(System.getenv("user.home")); return home.resolve(".rome").toAbsolutePath().toFile(); From 39d61bc1bee17d937ea390880aa2a048684f8858 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Tue, 16 May 2023 06:56:40 +0100 Subject: [PATCH 0758/1120] SHA256 -> SHA-256 --- .../com/diffplug/spotless/rome/RomeExecutableDownloader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java index 1307655e63..578916a54b 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java @@ -47,7 +47,7 @@ final class RomeExecutableDownloader { /** * The checksum algorithm to use for checking the integrity of downloaded files. */ - private static final String CHECKSUM_ALGORITHM = "SHA256"; + private static final String CHECKSUM_ALGORITHM = "SHA-256"; /** * The pattern for {@link String#format(String, Object...) String.format()} for From 49ee3e2188aad00eaefee6dd36ecd8d1c7bf329d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 16 May 2023 06:35:43 +0000 Subject: [PATCH 0759/1120] chore(deps): update plugin com.gradle.enterprise to v3.13.2 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 41c2a123e0..c609e09116 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,7 +23,7 @@ plugins { // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise - id 'com.gradle.enterprise' version '3.13' + id 'com.gradle.enterprise' version '3.13.2' // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md id 'dev.equo.ide' version '1.0.1' apply false } From 6c8bff185e91e3115eda160b20255b1d25f23ac9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 16 May 2023 23:10:56 -0700 Subject: [PATCH 0760/1120] Update changelogs. --- CHANGES.md | 3 +-- plugin-gradle/CHANGES.md | 7 ++----- plugin-maven/CHANGES.md | 4 +--- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9096e9735f..faf42c0cee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `Jvm.Support` now accepts `-SNAPSHOT` versions, treated as the non`-SNAPSHOT`. ([#1583](https://github.com/diffplug/spotless/issues/1583)) -* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. https://github.com/diffplug/spotless/pull/1663 +* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) ### Fixed * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) ### Changes @@ -29,7 +29,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) - * Bump default `scalafmt` version `3.7.1` -> `3.7.3`. ([#1584](https://github.com/diffplug/spotless/pull/1584)) * Bump default Eclipse formatters for the 2023-03 release. ([#1662](https://github.com/diffplug/spotless/pull/1662)) * JDT and GrEclipse `4.26` -> `4.27` diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e10542f364..5d68193da9 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,10 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. https://github.com/diffplug/spotless/pull/1663 - +* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) ### Fixed -* Added `@DisableCachingByDefault` to `RegisterDependenciesTask`. +* Added `@DisableCachingByDefault` to `RegisterDependenciesTask`. ([#1666](https://github.com/diffplug/spotless/pull/1666)) * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) ### Changes * Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) @@ -27,7 +26,6 @@ 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)). - ### Fixed * Stop using deprecated conventions when used in Gradle >= `7.1`. ([#1618](https://github.com/diffplug/spotless/pull/1618)) ### Changes @@ -36,7 +34,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) - * Bump default `scalafmt` version `3.7.1` -> `3.7.3`. ([#1584](https://github.com/diffplug/spotless/pull/1584)) * Bump default Eclipse formatters for the 2023-03 release. ([#1662](https://github.com/diffplug/spotless/pull/1662)) * JDT and GrEclipse `4.26` -> `4.27` diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index fca3c4263e..d5744acb77 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. https://github.com/diffplug/spotless/pull/1663### Fixed +* Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) ### Fixed * `palantir` step now accepts a `style` parameter, which is documentation had already claimed to do. ([#1694](https://github.com/diffplug/spotless/pull/1694)) * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) @@ -16,7 +16,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `removeUnusedImport` can be configured to rely on `cleanthat-javaparser-unnecessaryimport`. Default remains `google-java-format`. ([#1589](https://github.com/diffplug/spotless/pull/1589)) * 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)). - * Fix non deterministic computation of cache fingerprint when using multiple formatters. ([#1643](https://github.com/diffplug/spotless/pull/1643) fixes [#1642](https://github.com/diffplug/spotless/pull/1642)) ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) @@ -24,7 +23,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `diktat` version `1.2.4.2` -> `1.2.5`. ([#1631](https://github.com/diffplug/spotless/pull/1631)) * Bump default `flexmark` version `0.62.2` -> `0.64.0`. ([#1302](https://github.com/diffplug/spotless/pull/1302)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) - * Bump default `scalafmt` version `3.7.1` -> `3.7.3`. ([#1584](https://github.com/diffplug/spotless/pull/1584)) * Bump default Eclipse formatters for the 2023-03 release. ([#1662](https://github.com/diffplug/spotless/pull/1662)) * JDT and GrEclipse `4.26` -> `4.27` From ed4e5c237507665dc0ea918206ff3dced3d8c181 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 16 May 2023 23:14:13 -0700 Subject: [PATCH 0761/1120] Move RomeStepConfig into its own file since it's so big. --- .../gradle/spotless/FormatExtension.java | 239 --------------- .../gradle/spotless/RomeStepConfig.java | 273 ++++++++++++++++++ 2 files changed, 273 insertions(+), 239 deletions(-) create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index c429c469d2..4fa74bc2ea 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -22,7 +22,6 @@ import java.io.Serializable; import java.nio.charset.Charset; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -38,7 +37,6 @@ import org.gradle.api.Action; import org.gradle.api.GradleException; import org.gradle.api.Project; -import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import org.gradle.api.file.ConfigurableFileTree; import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.BasePlugin; @@ -65,7 +63,6 @@ import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; -import com.diffplug.spotless.rome.RomeStep; import groovy.lang.Closure; @@ -652,242 +649,6 @@ protected FormatterStep createStep() { } } - public abstract static class RomeStepConfig> { - /** - * Optional path to the directory with configuration file for Rome. The file - * must be named {@code rome.json}. When none is given, the default - * configuration is used. If this is a relative path, it is resolved against the - * project's base directory. - */ - @Nullable - private Object configPath; - - /** - * Optional directory where the downloaded Rome executable is placed. If this is - * a relative path, it is resolved against the project's base directory. - * Defaults to - * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. - */ - @Nullable - private Object downloadDir; - - /** - * Optional path to the Rome executable. Either a version or a - * pathToExe should be specified. When not given, an attempt is - * made to download the executable for the given version from the network. When - * given, the executable is used and the version parameter is - * ignored. - *

    - * When an absolute path is given, that path is used as-is. When a relative path - * is given, it is resolved against the project's base directory. When only a - * file name (i.e. without any slashes or back slash path separators such as - * {@code rome}) is given, this is interpreted as the name of a command with - * executable that is in your {@code path} environment variable. Use - * {@code ./executable-name} if you want to use an executable in the project's - * base directory. - */ - @Nullable - private Object pathToExe; - - /** A reference to the Gradle project for which spotless is executed. */ - private final Project project; - - /** Replaces the current Rome formatter step with the given step. */ - private final Consumer replaceStep; - - /** - * Rome version to download, applies only when no pathToExe is - * specified explicitly. Either a version or a - * pathToExe should be specified. When not given, a default known - * version is used. For stable builds, it is recommended that you always set the - * version explicitly. This parameter is ignored when you specify a - * pathToExe explicitly. - */ - @Nullable - private String version; - - protected RomeStepConfig(Project project, Consumer replaceStep, String version) { - this.project = requireNonNull(project); - this.replaceStep = requireNonNull(replaceStep); - this.version = version; - } - - /** - * Optional path to the directory with configuration file for Rome. The file - * must be named {@code rome.json}. When none is given, the default - * configuration is used. If this is a relative path, it is resolved against the - * project's base directory. - * @return This step for further configuration. - */ - public Self configPath(Object configPath) { - this.configPath = configPath; - replaceStep(); - return getThis(); - } - - /** - * Optional directory where the downloaded Rome executable is placed. If this is - * a relative path, it is resolved against the project's base directory. - * Defaults to - * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. - * @return This step for further configuration. - */ - public Self downloadDir(Object downloadDir) { - this.downloadDir = downloadDir; - replaceStep(); - return getThis(); - } - - /** - * Optional path to the Rome executable. Overwrites the configured version. No - * attempt is made to download the Rome executable from the network. - *

    - * When an absolute path is given, that path is used as-is. When a relative path - * is given, it is resolved against the project's base directory. When only a - * file name (i.e. without any slashes or back slash path separators such as - * {@code rome}) is given, this is interpreted as the name of a command with - * executable that is in your {@code path} environment variable. Use - * {@code ./executable-name} if you want to use an executable in the project's - * base directory. - * @return This step for further configuration. - */ - public Self pathToExe(Object pathToExe) { - this.pathToExe = pathToExe; - replaceStep(); - return getThis(); - } - - /** - * Creates a new formatter step that formats code by calling the Rome - * executable, using the current configuration. - * - * @return A new formatter step for the Rome formatter. - */ - protected FormatterStep createStep() { - var builder = newBuilder(); - if (configPath != null) { - var resolvedConfigPath = project.file(configPath); - builder.withConfigPath(resolvedConfigPath.toString()); - } - builder.withLanguage(getLanguage()); - return builder.create(); - } - - /** - * Gets the language (syntax) of the input files to format. When - * null or the empty string, the language is detected automatically - * from the file name. Currently the following languages are supported by Rome: - *

      - *
    • js (JavaScript)
    • - *
    • jsx (JavaScript + JSX)
    • - *
    • js? (JavaScript or JavaScript + JSX, depending on the file - * extension)
    • - *
    • ts (TypeScript)
    • - *
    • tsx (TypeScript + JSX)
    • - *
    • ts? (TypeScript or TypeScript + JSX, depending on the file - * extension)
    • - *
    • json (JSON)
    • - *
    - * - * @return The language of the input files. - */ - protected abstract String getLanguage(); - - /** - * @return This Rome config instance. - */ - protected abstract Self getThis(); - - /** - * Creates a new Rome step and replaces the existing Rome step in the list of - * format steps. - */ - protected void replaceStep() { - replaceStep.accept(createStep()); - } - - /** - * Finds the data directory that can be used for storing shared data such as - * Rome executable globally. This is a directory in the local repository, e.g. - * ~/.m2/repository/com/diffplus/spotless/spotless-data. - * - * @return The directory for storing shared data. - */ - private File findDataDir() { - var currentRepo = project.getRepositories().stream() - .filter(r -> r instanceof MavenArtifactRepository) - .map(r -> (MavenArtifactRepository) r) - .filter(r -> "file".equals(r.getUrl().getScheme())) - .findAny().orElse(null); - // Temporarily add mavenLocal() repository to get its file URL - var localRepo = currentRepo != null ? (MavenArtifactRepository) currentRepo : project.getRepositories().mavenLocal(); - try { - // e.g. ~/.m2/repository/ - var repoPath = Paths.get(localRepo.getUrl().getPath()); - var dataPath = repoPath.resolve("com").resolve("diffplug").resolve("spotless").resolve("spotless-data"); - return dataPath.toAbsolutePath().toFile(); - } finally { - // Remove mavenLocal() repository again if it was not part of the project - if (currentRepo == null) { - project.getRepositories().remove(localRepo); - } - } - } - - /** - * A new builder for configuring a Rome step that either downloads the Rome - * executable with the given version from the network, or uses the executable - * from the given path. - * - * @return A builder for a Rome step. - */ - private RomeStep newBuilder() { - if (pathToExe != null) { - var resolvedPathToExe = resolvePathToExe(); - return RomeStep.withExePath(resolvedPathToExe); - } else { - var downloadDir = resolveDownloadDir(); - return RomeStep.withExeDownload(version, downloadDir); - } - } - - /** - * Resolves the path to the Rome executable. When the path is only a file name, - * do not perform any resolution and interpret it as a command that must be on - * the user's path. Otherwise resolve the executable path against the project's - * base directory. - * - * @param config Configuration from the Maven Mojo execution with details about - * the currently executed project. - * @return The resolved path to the Rome executable. - */ - private String resolvePathToExe() { - var fileNameOnly = pathToExe instanceof String && Paths.get(pathToExe.toString()).getNameCount() == 1; - if (fileNameOnly) { - return pathToExe.toString(); - } else { - return project.file(pathToExe).toString(); - } - } - - /** - * Resolves the directory to use for storing downloaded Rome executable. When a - * {@link #downloadDir} is given, use that directory, resolved against the - * current project's directory. Otherwise, use the {@code Rome} sub folder in - * the shared data directory. - * - * @param config Configuration for this step. - * @return The download directory for the Rome executable. - */ - private String resolveDownloadDir() { - if (downloadDir != null) { - return project.file(downloadDir).toString(); - } else { - return findDataDir().toPath().resolve("rome").toString(); - } - } - } - /** * Generic Rome formatter step that detects the language of the input file from * the file name. It should be specified as a formatter step for a generic diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java new file mode 100644 index 0000000000..99519f1766 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java @@ -0,0 +1,273 @@ +/* + * 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.gradle.spotless; + +import static java.util.Objects.requireNonNull; + +import java.io.File; +import java.nio.file.Paths; +import java.util.function.Consumer; + +import javax.annotation.Nullable; + +import org.gradle.api.Project; +import org.gradle.api.artifacts.repositories.MavenArtifactRepository; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.rome.RomeStep; + +public abstract class RomeStepConfig> { + /** + * Optional path to the directory with configuration file for Rome. The file + * must be named {@code rome.json}. When none is given, the default + * configuration is used. If this is a relative path, it is resolved against the + * project's base directory. + */ + @Nullable + private Object configPath; + + /** + * Optional directory where the downloaded Rome executable is placed. If this is + * a relative path, it is resolved against the project's base directory. + * Defaults to + * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + */ + @Nullable + private Object downloadDir; + + /** + * Optional path to the Rome executable. Either a version or a + * pathToExe should be specified. When not given, an attempt is + * made to download the executable for the given version from the network. When + * given, the executable is used and the version parameter is + * ignored. + *

    + * When an absolute path is given, that path is used as-is. When a relative path + * is given, it is resolved against the project's base directory. When only a + * file name (i.e. without any slashes or back slash path separators such as + * {@code rome}) is given, this is interpreted as the name of a command with + * executable that is in your {@code path} environment variable. Use + * {@code ./executable-name} if you want to use an executable in the project's + * base directory. + */ + @Nullable + private Object pathToExe; + + /** + * A reference to the Gradle project for which spotless is executed. + */ + private final Project project; + + /** + * Replaces the current Rome formatter step with the given step. + */ + private final Consumer replaceStep; + + /** + * Rome version to download, applies only when no pathToExe is + * specified explicitly. Either a version or a + * pathToExe should be specified. When not given, a default known + * version is used. For stable builds, it is recommended that you always set the + * version explicitly. This parameter is ignored when you specify a + * pathToExe explicitly. + */ + @Nullable + private String version; + + protected RomeStepConfig(Project project, Consumer replaceStep, String version) { + this.project = requireNonNull(project); + this.replaceStep = requireNonNull(replaceStep); + this.version = version; + } + + /** + * Optional path to the directory with configuration file for Rome. The file + * must be named {@code rome.json}. When none is given, the default + * configuration is used. If this is a relative path, it is resolved against the + * project's base directory. + * + * @return This step for further configuration. + */ + public Self configPath(Object configPath) { + this.configPath = configPath; + replaceStep(); + return getThis(); + } + + /** + * Optional directory where the downloaded Rome executable is placed. If this is + * a relative path, it is resolved against the project's base directory. + * Defaults to + * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + * + * @return This step for further configuration. + */ + public Self downloadDir(Object downloadDir) { + this.downloadDir = downloadDir; + replaceStep(); + return getThis(); + } + + /** + * Optional path to the Rome executable. Overwrites the configured version. No + * attempt is made to download the Rome executable from the network. + *

    + * When an absolute path is given, that path is used as-is. When a relative path + * is given, it is resolved against the project's base directory. When only a + * file name (i.e. without any slashes or back slash path separators such as + * {@code rome}) is given, this is interpreted as the name of a command with + * executable that is in your {@code path} environment variable. Use + * {@code ./executable-name} if you want to use an executable in the project's + * base directory. + * + * @return This step for further configuration. + */ + public Self pathToExe(Object pathToExe) { + this.pathToExe = pathToExe; + replaceStep(); + return getThis(); + } + + /** + * Creates a new formatter step that formats code by calling the Rome + * executable, using the current configuration. + * + * @return A new formatter step for the Rome formatter. + */ + protected FormatterStep createStep() { + var builder = newBuilder(); + if (configPath != null) { + var resolvedConfigPath = project.file(configPath); + builder.withConfigPath(resolvedConfigPath.toString()); + } + builder.withLanguage(getLanguage()); + return builder.create(); + } + + /** + * Gets the language (syntax) of the input files to format. When + * null or the empty string, the language is detected automatically + * from the file name. Currently the following languages are supported by Rome: + *

      + *
    • js (JavaScript)
    • + *
    • jsx (JavaScript + JSX)
    • + *
    • js? (JavaScript or JavaScript + JSX, depending on the file + * extension)
    • + *
    • ts (TypeScript)
    • + *
    • tsx (TypeScript + JSX)
    • + *
    • ts? (TypeScript or TypeScript + JSX, depending on the file + * extension)
    • + *
    • json (JSON)
    • + *
    + * + * @return The language of the input files. + */ + protected abstract String getLanguage(); + + /** + * @return This Rome config instance. + */ + protected abstract Self getThis(); + + /** + * Creates a new Rome step and replaces the existing Rome step in the list of + * format steps. + */ + protected void replaceStep() { + replaceStep.accept(createStep()); + } + + /** + * Finds the data directory that can be used for storing shared data such as + * Rome executable globally. This is a directory in the local repository, e.g. + * ~/.m2/repository/com/diffplus/spotless/spotless-data. + * + * @return The directory for storing shared data. + */ + private File findDataDir() { + var currentRepo = project.getRepositories().stream() + .filter(r -> r instanceof MavenArtifactRepository) + .map(r -> (MavenArtifactRepository) r) + .filter(r -> "file".equals(r.getUrl().getScheme())) + .findAny().orElse(null); + // Temporarily add mavenLocal() repository to get its file URL + var localRepo = currentRepo != null ? (MavenArtifactRepository) currentRepo : project.getRepositories().mavenLocal(); + try { + // e.g. ~/.m2/repository/ + var repoPath = Paths.get(localRepo.getUrl().getPath()); + var dataPath = repoPath.resolve("com").resolve("diffplug").resolve("spotless").resolve("spotless-data"); + return dataPath.toAbsolutePath().toFile(); + } finally { + // Remove mavenLocal() repository again if it was not part of the project + if (currentRepo == null) { + project.getRepositories().remove(localRepo); + } + } + } + + /** + * A new builder for configuring a Rome step that either downloads the Rome + * executable with the given version from the network, or uses the executable + * from the given path. + * + * @return A builder for a Rome step. + */ + private RomeStep newBuilder() { + if (pathToExe != null) { + var resolvedPathToExe = resolvePathToExe(); + return RomeStep.withExePath(resolvedPathToExe); + } else { + var downloadDir = resolveDownloadDir(); + return RomeStep.withExeDownload(version, downloadDir); + } + } + + /** + * Resolves the path to the Rome executable. When the path is only a file name, + * do not perform any resolution and interpret it as a command that must be on + * the user's path. Otherwise resolve the executable path against the project's + * base directory. + * + * @param config Configuration from the Maven Mojo execution with details about + * the currently executed project. + * @return The resolved path to the Rome executable. + */ + private String resolvePathToExe() { + var fileNameOnly = pathToExe instanceof String && Paths.get(pathToExe.toString()).getNameCount() == 1; + if (fileNameOnly) { + return pathToExe.toString(); + } else { + return project.file(pathToExe).toString(); + } + } + + /** + * Resolves the directory to use for storing downloaded Rome executable. When a + * {@link #downloadDir} is given, use that directory, resolved against the + * current project's directory. Otherwise, use the {@code Rome} sub folder in + * the shared data directory. + * + * @param config Configuration for this step. + * @return The download directory for the Rome executable. + */ + private String resolveDownloadDir() { + if (downloadDir != null) { + return project.file(downloadDir).toString(); + } else { + return findDataDir().toPath().resolve("rome").toString(); + } + } +} From 09d8498fc3763934018af35c659cf6831f1cc1bc Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 16 May 2023 23:18:41 -0700 Subject: [PATCH 0762/1120] Fix root path issue in the Rome formatter. --- .../java/com/diffplug/gradle/spotless/RomeStepConfig.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java index 99519f1766..ab55152015 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java @@ -26,6 +26,7 @@ import org.gradle.api.Project; import org.gradle.api.artifacts.repositories.MavenArtifactRepository; +import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.rome.RomeStep; @@ -207,7 +208,11 @@ private File findDataDir() { var localRepo = currentRepo != null ? (MavenArtifactRepository) currentRepo : project.getRepositories().mavenLocal(); try { // e.g. ~/.m2/repository/ - var repoPath = Paths.get(localRepo.getUrl().getPath()); + var path = localRepo.getUrl().getPath(); + if (FileSignature.machineIsWin() && path.startsWith("/")) { + path = path.substring(1); + } + var repoPath = Paths.get(path); var dataPath = repoPath.resolve("com").resolve("diffplug").resolve("spotless").resolve("spotless-data"); return dataPath.toAbsolutePath().toFile(); } finally { From d8913c4fc92e58c3a738c58729df20488e0aff5e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 16 May 2023 23:20:24 -0700 Subject: [PATCH 0763/1120] Another changelog fix. --- plugin-maven/CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d5744acb77..993404f1fe 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `removeUnusedImport` can be configured to rely on `cleanthat-javaparser-unnecessaryimport`. Default remains `google-java-format`. ([#1589](https://github.com/diffplug/spotless/pull/1589)) * 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)). +### Fixed * Fix non deterministic computation of cache fingerprint when using multiple formatters. ([#1643](https://github.com/diffplug/spotless/pull/1643) fixes [#1642](https://github.com/diffplug/spotless/pull/1642)) ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) From a56e7e603aeccf123c5d8a15fd3ad33129c640f6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 May 2023 00:18:12 -0700 Subject: [PATCH 0764/1120] Use Path.of(URI) instead of manual string wrangling. --- .../com/diffplug/gradle/spotless/RomeStepConfig.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java index ab55152015..f739e922d2 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java @@ -18,6 +18,7 @@ import static java.util.Objects.requireNonNull; import java.io.File; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.function.Consumer; @@ -26,7 +27,6 @@ import org.gradle.api.Project; import org.gradle.api.artifacts.repositories.MavenArtifactRepository; -import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.rome.RomeStep; @@ -208,11 +208,7 @@ private File findDataDir() { var localRepo = currentRepo != null ? (MavenArtifactRepository) currentRepo : project.getRepositories().mavenLocal(); try { // e.g. ~/.m2/repository/ - var path = localRepo.getUrl().getPath(); - if (FileSignature.machineIsWin() && path.startsWith("/")) { - path = path.substring(1); - } - var repoPath = Paths.get(path); + var repoPath = Path.of(localRepo.getUrl()); var dataPath = repoPath.resolve("com").resolve("diffplug").resolve("spotless").resolve("spotless-data"); return dataPath.toAbsolutePath().toFile(); } finally { @@ -246,8 +242,6 @@ private RomeStep newBuilder() { * the user's path. Otherwise resolve the executable path against the project's * base directory. * - * @param config Configuration from the Maven Mojo execution with details about - * the currently executed project. * @return The resolved path to the Rome executable. */ private String resolvePathToExe() { @@ -265,7 +259,6 @@ private String resolvePathToExe() { * current project's directory. Otherwise, use the {@code Rome} sub folder in * the shared data directory. * - * @param config Configuration for this step. * @return The download directory for the Rome executable. */ private String resolveDownloadDir() { From 64ab3140d45d9a6336f5c3dd7c9f9cd54bba8185 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 17 May 2023 12:15:13 -0700 Subject: [PATCH 0765/1120] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index faf42c0cee..9d65dfd9b5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) ### Fixed * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) +* Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.38.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes * Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 5d68193da9..d064173af6 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,6 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Added `@DisableCachingByDefault` to `RegisterDependenciesTask`. ([#1666](https://github.com/diffplug/spotless/pull/1666)) * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) +* Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `6.18.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes * Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 993404f1fe..5777493c41 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,6 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * `palantir` step now accepts a `style` parameter, which is documentation had already claimed to do. ([#1694](https://github.com/diffplug/spotless/pull/1694)) * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) +* Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.36.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes * Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) From 5cf7a7e5a6f57795a20d9da012a89135c173f07e Mon Sep 17 00:00:00 2001 From: Mitchell Skaggs Date: Thu, 18 May 2023 12:16:52 -0500 Subject: [PATCH 0766/1120] Support KtLint 0.49.0, drop KtLint 0.46.0 Currently, we work around name-mangling issues with special Kotlin classes. The root issue is tracked here: https://github.com/pinterest/ktlint/issues/2041 Also fixes the IntelliJ .editorconfig import order property to better match Eclipse formatting --- .editorconfig | 2 +- lib/build.gradle | 10 +- .../compat/KtLintCompat0Dot46Dot0Adapter.java | 119 ---------- .../compat/KtLintCompat0Dot49Dot0Adapter.java | 210 ++++++++++++++++++ .../glue/ktlint/KtlintFormatterFunc.java | 12 +- .../diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../KtLintCompat0Dot49Dot0AdapterTest.java | 70 ++++++ .../resources/EmptyClassBody.kt | 3 + .../resources/FailsNoSemicolons.kt | 3 + .../spotless/kotlin/KtLintStepTest.java | 32 ++- 10 files changed, 321 insertions(+), 142 deletions(-) delete mode 100644 lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java create mode 100644 lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java create mode 100644 lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java create mode 100644 lib/src/testCompatKtLint0Dot49Dot0/resources/EmptyClassBody.kt create mode 100644 lib/src/testCompatKtLint0Dot49Dot0/resources/FailsNoSemicolons.kt diff --git a/.editorconfig b/.editorconfig index 4042d549fd..5d0704bd2b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,7 +14,7 @@ indent_size = 2 [*.java] # Doc: https://youtrack.jetbrains.com/issue/IDEA-170643#focus=streamItem-27-3708697.0-0 -ij_java_imports_layout = java.**,|,javax.**,|,org.**,|,com.**,|,com.diffplug.**,|,* +ij_java_imports_layout = $*,|,java.**,|,javax.**,|,org.**,|,com.**,|,com.diffplug.**,|,* ij_java_use_single_class_imports = true ij_java_class_count_to_use_import_on_demand = 999 ij_java_names_count_to_use_import_on_demand = 999 diff --git a/lib/build.gradle b/lib/build.gradle index 8db911e33e..c0564e5c12 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -44,9 +44,9 @@ versionCompatibility { // we will support no more than 2 breaking changes at a time = 3 incompatible versions // we will try to drop down to only one version if a stable API can be maintained for a full year versions = [ - '0.46.0', '0.47.0', '0.48.0', + '0.49.0', ] targetSourceSetName = 'ktlint' } @@ -96,20 +96,20 @@ dependencies { } } // ktlint - String VER_KTLINT='0.46.1' + String VER_KTLINT='0.47.1' ktlintCompileOnly "com.pinterest:ktlint:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-core:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" - compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.46.0' - compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.46.0' - compatKtLint0Dot46Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.46.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' + compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.49.0' + compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.49.0' + compatKtLint0Dot49Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0' // palantirJavaFormat palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm // scalafmt diff --git a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java b/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java deleted file mode 100644 index afaf2ad19f..0000000000 --- a/lib/src/compatKtLint0Dot46Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot46Dot0Adapter.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2022-2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.ktlint.compat; - -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import com.pinterest.ktlint.core.KtLint; -import com.pinterest.ktlint.core.LintError; -import com.pinterest.ktlint.core.RuleSet; -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; -import com.pinterest.ktlint.core.api.EditorConfigOverride; -import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; -import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; -import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; - -import kotlin.Pair; -import kotlin.Unit; -import kotlin.jvm.functions.Function2; - -public class KtLintCompat0Dot46Dot0Adapter implements KtLintCompatAdapter { - - static class FormatterCallback implements Function2 { - @Override - public Unit invoke(LintError lint, Boolean corrected) { - if (!corrected) { - KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); - } - return null; - } - } - - @Override - public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - Path editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { - final FormatterCallback formatterCallback = new FormatterCallback(); - - final List rulesets = new ArrayList<>(); - rulesets.add(new StandardRuleSetProvider().get()); - - if (useExperimental) { - rulesets.add(new ExperimentalRuleSetProvider().get()); - } - - EditorConfigOverride editorConfigOverride; - if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); - } else { - editorConfigOverride = createEditorConfigOverride(rulesets, editorConfigOverrideMap); - } - - return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - path.toFile().getAbsolutePath(), - text, - rulesets, - userData, - formatterCallback, - isScript, - editorConfigPath == null ? null : editorConfigPath.toFile().getAbsolutePath(), - false, - editorConfigOverride, - false)); - } - - /** - * Create EditorConfigOverride from user provided parameters. - * Calling this method requires KtLint 0.45.2. - */ - private static EditorConfigOverride createEditorConfigOverride(final List rulesets, Map editorConfigOverrideMap) { - // Get properties from rules in the rule sets - Stream> ruleProperties = rulesets.stream() - .flatMap(ruleSet -> Arrays.stream(ruleSet.getRules())) - .filter(rule -> rule instanceof UsesEditorConfigProperties) - .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); - - // Create a mapping of properties to their names based on rule properties and default properties - Map> supportedProperties = Stream - .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) - .distinct() - .collect(Collectors.toMap(property -> property.getType().getName(), property -> property)); - - // Create config properties based on provided property names and values - @SuppressWarnings("unchecked") - Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() - .map(entry -> { - UsesEditorConfigProperties.EditorConfigProperty property = supportedProperties.get(entry.getKey()); - if (property != null) { - return new Pair<>(property, entry.getValue()); - } else { - return null; - } - }) - .filter(Objects::nonNull) - .toArray(Pair[]::new); - - return EditorConfigOverride.Companion.from(properties); - } -} diff --git a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java new file mode 100644 index 0000000000..86ca69c352 --- /dev/null +++ b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java @@ -0,0 +1,210 @@ +/* + * 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.ktlint.compat; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.pinterest.ktlint.rule.engine.api.Code; +import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; +import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride; +import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine; +import com.pinterest.ktlint.rule.engine.api.LintError; +import com.pinterest.ktlint.rule.engine.core.api.Rule; +import com.pinterest.ktlint.rule.engine.core.api.RuleProvider; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EndOfLinePropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentSizeEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; +import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; + +import kotlin.Pair; +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat0Dot49Dot0Adapter implements KtLintCompatAdapter { + + private static final Logger logger = LoggerFactory.getLogger(KtLintCompat0Dot49Dot0Adapter.class); + + private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; + + static { + List> list = new ArrayList<>(); + list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); + list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY()); + list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); + list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); + list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); + list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); + list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); + DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + } + + private static final Method RULEID_METHOD; + private static final Method CREATE_RULESET_EXECUTION_METHOD; + private static final Method CREATE_RULE_EXECUTION_METHOD; + + static { + try { + RULEID_METHOD = LintError.class.getMethod("getRuleId-6XN97os"); + CREATE_RULESET_EXECUTION_METHOD = RuleExecutionEditorConfigPropertyKt.class.getMethod("createRuleSetExecutionEditorConfigProperty-fqiwTpU", String.class, RuleExecution.class); + CREATE_RULE_EXECUTION_METHOD = RuleExecutionEditorConfigPropertyKt.class.getMethod("createRuleExecutionEditorConfigProperty-U7AdEiY", String.class, RuleExecution.class); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + } + + private static String getRuleId(LintError lint) { + try { + return (String) RULEID_METHOD.invoke(lint); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + private static EditorConfigProperty createRuleSetExecution(String id, RuleExecution execution) { + try { + return (EditorConfigProperty) CREATE_RULESET_EXECUTION_METHOD.invoke(null, id, execution); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + private static EditorConfigProperty createRuleExecution(String id, RuleExecution execution) { + try { + return (EditorConfigProperty) CREATE_RULE_EXECUTION_METHOD.invoke(null, id, execution); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + static class FormatterCallback implements Function2 { + + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), getRuleId(lint), lint.getDetail()); + } + return Unit.INSTANCE; + } + } + + @Override + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + Path editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + Set allRuleProviders = new LinkedHashSet<>( + new StandardRuleSetProvider().getRuleProviders()); + + // TODO: Should we keep `useExperimental` now that ktlint uses an EditorConfig property for this purpose? + if (useExperimental) { + String experimentalRulesPropertyName = RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY().getName(); + Object experimentalOverride = editorConfigOverrideMap.get(experimentalRulesPropertyName); + if (experimentalOverride != null) { + logger.warn("`useExperimental` parameter is `true` and `ktlint_experimental` property is set, `useExperimental` will take priority!"); + editorConfigOverrideMap.put(experimentalRulesPropertyName, "enabled"); + } + } + + EditorConfigOverride editorConfigOverride; + if (editorConfigOverrideMap.isEmpty()) { + editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); + } else { + editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( + RuleProvider::createNewRuleInstance).collect(Collectors.toList()), + editorConfigOverrideMap); + } + EditorConfigDefaults editorConfig; + if (editorConfigPath == null || !Files.exists(editorConfigPath)) { + editorConfig = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); + } else { + editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath); + } + + return new KtLintRuleEngine( + allRuleProviders, + editorConfig, + editorConfigOverride, + false, + path.getFileSystem()) + .format(Code.Companion.fromPath(path), formatterCallback); + } + + /** + * Create EditorConfigOverride from user provided parameters. + */ + private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { + // Get properties from rules in the rule sets + Stream> ruleProperties = rules.stream() + .flatMap(rule -> rule.getUsesEditorConfigProperties().stream()); + + // Create a mapping of properties to their names based on rule properties and default properties + Map> supportedProperties = Stream + .concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream()) + .distinct() + .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); + + // Create config properties based on provided property names and values + @SuppressWarnings("unchecked") + Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() + .map(entry -> { + EditorConfigProperty property = supportedProperties.get(entry.getKey()); + if (property != null) { + return new Pair<>(property, entry.getValue()); + } else if (entry.getKey().startsWith("ktlint_")) { + String[] parts = entry.getKey().substring(7).split("_", 2); + if (parts.length == 1) { + // convert ktlint_{ruleset} to {ruleset} + String qualifiedRuleId = parts[0] + ":"; + property = createRuleSetExecution(qualifiedRuleId, RuleExecution.disabled); + } else { + // convert ktlint_{ruleset}_{rulename} to {ruleset}:{rulename} + String qualifiedRuleId = parts[0] + ":" + parts[1]; + property = createRuleExecution(qualifiedRuleId, RuleExecution.disabled); + } + return new Pair<>(property, entry.getValue()); + } else { + return null; + } + }) + .filter(Objects::nonNull) + .toArray(Pair[]::new); + + return EditorConfigOverride.Companion.from(properties); + } +} diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 02ff5355e3..f6f4203fef 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -38,15 +38,17 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, FileSignature editorConfigPath, Map userData, Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); - if (minorVersion >= 48) { + if (minorVersion >= 49) { + // Packages and modules moved around (`ktlint-core` -> `ktlint-rule-engine`) + // Experimental ruleset was replaced by implementing `Rule.Experimental` and checking the `ktlint_experimental` `.editorconfig` property + // `RuleId` and `RuleSetId` became inline classes (mangled to be unrepresentable in Java source code, so reflection is needed), tracked here: https://github.com/pinterest/ktlint/issues/2041 + this.adapter = new KtLintCompat0Dot49Dot0Adapter(); + } else if (minorVersion == 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class this.adapter = new KtLintCompat0Dot48Dot0Adapter(); - } else if (minorVersion == 47) { + } else { // rename RuleSet to RuleProvider this.adapter = new KtLintCompat0Dot47Dot0Adapter(); - } else { - // DefaultEditorConfigProperties.INSTANCE.getDefaultEditorConfigProperties() renamed to .getEditorConfigProperties() - this.adapter = new KtLintCompat0Dot46Dot0Adapter(); } this.editorConfigPath = editorConfigPath; this.useExperimental = useExperimental; diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 0d75460902..6e82538b04 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -36,7 +36,7 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.48.2"; + private static final String DEFAULT_VERSION = "0.49.1"; static final String NAME = "ktlint"; static final String PACKAGE = "com.pinterest"; static final String MAVEN_COORDINATE = PACKAGE + ":ktlint:"; diff --git a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java new file mode 100644 index 0000000000..ede67e0174 --- /dev/null +++ b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java @@ -0,0 +1,70 @@ +/* + * 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.ktlint.compat; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +public class KtLintCompat0Dot49Dot0AdapterTest { + @Test + public void testDefaults(@TempDir Path path) throws IOException { + KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); + String text = loadAndWriteText(path, "EmptyClassBody.kt"); + final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + + String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + assertEquals("class EmptyClassBody\n", formatted); + } + + @Test + public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { + KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); + String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("indent_style", "tab"); + editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + + String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); + } + + private static String loadAndWriteText(Path path, String name) throws IOException { + try (InputStream is = KtLintCompat0Dot49Dot0AdapterTest.class.getResourceAsStream("/" + name)) { + Files.copy(is, path.resolve(name)); + } + return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8); + } + +} diff --git a/lib/src/testCompatKtLint0Dot49Dot0/resources/EmptyClassBody.kt b/lib/src/testCompatKtLint0Dot49Dot0/resources/EmptyClassBody.kt new file mode 100644 index 0000000000..7da53fb78d --- /dev/null +++ b/lib/src/testCompatKtLint0Dot49Dot0/resources/EmptyClassBody.kt @@ -0,0 +1,3 @@ +class EmptyClassBody { + +} diff --git a/lib/src/testCompatKtLint0Dot49Dot0/resources/FailsNoSemicolons.kt b/lib/src/testCompatKtLint0Dot49Dot0/resources/FailsNoSemicolons.kt new file mode 100644 index 0000000000..4cf05ceacf --- /dev/null +++ b/lib/src/testCompatKtLint0Dot49Dot0/resources/FailsNoSemicolons.kt @@ -0,0 +1,3 @@ +class FailsNoSemicolons { + val i = 0; +} diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 6700be168d..9af6685906 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -31,20 +31,10 @@ void behavior() { .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo( "Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + + "rule: standard:no-wildcard-imports\n" + "Wildcard import"); } - @Test - void works0_46_0() { - FormatterStep step = KtLintStep.create("0.46.0", TestProvisioner.mavenCentral()); - StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + - "Wildcard import"); - } - @Test void works0_47_0() { FormatterStep step = KtLintStep.create("0.47.0", TestProvisioner.mavenCentral()); @@ -85,6 +75,26 @@ void works0_48_1() { "Wildcard import"); } + @Test + void works0_49_0() { + FormatterStep step = KtLintStep.create("0.49.0", TestProvisioner.mavenCentral()); + StepHarnessWithFile.forStep(this, step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: standard:no-wildcard-imports\n" + + "Wildcard import"); + } + + @Test + void works0_49_1() { + FormatterStep step = KtLintStep.create("0.49.1", TestProvisioner.mavenCentral()); + StepHarnessWithFile.forStep(this, step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: standard:no-wildcard-imports\n" + + "Wildcard import"); + } + @Test void equality() { new SerializableEqualityTester() { From a66ef3db9cc9b7b41e481394a84f2e7f8e32a39a Mon Sep 17 00:00:00 2001 From: Mitchell Skaggs Date: Thu, 18 May 2023 12:35:50 -0500 Subject: [PATCH 0767/1120] Add ktlint 0.49.1 update to changelog --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 9d65dfd9b5..3ab7fc3745 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.38.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes * Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) +* Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) ## [2.38.0] - 2023-04-06 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d064173af6..a5f9d8c6c6 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `6.18.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes * Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) +* Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) ## [6.18.0] - 2023-04-06 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 5777493c41..e006f3462d 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.36.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes * Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) +* Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) ## [2.36.0] - 2023-04-06 ### Added From 88845df2179c3ea457e67eff39f7b3541908363c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 19 May 2023 09:35:04 -0700 Subject: [PATCH 0768/1120] Tweak changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 3ab7fc3745..094f5b43f0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) * Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) + * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. ## [2.38.0] - 2023-04-06 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index a5f9d8c6c6..f140151867 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) * Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) + * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. ## [6.18.0] - 2023-04-06 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e006f3462d..154b2becaa 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) * Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) + * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. ## [2.36.0] - 2023-04-06 ### Added From 87efad89426314c4969807fcc3b5725dddd8c642 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 20 May 2023 16:07:56 -0700 Subject: [PATCH 0769/1120] Simplify ktlint build. --- lib/build.gradle | 5 ----- .../diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java | 3 --- 2 files changed, 8 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index c0564e5c12..058e5f4132 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -96,11 +96,6 @@ dependencies { } } // ktlint - String VER_KTLINT='0.47.1' - ktlintCompileOnly "com.pinterest:ktlint:$VER_KTLINT" - ktlintCompileOnly "com.pinterest.ktlint:ktlint-core:$VER_KTLINT" - ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" - ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index f6f4203fef..fba855bb9a 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -19,8 +19,6 @@ import java.nio.file.Path; import java.util.Map; -import org.jetbrains.annotations.NotNull; - import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.glue.ktlint.compat.*; @@ -29,7 +27,6 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { private final Map userData; private final boolean isScript; - @NotNull private final KtLintCompatAdapter adapter; private final boolean useExperimental; private final FileSignature editorConfigPath; From a10f2344c9bf6c60c737754f88cc8224a11c7858 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 20 May 2023 16:09:09 -0700 Subject: [PATCH 0770/1120] Fix rome formatter on Apple Silicon. --- .../main/java/com/diffplug/spotless/rome/Architecture.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java b/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java index 64e0a94640..9ceaeb8632 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/Architecture.java @@ -43,9 +43,6 @@ public static Architecture guess() { if (arch.equals("ppc64le")) { throw new IllegalStateException(msg); } - if (arch.equals("aarch64")) { - throw new IllegalStateException(msg); - } if (arch.equals("s390x")) { throw new IllegalStateException(msg); } @@ -55,6 +52,9 @@ public static Architecture guess() { if (arch.equals("ppc")) { throw new IllegalStateException(msg); } + if (arch.equals("aarch64")) { + return ARM64; + } if (arch.equals("arm")) { if (version.contains("v7")) { throw new IllegalStateException(msg); From e1c06a8ef55ef1ceb98b566459c298c0521cecf9 Mon Sep 17 00:00:00 2001 From: Patrick Schmidt Date: Mon, 22 May 2023 19:44:09 +0200 Subject: [PATCH 0771/1120] Introduce semantics-aware Java import ordering. (fixes #522) --- .../spotless/java/ImportOrderStep.java | 39 +++- .../diffplug/spotless/java/ImportSorter.java | 13 +- .../spotless/java/ImportSorterImpl.java | 203 ++++++++++++++++-- .../gradle/spotless/JavaExtension.java | 40 +++- .../spotless/maven/java/ImportOrder.java | 34 ++- .../JavaCodeSortedLexicographic.test | 13 ++ .../JavaCodeSortedSemanticSort.test | 13 ++ .../JavaCodeUnsortedSemanticSort.test | 15 ++ .../spotless/java/ImportOrderStepTest.java | 16 +- 9 files changed, 351 insertions(+), 35 deletions(-) create mode 100644 testlib/src/main/resources/java/importsorter/JavaCodeSortedLexicographic.test create mode 100644 testlib/src/main/resources/java/importsorter/JavaCodeSortedSemanticSort.test create mode 100644 testlib/src/main/resources/java/importsorter/JavaCodeUnsortedSemanticSort.test diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java index 686c9cfcaf..7f100e0adc 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -39,6 +40,9 @@ public final class ImportOrderStep { private static final boolean WILDCARDS_LAST_DEFAULT = false; + private static final boolean SEMANTIC_SORT_DEFAULT = true; + private static final Set TREAT_AS_PACKAGE_DEFAULT = null; + private static final Set TREAT_AS_CLASS_DEFAULT = null; private final String lineFormat; @@ -55,27 +59,34 @@ private ImportOrderStep(String lineFormat) { } public FormatterStep createFrom(String... importOrder) { - return createFrom(WILDCARDS_LAST_DEFAULT, importOrder); + return createFrom(WILDCARDS_LAST_DEFAULT, SEMANTIC_SORT_DEFAULT, TREAT_AS_PACKAGE_DEFAULT, + TREAT_AS_CLASS_DEFAULT, importOrder); } - public FormatterStep createFrom(boolean wildcardsLast, String... importOrder) { + public FormatterStep createFrom(boolean wildcardsLast, boolean semanticSort, Set treatAsPackage, + Set treatAsClass, String... importOrder) { // defensive copying and null checking List importOrderList = requireElementsNonNull(Arrays.asList(importOrder)); - return createFrom(wildcardsLast, () -> importOrderList); + return createFrom(wildcardsLast, semanticSort, treatAsPackage, treatAsClass, () -> importOrderList); } public FormatterStep createFrom(File importsFile) { - return createFrom(WILDCARDS_LAST_DEFAULT, importsFile); + return createFrom(WILDCARDS_LAST_DEFAULT, SEMANTIC_SORT_DEFAULT, TREAT_AS_PACKAGE_DEFAULT, + TREAT_AS_CLASS_DEFAULT, importsFile); } - public FormatterStep createFrom(boolean wildcardsLast, File importsFile) { + public FormatterStep createFrom(boolean wildcardsLast, boolean semanticSort, Set treatAsPackage, + Set treatAsClass, File importsFile) { Objects.requireNonNull(importsFile); - return createFrom(wildcardsLast, () -> getImportOrder(importsFile)); + return createFrom(wildcardsLast, semanticSort, treatAsPackage, treatAsClass, () -> getImportOrder(importsFile)); } - private FormatterStep createFrom(boolean wildcardsLast, Supplier> importOrder) { + private FormatterStep createFrom(boolean wildcardsLast, boolean semanticSort, Set treatAsPackage, + Set treatAsClass, Supplier> importOrder) { return FormatterStep.createLazy("importOrder", - () -> new State(importOrder.get(), lineFormat, wildcardsLast), + () -> new State(importOrder.get(), lineFormat, wildcardsLast, semanticSort, + treatAsPackage == null ? Set.of() : treatAsPackage, + treatAsClass == null ? Set.of() : treatAsClass), State::toFormatter); } @@ -106,15 +117,23 @@ private static final class State implements Serializable { private final List importOrder; private final String lineFormat; private final boolean wildcardsLast; + private final boolean semanticSort; + private final Set treatAsPackage; + private final Set treatAsClass; - State(List importOrder, String lineFormat, boolean wildcardsLast) { + State(List importOrder, String lineFormat, boolean wildcardsLast, boolean semanticSort, + Set treatAsPackage, Set treatAsClass) { this.importOrder = importOrder; this.lineFormat = lineFormat; this.wildcardsLast = wildcardsLast; + this.semanticSort = semanticSort; + this.treatAsPackage = treatAsPackage; + this.treatAsClass = treatAsClass; } FormatterFunc toFormatter() { - return raw -> new ImportSorter(importOrder, wildcardsLast).format(raw, lineFormat); + return raw -> new ImportSorter(importOrder, wildcardsLast, semanticSort, treatAsPackage, treatAsClass) + .format(raw, lineFormat); } } } diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorter.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorter.java index edfc948487..d6da23f254 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorter.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorter.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Scanner; +import java.util.Set; /** * @author Vojtech Krasa @@ -30,10 +31,17 @@ final class ImportSorter { private final List importsOrder; private final boolean wildcardsLast; + private final boolean semanticSort; + private final Set treatAsPackage; + private final Set treatAsClass; - ImportSorter(List importsOrder, boolean wildcardsLast) { + ImportSorter(List importsOrder, boolean wildcardsLast, boolean semanticSort, Set treatAsPackage, + Set treatAsClass) { this.importsOrder = new ArrayList<>(importsOrder); this.wildcardsLast = wildcardsLast; + this.semanticSort = semanticSort; + this.treatAsPackage = treatAsPackage; + this.treatAsClass = treatAsClass; } String format(String raw, String lineFormat) { @@ -81,7 +89,8 @@ String format(String raw, String lineFormat) { } scanner.close(); - List sortedImports = ImportSorterImpl.sort(imports, importsOrder, wildcardsLast, lineFormat); + List sortedImports = ImportSorterImpl.sort(imports, importsOrder, wildcardsLast, semanticSort, + treatAsPackage, treatAsClass, lineFormat); return applyImportsToDocument(raw, firstImportLine, lastImportLine, sortedImports); } diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index 1f014ba95e..828b5ef8f0 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -62,8 +62,10 @@ public List getSubGroups() { } } - static List sort(List imports, List importsOrder, boolean wildcardsLast, String lineFormat) { - ImportSorterImpl importsSorter = new ImportSorterImpl(importsOrder, wildcardsLast); + static List sort(List imports, List importsOrder, boolean wildcardsLast, + boolean semanticSort, Set treatAsPackage, Set treatAsClass, String lineFormat) { + ImportSorterImpl importsSorter = new ImportSorterImpl(importsOrder, wildcardsLast, semanticSort, treatAsPackage, + treatAsClass); return importsSorter.sort(imports, lineFormat); } @@ -76,12 +78,17 @@ private List sort(List imports, String lineFormat) { return getResult(sortedImported, lineFormat); } - private ImportSorterImpl(List importOrder, boolean wildcardsLast) { + private ImportSorterImpl(List importOrder, boolean wildcardsLast, boolean semanticSort, + Set treatAsPackage, Set treatAsClass) { importsGroups = importOrder.stream().filter(Objects::nonNull).map(ImportsGroup::new).collect(Collectors.toList()); putStaticItemIfNotExists(importsGroups); putCatchAllGroupIfNotExists(importsGroups); - ordering = new OrderingComparator(wildcardsLast); + if (semanticSort) { + ordering = new SemanticOrderingComparator(wildcardsLast, treatAsPackage, treatAsClass); + } else { + ordering = new LexicographicalOrderingComparator(wildcardsLast); + } List subgroups = importsGroups.stream().map(ImportsGroup::getSubGroups).flatMap(Collection::stream).collect(Collectors.toList()); this.allImportOrderItems.addAll(subgroups); @@ -233,30 +240,192 @@ private List getResult(List sortedImported, String lineFormat) { return null; } - private static class OrderingComparator implements Comparator, Serializable { + private static int compareWithWildcare(String string1, String string2, boolean wildcardsLast) { + int string1WildcardIndex = string1.indexOf('*'); + int string2WildcardIndex = string2.indexOf('*'); + boolean string1IsWildcard = string1WildcardIndex >= 0; + boolean string2IsWildcard = string2WildcardIndex >= 0; + if (string1IsWildcard == string2IsWildcard) { + return string1.compareTo(string2); + } + int prefixLength = string1IsWildcard ? string1WildcardIndex : string2WildcardIndex; + boolean samePrefix = string1.regionMatches(0, string2, 0, prefixLength); + if (!samePrefix) { + return string1.compareTo(string2); + } + return (string1IsWildcard == wildcardsLast) ? 1 : -1; + } + + private static class LexicographicalOrderingComparator implements Comparator, Serializable { private static final long serialVersionUID = 1; private final boolean wildcardsLast; - private OrderingComparator(boolean wildcardsLast) { + private LexicographicalOrderingComparator(boolean wildcardsLast) { this.wildcardsLast = wildcardsLast; } @Override public int compare(String string1, String string2) { - int string1WildcardIndex = string1.indexOf('*'); - int string2WildcardIndex = string2.indexOf('*'); - boolean string1IsWildcard = string1WildcardIndex >= 0; - boolean string2IsWildcard = string2WildcardIndex >= 0; - if (string1IsWildcard == string2IsWildcard) { - return string1.compareTo(string2); + return compareWithWildcare(string1, string2, wildcardsLast); + } + } + + private static class SemanticOrderingComparator implements Comparator, Serializable { + private static final long serialVersionUID = 1; + + private final boolean wildcardsLast; + private final Set treatAsPackage; + private final Set treatAsClass; + + private SemanticOrderingComparator(boolean wildcardsLast, Set treatAsPackage, + Set treatAsClass) { + this.wildcardsLast = wildcardsLast; + this.treatAsPackage = treatAsPackage; + this.treatAsClass = treatAsClass; + } + + @Override + public int compare(String string1, String string2) { + /* + * Ordering uses semantics of the import string by splitting it into package, + * class name(s) and static member (for static imports) and then comparing by + * each of those three substrings in sequence. + * + * When comparing static imports, the last segment in the dot-separated string + * is considered to be the member (field, method, type) name. + * + * The first segment starting with an upper case letter is considered to be the + * (first) class name. Since this comparator has no actual type information, + * this auto-detection will fail for upper case package names and lower case + * class names. treatAsPackage and treatAsClass can be used respectively to + * provide hints to the auto-detection. + */ + if (string1.startsWith(STATIC_KEYWORD)) { + String[] split = splitFqcnAndMember(string1); + String fqcn1 = split[0]; + String member1 = split[1]; + + split = splitFqcnAndMember(string2); + String fqcn2 = split[0]; + String member2 = split[1]; + + int result = compareFullyQualifiedClassName(fqcn1, fqcn2); + if (result != 0) + return result; + + return compareWithWildcare(member1, member2, wildcardsLast); + } else { + return compareFullyQualifiedClassName(string1, string2); + } + } + + /** + * Compares two fully qualified class names by splitting them into package and + * (nested) class names. + */ + private int compareFullyQualifiedClassName(String fqcn1, String fqcn2) { + String[] split = splitPackageAndClasses(fqcn1); + String p1 = split[0]; + String c1 = split[1]; + + split = splitPackageAndClasses(fqcn2); + String p2 = split[0]; + String c2 = split[1]; + + int result = p1.compareTo(p2); + if (result != 0) + return result; + + return compareWithWildcare(c1, c2, wildcardsLast); + } + + /** + * Splits the provided static import string into fully qualified class name and + * the imported static member (field, method or type). + */ + private String[] splitFqcnAndMember(String importString) { + String s = importString.substring(STATIC_KEYWORD.length()).trim(); + + String fqcn; + String member; + + int dot = s.lastIndexOf("."); + if (!Character.isUpperCase(s.charAt(dot + 1))) { + fqcn = s.substring(0, dot); + member = s.substring(dot + 1); + } else { + fqcn = s; + member = null; } - int prefixLength = string1IsWildcard ? string1WildcardIndex : string2WildcardIndex; - boolean samePrefix = string1.regionMatches(0, string2, 0, prefixLength); - if (!samePrefix) { - return string1.compareTo(string2); + + return new String[] { fqcn, member }; + } + + /** + * Splits the fully qualified class name into package and class name(s). + */ + private String[] splitPackageAndClasses(String fqcn) { + String packageNames = null; + String classNames = null; + + /* + * The first segment that starts with an upper case letter starts the class + * name(s), unless it matches treatAsPackage (then it's explicitly declared as + * package via configuration). If no segment starts with an upper case letter + * then the last segment must be a class name (unless the method input is + * garbage). + */ + int dot = fqcn.indexOf('.'); + while (dot > -1) { + int nextDot = fqcn.indexOf('.', dot + 1); + if (nextDot > -1) { + if (Character.isUpperCase(fqcn.charAt(dot + 1))) { + // if upper case, check if should be treated as package nonetheless + if (!treatAsPackage(fqcn.substring(0, nextDot))) { + packageNames = fqcn.substring(0, dot); + classNames = fqcn.substring(dot + 1); + break; + } + } else { + // if lower case, check if should be treated as class nonetheless + if (treatAsClass(fqcn.substring(0, nextDot))) { + packageNames = fqcn.substring(0, dot); + classNames = fqcn.substring(dot + 1); + break; + } + } + } + + dot = nextDot; } - return (string1IsWildcard == wildcardsLast) ? 1 : -1; + + if (packageNames == null) { + int i = fqcn.lastIndexOf("."); + packageNames = fqcn.substring(0, i); + classNames = fqcn.substring(i + 1); + } + + return new String[] { packageNames, classNames }; } + + /** + * Returns whether the provided prefix matches any entry of + * {@code treatAsPackage}. + */ + private boolean treatAsPackage(String prefix) { + // This would be the place to introduce wild cards or even regex matching. + return treatAsPackage.contains(prefix); + } + + /** + * Returns whether the provided prefix name matches any entry of + * {@code treatAsClass}. + */ + private boolean treatAsClass(String prefix) { + // This would be the place to introduce wild cards or even regex matching. + return treatAsClass.contains(prefix); + } + } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index d8dd77a09c..3016a94413 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -19,10 +19,13 @@ import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import javax.inject.Inject; @@ -74,6 +77,9 @@ public class ImportOrderConfig { final File importOrderFile; boolean wildcardsLast = false; + boolean semanticSort = true; + Set treatAsPackage = Set.of(); + Set treatAsClass = Set.of(); ImportOrderConfig(String[] importOrder) { this.importOrder = importOrder; @@ -98,12 +104,42 @@ public ImportOrderConfig wildcardsLast(boolean wildcardsLast) { return this; } + public ImportOrderConfig semanticSort() { + return semanticSort(true); + } + + public ImportOrderConfig semanticSort(boolean semanticSort) { + this.semanticSort = semanticSort; + replaceStep(createStep()); + return this; + } + + public ImportOrderConfig treatAsPackage(String... treatAsPackage) { + return treatAsPackage(Arrays.asList(treatAsPackage)); + } + + public ImportOrderConfig treatAsPackage(Collection treatAsPackage) { + this.treatAsPackage = new HashSet<>(treatAsPackage); + replaceStep(createStep()); + return this; + } + + public ImportOrderConfig treatAsClass(String... treatAsClass) { + return treatAsClass(Arrays.asList(treatAsClass)); + } + + public ImportOrderConfig treatAsClass(Collection treatAsClass) { + this.treatAsClass = new HashSet<>(treatAsClass); + replaceStep(createStep()); + return this; + } + private FormatterStep createStep() { ImportOrderStep importOrderStep = ImportOrderStep.forJava(); return importOrderFile != null - ? importOrderStep.createFrom(wildcardsLast, getProject().file(importOrderFile)) - : importOrderStep.createFrom(wildcardsLast, importOrder); + ? importOrderStep.createFrom(wildcardsLast, semanticSort, treatAsPackage, treatAsClass, getProject().file(importOrderFile)) + : importOrderStep.createFrom(wildcardsLast, semanticSort, treatAsPackage, treatAsClass, importOrder); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java index 8476b83733..94a89478bb 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java @@ -16,6 +16,8 @@ package com.diffplug.spotless.maven.java; import java.io.File; +import java.util.HashSet; +import java.util.Set; import org.apache.maven.plugins.annotations.Parameter; @@ -34,17 +36,43 @@ public class ImportOrder implements FormatterStepFactory { @Parameter private boolean wildcardsLast = false; + /** + * Whether imports should be sorted based on semantics (i.e. sorted by package, + * class and then static member). This considers treatAsPackage and + * treatAsClass, and assumes default upper and lower case + * conventions otherwise. When turned off, imports are sorted purely + * lexicographically. + */ + @Parameter + private boolean semanticSort = true; + + /** + * The prefixes that should be treated as packages for + * semanticSort. Useful for upper case package names. + */ + @Parameter + private Set treatAsPackage = new HashSet<>(); + + /** + * The prefixes that should be treated as classes for + * semanticSort. Useful for lower case class names. + */ + @Parameter + private Set treatAsClass = new HashSet<>(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { if (file != null ^ order != null) { if (file != null) { File importsFile = config.getFileLocator().locateFile(file); - return ImportOrderStep.forJava().createFrom(wildcardsLast, importsFile); + return ImportOrderStep.forJava().createFrom(wildcardsLast, semanticSort, treatAsPackage, treatAsClass, + importsFile); } else { - return ImportOrderStep.forJava().createFrom(wildcardsLast, order.split(",", -1)); + return ImportOrderStep.forJava().createFrom(wildcardsLast, semanticSort, treatAsPackage, treatAsClass, + order.split(",", -1)); } } else if (file == null && order == null) { - return ImportOrderStep.forJava().createFrom(wildcardsLast); + return ImportOrderStep.forJava().createFrom(wildcardsLast, semanticSort, treatAsPackage, treatAsClass); } else { throw new IllegalArgumentException("Must specify exactly one of 'file' or 'order'."); } diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeSortedLexicographic.test b/testlib/src/main/resources/java/importsorter/JavaCodeSortedLexicographic.test new file mode 100644 index 0000000000..731cbb5878 --- /dev/null +++ b/testlib/src/main/resources/java/importsorter/JavaCodeSortedLexicographic.test @@ -0,0 +1,13 @@ +import static com.example.Test.*; +import static com.example.Test.A_CONST; +import static com.example.Test.Nested.B_CONST; +import static com.example.Test.Z_CONST; + +import com.example.Test; +import com.example.Test.*; +import com.example.Test.Nested; +import com.example.a.A; +import com.example.b; +import com.example.c.C; +import com.sun.jna.platform.win32.COM.Unknown; +import com.sun.jna.platform.win32.Guid.CLSID; diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeSortedSemanticSort.test b/testlib/src/main/resources/java/importsorter/JavaCodeSortedSemanticSort.test new file mode 100644 index 0000000000..aaab4c1b86 --- /dev/null +++ b/testlib/src/main/resources/java/importsorter/JavaCodeSortedSemanticSort.test @@ -0,0 +1,13 @@ +import static com.example.Test.*; +import static com.example.Test.A_CONST; +import static com.example.Test.Nested.B_CONST; +import static com.example.Test.Z_CONST; + +import com.example.Test; +import com.example.Test.*; +import com.example.Test.Nested; +import com.example.b; +import com.example.a.A; +import com.example.c.C; +import com.sun.jna.platform.win32.Guid.CLSID; +import com.sun.jna.platform.win32.COM.Unknown; diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedSemanticSort.test b/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedSemanticSort.test new file mode 100644 index 0000000000..766322936d --- /dev/null +++ b/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedSemanticSort.test @@ -0,0 +1,15 @@ +import static com.example.Test.*; +import static com.example.Test.A_CONST; +import static com.example.Test.Z_CONST; +import static com.example.Test.Nested.B_CONST; + +import com.example.Test.Nested; +import com.example.Test; +import com.example.Test.*; + +import com.sun.jna.platform.win32.COM.Unknown; +import com.sun.jna.platform.win32.Guid.CLSID; + +import com.example.a.A; +import com.example.b; +import com.example.c.C; diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index ca6bd39825..57b1401554 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java @@ -21,6 +21,7 @@ import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; import com.diffplug.spotless.StepHarness; +import java.util.Set; class ImportOrderStepTest extends ResourceHarness { @Test @@ -61,7 +62,7 @@ void sortImportsUnmatched() { @Test void sortImportsWildcardsLast() { - FormatterStep step = ImportOrderStep.forJava().createFrom(true); + FormatterStep step = ImportOrderStep.forJava().createFrom(true, true, null, null); StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedImports.test", "java/importsorter/JavaCodeSortedImportsWildcardsLast.test"); } @@ -89,6 +90,19 @@ void empty() { StepHarness.forStep(step).testResource("java/importsorter/JavaCodeEmptyFile.test", "java/importsorter/JavaCodeEmptyFile.test"); } + @Test + void lexicographicSort() { + FormatterStep step = ImportOrderStep.forJava().createFrom(false, false, null, null, createTestFile("java/importsorter/import.properties")); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedSemanticSort.test", "java/importsorter/JavaCodeSortedLexicographic.test"); + } + + @Test + void semanticSort() { + FormatterStep step = ImportOrderStep.forJava().createFrom(false, true, Set.of("com.sun.jna.platform.win32.COM"), + Set.of("com.example.b"), createTestFile("java/importsorter/import.properties")); + StepHarness.forStep(step).testResource("java/importsorter/JavaCodeUnsortedSemanticSort.test", "java/importsorter/JavaCodeSortedSemanticSort.test"); + } + @Test void groovyImports() { FormatterStep step = ImportOrderStep.forGroovy().createFrom(createTestFile("java/importsorter/import.properties")); From 7deb02e52e6a45f888658028f0a1003c3f3eb19e Mon Sep 17 00:00:00 2001 From: Patrick Schmidt Date: Mon, 22 May 2023 19:46:10 +0200 Subject: [PATCH 0772/1120] Update changelog and readme. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + plugin-maven/README.md | 7 +++++++ 4 files changed, 10 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 9d65dfd9b5..873bbbe84e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * `Jvm.Support` now accepts `-SNAPSHOT` versions, treated as the non`-SNAPSHOT`. ([#1583](https://github.com/diffplug/spotless/issues/1583)) * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) +* Add semantics-aware Java import ordering (i.e. sort by package, then class, then member). ([#522](https://github.com/diffplug/spotless/issues/522)) ### Fixed * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.38.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d064173af6..7b1b401f14 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) +* Add semantics-aware Java import ordering (i.e. sort by package, then class, then member). ([#522](https://github.com/diffplug/spotless/issues/522)) ### Fixed * Added `@DisableCachingByDefault` to `RegisterDependenciesTask`. ([#1666](https://github.com/diffplug/spotless/pull/1666)) * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 5777493c41..139b0fa265 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) +* Add semantics-aware Java import ordering (i.e. sort by package, then class, then member). ([#522](https://github.com/diffplug/spotless/issues/522)) ### Fixed * `palantir` step now accepts a `style` parameter, which is documentation had already claimed to do. ([#1694](https://github.com/diffplug/spotless/pull/1694)) * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index b11e2c164d..7facd99a0d 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -196,6 +196,13 @@ any other maven phase (i.e. compile) then it can be configured as below; false java|javax,org,com,com.diffplug,,\#com.diffplug,\# + false + + com.example.MyPackage + + + com.example.myClass + From 5494c80f014f048717786a949cfbb49d605968f4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 22 May 2023 18:47:43 +0000 Subject: [PATCH 0773/1120] fix(deps): update dependency com.google.googlejavaformat:google-java-format to v1.17.0 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 8db911e33e..00df2648de 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -81,7 +81,7 @@ dependencies { gherkinCompileOnly 'io.cucumber:gherkin-utils:8.0.2' gherkinCompileOnly 'org.slf4j:slf4j-api:2.0.0' // googleJavaFormat - googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.16.0' + googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.17.0' // gson gsonCompileOnly 'com.google.code.gson:gson:2.10.1' // jackson From 10610f8a8d12bfdc8303645daafc4d68c17c9165 Mon Sep 17 00:00:00 2001 From: Patrick Schmidt Date: Mon, 22 May 2023 21:03:16 +0200 Subject: [PATCH 0774/1120] fixup! Introduce semantics-aware Java import ordering. (fixes #522) --- .../diffplug/spotless/java/ImportOrderStep.java | 16 ++++++++-------- .../diffplug/spotless/java/ImportSorterImpl.java | 4 ++-- .../diffplug/gradle/spotless/JavaExtension.java | 2 +- .../spotless/maven/java/ImportOrder.java | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java index 7f100e0adc..e986875a48 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.TreeSet; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -40,7 +41,7 @@ public final class ImportOrderStep { private static final boolean WILDCARDS_LAST_DEFAULT = false; - private static final boolean SEMANTIC_SORT_DEFAULT = true; + private static final boolean SEMANTIC_SORT_DEFAULT = false; private static final Set TREAT_AS_PACKAGE_DEFAULT = null; private static final Set TREAT_AS_CLASS_DEFAULT = null; @@ -84,9 +85,8 @@ public FormatterStep createFrom(boolean wildcardsLast, boolean semanticSort, Set private FormatterStep createFrom(boolean wildcardsLast, boolean semanticSort, Set treatAsPackage, Set treatAsClass, Supplier> importOrder) { return FormatterStep.createLazy("importOrder", - () -> new State(importOrder.get(), lineFormat, wildcardsLast, semanticSort, - treatAsPackage == null ? Set.of() : treatAsPackage, - treatAsClass == null ? Set.of() : treatAsClass), + () -> new State(importOrder.get(), lineFormat, wildcardsLast, semanticSort, treatAsPackage, + treatAsClass), State::toFormatter); } @@ -118,8 +118,8 @@ private static final class State implements Serializable { private final String lineFormat; private final boolean wildcardsLast; private final boolean semanticSort; - private final Set treatAsPackage; - private final Set treatAsClass; + private final TreeSet treatAsPackage; + private final TreeSet treatAsClass; State(List importOrder, String lineFormat, boolean wildcardsLast, boolean semanticSort, Set treatAsPackage, Set treatAsClass) { @@ -127,8 +127,8 @@ private static final class State implements Serializable { this.lineFormat = lineFormat; this.wildcardsLast = wildcardsLast; this.semanticSort = semanticSort; - this.treatAsPackage = treatAsPackage; - this.treatAsClass = treatAsClass; + this.treatAsPackage = treatAsPackage == null ? null : new TreeSet<>(treatAsPackage); + this.treatAsClass = treatAsClass == null ? null : new TreeSet<>(treatAsClass); } FormatterFunc toFormatter() { diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index 828b5ef8f0..a6d5af675c 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -415,7 +415,7 @@ private String[] splitPackageAndClasses(String fqcn) { */ private boolean treatAsPackage(String prefix) { // This would be the place to introduce wild cards or even regex matching. - return treatAsPackage.contains(prefix); + return treatAsPackage != null && treatAsPackage.contains(prefix); } /** @@ -424,7 +424,7 @@ private boolean treatAsPackage(String prefix) { */ private boolean treatAsClass(String prefix) { // This would be the place to introduce wild cards or even regex matching. - return treatAsClass.contains(prefix); + return treatAsClass != null && treatAsClass.contains(prefix); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index 3016a94413..ecb519bd6e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -77,7 +77,7 @@ public class ImportOrderConfig { final File importOrderFile; boolean wildcardsLast = false; - boolean semanticSort = true; + boolean semanticSort = false; Set treatAsPackage = Set.of(); Set treatAsClass = Set.of(); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java index 94a89478bb..fe6dc10fc8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java @@ -44,7 +44,7 @@ public class ImportOrder implements FormatterStepFactory { * lexicographically. */ @Parameter - private boolean semanticSort = true; + private boolean semanticSort = false; /** * The prefixes that should be treated as packages for From ff38088bc57fd2a9b15d5b33abfecec6f7de25a0 Mon Sep 17 00:00:00 2001 From: Patrick Schmidt Date: Mon, 22 May 2023 21:29:55 +0200 Subject: [PATCH 0775/1120] fixup! Introduce semantics-aware Java import ordering. (fixes #522) --- .../java/com/diffplug/spotless/java/ImportOrderStep.java | 2 +- .../java/com/diffplug/spotless/java/ImportSorter.java | 2 +- .../java/com/diffplug/spotless/java/ImportSorterImpl.java | 8 ++++---- .../java/com/diffplug/gradle/spotless/JavaExtension.java | 4 ++-- .../com/diffplug/spotless/maven/java/ImportOrder.java | 2 +- .../com/diffplug/spotless/java/ImportOrderStepTest.java | 3 ++- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java index e986875a48..6f0f2a0e8f 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.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. diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorter.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorter.java index d6da23f254..6cd7dd4978 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorter.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorter.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. diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index a6d5af675c..a3fe621e13 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -291,10 +291,10 @@ public int compare(String string1, String string2) { * Ordering uses semantics of the import string by splitting it into package, * class name(s) and static member (for static imports) and then comparing by * each of those three substrings in sequence. - * + * * When comparing static imports, the last segment in the dot-separated string * is considered to be the member (field, method, type) name. - * + * * The first segment starting with an upper case letter is considered to be the * (first) class name. Since this comparator has no actual type information, * this auto-detection will fail for upper case package names and lower case @@ -359,7 +359,7 @@ private String[] splitFqcnAndMember(String importString) { member = null; } - return new String[] { fqcn, member }; + return new String[]{fqcn, member}; } /** @@ -406,7 +406,7 @@ private String[] splitPackageAndClasses(String fqcn) { classNames = fqcn.substring(i + 1); } - return new String[] { packageNames, classNames }; + return new String[]{packageNames, classNames}; } /** diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index ecb519bd6e..13fe674168 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -127,13 +127,13 @@ public ImportOrderConfig treatAsPackage(Collection treatAsPackage) { public ImportOrderConfig treatAsClass(String... treatAsClass) { return treatAsClass(Arrays.asList(treatAsClass)); } - + public ImportOrderConfig treatAsClass(Collection treatAsClass) { this.treatAsClass = new HashSet<>(treatAsClass); replaceStep(createStep()); return this; } - + private FormatterStep createStep() { ImportOrderStep importOrderStep = ImportOrderStep.forJava(); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java index fe6dc10fc8..88f47a2a64 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/ImportOrder.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. diff --git a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java index 57b1401554..75cd984f08 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/ImportOrderStepTest.java @@ -15,13 +15,14 @@ */ package com.diffplug.spotless.java; +import java.util.Set; + import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.ResourceHarness; import com.diffplug.spotless.SerializableEqualityTester; import com.diffplug.spotless.StepHarness; -import java.util.Set; class ImportOrderStepTest extends ResourceHarness { @Test From d72a11ce0305b45a8b4a54afdde861280434595c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 22 May 2023 14:58:11 -0700 Subject: [PATCH 0776/1120] Fix spotbugs. --- .../main/java/com/diffplug/spotless/java/ImportOrderStep.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java index 6f0f2a0e8f..e1e63458d9 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java @@ -42,8 +42,8 @@ public final class ImportOrderStep { private static final boolean WILDCARDS_LAST_DEFAULT = false; private static final boolean SEMANTIC_SORT_DEFAULT = false; - private static final Set TREAT_AS_PACKAGE_DEFAULT = null; - private static final Set TREAT_AS_CLASS_DEFAULT = null; + private static final Set TREAT_AS_PACKAGE_DEFAULT = Set.of(); + private static final Set TREAT_AS_CLASS_DEFAULT = Set.of(); private final String lineFormat; From a8a94c06f1e050dc6937707acb2ef804d921755c Mon Sep 17 00:00:00 2001 From: Patrick Schmidt Date: Tue, 23 May 2023 20:45:25 +0200 Subject: [PATCH 0777/1120] Fix semantics-aware sorting of static imports (fixes #522) --- .../spotless/java/ImportSorterImpl.java | 17 ++++++----------- .../JavaCodeSortedLexicographic.test | 4 ++++ .../JavaCodeSortedSemanticSort.test | 6 +++++- .../JavaCodeUnsortedSemanticSort.test | 4 ++++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java index a3fe621e13..4d343d41d8 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java +++ b/lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java @@ -347,18 +347,13 @@ private int compareFullyQualifiedClassName(String fqcn1, String fqcn2) { private String[] splitFqcnAndMember(String importString) { String s = importString.substring(STATIC_KEYWORD.length()).trim(); - String fqcn; - String member; - + /* + * Static imports always contain a member or wildcard and it's always the last + * segment. + */ int dot = s.lastIndexOf("."); - if (!Character.isUpperCase(s.charAt(dot + 1))) { - fqcn = s.substring(0, dot); - member = s.substring(dot + 1); - } else { - fqcn = s; - member = null; - } - + String fqcn = s.substring(0, dot); + String member = s.substring(dot + 1); return new String[]{fqcn, member}; } diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeSortedLexicographic.test b/testlib/src/main/resources/java/importsorter/JavaCodeSortedLexicographic.test index 731cbb5878..2b59d52e58 100644 --- a/testlib/src/main/resources/java/importsorter/JavaCodeSortedLexicographic.test +++ b/testlib/src/main/resources/java/importsorter/JavaCodeSortedLexicographic.test @@ -1,3 +1,7 @@ +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import static com.example.Test.*; import static com.example.Test.A_CONST; import static com.example.Test.Nested.B_CONST; diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeSortedSemanticSort.test b/testlib/src/main/resources/java/importsorter/JavaCodeSortedSemanticSort.test index aaab4c1b86..3ab813b227 100644 --- a/testlib/src/main/resources/java/importsorter/JavaCodeSortedSemanticSort.test +++ b/testlib/src/main/resources/java/importsorter/JavaCodeSortedSemanticSort.test @@ -1,7 +1,11 @@ +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import static com.example.Test.*; import static com.example.Test.A_CONST; -import static com.example.Test.Nested.B_CONST; import static com.example.Test.Z_CONST; +import static com.example.Test.Nested.B_CONST; import com.example.Test; import com.example.Test.*; diff --git a/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedSemanticSort.test b/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedSemanticSort.test index 766322936d..7bfcfc6f7a 100644 --- a/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedSemanticSort.test +++ b/testlib/src/main/resources/java/importsorter/JavaCodeUnsortedSemanticSort.test @@ -13,3 +13,7 @@ import com.sun.jna.platform.win32.Guid.CLSID; import com.example.a.A; import com.example.b; import com.example.c.C; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.when; From 655bc7ba0c68d3d505fc670c174f6a2a0fc4b835 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 May 2023 14:44:49 -0700 Subject: [PATCH 0778/1120] Bump solstice and durian-swt to latest. --- lib-extra/build.gradle | 2 +- .../com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 5e491eaf20..1158ca0893 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -7,7 +7,7 @@ version = rootProject.spotlessChangelog.versionNext apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') -String VER_SOLSTICE = '1.0.3' +String VER_SOLSTICE = '1.3.1' dependencies { api project(':lib') // misc useful utilities diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 7f0e181837..586deeb5bf 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -110,8 +110,8 @@ EquoBasedStepBuilder.State get() throws Exception { } var classpath = new ArrayList(); var mavenDeps = new ArrayList(); - mavenDeps.add("dev.equo.ide:solstice:1.0.3"); - mavenDeps.add("com.diffplug.durian:durian-swt.os:4.1.1"); + mavenDeps.add("dev.equo.ide:solstice:1.3.1"); + mavenDeps.add("com.diffplug.durian:durian-swt.os:4.2.0"); mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); classpath.addAll(query.getJarsNotOnMavenCentral()); From aa8d02922a27ea9bd4114c3fb226e0558fd16e66 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 May 2023 14:51:27 -0700 Subject: [PATCH 0779/1120] Bump ktfmt default version to 0.44. --- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java index d6a20bc5b3..098f68d5bd 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -39,7 +39,7 @@ public class KtfmtStep { // prevent direct instantiation private KtfmtStep() {} - private static final String DEFAULT_VERSION = "0.43"; + private static final String DEFAULT_VERSION = "0.44"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; From 7d0d409abca37e537ae53d7ec160bcd62049dda5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 May 2023 14:52:01 -0700 Subject: [PATCH 0780/1120] Bump gjf default to 1.17.0 and mark it as the minimum required for Java 21. --- .../java/com/diffplug/spotless/java/GoogleJavaFormatStep.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java index d7ba26f384..321d05420f 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java @@ -72,7 +72,8 @@ public static FormatterStep create(String groupArtifact, String version, String static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME) .addMin(11, "1.8") // we only support google-java-format >= 1.8 due to api changes .addMin(16, "1.10.0") // java 16 requires at least 1.10.0 due to jdk api changes in JavaTokenizer - .add(11, "1.16.0"); // default version + .addMin(21, "1.17.0") // java 21 requires at least 1.17.0 due to https://github.com/google/google-java-format/issues/898 + .add(11, "1.17.0"); // default version public static String defaultGroupArtifact() { return MAVEN_COORDINATE; From 187b7fe48eb9a31f1689e1923423763ad5fd812c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 May 2023 15:00:11 -0700 Subject: [PATCH 0781/1120] Fix compile error. --- .../spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java index 7c29209157..163816c1a4 100644 --- a/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java +++ b/lib-extra/src/groovy/java/com/diffplug/spotless/extra/glue/groovy/GrEclipseFormatterStepImpl.java @@ -52,7 +52,7 @@ public class GrEclipseFormatterStepImpl { static { NestedJars.setToWarnOnly(); - NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.nestedJars()); + NestedJars.onClassPath().confirmAllNestedJarsArePresentOnClasspath(CacheLocations.p2nestedJars()); try { var solstice = Solstice.findBundlesOnClasspath(); solstice.warnAndModifyManifestsToFix(); From 34fb099d422c6a4b36b00d2693ec8442093c8617 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 May 2023 15:51:41 -0700 Subject: [PATCH 0782/1120] Bump changelogs. --- CHANGES.md | 3 ++- plugin-gradle/CHANGES.md | 3 ++- plugin-maven/CHANGES.md | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 40e4b651df..026f66bf43 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,9 +18,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.38.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes -* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) +* Bump default `googleJavaFormat` version to latest `1.16.0` -> `1.17.0`. ([#1710](https://github.com/diffplug/spotless/pull/1710)) * Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. +* Bump default `sortpom` version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) ## [2.38.0] - 2023-04-06 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c85a3ac3a2..8694784fd8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -11,9 +11,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `6.18.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes -* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) +* Bump default `googleJavaFormat` version to latest `1.16.0` -> `1.17.0`. ([#1710](https://github.com/diffplug/spotless/pull/1710)) * Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. +* Bump default `sortpom` version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) ## [6.18.0] - 2023-04-06 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 33168309ae..3ab9a3f92c 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,9 +11,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.36.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes -* Bump default sortpom version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) +* Bump default `googleJavaFormat` version to latest `1.16.0` -> `1.17.0`. ([#1710](https://github.com/diffplug/spotless/pull/1710)) * Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. +* Bump default `sortpom` version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) ## [2.36.0] - 2023-04-06 ### Added From d88928a9386562cb7864dc7f65d4900e96a825fd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 May 2023 15:53:56 -0700 Subject: [PATCH 0783/1120] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 026f66bf43..c75da2ca95 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.38.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes * Bump default `googleJavaFormat` version to latest `1.16.0` -> `1.17.0`. ([#1710](https://github.com/diffplug/spotless/pull/1710)) +* Bump default `ktfmt` version to latest `0.43` -> `0.44`.([#1691](https://github.com/diffplug/spotless/pull/1691)) * Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. * Bump default `sortpom` version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 8694784fd8..72889452ff 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `6.18.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes * Bump default `googleJavaFormat` version to latest `1.16.0` -> `1.17.0`. ([#1710](https://github.com/diffplug/spotless/pull/1710)) +* Bump default `ktfmt` version to latest `0.43` -> `0.44`.([#1691](https://github.com/diffplug/spotless/pull/1691)) * Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. * Bump default `sortpom` version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 3ab9a3f92c..1f7412104a 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.36.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) ### Changes * Bump default `googleJavaFormat` version to latest `1.16.0` -> `1.17.0`. ([#1710](https://github.com/diffplug/spotless/pull/1710)) +* Bump default `ktfmt` version to latest `0.43` -> `0.44`.([#1691](https://github.com/diffplug/spotless/pull/1691)) * Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. * Bump default `sortpom` version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) From 973f285218b7a35eb0d124f046265a3ad2cc8988 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 May 2023 15:54:28 -0700 Subject: [PATCH 0784/1120] Why is KtfmtStepTest disabled? --- .../test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java index bfa971fc40..0bbfcabe05 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java @@ -15,12 +15,10 @@ */ package com.diffplug.spotless.kotlin; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.spotless.*; -@Disabled class KtfmtStepTest extends ResourceHarness { @Test void behavior() throws Exception { From a9fde3e4ec8b7a7162e88564f2cc926f809c318a Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 May 2023 15:57:20 -0700 Subject: [PATCH 0785/1120] Fix the broken parts of the test. --- .../com/diffplug/spotless/kotlin/KtfmtStepTest.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java index 0bbfcabe05..72e0adb4e2 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtfmtStepTest.java @@ -32,23 +32,17 @@ void dropboxStyle_0_18() throws Exception { StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic-dropboxstyle.clean"); } - @Test - void dropboxStyle_0_19() throws Exception { - FormatterStep step = KtfmtStep.create("0.19", TestProvisioner.mavenCentral(), KtfmtStep.Style.DROPBOX, null); - StepHarness.forStep(step).testResource("kotlin/ktfmt/basic.dirty", "kotlin/ktfmt/basic-dropboxstyle.clean"); - } - @Test void equality() throws Exception { new SerializableEqualityTester() { - String version = "0.13"; + String version = "0.18"; @Override protected void setupTest(API api) { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "0.12"; + version = KtfmtStep.defaultVersion(); api.areDifferentThan(); } From d4c55ac470139c255a8daa213717e5737e06a920 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 23 May 2023 17:17:01 -0700 Subject: [PATCH 0786/1120] Bump changelogs. --- CHANGES.md | 8 +++++--- plugin-gradle/CHANGES.md | 8 +++++--- plugin-maven/CHANGES.md | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c75da2ca95..ccc6f8480b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,12 +15,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) * Add semantics-aware Java import ordering (i.e. sort by package, then class, then member). ([#522](https://github.com/diffplug/spotless/issues/522)) ### Fixed -* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.38.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) +* Equo-based formatters now work on platforms unsupported by Eclipse such as PowerPC (fixes [durian-swt#20](https://github.com/diffplug/durian-swt/issues/20)) +* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) ### Changes +* Equo-based formatters now download metadata to `~/.m2/repository/dev/equo/p2-data` rather than `~/.equo`, and for CI machines without a home directory the p2 data goes to `$GRADLE_USER_HOME/caches/p2-data`. ([#1714](https://github.com/diffplug/spotless/pull/1714)) * Bump default `googleJavaFormat` version to latest `1.16.0` -> `1.17.0`. ([#1710](https://github.com/diffplug/spotless/pull/1710)) -* Bump default `ktfmt` version to latest `0.43` -> `0.44`.([#1691](https://github.com/diffplug/spotless/pull/1691)) -* Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) +* Bump default `ktfmt` version to latest `0.43` -> `0.44`. ([#1691](https://github.com/diffplug/spotless/pull/1691)) +* Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`. ([#1696](https://github.com/diffplug/spotless/issues/1696)) * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. * Bump default `sortpom` version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 72889452ff..2c0b8aed4e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,12 +8,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add semantics-aware Java import ordering (i.e. sort by package, then class, then member). ([#522](https://github.com/diffplug/spotless/issues/522)) ### Fixed * Added `@DisableCachingByDefault` to `RegisterDependenciesTask`. ([#1666](https://github.com/diffplug/spotless/pull/1666)) -* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `6.18.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) +* Equo-based formatters now work on platforms unsupported by Eclipse such as PowerPC (fixes [durian-swt#20](https://github.com/diffplug/durian-swt/issues/20)) +* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) ### Changes +* Equo-based formatters now download metadata to `~/.m2/repository/dev/equo/p2-data` rather than `~/.equo`, and for CI machines without a home directory the p2 data goes to `$GRADLE_USER_HOME/caches/p2-data`. ([#1714](https://github.com/diffplug/spotless/pull/1714)) * Bump default `googleJavaFormat` version to latest `1.16.0` -> `1.17.0`. ([#1710](https://github.com/diffplug/spotless/pull/1710)) -* Bump default `ktfmt` version to latest `0.43` -> `0.44`.([#1691](https://github.com/diffplug/spotless/pull/1691)) -* Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) +* Bump default `ktfmt` version to latest `0.43` -> `0.44`. ([#1691](https://github.com/diffplug/spotless/pull/1691)) +* Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`. ([#1696](https://github.com/diffplug/spotless/issues/1696)) * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. * Bump default `sortpom` version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1f7412104a..92cfc66ed6 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,12 +8,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add semantics-aware Java import ordering (i.e. sort by package, then class, then member). ([#522](https://github.com/diffplug/spotless/issues/522)) ### Fixed * `palantir` step now accepts a `style` parameter, which is documentation had already claimed to do. ([#1694](https://github.com/diffplug/spotless/pull/1694)) -* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) * Fixed a regression which changed the import sorting order in `googleJavaFormat` introduced in `2.36.0`. ([#1680](https://github.com/diffplug/spotless/pull/1680)) +* Equo-based formatters now work on platforms unsupported by Eclipse such as PowerPC (fixes [durian-swt#20](https://github.com/diffplug/durian-swt/issues/20)) +* When P2 download fails, indicate the responsible formatter. ([#1698](https://github.com/diffplug/spotless/issues/1698)) ### Changes +* Equo-based formatters now download metadata to `~/.m2/repository/dev/equo/p2-data` rather than `~/.equo`, and for CI machines without a home directory the p2 data goes to `$GRADLE_USER_HOME/caches/p2-data`. ([#1714](https://github.com/diffplug/spotless/pull/1714)) * Bump default `googleJavaFormat` version to latest `1.16.0` -> `1.17.0`. ([#1710](https://github.com/diffplug/spotless/pull/1710)) -* Bump default `ktfmt` version to latest `0.43` -> `0.44`.([#1691](https://github.com/diffplug/spotless/pull/1691)) -* Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`.([#1696](https://github.com/diffplug/spotless/issues/1696)) +* Bump default `ktfmt` version to latest `0.43` -> `0.44`. ([#1691](https://github.com/diffplug/spotless/pull/1691)) +* Bump default `ktlint` version to latest `0.48.2` -> `0.49.1`. ([#1696](https://github.com/diffplug/spotless/issues/1696)) * Dropped support for `ktlint 0.46.x` following our policy of supporting two breaking changes at a time. * Bump default `sortpom` version to latest `3.0.0` -> `3.2.1`. ([#1675](https://github.com/diffplug/spotless/pull/1675)) From 0d19de79c77da9b9cb316101d194a44ab527e4f7 Mon Sep 17 00:00:00 2001 From: runner Date: Wed, 24 May 2023 02:38:06 +0000 Subject: [PATCH 0787/1120] Published lib/2.39.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ccc6f8480b..e545f20dcb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.39.0] - 2023-05-24 ### Added * `Jvm.Support` now accepts `-SNAPSHOT` versions, treated as the non`-SNAPSHOT`. ([#1583](https://github.com/diffplug/spotless/issues/1583)) * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) From 04c37147c2444546802d8c0964ba64a87450f8a4 Mon Sep 17 00:00:00 2001 From: runner Date: Wed, 24 May 2023 02:39:35 +0000 Subject: [PATCH 0788/1120] Published gradle/6.19.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 52 ++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 2c0b8aed4e..51cdb016a8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.19.0] - 2023-05-24 ### Added * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) * Add semantics-aware Java import ordering (i.e. sort by package, then class, then member). ([#522](https://github.com/diffplug/spotless/issues/522)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index c853f82a3f..0390c64323 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.18.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.19.0-blue.svg)](CHANGES.md) [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -126,10 +126,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -142,7 +142,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer. ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -299,8 +299,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -350,8 +350,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -422,7 +422,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -454,7 +454,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -486,7 +486,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -520,7 +520,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -541,7 +541,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -566,7 +566,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -606,7 +606,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -700,7 +700,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -765,7 +765,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -841,7 +841,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -872,7 +872,7 @@ spotless { ## Gherkin -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.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.19.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 { @@ -1260,7 +1260,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1333,9 +1333,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1368,11 +1368,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.18.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 609ac5fb36b296973792f54d8c80d521df620db5 Mon Sep 17 00:00:00 2001 From: runner Date: Wed, 24 May 2023 02:41:23 +0000 Subject: [PATCH 0789/1120] Published maven/2.37.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 92cfc66ed6..00f577b41e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.37.0] - 2023-05-24 ### Added * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) * Add semantics-aware Java import ordering (i.e. sort by package, then class, then member). ([#522](https://github.com/diffplug/spotless/issues/522)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 7facd99a0d..519250c5ac 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.36.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.36.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.37.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.37.0/index.html) java|javax,org,com,com.diffplug,,\#com.diffplug,\# - false + false com.example.MyPackage From f9f1f307d7e21a237f9c256ad39e25dec6be773b Mon Sep 17 00:00:00 2001 From: tison Date: Mon, 29 May 2023 12:01:32 +0800 Subject: [PATCH 0794/1120] feat: support pass skip from command-line for maven-plugin --- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0b019ea844..2c295cef27 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 @@ -100,7 +100,7 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter(defaultValue = "${mojoExecution.goal}", required = true, readonly = true) private String goal; - @Parameter(defaultValue = "false") + @Parameter(property = "spotless.skip", defaultValue = "false") private boolean skip; @Parameter(property = "spotless.apply.skip", defaultValue = "false") From 9be7e5f514841c794e633d7002f7097b39c2ec02 Mon Sep 17 00:00:00 2001 From: Vincent Galloy Date: Thu, 1 Jun 2023 11:42:51 +0200 Subject: [PATCH 0795/1120] Kotlin dsl for yaml formatter in can't use the syntax jackson().yamlFeature(String, boolean) Motivation In gradle, kotlin DSL is compiled. Since YamlExtension#jackson return a AJacksonGradleConfig class, we can't use the method #yamlFeature(String, boolean) without casting the object --- .../gradle/spotless/AJacksonGradleConfig.java | 12 +++++++----- .../com/diffplug/gradle/spotless/JsonExtension.java | 9 +++++++-- .../com/diffplug/gradle/spotless/YamlExtension.java | 11 ++++++++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java index c017d41d04..2185f3693a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/AJacksonGradleConfig.java @@ -21,7 +21,7 @@ import com.diffplug.spotless.json.JacksonConfig; import com.diffplug.spotless.json.JacksonJsonStep; -public abstract class AJacksonGradleConfig { +public abstract class AJacksonGradleConfig { protected final FormatExtension formatExtension; protected JacksonConfig jacksonConfig; @@ -35,17 +35,19 @@ public AJacksonGradleConfig(JacksonConfig jacksonConfig, FormatExtension formatE this.jacksonConfig = jacksonConfig; } - public AJacksonGradleConfig feature(String feature, boolean toggle) { + public T feature(String feature, boolean toggle) { this.jacksonConfig.appendFeatureToToggle(Collections.singletonMap(feature, toggle)); formatExtension.replaceStep(createStep()); - return this; + return self(); } - public AJacksonGradleConfig version(String version) { + public T version(String version) { this.version = version; formatExtension.replaceStep(createStep()); - return this; + return self(); } + public abstract T self(); + protected abstract FormatterStep createStep(); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 510ac529e8..2fa567472f 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -132,7 +132,7 @@ private FormatterStep createStep() { } } - public static class JacksonJsonGradleConfig extends AJacksonGradleConfig { + public static class JacksonJsonGradleConfig extends AJacksonGradleConfig { protected JacksonJsonConfig jacksonConfig; public JacksonJsonGradleConfig(JacksonJsonConfig jacksonConfig, FormatExtension formatExtension) { @@ -149,12 +149,17 @@ public JacksonJsonGradleConfig(FormatExtension formatExtension) { /** * Refers to com.fasterxml.jackson.core.JsonGenerator.Feature */ - public AJacksonGradleConfig jsonFeature(String feature, boolean toggle) { + public JacksonJsonGradleConfig jsonFeature(String feature, boolean toggle) { this.jacksonConfig.appendJsonFeatureToToggle(Collections.singletonMap(feature, toggle)); formatExtension.replaceStep(createStep()); return this; } + @Override + public JacksonJsonGradleConfig self() { + return this; + } + // 'final' as it is called in the constructor @Override protected final FormatterStep createStep() { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java index abc2dce359..c0872e8fb9 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java @@ -39,11 +39,11 @@ protected void setupTask(SpotlessTask task) { super.setupTask(task); } - public AJacksonGradleConfig jackson() { + public JacksonYamlGradleConfig jackson() { return new JacksonYamlGradleConfig(this); } - public class JacksonYamlGradleConfig extends AJacksonGradleConfig { + public class JacksonYamlGradleConfig extends AJacksonGradleConfig { protected JacksonYamlConfig jacksonConfig; public JacksonYamlGradleConfig(JacksonYamlConfig jacksonConfig, FormatExtension formatExtension) { @@ -61,12 +61,17 @@ public JacksonYamlGradleConfig(FormatExtension formatExtension) { /** * Refers to com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature */ - public AJacksonGradleConfig yamlFeature(String feature, boolean toggle) { + public JacksonYamlGradleConfig yamlFeature(String feature, boolean toggle) { this.jacksonConfig.appendYamlFeatureToToggle(Collections.singletonMap(feature, toggle)); formatExtension.replaceStep(createStep()); return this; } + @Override + public JacksonYamlGradleConfig self() { + return this; + } + // 'final' as it is called in the constructor @Override protected final FormatterStep createStep() { From 3ae8940b391384c031a4fcb2e92d709aed9d54bd Mon Sep 17 00:00:00 2001 From: Vincent Galloy Date: Thu, 1 Jun 2023 11:55:05 +0200 Subject: [PATCH 0796/1120] Update CHANGES.md --- plugin-gradle/CHANGES.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 51cdb016a8..744c6efce7 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Fixed +* Correctly support the syntax + ``` + spotless { + yaml { + jackson().yamlFeature("MINIMIZE_QUOTES", true) + } + } + ``` + ## [6.19.0] - 2023-05-24 ### Added * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663)) From 6a1eb5f00e13d06de4017571eef6255728c16ba0 Mon Sep 17 00:00:00 2001 From: tison Date: Mon, 5 Jun 2023 16:33:58 +0800 Subject: [PATCH 0797/1120] update changelog Signed-off-by: tison --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 00f577b41e..f86e1d62b4 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Support pass skip (`-Dspotless.skip=true`) from command-line. ([#1729](https://github.com/diffplug/spotless/pull/1729)) ## [2.37.0] - 2023-05-24 ### Added From 4330ee28ab42876cfcc296770c7c1009148ff7fd Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 5 Jun 2023 23:37:04 +0000 Subject: [PATCH 0798/1120] Update plugin de.benediktritter.maven-plugin-development to v0.4.2 --- plugin-maven/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index dda98ad79a..7cfb38c2e9 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -3,7 +3,7 @@ import de.benediktritter.maven.plugin.development.task.GenerateMavenPluginDescri plugins { // https://www.benediktritter.de/maven-plugin-development/#release-history - id 'de.benediktritter.maven-plugin-development' version '0.4.1' + id 'de.benediktritter.maven-plugin-development' version '0.4.2' } apply from: rootProject.file('gradle/changelog.gradle') From 56e1e113527347e5dd8bc9ad40832def1ad6d68a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Jun 2023 12:33:41 +0000 Subject: [PATCH 0799/1120] fix(deps): update dependency org.eclipse.jgit:org.eclipse.jgit to v6.6.0.202305301015-r --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 31bed9971d..ce29bbfaeb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -29,7 +29,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 -VER_JGIT=6.5.0.202303070854-r +VER_JGIT=6.6.0.202305301015-r VER_JUNIT=5.9.3 VER_ASSERTJ=3.24.2 VER_MOCKITO=5.3.1 From b5c1a5417c98e0782d9a63cad3ac72934800a8d4 Mon Sep 17 00:00:00 2001 From: Edu Date: Wed, 21 Jun 2023 13:01:35 -0400 Subject: [PATCH 0800/1120] Update README.md Fix removeUnusedImports docs --- plugin-gradle/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 0390c64323..ef93e31d45 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -192,7 +192,7 @@ spotless { removeUnusedImports() // optional: you may switch for `google-java-format` as underlying engine to `cleanthat-javaparser-unnecessaryimport` // which enables processing any language level source file with a JDK8+ Runtime - removeUnusedImports().engine('cleanthat-javaparser-unnecessaryimport') + removeUnusedImports('cleanthat-javaparser-unnecessaryimport') ``` ### google-java-format From 21a4eecca204a80b75afca9e3160a75c04e8dfb8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 30 Jun 2023 16:58:51 +0000 Subject: [PATCH 0801/1120] chore(deps): update dependency gradle to v7.6.2 --- gradle/wrapper/gradle-wrapper.jar | Bin 61574 -> 61624 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 943f0cbfa754578e88a3dae77fce6e3dea56edbf..afba109285af78dbd2a1d187e33ac4f87c76e392 100755 GIT binary patch delta 6679 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 Cn(^uY delta 6711 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 N0Rn>h&;K*$e*kC({~`bY diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 508322917b..4e86b92707 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 460f5162cc3ce625d8d60e17a14dfa77908f5f3f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 30 Jun 2023 19:56:32 +0000 Subject: [PATCH 0802/1120] fix(deps): update dependency io.github.solven-eu.cleanthat:java to v2.17 --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index a9d5181569..8a2b82d196 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -70,7 +70,7 @@ dependencies { // GLUE CODE (alphabetic order please) // cleanthat - String VER_CLEANTHAT='2.16' + String VER_CLEANTHAT='2.17' cleanthatCompileOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT" compatCleanthat2Dot1CompileAndTestOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT" // diktat From 3bafa6a28e4c3f1f982f06f652b793758f443169 Mon Sep 17 00:00:00 2001 From: Mitchell Skaggs Date: Fri, 7 Jul 2023 21:38:25 -0500 Subject: [PATCH 0803/1120] Support ktlint `0.50.0` and drop support for `0.47.0` Closes https://github.com/diffplug/spotless/issues/1741 --- CHANGES.md | 3 + lib/build.gradle | 12 +- .../compat/KtLintCompat0Dot47Dot0Adapter.java | 139 -------------- .../compat/KtLintCompat0Dot50Dot0Adapter.java | 173 ++++++++++++++++++ .../glue/ktlint/KtlintFormatterFunc.java | 12 +- .../diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../KtLintCompat0Dot50Dot0AdapterTest.java | 70 +++++++ .../resources/EmptyClassBody.kt | 3 + .../resources/FailsNoSemicolons.kt | 3 + plugin-gradle/CHANGES.md | 4 +- plugin-maven/CHANGES.md | 2 + .../resources/kotlin/ktlint/basic-old.clean | 5 + .../main/resources/kotlin/ktlint/basic.clean | 5 +- .../spotless/kotlin/KtLintStepTest.java | 47 ++--- 14 files changed, 299 insertions(+), 181 deletions(-) delete mode 100644 lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java create mode 100644 lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java create mode 100644 lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java create mode 100644 lib/src/testCompatKtLint0Dot50Dot0/resources/EmptyClassBody.kt create mode 100644 lib/src/testCompatKtLint0Dot50Dot0/resources/FailsNoSemicolons.kt create mode 100644 testlib/src/main/resources/kotlin/ktlint/basic-old.clean diff --git a/CHANGES.md b/CHANGES.md index ab72dc3ab0..a0a6b309ee 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,9 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`.([#1741](https://github.com/diffplug/spotless/issues/1741)) + * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. ### Changes * Bump default `cleanthat` version to latest `2.13` -> `2.16`. ([#1725](https://github.com/diffplug/spotless/pull/1725)) ### Fixed diff --git a/lib/build.gradle b/lib/build.gradle index a9d5181569..36921698f0 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -44,9 +44,9 @@ versionCompatibility { // we will support no more than 2 breaking changes at a time = 3 incompatible versions // we will try to drop down to only one version if a stable API can be maintained for a full year versions = [ - '0.47.0', '0.48.0', '0.49.0', + '0.50.0', ] targetSourceSetName = 'ktlint' } @@ -95,16 +95,18 @@ dependencies { strictly '1.7' // for JDK 8 compatibility } } - // ktlint - compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' - compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' - compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' + // ktlint oldest supported version compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' + // ktlint previous supported version compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.49.0' compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.49.0' compatKtLint0Dot49Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0' + // ktlint latest supported version + compatKtLint0Dot50Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.50.0' + compatKtLint0Dot50Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.50.0' + compatKtLint0Dot50Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0' // palantirJavaFormat palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm // scalafmt diff --git a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java b/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java deleted file mode 100644 index 0a38730b6a..0000000000 --- a/lib/src/compatKtLint0Dot47Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot47Dot0Adapter.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2022-2023 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.ktlint.compat; - -import static java.util.Collections.emptySet; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import com.pinterest.ktlint.core.KtLint; -import com.pinterest.ktlint.core.LintError; -import com.pinterest.ktlint.core.Rule; -import com.pinterest.ktlint.core.RuleProvider; -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; -import com.pinterest.ktlint.core.api.EditorConfigDefaults; -import com.pinterest.ktlint.core.api.EditorConfigOverride; -import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; -import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; -import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; - -import kotlin.Pair; -import kotlin.Unit; -import kotlin.jvm.functions.Function2; - -public class KtLintCompat0Dot47Dot0Adapter implements KtLintCompatAdapter { - - static class FormatterCallback implements Function2 { - @Override - public Unit invoke(LintError lint, Boolean corrected) { - if (!corrected) { - KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); - } - return null; - } - } - - @Override - public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - Path editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { - final FormatterCallback formatterCallback = new FormatterCallback(); - - Set allRuleProviders = new LinkedHashSet<>( - new StandardRuleSetProvider().getRuleProviders()); - if (useExperimental) { - allRuleProviders.addAll(new ExperimentalRuleSetProvider().getRuleProviders()); - } - - EditorConfigOverride editorConfigOverride; - if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = new EditorConfigOverride(); - } else { - editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( - RuleProvider::createNewRuleInstance).collect( - Collectors.toList()), - editorConfigOverrideMap); - } - - EditorConfigDefaults editorConfig; - if (editorConfigPath == null || !Files.exists(editorConfigPath)) { - editorConfig = EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(); - } else { - editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath); - } - - return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - path.toFile().getAbsolutePath(), - text, - emptySet(), - allRuleProviders, - userData, - formatterCallback, - isScript, - null, - false, - editorConfig, - editorConfigOverride, - false)); - } - - /** - * Create EditorConfigOverride from user provided parameters. - * Calling this method requires KtLint 0.45.2. - */ - private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { - // Get properties from rules in the rule sets - Stream> ruleProperties = rules.stream() - .filter(rule -> rule instanceof UsesEditorConfigProperties) - .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); - - // get complete list of supported properties in DefaultEditorConfigProperties.INSTANCE - List> editorConfigProperties = new ArrayList<>(DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties()); - editorConfigProperties.add(DefaultEditorConfigProperties.INSTANCE.getKtlintDisabledRulesProperty()); - - // Create a mapping of properties to their names based on rule properties and default properties - Map> supportedProperties = Stream - .concat(ruleProperties, editorConfigProperties.stream()) - .distinct() - .collect(Collectors.toMap(property -> property.getType().getName(), property -> property)); - - // Create config properties based on provided property names and values - @SuppressWarnings("unchecked") - Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() - .map(entry -> { - UsesEditorConfigProperties.EditorConfigProperty property = supportedProperties.get(entry.getKey()); - if (property != null) { - return new Pair<>(property, entry.getValue()); - } else { - return null; - } - }) - .filter(Objects::nonNull) - .toArray(Pair[]::new); - - return EditorConfigOverride.Companion.from(properties); - } -} diff --git a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java new file mode 100644 index 0000000000..642e15adc2 --- /dev/null +++ b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java @@ -0,0 +1,173 @@ +/* + * 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.ktlint.compat; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.pinterest.ktlint.rule.engine.api.Code; +import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; +import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride; +import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine; +import com.pinterest.ktlint.rule.engine.api.LintError; +import com.pinterest.ktlint.rule.engine.core.api.Rule; +import com.pinterest.ktlint.rule.engine.core.api.RuleId; +import com.pinterest.ktlint.rule.engine.core.api.RuleProvider; +import com.pinterest.ktlint.rule.engine.core.api.RuleSetId; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EndOfLinePropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentSizeEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; +import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; + +import kotlin.Pair; +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat0Dot50Dot0Adapter implements KtLintCompatAdapter { + + private static final Logger logger = LoggerFactory.getLogger(KtLintCompat0Dot50Dot0Adapter.class); + + private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; + + static { + List> list = new ArrayList<>(); + list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); + list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY()); + list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); + list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); + list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); + list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); + list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); + DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + } + + static class FormatterCallback implements Function2 { + + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId().getValue(), lint.getDetail()); + } + return Unit.INSTANCE; + } + } + + @Override + public String format(final String text, Path path, final boolean isScript, + final boolean useExperimental, + Path editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + Set allRuleProviders = new LinkedHashSet<>( + new StandardRuleSetProvider().getRuleProviders()); + + // TODO: Should we keep `useExperimental` now that ktlint uses an EditorConfig property for this purpose? + if (useExperimental) { + String experimentalRulesPropertyName = RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY().getName(); + Object experimentalOverride = editorConfigOverrideMap.get(experimentalRulesPropertyName); + if (experimentalOverride != null) { + logger.warn("`useExperimental` parameter is `true` and `ktlint_experimental` property is set, `useExperimental` will take priority!"); + editorConfigOverrideMap.put(experimentalRulesPropertyName, "enabled"); + } + } + + EditorConfigOverride editorConfigOverride; + if (editorConfigOverrideMap.isEmpty()) { + editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); + } else { + editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( + RuleProvider::createNewRuleInstance).collect(Collectors.toList()), + editorConfigOverrideMap); + } + EditorConfigDefaults editorConfig; + if (editorConfigPath == null || !Files.exists(editorConfigPath)) { + editorConfig = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); + } else { + editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath, Collections.emptySet()); + } + + return new KtLintRuleEngine( + allRuleProviders, + editorConfig, + editorConfigOverride, + true, + false, + path.getFileSystem()) + .format(Code.Companion.fromPath(path), formatterCallback); + } + + /** + * Create EditorConfigOverride from user provided parameters. + */ + private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { + // Get properties from rules in the rule sets + Stream> ruleProperties = rules.stream() + .flatMap(rule -> rule.getUsesEditorConfigProperties().stream()); + + // Create a mapping of properties to their names based on rule properties and default properties + Map> supportedProperties = Stream + .concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream()) + .distinct() + .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); + + // Create config properties based on provided property names and values + @SuppressWarnings("unchecked") + Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() + .map(entry -> { + EditorConfigProperty property = supportedProperties.get(entry.getKey()); + if (property != null) { + return new Pair<>(property, entry.getValue()); + } else if (entry.getKey().startsWith("ktlint_")) { + String[] parts = entry.getKey().substring(7).split("_", 2); + if (parts.length == 1) { + // convert ktlint_{ruleset} to RuleSetId + RuleSetId id = new RuleSetId(parts[0]); + property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(id, RuleExecution.disabled); + } else { + // convert ktlint_{ruleset}_{rulename} to RuleId + RuleId id = new RuleId(parts[0] + ":" + parts[1]); + property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(id, RuleExecution.disabled); + } + return new Pair<>(property, entry.getValue()); + } else { + return null; + } + }) + .filter(Objects::nonNull) + .toArray(Pair[]::new); + + return EditorConfigOverride.Companion.from(properties); + } +} diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index fba855bb9a..9f773d4016 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -35,17 +35,19 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, FileSignature editorConfigPath, Map userData, Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); - if (minorVersion >= 49) { + if (minorVersion >= 50) { + // Fixed `RuleId` and `RuleSetId` issues + // New argument to `EditorConfigDefaults.Companion.load(...)` for custom property type parsing + // New argument to `new KtLintRuleEngine(...)` to fail on usage of `treeCopyHandler` extension point + this.adapter = new KtLintCompat0Dot50Dot0Adapter(); + } else if (minorVersion == 49) { // Packages and modules moved around (`ktlint-core` -> `ktlint-rule-engine`) // Experimental ruleset was replaced by implementing `Rule.Experimental` and checking the `ktlint_experimental` `.editorconfig` property // `RuleId` and `RuleSetId` became inline classes (mangled to be unrepresentable in Java source code, so reflection is needed), tracked here: https://github.com/pinterest/ktlint/issues/2041 this.adapter = new KtLintCompat0Dot49Dot0Adapter(); - } else if (minorVersion == 48) { + } else { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class this.adapter = new KtLintCompat0Dot48Dot0Adapter(); - } else { - // rename RuleSet to RuleProvider - this.adapter = new KtLintCompat0Dot47Dot0Adapter(); } this.editorConfigPath = editorConfigPath; this.useExperimental = useExperimental; diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 6e82538b04..a844a93bff 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -36,7 +36,7 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.49.1"; + private static final String DEFAULT_VERSION = "0.50.0"; static final String NAME = "ktlint"; static final String PACKAGE = "com.pinterest"; static final String MAVEN_COORDINATE = PACKAGE + ":ktlint:"; diff --git a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java new file mode 100644 index 0000000000..575515a66e --- /dev/null +++ b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java @@ -0,0 +1,70 @@ +/* + * 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.ktlint.compat; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +public class KtLintCompat0Dot50Dot0AdapterTest { + @Test + public void testDefaults(@TempDir Path path) throws IOException { + KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); + String text = loadAndWriteText(path, "EmptyClassBody.kt"); + final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + + String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + assertEquals("class EmptyClassBody\n", formatted); + } + + @Test + public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { + KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); + String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("indent_style", "tab"); + editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + + String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); + } + + private static String loadAndWriteText(Path path, String name) throws IOException { + try (InputStream is = KtLintCompat0Dot50Dot0AdapterTest.class.getResourceAsStream("/" + name)) { + Files.copy(is, path.resolve(name)); + } + return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8); + } + +} diff --git a/lib/src/testCompatKtLint0Dot50Dot0/resources/EmptyClassBody.kt b/lib/src/testCompatKtLint0Dot50Dot0/resources/EmptyClassBody.kt new file mode 100644 index 0000000000..7da53fb78d --- /dev/null +++ b/lib/src/testCompatKtLint0Dot50Dot0/resources/EmptyClassBody.kt @@ -0,0 +1,3 @@ +class EmptyClassBody { + +} diff --git a/lib/src/testCompatKtLint0Dot50Dot0/resources/FailsNoSemicolons.kt b/lib/src/testCompatKtLint0Dot50Dot0/resources/FailsNoSemicolons.kt new file mode 100644 index 0000000000..4cf05ceacf --- /dev/null +++ b/lib/src/testCompatKtLint0Dot50Dot0/resources/FailsNoSemicolons.kt @@ -0,0 +1,3 @@ +class FailsNoSemicolons { + val i = 0; +} diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 744c6efce7..af7d966755 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,7 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] - +### Added +* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`.([#1741](https://github.com/diffplug/spotless/issues/1741)) + * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. ### Fixed * Correctly support the syntax ``` diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c19cc804af..db7fff9851 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support pass skip (`-Dspotless.skip=true`) from command-line. ([#1729](https://github.com/diffplug/spotless/pull/1729)) +* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`.([#1741](https://github.com/diffplug/spotless/issues/1741)) + * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. ### Fixed * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728)) diff --git a/testlib/src/main/resources/kotlin/ktlint/basic-old.clean b/testlib/src/main/resources/kotlin/ktlint/basic-old.clean new file mode 100644 index 0000000000..fd5371bed2 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/basic-old.clean @@ -0,0 +1,5 @@ +fun main() { + fun name() { a(); return b } + println(";") + println() +} diff --git a/testlib/src/main/resources/kotlin/ktlint/basic.clean b/testlib/src/main/resources/kotlin/ktlint/basic.clean index fd5371bed2..b727a7d016 100644 --- a/testlib/src/main/resources/kotlin/ktlint/basic.clean +++ b/testlib/src/main/resources/kotlin/ktlint/basic.clean @@ -1,5 +1,8 @@ fun main() { - fun name() { a(); return b } + fun name() { + a() + return b + } println(";") println() } diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 9af6685906..5b62eeed48 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -25,59 +25,48 @@ class KtLintStepTest extends ResourceHarness { @Test - void behavior() { - FormatterStep step = KtLintStep.create(TestProvisioner.mavenCentral()); - StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo( - "Error on line: 1, column: 1\n" + - "rule: standard:no-wildcard-imports\n" + - "Wildcard import"); - } - - @Test - void works0_47_0() { - FormatterStep step = KtLintStep.create("0.47.0", TestProvisioner.mavenCentral()); + void works0_48_0() { + FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic-old.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + "rule: no-wildcard-imports\n" + "Wildcard import"); } @Test - void works0_47_1() { - FormatterStep step = KtLintStep.create("0.47.1", TestProvisioner.mavenCentral()); + void works0_48_1() { + FormatterStep step = KtLintStep.create("0.48.1", TestProvisioner.mavenCentral()); StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic-old.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + "rule: no-wildcard-imports\n" + "Wildcard import"); } @Test - void works0_48_0() { - FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); + void works0_49_0() { + FormatterStep step = KtLintStep.create("0.49.0", TestProvisioner.mavenCentral()); StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic-old.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + + "rule: standard:no-wildcard-imports\n" + "Wildcard import"); } @Test - void works0_48_1() { - FormatterStep step = KtLintStep.create("0.48.1", TestProvisioner.mavenCentral()); + void works0_49_1() { + FormatterStep step = KtLintStep.create("0.49.1", TestProvisioner.mavenCentral()); StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic-old.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + - "rule: no-wildcard-imports\n" + + "rule: standard:no-wildcard-imports\n" + "Wildcard import"); } @Test - void works0_49_0() { - FormatterStep step = KtLintStep.create("0.49.0", TestProvisioner.mavenCentral()); + void works0_50_0() { + FormatterStep step = KtLintStep.create("0.50.0", TestProvisioner.mavenCentral()); StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + @@ -86,8 +75,8 @@ void works0_49_0() { } @Test - void works0_49_1() { - FormatterStep step = KtLintStep.create("0.49.1", TestProvisioner.mavenCentral()); + void behavior() { + FormatterStep step = KtLintStep.create(TestProvisioner.mavenCentral()); StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + From f9dd7bec434bc49ed3b68d8583bdffe4460be94d Mon Sep 17 00:00:00 2001 From: David Gregory <2992938+DavidGregory084@users.noreply.github.com> Date: Wed, 12 Jul 2023 15:12:20 +0100 Subject: [PATCH 0804/1120] Enable Gradle users to create steps that require a provisioner --- .../com/diffplug/gradle/spotless/FormatExtension.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 4fa74bc2ea..735f5bfabd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -30,6 +30,7 @@ import java.util.Random; import java.util.TreeMap; import java.util.function.Consumer; +import java.util.function.Function; import javax.annotation.Nullable; import javax.inject.Inject; @@ -300,6 +301,13 @@ public void addStep(FormatterStep newStep) { steps.add(newStep); } + /** Adds a new step that requires a Provisioner. */ + public void addStep(Function createStepFn) { + requireNonNull(createStepFn); + FormatterStep newStep = createStepFn.apply(provisioner()); + addStep(newStep); + } + /** Returns the index of the existing step with the given name, or -1 if no such step exists. */ protected int getExistingStepIdx(String stepName) { for (int i = 0; i < steps.size(); ++i) { From 9fc857e14401187a08cfaa3daa38c861dd420e24 Mon Sep 17 00:00:00 2001 From: David Gregory <2992938+DavidGregory084@users.noreply.github.com> Date: Wed, 12 Jul 2023 19:48:41 +0100 Subject: [PATCH 0805/1120] Update CHANGES.md --- plugin-gradle/CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 744c6efce7..4ea854b86a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Added + +* Add an overload for `FormatExtension.addStep` which provides access to the `FormatExtension`'s `Provisioner`, enabling custom steps to make use of third-party dependencies. + ### Fixed * Correctly support the syntax ``` From 55c2a6bd1a5a49af0c289376e0b79da4b6dedc1f Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Wed, 12 Jul 2023 22:05:26 +0200 Subject: [PATCH 0806/1120] Add targetExcludeIfContentContains API to the Gradle plugin --- plugin-gradle/CHANGES.md | 2 + .../gradle/spotless/FormatExtension.java | 11 ++ .../TargetExcludeIfContentContainsTest.java | 110 ++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 744c6efce7..f351495462 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Added +* Add target option `targetExcludeIfContentContains` to exclude files by text they contain. ### Fixed * Correctly support the syntax ``` diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 4fa74bc2ea..7e2e755f5d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -161,6 +161,12 @@ public void encoding(String charset) { /** The files to be formatted = (target - targetExclude). */ protected FileCollection target, targetExclude; + /** + * The values from which files will be excluded if their content contain at least one of the + * `targetExcludeIfContentContains`. + */ + protected List targetExcludeIfContentContains = new ArrayList<>(); + protected boolean isLicenseHeaderStep(FormatterStep formatterStep) { String formatterStepName = formatterStep.getName(); @@ -202,6 +208,11 @@ public void targetExclude(Object... targets) { this.targetExclude = parseTargetsIsExclude(targets, true); } + /** Excludes all files whose content contains at least one of the `values`. */ + public void targetExcludeIfContentContains(String... values) { + this.targetExcludeIfContentContains.addAll(List.of(values)); + } + private FileCollection parseTargetsIsExclude(Object[] targets, boolean isExclude) { requireElementsNonNull(targets); if (targets.length == 0) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java new file mode 100644 index 0000000000..66dfc60f4c --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java @@ -0,0 +1,110 @@ +/* + * Copyright 2020-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.gradle.spotless; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +class TargetExcludeIfContentContainsTest extends GradleIntegrationHarness { + @Test + void targetExcludeIfContentContainsWithOneValue() throws IOException { + setFile("build.gradle").toLines( + "plugins { id 'com.diffplug.spotless' }", + "spotless {", + " format 'toLower', {", + " target '**/*.md'", + " targetExcludeIfContentContains '// Generated by Mr. Roboto'", + " custom 'lowercase', { str -> str.toLowerCase() }", + " toggleOffOn()", + " }", + "}"); + String content = "// Generated by Mr. Roboto, do not edit.\n" + + "A B C\n" + + "D E F\n" + + "G H I"; + setFile("test_generated.md").toContent(content); + setFile("test_manual.md").toLines( + "A B C", + "D E F", + "G H I"); + gradleRunner().withArguments("spotlessApply").build(); + // `test_generated` contains the excluding text so didn't change. + assertFile("test_generated.md").hasContent(content); + // `test_manual` does not so it changed. + assertFile("test_manual.md").hasLines( + "a b c", + "d e f", + "g h i"); + } + + @Test + void targetExcludeIfContentContainsWithMultipleValues() throws IOException { + setFile("build.gradle").toLines( + "plugins { id 'com.diffplug.spotless' }", + "spotless {", + " format 'toLower', {", + " target '**/*.md'", + " targetExcludeIfContentContains '// Generated by Mr. Roboto', '// Generated by Mrs. Call'", + " custom 'lowercase', { str -> str.toLowerCase() }", + " toggleOffOn()", + " }", + "}"); + String robotoContent = "A B C\n" + + "// Generated by Mr. Roboto, do not edit.\n" + + "D E F\n" + + "G H I"; + setFile("test_generated_roboto.md").toContent(robotoContent); + String callContent = "A B C\n" + + "D E F\n" + + "// Generated by Mrs. Call, do not edit.\n" + + "G H I"; + setFile("test_generated_call.md").toContent(callContent); + String collaborationContent = "A B C\n" + + "// Generated by Mr. Roboto, do not edit.\n" + + "D E F\n" + + "// Generated by Mrs. Call, do not edit.\n" + + "G H I"; + setFile("test_generated_collaboration.md").toContent(collaborationContent); + String intruderContent = "A B C\n" + + "// Generated by K2000, do not edit.\n" + + "D E F\n" + + "G H I"; + setFile("test_generated_intruder.md").toContent(intruderContent); + setFile("test_manual.md").toLines( + "A B C", + "D E F", + "G H I"); + gradleRunner().withArguments("spotlessApply").build(); + // Part of the excluding values so has not changed. + assertFile("test_generated_roboto.md").hasContent(robotoContent); + // Part of the excluding values so has not changed. + assertFile("test_generated_call.md").hasContent(callContent); + // Part of the excluding values so has not changed. + assertFile("test_generated_collaboration.md").hasContent(collaborationContent); + // Not part of the excluding values so has changed. + assertFile("test_generated_intruder.md").hasContent( + "a b c\n" + + "// generated by k2000, do not edit.\n" + + "d e f\n" + + "g h i"); + // `test_manual` does not so it changed. + assertFile("test_manual.md").hasLines( + "a b c", + "d e f", + "g h i"); + } +} From 13a36fc7362864929ce57a6373d3250ba7a3f323 Mon Sep 17 00:00:00 2001 From: Mitchell Skaggs Date: Wed, 12 Jul 2023 19:40:34 -0500 Subject: [PATCH 0807/1120] Remove deprecated `useExperimental` parameter in favor of `ktlint_${RuleSetId}` properties and loading all current `RuleSetProvider`s --- CHANGES.md | 1 + .../compat/KtLintCompat0Dot48Dot0Adapter.java | 17 ++++++-------- .../compat/KtLintCompat0Dot49Dot0Adapter.java | 23 ++++++------------- .../compat/KtLintCompat0Dot50Dot0Adapter.java | 23 ++++++------------- .../ktlint/compat/KtLintCompatAdapter.java | 4 ++-- .../glue/ktlint/KtlintFormatterFunc.java | 6 ++--- .../diffplug/spotless/kotlin/KtLintStep.java | 22 +++++++----------- .../KtLintCompat0Dot48Dot0AdapterTest.java | 4 ++-- .../KtLintCompat0Dot49Dot0AdapterTest.java | 4 ++-- .../KtLintCompat0Dot50Dot0AdapterTest.java | 4 ++-- plugin-gradle/CHANGES.md | 3 ++- plugin-gradle/README.md | 5 ++-- .../gradle/spotless/KotlinExtension.java | 16 ++++--------- .../spotless/KotlinGradleExtension.java | 13 ++--------- .../gradle/spotless/KotlinExtensionTest.java | 10 ++++---- .../spotless/KotlinGradleExtensionTest.java | 10 ++++---- .../spotless/maven/kotlin/Ktlint.java | 2 +- 17 files changed, 61 insertions(+), 106 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a0a6b309ee..2c9a855114 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`.([#1741](https://github.com/diffplug/spotless/issues/1741)) * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. + * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. ### Changes * Bump default `cleanthat` version to latest `2.13` -> `2.16`. ([#1725](https://github.com/diffplug/spotless/pull/1725)) ### Fixed diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 1e54a80859..3b01470c8e 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -19,10 +19,10 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.ServiceLoader; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -31,6 +31,7 @@ import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.Rule; import com.pinterest.ktlint.core.RuleProvider; +import com.pinterest.ktlint.core.RuleSetProviderV2; import com.pinterest.ktlint.core.api.EditorConfigDefaults; import com.pinterest.ktlint.core.api.EditorConfigOverride; import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; @@ -42,8 +43,6 @@ import com.pinterest.ktlint.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt; import com.pinterest.ktlint.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; import com.pinterest.ktlint.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; -import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; -import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; import kotlin.Pair; import kotlin.Unit; @@ -79,16 +78,14 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - Path editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); - Set allRuleProviders = new LinkedHashSet<>( - new StandardRuleSetProvider().getRuleProviders()); - if (useExperimental) { - allRuleProviders.addAll(new ExperimentalRuleSetProvider().getRuleProviders()); - } + Set allRuleProviders = ServiceLoader.load(RuleSetProviderV2.class, RuleSetProviderV2.class.getClassLoader()) + .stream() + .flatMap(loader -> loader.get().getRuleProviders().stream()) + .collect(Collectors.toUnmodifiableSet()); EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { diff --git a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java index 86ca69c352..ccff718b01 100644 --- a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java @@ -21,10 +21,10 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.ServiceLoader; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -32,6 +32,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3; import com.pinterest.ktlint.rule.engine.api.Code; import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride; @@ -48,7 +49,6 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution; import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; -import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; import kotlin.Pair; import kotlin.Unit; @@ -123,23 +123,14 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - Path editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); - Set allRuleProviders = new LinkedHashSet<>( - new StandardRuleSetProvider().getRuleProviders()); - - // TODO: Should we keep `useExperimental` now that ktlint uses an EditorConfig property for this purpose? - if (useExperimental) { - String experimentalRulesPropertyName = RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY().getName(); - Object experimentalOverride = editorConfigOverrideMap.get(experimentalRulesPropertyName); - if (experimentalOverride != null) { - logger.warn("`useExperimental` parameter is `true` and `ktlint_experimental` property is set, `useExperimental` will take priority!"); - editorConfigOverrideMap.put(experimentalRulesPropertyName, "enabled"); - } - } + Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) + .stream() + .flatMap(loader -> loader.get().getRuleProviders().stream()) + .collect(Collectors.toUnmodifiableSet()); EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { diff --git a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java index 642e15adc2..009392b9e1 100644 --- a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java @@ -19,10 +19,10 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.ServiceLoader; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -30,6 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3; import com.pinterest.ktlint.rule.engine.api.Code; import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride; @@ -48,7 +49,6 @@ import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution; import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; -import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; import kotlin.Pair; import kotlin.Unit; @@ -85,23 +85,14 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - final boolean useExperimental, - Path editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); - Set allRuleProviders = new LinkedHashSet<>( - new StandardRuleSetProvider().getRuleProviders()); - - // TODO: Should we keep `useExperimental` now that ktlint uses an EditorConfig property for this purpose? - if (useExperimental) { - String experimentalRulesPropertyName = RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY().getName(); - Object experimentalOverride = editorConfigOverrideMap.get(experimentalRulesPropertyName); - if (experimentalOverride != null) { - logger.warn("`useExperimental` parameter is `true` and `ktlint_experimental` property is set, `useExperimental` will take priority!"); - editorConfigOverrideMap.put(experimentalRulesPropertyName, "enabled"); - } - } + Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) + .stream() + .flatMap(loader -> loader.get().getRuleProviders().stream()) + .collect(Collectors.toUnmodifiableSet()); EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 68a65eb6c8..64576d7e19 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -20,6 +20,6 @@ public interface KtLintCompatAdapter { - String format(String text, Path path, boolean isScript, boolean useExperimental, Path editorConfigPath, Map userData, - Map editorConfigOverrideMap); + String format(String text, Path path, boolean isScript, Path editorConfigPath, Map userData, + Map editorConfigOverrideMap); } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 9f773d4016..2f9f67bd72 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -28,11 +28,10 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { private final Map userData; private final boolean isScript; private final KtLintCompatAdapter adapter; - private final boolean useExperimental; private final FileSignature editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, boolean isScript, boolean useExperimental, FileSignature editorConfigPath, Map userData, + public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath, Map userData, Map editorConfigOverrideMap) { int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 50) { @@ -50,7 +49,6 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime this.adapter = new KtLintCompat0Dot48Dot0Adapter(); } this.editorConfigPath = editorConfigPath; - this.useExperimental = useExperimental; this.editorConfigOverrideMap = editorConfigOverrideMap; this.userData = userData; this.isScript = isScript; @@ -63,6 +61,6 @@ public String applyWithFile(String unix, File file) { if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } - return adapter.format(unix, file.toPath(), isScript, useExperimental, absoluteEditorConfigPath, userData, editorConfigOverrideMap); + return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, userData, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index a844a93bff..36bf5d42f4 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -46,28 +46,26 @@ public static FormatterStep create(Provisioner provisioner) { } public static FormatterStep create(String version, Provisioner provisioner) { - return create(version, provisioner, false, Collections.emptyMap(), Collections.emptyMap()); + return create(version, provisioner, Collections.emptyMap(), Collections.emptyMap()); } - public static FormatterStep create(String version, Provisioner provisioner, boolean useExperimental, - Map userData, Map editorConfigOverride) { - return create(version, provisioner, false, useExperimental, null, userData, editorConfigOverride); + public static FormatterStep create(String version, Provisioner provisioner, + Map userData, Map editorConfigOverride) { + return create(version, provisioner, false, null, userData, editorConfigOverride); } public static FormatterStep createForScript(String version, Provisioner provisioner) { - return create(version, provisioner, true, false, null, Collections.emptyMap(), Collections.emptyMap()); + return create(version, provisioner, true, null, Collections.emptyMap(), Collections.emptyMap()); } public static FormatterStep createForScript(String version, Provisioner provisioner, - boolean useExperimental, @Nullable FileSignature editorConfigPath, Map userData, Map editorConfigOverride) { return create(version, provisioner, true, - useExperimental, editorConfigPath, userData, editorConfigOverride); @@ -76,14 +74,13 @@ public static FormatterStep createForScript(String version, public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, - boolean useExperimental, @Nullable FileSignature editorConfig, Map userData, Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, isScript, useExperimental, editorConfig, userData, editorConfigOverride), + () -> new State(version, provisioner, isScript, editorConfig, userData, editorConfigOverride), State::createFormat); } @@ -98,7 +95,6 @@ static final class State implements Serializable { private final boolean isScript; /** The jar that contains the formatter. */ final JarState jarState; - private final boolean useExperimental; private final TreeMap userData; private final TreeMap editorConfigOverride; private final String version; @@ -108,7 +104,6 @@ static final class State implements Serializable { State(String version, Provisioner provisioner, boolean isScript, - boolean useExperimental, @Nullable FileSignature editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { @@ -116,7 +111,6 @@ static final class State implements Serializable { throw new IllegalStateException("KtLint versions < 0.46.0 not supported!"); } this.version = version; - this.useExperimental = useExperimental; this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); @@ -128,8 +122,8 @@ FormatterFunc createFormat() throws Exception { final ClassLoader classLoader = jarState.getClassLoader(); Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); Constructor constructor = formatterFunc.getConstructor( - String.class, boolean.class, boolean.class, FileSignature.class, Map.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, useExperimental, editorConfigPath, userData, editorConfigOverride); + String.class, boolean.class, FileSignature.class, Map.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, userData, editorConfigOverride); } } } diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index c811b51233..7fc9d1d9a4 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -40,7 +40,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @@ -58,7 +58,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { // ktlint_filename is an invalid rule in ktlint 0.48.0 editorConfigOverrideMap.put("ktlint_filename", "disabled"); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java index ede67e0174..a0db6ecddc 100644 --- a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java @@ -40,7 +40,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -56,7 +56,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java index 575515a66e..f5b76ccae0 100644 --- a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java @@ -40,7 +40,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -56,7 +56,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index af7d966755..9f366e5f80 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,8 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`.([#1741](https://github.com/diffplug/spotless/issues/1741)) +* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741)) * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. + * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. ### Fixed * Correctly support the syntax ``` diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index ef93e31d45..704e3b694a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -397,9 +397,8 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```kotlin spotless { kotlin { - // version, setUseExperimental, userData and editorConfigOverride are all optional - ktlint("0.45.2") - .setUseExperimental(true) + // version, userData and editorConfigOverride are all optional + ktlint("0.50.0") .userData(mapOf("android" to "true")) .setEditorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement .editorConfigOverride(mapOf("indent_size" to 2)) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 363a9cac6f..997fe3b9d6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -61,7 +61,7 @@ public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version); File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; - return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); + return new KotlinFormatExtension(version, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); } public KotlinFormatExtension ktlint() throws IOException { @@ -71,28 +71,20 @@ public KotlinFormatExtension ktlint() throws IOException { public class KotlinFormatExtension { private final String version; - private boolean useExperimental; @Nullable private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, @Nullable FileSignature editorConfigPath, Map config, - Map editorConfigOverride) { + KotlinFormatExtension(String version, @Nullable FileSignature editorConfigPath, Map config, + Map editorConfigOverride) { this.version = version; - this.useExperimental = useExperimental; this.editorConfigPath = editorConfigPath; this.userData = config; this.editorConfigOverride = editorConfigOverride; addStep(createStep()); } - public KotlinFormatExtension setUseExperimental(boolean useExperimental) { - this.useExperimental = useExperimental; - replaceStep(createStep()); - return this; - } - public KotlinFormatExtension setEditorConfigPath(Object editorConfigFile) throws IOException { if (editorConfigFile == null) { this.editorConfigPath = null; @@ -120,7 +112,7 @@ public KotlinFormatExtension editorConfigOverride(Map editorConf } private FormatterStep createStep() { - return KtLintStep.create(version, provisioner(), useExperimental, false, editorConfigPath, userData, editorConfigOverride); + return KtLintStep.create(version, provisioner(), false, editorConfigPath, userData, editorConfigOverride); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index a0657e99d9..b3351194ba 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -49,7 +49,7 @@ public KotlinFormatExtension ktlint(String version) throws IOException { Objects.requireNonNull(version, "version"); File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; - return new KotlinFormatExtension(version, false, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); + return new KotlinFormatExtension(version, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); } public KotlinFormatExtension ktlint() throws IOException { @@ -59,16 +59,14 @@ public KotlinFormatExtension ktlint() throws IOException { public class KotlinFormatExtension { private final String version; - private boolean useExperimental; @Nullable private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KotlinFormatExtension(String version, boolean useExperimental, FileSignature editorConfigPath, Map config, + KotlinFormatExtension(String version, FileSignature editorConfigPath, Map config, Map editorConfigOverride) { this.version = version; - this.useExperimental = useExperimental; this.editorConfigPath = editorConfigPath; this.userData = config; this.editorConfigOverride = editorConfigOverride; @@ -86,12 +84,6 @@ public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws return this; } - public KotlinFormatExtension setUseExperimental(boolean useExperimental) { - this.useExperimental = useExperimental; - replaceStep(createStep()); - return this; - } - public KotlinFormatExtension userData(Map userData) { // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized // representation. @@ -112,7 +104,6 @@ private FormatterStep createStep() { return KtLintStep.createForScript( version, provisioner(), - useExperimental, editorConfigPath, userData, editorConfigOverride); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 947b5bd728..10fbe5bd90 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -69,11 +69,11 @@ void withExperimentalEditorConfigOverride() throws IOException { "repositories { mavenCentral() }", "spotless {", " kotlin {", - " ktlint().setUseExperimental(true)", - " .editorConfigOverride([", - " ij_kotlin_allow_trailing_comma: true,", - " ij_kotlin_allow_trailing_comma_on_call_site: true", - " ])", + " ktlint().editorConfigOverride([", + " ktlint_experimental: \"enabled\",", + " ij_kotlin_allow_trailing_comma: true,", + " ij_kotlin_allow_trailing_comma_on_call_site: true", + " ])", " }", "}"); setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 13a7cd8472..7dade5f2ff 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -51,11 +51,11 @@ void withExperimentalEditorConfigOverride() throws IOException { "repositories { mavenCentral() }", "spotless {", " kotlinGradle {", - " ktlint().setUseExperimental(true)", - " .editorConfigOverride([", - " ij_kotlin_allow_trailing_comma: true,", - " ij_kotlin_allow_trailing_comma_on_call_site: true", - " ])", + " ktlint().editorConfigOverride([", + " ktlint_experimental: \"enabled\",", + " ij_kotlin_allow_trailing_comma: true,", + " ij_kotlin_allow_trailing_comma_on_call_site: true", + " ])", " }", "}"); setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 2825980733..fd59d8ba9d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -48,6 +48,6 @@ public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { editorConfigOverride = new HashMap<>(); } - return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, false, configPath, Collections.emptyMap(), editorConfigOverride); + return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, configPath, Collections.emptyMap(), editorConfigOverride); } } From e5a31679260d17ff133a1e77c14aa4c4e2578c17 Mon Sep 17 00:00:00 2001 From: Mitchell Skaggs Date: Wed, 12 Jul 2023 19:42:35 -0500 Subject: [PATCH 0808/1120] Move ktlint version check closer to actual version use --- .../diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java | 4 +++- .../main/java/com/diffplug/spotless/kotlin/KtLintStep.java | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 2f9f67bd72..1a11e8bcce 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -44,9 +44,11 @@ public KtlintFormatterFunc(String version, boolean isScript, FileSignature edito // Experimental ruleset was replaced by implementing `Rule.Experimental` and checking the `ktlint_experimental` `.editorconfig` property // `RuleId` and `RuleSetId` became inline classes (mangled to be unrepresentable in Java source code, so reflection is needed), tracked here: https://github.com/pinterest/ktlint/issues/2041 this.adapter = new KtLintCompat0Dot49Dot0Adapter(); - } else { + } else if (minorVersion == 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class this.adapter = new KtLintCompat0Dot48Dot0Adapter(); + } else { + throw new IllegalStateException("Ktlint versions < 0.48.0 not supported!"); } this.editorConfigPath = editorConfigPath; this.editorConfigOverrideMap = editorConfigOverrideMap; diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 36bf5d42f4..32f9f4ef1f 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -107,9 +107,6 @@ static final class State implements Serializable { @Nullable FileSignature editorConfigPath, Map userData, Map editorConfigOverride) throws IOException { - if (BadSemver.version(version) < BadSemver.version(0, 46, 0)) { - throw new IllegalStateException("KtLint versions < 0.46.0 not supported!"); - } this.version = version; this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); From 135372388430e3b3f8824ca294005b6d663f6529 Mon Sep 17 00:00:00 2001 From: Mitchell Skaggs Date: Wed, 12 Jul 2023 20:13:17 -0500 Subject: [PATCH 0809/1120] Clarify ktlint property-matching control flow for ruleset properties --- .../compat/KtLintCompat0Dot48Dot0Adapter.java | 12 ++++++----- .../compat/KtLintCompat0Dot49Dot0Adapter.java | 20 ++++++++++--------- .../compat/KtLintCompat0Dot50Dot0Adapter.java | 16 ++++++++------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 3b01470c8e..3efddcf55f 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -131,9 +131,8 @@ private static EditorConfigOverride createEditorConfigOverride(final List Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() .map(entry -> { EditorConfigProperty property = supportedProperties.get(entry.getKey()); - if (property != null) { - return new Pair<>(property, entry.getValue()); - } else if (entry.getKey().startsWith("ktlint_")) { + + if (property == null && entry.getKey().startsWith("ktlint_")) { String[] parts = entry.getKey().substring(7).split("_", 2); if (parts.length == 1) { // convert ktlint_{ruleset} to {ruleset} @@ -144,9 +143,12 @@ private static EditorConfigOverride createEditorConfigOverride(final List String qualifiedRuleId = parts[0] + ":" + parts[1]; property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(qualifiedRuleId); } - return new Pair<>(property, entry.getValue()); - } else { + } + + if (property == null) { return null; + } else { + return new Pair<>(property, entry.getValue()); } }) .filter(Objects::nonNull) diff --git a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java index ccff718b01..1fee28778d 100644 --- a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java @@ -175,22 +175,24 @@ private static EditorConfigOverride createEditorConfigOverride(final List Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() .map(entry -> { EditorConfigProperty property = supportedProperties.get(entry.getKey()); - if (property != null) { - return new Pair<>(property, entry.getValue()); - } else if (entry.getKey().startsWith("ktlint_")) { + + if (property == null && entry.getKey().startsWith("ktlint_")) { String[] parts = entry.getKey().substring(7).split("_", 2); if (parts.length == 1) { // convert ktlint_{ruleset} to {ruleset} - String qualifiedRuleId = parts[0] + ":"; - property = createRuleSetExecution(qualifiedRuleId, RuleExecution.disabled); + String id = parts[0]; + property = createRuleSetExecution(id, RuleExecution.enabled); } else { // convert ktlint_{ruleset}_{rulename} to {ruleset}:{rulename} - String qualifiedRuleId = parts[0] + ":" + parts[1]; - property = createRuleExecution(qualifiedRuleId, RuleExecution.disabled); + String id = parts[0] + ":" + parts[1]; + property = createRuleExecution(id, RuleExecution.enabled); } - return new Pair<>(property, entry.getValue()); - } else { + } + + if (property == null) { return null; + } else { + return new Pair<>(property, entry.getValue()); } }) .filter(Objects::nonNull) diff --git a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java index 009392b9e1..18057ba1d3 100644 --- a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java @@ -138,22 +138,24 @@ private static EditorConfigOverride createEditorConfigOverride(final List Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() .map(entry -> { EditorConfigProperty property = supportedProperties.get(entry.getKey()); - if (property != null) { - return new Pair<>(property, entry.getValue()); - } else if (entry.getKey().startsWith("ktlint_")) { + + if (property == null && entry.getKey().startsWith("ktlint_")) { String[] parts = entry.getKey().substring(7).split("_", 2); if (parts.length == 1) { // convert ktlint_{ruleset} to RuleSetId RuleSetId id = new RuleSetId(parts[0]); - property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(id, RuleExecution.disabled); + property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(id, RuleExecution.enabled); } else { // convert ktlint_{ruleset}_{rulename} to RuleId RuleId id = new RuleId(parts[0] + ":" + parts[1]); - property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(id, RuleExecution.disabled); + property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(id, RuleExecution.enabled); } - return new Pair<>(property, entry.getValue()); - } else { + } + + if (property == null) { return null; + } else { + return new Pair<>(property, entry.getValue()); } }) .filter(Objects::nonNull) From c0bee92fb9b752349a83a5d6726f121e38505725 Mon Sep 17 00:00:00 2001 From: Mitchell Skaggs Date: Wed, 12 Jul 2023 21:14:04 -0500 Subject: [PATCH 0810/1120] Fix formatting --- .../ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java | 10 +++++----- .../ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java | 8 ++++---- .../ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java | 8 ++++---- .../glue/ktlint/compat/KtLintCompatAdapter.java | 2 +- .../java/com/diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../com/diffplug/gradle/spotless/KotlinExtension.java | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 3efddcf55f..4ee70c6c88 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -78,14 +78,14 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV2.class, RuleSetProviderV2.class.getClassLoader()) - .stream() - .flatMap(loader -> loader.get().getRuleProviders().stream()) - .collect(Collectors.toUnmodifiableSet()); + .stream() + .flatMap(loader -> loader.get().getRuleProviders().stream()) + .collect(Collectors.toUnmodifiableSet()); EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { @@ -108,7 +108,7 @@ public String format(final String text, Path path, final boolean isScript, editorConfig, editorConfigOverride, false) - .format(path, formatterCallback); + .format(path, formatterCallback); } /** diff --git a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java index 1fee28778d..b391c7b740 100644 --- a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java @@ -123,14 +123,14 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) - .stream() - .flatMap(loader -> loader.get().getRuleProviders().stream()) - .collect(Collectors.toUnmodifiableSet()); + .stream() + .flatMap(loader -> loader.get().getRuleProviders().stream()) + .collect(Collectors.toUnmodifiableSet()); EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { diff --git a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java index 18057ba1d3..22333392c1 100644 --- a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java @@ -85,14 +85,14 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, + Path editorConfigPath, final Map userData, final Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) - .stream() - .flatMap(loader -> loader.get().getRuleProviders().stream()) - .collect(Collectors.toUnmodifiableSet()); + .stream() + .flatMap(loader -> loader.get().getRuleProviders().stream()) + .collect(Collectors.toUnmodifiableSet()); EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 64576d7e19..5e5e5fb445 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -21,5 +21,5 @@ public interface KtLintCompatAdapter { String format(String text, Path path, boolean isScript, Path editorConfigPath, Map userData, - Map editorConfigOverrideMap); + Map editorConfigOverrideMap); } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 32f9f4ef1f..8f3fde5731 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -50,7 +50,7 @@ public static FormatterStep create(String version, Provisioner provisioner) { } public static FormatterStep create(String version, Provisioner provisioner, - Map userData, Map editorConfigOverride) { + Map userData, Map editorConfigOverride) { return create(version, provisioner, false, null, userData, editorConfigOverride); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 997fe3b9d6..f2c3a29d75 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -77,7 +77,7 @@ public class KotlinFormatExtension { private Map editorConfigOverride; KotlinFormatExtension(String version, @Nullable FileSignature editorConfigPath, Map config, - Map editorConfigOverride) { + Map editorConfigOverride) { this.version = version; this.editorConfigPath = editorConfigPath; this.userData = config; From 6459aa89344d4de9111ee67f1670d504cb218548 Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Thu, 13 Jul 2023 10:23:23 +0200 Subject: [PATCH 0811/1120] Implement excludingByContent for Gradle extensions --- .../FilterByContentPatternFormatterStep.java | 10 +++-- .../com/diffplug/spotless/FormatterStep.java | 16 +++++++- .../gradle/spotless/FormatExtension.java | 17 ++++---- .../TargetExcludeIfContentContainsTest.java | 39 +++++++++++++++++-- 4 files changed, 66 insertions(+), 16 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java index d9a6fe4093..51935b07bd 100644 --- a/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -24,10 +24,13 @@ final class FilterByContentPatternFormatterStep extends DelegateFormatterStep { final Pattern contentPattern; + final boolean formatIfMatches; - FilterByContentPatternFormatterStep(FormatterStep delegateStep, String contentPattern) { + FilterByContentPatternFormatterStep(FormatterStep delegateStep, String contentPattern, + boolean formatIfMatches) { super(delegateStep); this.contentPattern = Pattern.compile(Objects.requireNonNull(contentPattern)); + this.formatIfMatches = formatIfMatches; } @Override @@ -35,7 +38,8 @@ final class FilterByContentPatternFormatterStep extends DelegateFormatterStep { Objects.requireNonNull(raw, "raw"); Objects.requireNonNull(file, "file"); Matcher matcher = contentPattern.matcher(raw); - if (matcher.find()) { + boolean found = matcher.find(); + if (formatIfMatches == found) { return delegateStep.format(raw, file); } else { return raw; diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index ce09f68450..85fbeaf953 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -54,7 +54,21 @@ public interface FormatterStep extends Serializable { * @return FormatterStep */ public default FormatterStep filterByContentPattern(String contentPattern) { - return new FilterByContentPatternFormatterStep(this, contentPattern); + return filterByContentPattern(contentPattern, true); + } + + /** + * Returns a new {@code FormatterStep} which, observing the value of {@code formatIfMatches}, + * will only apply, or not, its changes to files which pass the given filter. + * + * @param contentPattern + * java regular expression used to filter in or out files which content contain pattern + * @param formatIfMatches + * True to format only when {@code contentPattern} is found; false to format only when {@code contentPattern} is not found + * @return FormatterStep + */ + public default FormatterStep filterByContentPattern(String contentPattern, boolean formatIfMatches) { + return new FilterByContentPatternFormatterStep(this, contentPattern, formatIfMatches); } /** diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 7e2e755f5d..1a2daa1cb9 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -161,11 +161,9 @@ public void encoding(String charset) { /** The files to be formatted = (target - targetExclude). */ protected FileCollection target, targetExclude; - /** - * The values from which files will be excluded if their content contain at least one of the - * `targetExcludeIfContentContains`. - */ - protected List targetExcludeIfContentContains = new ArrayList<>(); + /** The value from which files will be excluded if their content contain it. */ + @Nullable + protected String targetExcludeIfContentContains = null; protected boolean isLicenseHeaderStep(FormatterStep formatterStep) { String formatterStepName = formatterStep.getName(); @@ -208,9 +206,9 @@ public void targetExclude(Object... targets) { this.targetExclude = parseTargetsIsExclude(targets, true); } - /** Excludes all files whose content contains at least one of the `values`. */ - public void targetExcludeIfContentContains(String... values) { - this.targetExcludeIfContentContains.addAll(List.of(values)); + /** Excludes all files whose content contains {@code value}. */ + public void targetExcludeIfContentContains(String value) { + this.targetExcludeIfContentContains = value; } private FileCollection parseTargetsIsExclude(Object[] targets, boolean isExclude) { @@ -900,6 +898,9 @@ protected void setupTask(SpotlessTask task) { } else { steps = this.steps; } + if (targetExcludeIfContentContains != null) { + steps.replaceAll(formatterStep -> formatterStep.filterByContentPattern(targetExcludeIfContentContains, false)); + } task.setSteps(steps); task.setLineEndingsPolicy(getLineEndings().createPolicy(getProject().getProjectDir(), () -> totalTarget)); spotless.getRegisterDependenciesTask().hookSubprojectTask(task); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java index 66dfc60f4c..76ef341ab9 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java @@ -29,7 +29,6 @@ void targetExcludeIfContentContainsWithOneValue() throws IOException { " target '**/*.md'", " targetExcludeIfContentContains '// Generated by Mr. Roboto'", " custom 'lowercase', { str -> str.toLowerCase() }", - " toggleOffOn()", " }", "}"); String content = "// Generated by Mr. Roboto, do not edit.\n" + @@ -51,6 +50,39 @@ void targetExcludeIfContentContainsWithOneValue() throws IOException { "g h i"); } + @Test + void targetExcludeIfContentContainsWithMultipleSteps() throws IOException { + setFile("build.gradle").toLines( + "plugins { id 'com.diffplug.spotless' }", + "spotless {", + " format 'toLower', {", + " target '**/*.md'", + " targetExcludeIfContentContains '// Generated by Mr. Roboto'", + " custom 'lowercase', { str -> str.toLowerCase() }", + " licenseHeader('" + "// My CopyRights header" + "', '--')", + " }", + "}"); + String generatedContent = "// Generated by Mr. Roboto, do not edit.\n" + + "--\n" + + "public final class MyMessage {}\n"; + setFile("test_generated.md").toContent(generatedContent); + String manualContent = "// Typo in License\n" + + "--\n" + + "public final class MyMessage {\n" + + "}"; + setFile("test_manual.md").toContent(manualContent); + gradleRunner().withArguments("spotlessApply").build(); + + // `test_generated` contains the excluding text so didn't change, including the header. + assertFile("test_generated.md").hasContent(generatedContent); + // `test_manual` does not, it changed. + assertFile("test_manual.md").hasContent( + "// My CopyRights header\n" + + "--\n" + + "public final class mymessage {\n" + + "}"); + } + @Test void targetExcludeIfContentContainsWithMultipleValues() throws IOException { setFile("build.gradle").toLines( @@ -58,9 +90,8 @@ void targetExcludeIfContentContainsWithMultipleValues() throws IOException { "spotless {", " format 'toLower', {", " target '**/*.md'", - " targetExcludeIfContentContains '// Generated by Mr. Roboto', '// Generated by Mrs. Call'", + " targetExcludeIfContentContains '// Generated by Mr. Roboto|// Generated by Mrs. Call'", " custom 'lowercase', { str -> str.toLowerCase() }", - " toggleOffOn()", " }", "}"); String robotoContent = "A B C\n" + @@ -101,7 +132,7 @@ void targetExcludeIfContentContainsWithMultipleValues() throws IOException { "// generated by k2000, do not edit.\n" + "d e f\n" + "g h i"); - // `test_manual` does not so it changed. + // `test_manual` does not, it changed. assertFile("test_manual.md").hasLines( "a b c", "d e f", From a12b7caf62a8c004cd380ecd4f445a1512c248cb Mon Sep 17 00:00:00 2001 From: David Gregory <2992938+DavidGregory084@users.noreply.github.com> Date: Thu, 13 Jul 2023 11:31:53 +0100 Subject: [PATCH 0812/1120] Add ApplyJsonPatchStep --- .gitignore | 3 + lib/build.gradle | 5 +- .../spotless/json/ApplyJsonPatchStep.java | 90 +++++++++++++++++++ .../json/ApplyJsonPatchFormatterFunc.java | 58 ++++++++++++ .../gradle/spotless/JsonExtension.java | 37 ++++++++ .../gradle/spotless/JsonExtensionTest.java | 40 +++++++++ .../spotless/maven/json/ApplyJsonPatch.java | 41 +++++++++ .../diffplug/spotless/maven/json/Json.java | 4 + .../spotless/maven/json/JsonTest.java | 19 ++++ .../json/patchObjectAfterReplaceString.json | 11 +++ .../patchObjectAfterReplaceWithObject.json | 13 +++ .../resources/json/patchObjectBefore.json | 11 +++ 12 files changed, 331 insertions(+), 1 deletion(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/json/ApplyJsonPatchStep.java create mode 100644 lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/json/ApplyJsonPatch.java create mode 100644 testlib/src/main/resources/json/patchObjectAfterReplaceString.json create mode 100644 testlib/src/main/resources/json/patchObjectAfterReplaceWithObject.json create mode 100644 testlib/src/main/resources/json/patchObjectBefore.json diff --git a/.gitignore b/.gitignore index 138bb77159..8a0bc11e97 100644 --- a/.gitignore +++ b/.gitignore @@ -124,3 +124,6 @@ nb-configuration.xml # MacOS jenv .java-version + +# VS Code +.vscode/ diff --git a/lib/build.gradle b/lib/build.gradle index a9d5181569..3f1ba0bb25 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -20,7 +20,8 @@ def NEEDS_GLUE = [ 'ktlint', 'palantirJavaFormat', 'scalafmt', - 'sortPom' + 'sortPom', + 'zjsonPatch', ] for (glue in NEEDS_GLUE) { sourceSets.register(glue) { @@ -112,6 +113,8 @@ dependencies { // sortPom sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.2.1' sortPomCompileOnly 'org.slf4j:slf4j-api:2.0.0' + // zjsonPatch + zjsonPatchCompileOnly 'com.flipkart.zjsonpatch:zjsonpatch:0.4.14' } // we'll hold the core lib to a high standard diff --git a/lib/src/main/java/com/diffplug/spotless/json/ApplyJsonPatchStep.java b/lib/src/main/java/com/diffplug/spotless/json/ApplyJsonPatchStep.java new file mode 100644 index 0000000000..84f39f5b23 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/json/ApplyJsonPatchStep.java @@ -0,0 +1,90 @@ +/* + * 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.json; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import java.util.Map; +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 ApplyJsonPatchStep { + // https://mvnrepository.com/artifact/com.flipkart.zjsonpatch/zjsonpatch + static final String MAVEN_COORDINATE = "com.flipkart.zjsonpatch:zjsonpatch"; + static final String DEFAULT_VERSION = "0.4.14"; + + private ApplyJsonPatchStep() {} + + public static FormatterStep create(String patchString, Provisioner provisioner) { + return create(DEFAULT_VERSION, patchString, provisioner); + } + + public static FormatterStep create(String zjsonPatchVersion, String patchString, Provisioner provisioner) { + Objects.requireNonNull(zjsonPatchVersion, "zjsonPatchVersion cannot be null"); + Objects.requireNonNull(patchString, "patchString cannot be null"); + Objects.requireNonNull(provisioner, "provisioner cannot be null"); + return FormatterStep.createLazy("apply-json-patch", () -> new State(zjsonPatchVersion, patchString, provisioner), State::toFormatter); + } + + public static FormatterStep create(List> patch, Provisioner provisioner) { + return create(DEFAULT_VERSION, patch, provisioner); + } + + public static FormatterStep create(String zjsonPatchVersion, List> patch, Provisioner provisioner) { + Objects.requireNonNull(zjsonPatchVersion, "zjsonPatchVersion cannot be null"); + Objects.requireNonNull(patch, "patch cannot be null"); + Objects.requireNonNull(provisioner, "provisioner cannot be null"); + return FormatterStep.createLazy("apply-json-patch", () -> new State(zjsonPatchVersion, patch, provisioner), State::toFormatter); + } + + static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + private final JarState jarState; + private final List> patch; + private final String patchString; + + private State(String zjsonPatchVersion, List> patch, Provisioner provisioner) throws IOException { + this.jarState = JarState.from(MAVEN_COORDINATE + ":" + zjsonPatchVersion, provisioner); + this.patch = patch; + this.patchString = null; + } + + private State(String zjsonPatchVersion, String patchString, Provisioner provisioner) throws IOException { + this.jarState = JarState.from(MAVEN_COORDINATE + ":" + zjsonPatchVersion, provisioner); + this.patch = null; + this.patchString = patchString; + } + + FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.json.ApplyJsonPatchFormatterFunc"); + if (this.patch != null) { + Constructor constructor = formatterFunc.getConstructor(List.class); + return (FormatterFunc) constructor.newInstance(patch); + } else { + Constructor constructor = formatterFunc.getConstructor(String.class); + return (FormatterFunc) constructor.newInstance(patchString); + } + } + } +} diff --git a/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java b/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java new file mode 100644 index 0000000000..42c14c9e2b --- /dev/null +++ b/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java @@ -0,0 +1,58 @@ +/* + * 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.json; + +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.zjsonpatch.JsonPatch; + +import com.diffplug.spotless.FormatterFunc; + +public class ApplyJsonPatchFormatterFunc implements FormatterFunc { + private final ObjectMapper objectMapper; + private final List> patch; + private final String patchString; + + public ApplyJsonPatchFormatterFunc(String patchString) { + this.objectMapper = new ObjectMapper(); + this.objectMapper.setDefaultPrettyPrinter(new DefaultPrettyPrinter()); + this.patch = null; + this.patchString = patchString; + } + + public ApplyJsonPatchFormatterFunc(List> patch) { + this.objectMapper = new ObjectMapper(); + this.objectMapper.setDefaultPrettyPrinter(new DefaultPrettyPrinter()); + this.patch = patch; + this.patchString = null; + } + + @Override + public String apply(String input) throws Exception { + var patchNode = this.patch == null + ? objectMapper.readTree(patchString) + : objectMapper.valueToTree(patch); + + var inputNode = objectMapper.readTree(input); + + var patchedNode = JsonPatch.apply(patchNode, inputNode); + + return objectMapper.writeValueAsString(patchedNode); + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 2fa567472f..5e587dbd9f 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -16,10 +16,13 @@ package com.diffplug.gradle.spotless; import java.util.Collections; +import java.util.List; +import java.util.Map; import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.ApplyJsonPatchStep; import com.diffplug.spotless.json.JacksonJsonConfig; import com.diffplug.spotless.json.JacksonJsonStep; import com.diffplug.spotless.json.JsonSimpleStep; @@ -28,6 +31,7 @@ public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; private static final String DEFAULT_GSON_VERSION = "2.10.1"; + private static final String DEFAULT_ZJSONPATCH_VERSION = "0.4.14"; static final String NAME = "json"; @Inject @@ -71,6 +75,14 @@ public RomeJson rome(String version) { return romeConfig; } + public ApplyJsonPatchConfig applyJsonPatch(List> patch) { + return new ApplyJsonPatchConfig(patch); + } + + public ApplyJsonPatchConfig applyJsonPatch(String zjsonPatchVersion, List> patch) { + return new ApplyJsonPatchConfig(zjsonPatchVersion, patch); + } + public class SimpleConfig { private int indent; @@ -191,4 +203,29 @@ protected RomeJson getThis() { return this; } } + + public class ApplyJsonPatchConfig { + private String zjsonPatchVersion; + private List> patch; + + public ApplyJsonPatchConfig(List> patch) { + this(DEFAULT_ZJSONPATCH_VERSION, patch); + } + + public ApplyJsonPatchConfig(String zjsonPatchVersion, List> patch) { + this.zjsonPatchVersion = zjsonPatchVersion; + this.patch = patch; + addStep(createStep()); + } + + public ApplyJsonPatchConfig version(String zjsonPatchVersion) { + this.zjsonPatchVersion = zjsonPatchVersion; + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return ApplyJsonPatchStep.create(zjsonPatchVersion, patch, provisioner()); + } + } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java index a878615eaa..ea1358ccee 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java @@ -156,4 +156,44 @@ void jacksonFormattingWithSortingByKeys() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("src/main/resources/example.json").sameAsResource("json/sortByKeysAfter_Jackson.json"); } + + @Test + void applyJsonPatchReplaceString() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'src/**/*.json'", + " applyJsonPatch([[op: 'replace', path: '/abc', value: 'ghi']])", + " gson()", + " }", + "}"); + setFile("src/main/resources/example.json").toResource("json/patchObjectBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/patchObjectAfterReplaceString.json"); + } + + @Test + void applyJsonPatchReplaceWithObject() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target 'src/**/*.json'", + " applyJsonPatch([[op: 'replace', path: '/abc', value: [def: 'ghi']]])", + " gson()", + " }", + "}"); + setFile("src/main/resources/example.json").toResource("json/patchObjectBefore.json"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.json").sameAsResource("json/patchObjectAfterReplaceWithObject.json"); + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/ApplyJsonPatch.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/ApplyJsonPatch.java new file mode 100644 index 0000000000..6e18ea9388 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/ApplyJsonPatch.java @@ -0,0 +1,41 @@ +/* + * 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.json; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.json.ApplyJsonPatchStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +/** + * A {@link FormatterStepFactory} implementation that corresponds to {@code ...} configuration element. + */ +public class ApplyJsonPatch implements FormatterStepFactory { + private static final String DEFAULT_ZJSONPATCH_VERSION = "0.4.14"; + + @Parameter + String zjsonPatchVersion = DEFAULT_ZJSONPATCH_VERSION; + + @Parameter + String patch; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + return ApplyJsonPatchStep.create(zjsonPatchVersion, patch, stepConfig.getProvisioner()); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index adbb2b7883..76a5c43221 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -53,4 +53,8 @@ public void addJackson(JacksonJson jackson) { public void addRome(RomeJson rome) { addStepFactory(rome); } + + public void addApplyJsonPatch(ApplyJsonPatch applyJsonPatch) { + addStepFactory(applyJsonPatch); + } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java index 1897cc764a..49becde33a 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java @@ -90,4 +90,23 @@ public void testFormatJson_WithJackson_sortByKeys_spaceAfterKeySeparator() throw assertFile("json_test.json").sameAsResource("json/sortByKeysAfter_Jackson_spaceAfterKeySeparator.json"); } + @Test + public void testFormatJson_ApplyJsonPatch_replaceString() throws Exception { + writePomWithJsonSteps("[{\"op\":\"replace\",\"path\":\"/abc\",\"value\":\"ghi\"}]"); + + setFile("json_test.json").toResource("json/patchObjectBefore.json"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("json_test.json").sameAsResource("json/patchObjectAfterReplaceString.json"); + } + + @Test + public void testFormatJson_ApplyJsonPatch_replaceWithObject() throws Exception { + writePomWithJsonSteps("[{\"op\":\"replace\",\"path\":\"/abc\",\"value\":{\"def\":\"ghi\"}}]"); + + setFile("json_test.json").toResource("json/patchObjectBefore.json"); + + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("json_test.json").sameAsResource("json/patchObjectAfterReplaceWithObject.json"); + } } diff --git a/testlib/src/main/resources/json/patchObjectAfterReplaceString.json b/testlib/src/main/resources/json/patchObjectAfterReplaceString.json new file mode 100644 index 0000000000..1da41d5ac2 --- /dev/null +++ b/testlib/src/main/resources/json/patchObjectAfterReplaceString.json @@ -0,0 +1,11 @@ +{ + "abc": "ghi", + "obj": { + "arr": [ + 1, + 2, + 3 + ], + "val": 5 + } +} diff --git a/testlib/src/main/resources/json/patchObjectAfterReplaceWithObject.json b/testlib/src/main/resources/json/patchObjectAfterReplaceWithObject.json new file mode 100644 index 0000000000..533691261c --- /dev/null +++ b/testlib/src/main/resources/json/patchObjectAfterReplaceWithObject.json @@ -0,0 +1,13 @@ +{ + "abc": { + "def": "ghi" + }, + "obj": { + "arr": [ + 1, + 2, + 3 + ], + "val": 5 + } +} diff --git a/testlib/src/main/resources/json/patchObjectBefore.json b/testlib/src/main/resources/json/patchObjectBefore.json new file mode 100644 index 0000000000..070dfc481e --- /dev/null +++ b/testlib/src/main/resources/json/patchObjectBefore.json @@ -0,0 +1,11 @@ +{ + "abc": "def", + "obj": { + "arr": [ + 1, + 2, + 3 + ], + "val": 5 + } +} From 7f9ed128d3ef15ed700f91db34b01f2effc78a55 Mon Sep 17 00:00:00 2001 From: David Gregory <2992938+DavidGregory084@users.noreply.github.com> Date: Thu, 13 Jul 2023 12:05:23 +0100 Subject: [PATCH 0813/1120] Remove unnecessary configuration of ObjectMapper's pretty printer in ApplyJsonPatchFormatterFunc --- .../spotless/glue/json/ApplyJsonPatchFormatterFunc.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java b/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java index 42c14c9e2b..1ba6084a67 100644 --- a/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java +++ b/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.Map; -import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.zjsonpatch.JsonPatch; @@ -31,14 +30,12 @@ public class ApplyJsonPatchFormatterFunc implements FormatterFunc { public ApplyJsonPatchFormatterFunc(String patchString) { this.objectMapper = new ObjectMapper(); - this.objectMapper.setDefaultPrettyPrinter(new DefaultPrettyPrinter()); this.patch = null; this.patchString = patchString; } public ApplyJsonPatchFormatterFunc(List> patch) { this.objectMapper = new ObjectMapper(); - this.objectMapper.setDefaultPrettyPrinter(new DefaultPrettyPrinter()); this.patch = patch; this.patchString = null; } From 85445a9315b6a33ab1afe23328ace82844160c4c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 14 Jul 2023 09:37:43 -0700 Subject: [PATCH 0814/1120] Add regex method, and escape string for the standard method. --- .../gradle/spotless/FormatExtension.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index d7f4d605dc..a4b3d17ad8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -31,6 +31,7 @@ import java.util.TreeMap; import java.util.function.Consumer; import java.util.function.Function; +import java.util.regex.Pattern; import javax.annotation.Nullable; import javax.inject.Inject; @@ -207,9 +208,22 @@ public void targetExclude(Object... targets) { this.targetExclude = parseTargetsIsExclude(targets, true); } - /** Excludes all files whose content contains {@code value}. */ - public void targetExcludeIfContentContains(String value) { - this.targetExcludeIfContentContains = value; + /** + * Excludes all files whose content contains {@code value}. + * + * When this method is called multiple times, only the last call has any effect. + */ + public void targetExcludeIfContentContains(String string) { + targetExcludeIfContentContainsRegex(Pattern.quote(string)); + } + + /** + * Excludes all files whose content can find the given regex. + * + * When this method is called multiple times, only the last call has any effect. + */ + public void targetExcludeIfContentContainsRegex(String regex) { + this.targetExcludeIfContentContains = regex; } private FileCollection parseTargetsIsExclude(Object[] targets, boolean isExclude) { From 050fff41b9b708e3f950ef542966a7fb4498ddef Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 14 Jul 2023 09:56:14 -0700 Subject: [PATCH 0815/1120] Make boolean logic more readable. --- .../java/com/diffplug/spotless/Filter.java | 21 +++++++++++++++++++ .../FilterByContentPatternFormatterStep.java | 9 ++++---- .../com/diffplug/spotless/FormatterStep.java | 11 +++++----- .../spotless/generic/LicenseHeaderStep.java | 3 ++- .../gradle/spotless/FormatExtension.java | 3 ++- 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 lib/src/main/java/com/diffplug/spotless/Filter.java diff --git a/lib/src/main/java/com/diffplug/spotless/Filter.java b/lib/src/main/java/com/diffplug/spotless/Filter.java new file mode 100644 index 0000000000..c5367766c6 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/Filter.java @@ -0,0 +1,21 @@ +/* + * 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; + +/** Enum to make boolean logic more readable. */ +public enum Filter { + INCLUDE, EXCLUDE +} diff --git a/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java index 51935b07bd..d6f3ac377c 100644 --- a/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java @@ -24,13 +24,13 @@ final class FilterByContentPatternFormatterStep extends DelegateFormatterStep { final Pattern contentPattern; - final boolean formatIfMatches; + final Filter includeOrExclude; FilterByContentPatternFormatterStep(FormatterStep delegateStep, String contentPattern, - boolean formatIfMatches) { + Filter includeOrExclude) { super(delegateStep); this.contentPattern = Pattern.compile(Objects.requireNonNull(contentPattern)); - this.formatIfMatches = formatIfMatches; + this.includeOrExclude = includeOrExclude; } @Override @@ -38,8 +38,7 @@ final class FilterByContentPatternFormatterStep extends DelegateFormatterStep { Objects.requireNonNull(raw, "raw"); Objects.requireNonNull(file, "file"); Matcher matcher = contentPattern.matcher(raw); - boolean found = matcher.find(); - if (formatIfMatches == found) { + if (matcher.find() == (includeOrExclude == Filter.INCLUDE)) { return delegateStep.format(raw, file); } else { return raw; diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index 85fbeaf953..38f5872ef6 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -53,8 +53,9 @@ public interface FormatterStep extends Serializable { * java regular expression used to filter out files which content doesn't contain pattern * @return FormatterStep */ + @Deprecated public default FormatterStep filterByContentPattern(String contentPattern) { - return filterByContentPattern(contentPattern, true); + return filterByContent(contentPattern, Filter.INCLUDE); } /** @@ -63,12 +64,12 @@ public default FormatterStep filterByContentPattern(String contentPattern) { * * @param contentPattern * java regular expression used to filter in or out files which content contain pattern - * @param formatIfMatches - * True to format only when {@code contentPattern} is found; false to format only when {@code contentPattern} is not found + * @param includeOrExclude + * determines if matches are included or excluded * @return FormatterStep */ - public default FormatterStep filterByContentPattern(String contentPattern, boolean formatIfMatches) { - return new FilterByContentPatternFormatterStep(this, contentPattern, formatIfMatches); + public default FormatterStep filterByContent(String contentPattern, Filter includeOrExclude) { + return new FilterByContentPatternFormatterStep(this, contentPattern, includeOrExclude); } /** diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 073af855d3..72cc166965 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory; import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.Filter; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.LineEnding; @@ -150,7 +151,7 @@ public FormatterStep build() { return formatterStep; } - return formatterStep.filterByContentPattern(contentPattern); + return formatterStep.filterByContent(contentPattern, Filter.INCLUDE); } private String sanitizeName(@Nullable String name) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index a4b3d17ad8..b873829577 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -45,6 +45,7 @@ import org.gradle.api.tasks.TaskProvider; import com.diffplug.common.base.Preconditions; +import com.diffplug.spotless.Filter; import com.diffplug.spotless.FormatExceptionPolicyStrict; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; @@ -921,7 +922,7 @@ protected void setupTask(SpotlessTask task) { steps = this.steps; } if (targetExcludeIfContentContains != null) { - steps.replaceAll(formatterStep -> formatterStep.filterByContentPattern(targetExcludeIfContentContains, false)); + steps.replaceAll(formatterStep -> formatterStep.filterByContent(targetExcludeIfContentContains, Filter.EXCLUDE)); } task.setSteps(steps); task.setLineEndingsPolicy(getLineEndings().createPolicy(getProject().getProjectDir(), () -> totalTarget)); From 4763002f2ddb67c47c026b2dfbcc06f606787924 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 14 Jul 2023 10:00:23 -0700 Subject: [PATCH 0816/1120] Add `include/exclude` as part of the equality logic of `FilterByContentPatternFormatterStep`. --- .../FilterByContentPatternFormatterStep.java | 12 ++++++------ .../java/com/diffplug/spotless/FormatterStep.java | 6 +++--- .../diffplug/spotless/generic/LicenseHeaderStep.java | 2 +- .../diffplug/gradle/spotless/FormatExtension.java | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java index d6f3ac377c..d858e9102f 100644 --- a/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java @@ -23,14 +23,13 @@ import javax.annotation.Nullable; final class FilterByContentPatternFormatterStep extends DelegateFormatterStep { - final Pattern contentPattern; final Filter includeOrExclude; + final Pattern contentPattern; - FilterByContentPatternFormatterStep(FormatterStep delegateStep, String contentPattern, - Filter includeOrExclude) { + FilterByContentPatternFormatterStep(FormatterStep delegateStep, Filter includeOrExclude, String contentPattern) { super(delegateStep); - this.contentPattern = Pattern.compile(Objects.requireNonNull(contentPattern)); this.includeOrExclude = includeOrExclude; + this.contentPattern = Pattern.compile(Objects.requireNonNull(contentPattern)); } @Override @@ -55,13 +54,14 @@ public boolean equals(Object o) { } FilterByContentPatternFormatterStep that = (FilterByContentPatternFormatterStep) o; return Objects.equals(delegateStep, that.delegateStep) && + Objects.equals(includeOrExclude, that.includeOrExclude) && Objects.equals(contentPattern.pattern(), that.contentPattern.pattern()); } @Override public int hashCode() { - return Objects.hash(delegateStep, contentPattern.pattern()); + return Objects.hash(delegateStep, includeOrExclude, contentPattern.pattern()); } - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; } diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index 38f5872ef6..cc35bddb76 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -55,7 +55,7 @@ public interface FormatterStep extends Serializable { */ @Deprecated public default FormatterStep filterByContentPattern(String contentPattern) { - return filterByContent(contentPattern, Filter.INCLUDE); + return filterByContent(Filter.INCLUDE, contentPattern); } /** @@ -68,8 +68,8 @@ public default FormatterStep filterByContentPattern(String contentPattern) { * determines if matches are included or excluded * @return FormatterStep */ - public default FormatterStep filterByContent(String contentPattern, Filter includeOrExclude) { - return new FilterByContentPatternFormatterStep(this, contentPattern, includeOrExclude); + public default FormatterStep filterByContent(Filter includeOrExclude, String contentPattern) { + return new FilterByContentPatternFormatterStep(this, includeOrExclude, contentPattern); } /** diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index 72cc166965..b41768f2ba 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -151,7 +151,7 @@ public FormatterStep build() { return formatterStep; } - return formatterStep.filterByContent(contentPattern, Filter.INCLUDE); + return formatterStep.filterByContent(Filter.INCLUDE, contentPattern); } private String sanitizeName(@Nullable String name) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index b873829577..44d08e685d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -166,7 +166,7 @@ public void encoding(String charset) { /** The value from which files will be excluded if their content contain it. */ @Nullable - protected String targetExcludeIfContentContains = null; + protected String targetExcludeContentPattern = null; protected boolean isLicenseHeaderStep(FormatterStep formatterStep) { String formatterStepName = formatterStep.getName(); @@ -210,7 +210,7 @@ public void targetExclude(Object... targets) { } /** - * Excludes all files whose content contains {@code value}. + * Excludes all files whose content contains {@code string}. * * When this method is called multiple times, only the last call has any effect. */ @@ -219,12 +219,12 @@ public void targetExcludeIfContentContains(String string) { } /** - * Excludes all files whose content can find the given regex. + * Excludes all files whose content contains the given regex. * * When this method is called multiple times, only the last call has any effect. */ public void targetExcludeIfContentContainsRegex(String regex) { - this.targetExcludeIfContentContains = regex; + this.targetExcludeContentPattern = regex; } private FileCollection parseTargetsIsExclude(Object[] targets, boolean isExclude) { @@ -921,8 +921,8 @@ protected void setupTask(SpotlessTask task) { } else { steps = this.steps; } - if (targetExcludeIfContentContains != null) { - steps.replaceAll(formatterStep -> formatterStep.filterByContent(targetExcludeIfContentContains, Filter.EXCLUDE)); + if (targetExcludeContentPattern != null) { + steps.replaceAll(formatterStep -> formatterStep.filterByContent(Filter.EXCLUDE, targetExcludeContentPattern)); } task.setSteps(steps); task.setLineEndingsPolicy(getLineEndings().createPolicy(getProject().getProjectDir(), () -> totalTarget)); From 1d8fda9e8bae449ac157aff90f1cf6948e6eab12 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 14 Jul 2023 10:07:08 -0700 Subject: [PATCH 0817/1120] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2c9a855114..47edb7c365 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* `enum Filter { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#1749](https://github.com/diffplug/spotless/pull/1749)) * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`.([#1741](https://github.com/diffplug/spotless/issues/1741)) * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index cfdf688927..31c307d529 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Add target option `targetExcludeIfContentContains` to exclude files by text they contain. +* Add target option `targetExcludeIfContentContains` and `targetExcludeIfContentContainsRegex` to exclude files based on their text content. ([#1749](https://github.com/diffplug/spotless/pull/1749)) * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741)) * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. From 196b9a6cfd5c026bbf539344abbb2ae82500b34b Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 14 Jul 2023 10:14:02 -0700 Subject: [PATCH 0818/1120] Fix javadoc param order. --- lib/src/main/java/com/diffplug/spotless/FormatterStep.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index cc35bddb76..d33ab7dde2 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -62,10 +62,10 @@ public default FormatterStep filterByContentPattern(String contentPattern) { * Returns a new {@code FormatterStep} which, observing the value of {@code formatIfMatches}, * will only apply, or not, its changes to files which pass the given filter. * - * @param contentPattern - * java regular expression used to filter in or out files which content contain pattern * @param includeOrExclude * determines if matches are included or excluded + * @param contentPattern + * java regular expression used to filter in or out files which content contain pattern * @return FormatterStep */ public default FormatterStep filterByContent(Filter includeOrExclude, String contentPattern) { From 306491883fe3c11511756e95e91b08cb431ca7d2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 14 Jul 2023 10:16:09 -0700 Subject: [PATCH 0819/1120] Rename `Filter` to `OnMatch`. --- CHANGES.md | 2 +- .../FilterByContentPatternFormatterStep.java | 12 ++++++------ .../java/com/diffplug/spotless/FormatterStep.java | 8 ++++---- .../diffplug/spotless/{Filter.java => OnMatch.java} | 2 +- .../diffplug/spotless/generic/LicenseHeaderStep.java | 4 ++-- .../diffplug/gradle/spotless/FormatExtension.java | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) rename lib/src/main/java/com/diffplug/spotless/{Filter.java => OnMatch.java} (96%) diff --git a/CHANGES.md b/CHANGES.md index 47edb7c365..0faf333268 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* `enum Filter { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#1749](https://github.com/diffplug/spotless/pull/1749)) +* `enum OnMatch { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#1749](https://github.com/diffplug/spotless/pull/1749)) * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`.([#1741](https://github.com/diffplug/spotless/issues/1741)) * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. diff --git a/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java index d858e9102f..4cc336e101 100644 --- a/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java @@ -23,12 +23,12 @@ import javax.annotation.Nullable; final class FilterByContentPatternFormatterStep extends DelegateFormatterStep { - final Filter includeOrExclude; + final OnMatch onMatch; final Pattern contentPattern; - FilterByContentPatternFormatterStep(FormatterStep delegateStep, Filter includeOrExclude, String contentPattern) { + FilterByContentPatternFormatterStep(FormatterStep delegateStep, OnMatch onMatch, String contentPattern) { super(delegateStep); - this.includeOrExclude = includeOrExclude; + this.onMatch = onMatch; this.contentPattern = Pattern.compile(Objects.requireNonNull(contentPattern)); } @@ -37,7 +37,7 @@ final class FilterByContentPatternFormatterStep extends DelegateFormatterStep { Objects.requireNonNull(raw, "raw"); Objects.requireNonNull(file, "file"); Matcher matcher = contentPattern.matcher(raw); - if (matcher.find() == (includeOrExclude == Filter.INCLUDE)) { + if (matcher.find() == (onMatch == OnMatch.INCLUDE)) { return delegateStep.format(raw, file); } else { return raw; @@ -54,13 +54,13 @@ public boolean equals(Object o) { } FilterByContentPatternFormatterStep that = (FilterByContentPatternFormatterStep) o; return Objects.equals(delegateStep, that.delegateStep) && - Objects.equals(includeOrExclude, that.includeOrExclude) && + Objects.equals(onMatch, that.onMatch) && Objects.equals(contentPattern.pattern(), that.contentPattern.pattern()); } @Override public int hashCode() { - return Objects.hash(delegateStep, includeOrExclude, contentPattern.pattern()); + return Objects.hash(delegateStep, onMatch, contentPattern.pattern()); } private static final long serialVersionUID = 2L; diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index d33ab7dde2..5f6ec168d4 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -55,21 +55,21 @@ public interface FormatterStep extends Serializable { */ @Deprecated public default FormatterStep filterByContentPattern(String contentPattern) { - return filterByContent(Filter.INCLUDE, contentPattern); + return filterByContent(OnMatch.INCLUDE, contentPattern); } /** * Returns a new {@code FormatterStep} which, observing the value of {@code formatIfMatches}, * will only apply, or not, its changes to files which pass the given filter. * - * @param includeOrExclude + * @param onMatch * determines if matches are included or excluded * @param contentPattern * java regular expression used to filter in or out files which content contain pattern * @return FormatterStep */ - public default FormatterStep filterByContent(Filter includeOrExclude, String contentPattern) { - return new FilterByContentPatternFormatterStep(this, includeOrExclude, contentPattern); + public default FormatterStep filterByContent(OnMatch onMatch, String contentPattern) { + return new FilterByContentPatternFormatterStep(this, onMatch, contentPattern); } /** diff --git a/lib/src/main/java/com/diffplug/spotless/Filter.java b/lib/src/main/java/com/diffplug/spotless/OnMatch.java similarity index 96% rename from lib/src/main/java/com/diffplug/spotless/Filter.java rename to lib/src/main/java/com/diffplug/spotless/OnMatch.java index c5367766c6..098fb28f13 100644 --- a/lib/src/main/java/com/diffplug/spotless/Filter.java +++ b/lib/src/main/java/com/diffplug/spotless/OnMatch.java @@ -16,6 +16,6 @@ package com.diffplug.spotless; /** Enum to make boolean logic more readable. */ -public enum Filter { +public enum OnMatch { INCLUDE, EXCLUDE } diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index b41768f2ba..cd6b9a6525 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory; import com.diffplug.spotless.FileSignature; -import com.diffplug.spotless.Filter; +import com.diffplug.spotless.OnMatch; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.LineEnding; @@ -151,7 +151,7 @@ public FormatterStep build() { return formatterStep; } - return formatterStep.filterByContent(Filter.INCLUDE, contentPattern); + return formatterStep.filterByContent(OnMatch.INCLUDE, contentPattern); } private String sanitizeName(@Nullable String name) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 44d08e685d..3275ee91e8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -45,7 +45,7 @@ import org.gradle.api.tasks.TaskProvider; import com.diffplug.common.base.Preconditions; -import com.diffplug.spotless.Filter; +import com.diffplug.spotless.OnMatch; import com.diffplug.spotless.FormatExceptionPolicyStrict; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; @@ -922,7 +922,7 @@ protected void setupTask(SpotlessTask task) { steps = this.steps; } if (targetExcludeContentPattern != null) { - steps.replaceAll(formatterStep -> formatterStep.filterByContent(Filter.EXCLUDE, targetExcludeContentPattern)); + steps.replaceAll(formatterStep -> formatterStep.filterByContent(OnMatch.EXCLUDE, targetExcludeContentPattern)); } task.setSteps(steps); task.setLineEndingsPolicy(getLineEndings().createPolicy(getProject().getProjectDir(), () -> totalTarget)); From b24e435cc405b6a109844bf2ab5fbb625e63b965 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 14 Jul 2023 10:40:09 -0700 Subject: [PATCH 0820/1120] spotlessApply --- .../java/com/diffplug/spotless/generic/LicenseHeaderStep.java | 2 +- .../main/java/com/diffplug/gradle/spotless/FormatExtension.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java index cd6b9a6525..6d04c25962 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/LicenseHeaderStep.java @@ -35,10 +35,10 @@ import org.slf4j.LoggerFactory; import com.diffplug.spotless.FileSignature; -import com.diffplug.spotless.OnMatch; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.LineEnding; +import com.diffplug.spotless.OnMatch; import com.diffplug.spotless.SerializableFileFilter; import com.diffplug.spotless.ThrowingEx; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 3275ee91e8..e28ec13dcd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -45,12 +45,12 @@ import org.gradle.api.tasks.TaskProvider; import com.diffplug.common.base.Preconditions; -import com.diffplug.spotless.OnMatch; import com.diffplug.spotless.FormatExceptionPolicyStrict; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.LazyForwardingEquality; import com.diffplug.spotless.LineEnding; +import com.diffplug.spotless.OnMatch; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.cpp.ClangFormatStep; import com.diffplug.spotless.extra.EclipseBasedStepBuilder; From c63eec46bcb28dc37220af6d03aaaf84132ee4a6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 14 Jul 2023 10:54:46 -0700 Subject: [PATCH 0821/1120] Add regex test. --- .../gradle/spotless/TargetExcludeIfContentContainsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java index 76ef341ab9..f1a2cf4298 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java @@ -84,13 +84,13 @@ void targetExcludeIfContentContainsWithMultipleSteps() throws IOException { } @Test - void targetExcludeIfContentContainsWithMultipleValues() throws IOException { + void targetExcludeIfContentContainsRegex() throws IOException { setFile("build.gradle").toLines( "plugins { id 'com.diffplug.spotless' }", "spotless {", " format 'toLower', {", " target '**/*.md'", - " targetExcludeIfContentContains '// Generated by Mr. Roboto|// Generated by Mrs. Call'", + " targetExcludeIfContentContainsRegex '// Generated by Mr. Roboto|// Generated by Mrs. Call'", " custom 'lowercase', { str -> str.toLowerCase() }", " }", "}"); From 9b6da79f762fbd86ff8332c7d266d4f70d3934c9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 14 Jul 2023 11:21:47 -0700 Subject: [PATCH 0822/1120] Bump changelogs. --- CHANGES.md | 10 +++++----- plugin-gradle/CHANGES.md | 8 +++++--- plugin-maven/CHANGES.md | 7 +++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0faf333268..6484eadf77 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,13 +12,13 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * `enum OnMatch { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#1749](https://github.com/diffplug/spotless/pull/1749)) -* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`.([#1741](https://github.com/diffplug/spotless/issues/1741)) - * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. - * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. -### Changes -* Bump default `cleanthat` version to latest `2.13` -> `2.16`. ([#1725](https://github.com/diffplug/spotless/pull/1725)) ### Fixed * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728)) +### Changes +* Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) +* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741)) + * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. + * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. ## [2.39.0] - 2023-05-24 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 31c307d529..b3b700691a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,9 +5,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Add target option `targetExcludeIfContentContains` and `targetExcludeIfContentContainsRegex` to exclude files based on their text content. ([#1749](https://github.com/diffplug/spotless/pull/1749)) -* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741)) - * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. - * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. * Add an overload for `FormatExtension.addStep` which provides access to the `FormatExtension`'s `Provisioner`, enabling custom steps to make use of third-party dependencies. ### Fixed * Correctly support the syntax @@ -18,6 +15,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( } } ``` +### Changes +* Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) +* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741)) + * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. + * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. ## [6.19.0] - 2023-05-24 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index db7fff9851..231cee0edb 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,10 +5,13 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support pass skip (`-Dspotless.skip=true`) from command-line. ([#1729](https://github.com/diffplug/spotless/pull/1729)) -* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`.([#1741](https://github.com/diffplug/spotless/issues/1741)) - * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. ### Fixed * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728)) +### Changes +* Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734)) +* Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741)) + * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time. + * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property. ## [2.37.0] - 2023-05-24 ### Added From d832ca94a56da4445f3b278bfb18b61b785e5d20 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 14 Jul 2023 11:57:37 -0700 Subject: [PATCH 0823/1120] Disable failing test (maven & gradle) `useEslintXoStandardRules` (#1756) --- .../com/diffplug/gradle/spotless/TypescriptExtensionTest.java | 2 ++ .../spotless/maven/typescript/TypescriptFormatStepTest.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java index 9b4ec8372e..eaf2729296 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TypescriptExtensionTest.java @@ -17,6 +17,7 @@ import java.io.IOException; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.spotless.npm.EslintFormatterStep; @@ -169,6 +170,7 @@ void useEslint() throws IOException { } @Test + @Disabled("https://github.com/diffplug/spotless/issues/1756") void useEslintXoStandardRules() throws IOException { setFile(".eslintrc.js").toResource("npm/eslint/typescript/styleguide/xo/.eslintrc.js"); setFile("tsconfig.json").toResource("npm/eslint/typescript/styleguide/xo/tsconfig.json"); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java index a09111d30d..911cfad201 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java @@ -19,6 +19,7 @@ import java.io.IOException; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.diffplug.spotless.ProcessRunner; @@ -210,6 +211,7 @@ void eslintStyleguideStandardWithTypescript() throws Exception { } @Test + @Disabled("https://github.com/diffplug/spotless/issues/1756") void eslintStyleguideXo() throws Exception { writePomWithTypescriptSteps( TEST_FILE_PATH, From 0e3be7dc7eec2f967adc709f1834955296df6be8 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 14 Jul 2023 20:37:10 -0400 Subject: [PATCH 0824/1120] update link --- plugin-gradle/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index ec97352749..afbb91ef4f 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -475,7 +475,7 @@ spotless { } ``` -When used in conjunction with the [buf-gradle-plugin](https://github.com/andrewparmet/buf-gradle-plugin), the `buf` executable can be resolved from its `bufTool` configuration: +When used in conjunction with the [buf-gradle-plugin](https://github.com/bufbuild/buf-gradle-plugin), the `buf` executable can be resolved from its `bufTool` configuration: ```gradle spotless { From 3c1bb4c186021ba9a35dc893622cf93a9f76ab65 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 14 Jul 2023 20:37:31 -0400 Subject: [PATCH 0825/1120] update link --- .../java/com/diffplug/gradle/spotless/ProtobufExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index 283fe21c58..f0d5a0245c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -70,7 +70,7 @@ public class BufFormatExtension { } /** - * When used in conjunction with the {@code buf-gradle-plugin}, + * When used in conjunction with the {@code buf-gradle-plugin}, * the {@code buf} executable can be resolved from its {@code bufTool} configuration: * *
    
    From 3d2d2b86adee71213521d8953b7e4b0e05ed6fce Mon Sep 17 00:00:00 2001
    From: Andrew Parmet 
    Date: Sat, 15 Jul 2023 12:34:53 -0400
    Subject: [PATCH 0826/1120] update default version
    
    ---
     lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    index 601a47f193..28058ffd4f 100644
    --- a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    @@ -38,7 +38,7 @@ public static String name() {
     	}
     
     	public static String defaultVersion() {
    -		return "1.4.0";
    +		return "1.24.0";
     	}
     
     	private final String version;
    
    From 6e7556f527e8c4bedaa82367c6f24164d91722d5 Mon Sep 17 00:00:00 2001
    From: Ned Twigg 
    Date: Sat, 15 Jul 2023 19:32:31 -0700
    Subject: [PATCH 0827/1120] spotlessApply
    
    ---
     lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java   | 2 +-
     .../java/com/diffplug/spotless/protobuf/ProtobufConstants.java  | 2 +-
     plugin-gradle/README.md                                         | 2 +-
     .../java/com/diffplug/gradle/spotless/ProtobufExtension.java    | 2 +-
     .../java/com/diffplug/gradle/spotless/SpotlessExtension.java    | 2 +-
     .../java/com/diffplug/gradle/spotless/BufIntegrationTest.java   | 2 +-
     testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java    | 2 +-
     .../test/java/com/diffplug/spotless/protobuf/BufStepTest.java   | 2 +-
     8 files changed, 8 insertions(+), 8 deletions(-)
    
    diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    index 28058ffd4f..c9b9efa543 100644
    --- a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2022 DiffPlug
    + * Copyright 2022-2023 DiffPlug
      *
      * Licensed under the Apache License, Version 2.0 (the "License");
      * you may not use this file except in compliance with the License.
    diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java b/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java
    index b24df7cc38..cd91e2671c 100644
    --- a/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java
    +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2022 DiffPlug
    + * Copyright 2022-2023 DiffPlug
      *
      * Licensed under the Apache License, Version 2.0 (the "License");
      * you may not use this file except in compliance with the License.
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 716de842aa..efec76a048 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -522,7 +522,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe')
     
     ### buf
     
    -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java)
    +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java)
     
     ```gradle
     spotless {
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
    index f0d5a0245c..77e4fbc7c7 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2022 DiffPlug
    + * Copyright 2022-2023 DiffPlug
      *
      * Licensed under the Apache License, Version 2.0 (the "License");
      * you may not use this file except in compliance with the License.
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java
    index 2e6bf0e9b7..c3cf5123c0 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java
    @@ -197,7 +197,7 @@ public void json(Action closure) {
     	public void protobuf(Action closure) {
     		requireNonNull(closure);
     		format(ProtobufExtension.NAME, ProtobufExtension.class, closure);
    -  }
    +	}
     
     	/** Configures the special YAML-specific extension. */
     	public void yaml(Action closure) {
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java
    index ba08c51838..b91512c7ed 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2022 DiffPlug
    + * Copyright 2022-2023 DiffPlug
      *
      * Licensed under the Apache License, Version 2.0 (the "License");
      * you may not use this file except in compliance with the License.
    diff --git a/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java
    index 490218ef7b..90f32ec6c3 100644
    --- a/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java
    +++ b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2022 DiffPlug
    + * Copyright 2022-2023 DiffPlug
      *
      * Licensed under the Apache License, Version 2.0 (the "License");
      * you may not use this file except in compliance with the License.
    diff --git a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
    index 0cd72129c6..9b5fa2fcf5 100644
    --- a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
    +++ b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2022 DiffPlug
    + * Copyright 2022-2023 DiffPlug
      *
      * Licensed under the Apache License, Version 2.0 (the "License");
      * you may not use this file except in compliance with the License.
    
    From 0943a81bec7b3327b9b3e706d928af00cf49b4ed Mon Sep 17 00:00:00 2001
    From: Ned Twigg 
    Date: Sat, 15 Jul 2023 19:47:21 -0700
    Subject: [PATCH 0828/1120] Fix BufStepTest for the changes we've had in test
     infrastructure.
    
    ---
     .../java/com/diffplug/spotless/protobuf/BufStepTest.java | 9 ++++-----
     1 file changed, 4 insertions(+), 5 deletions(-)
    
    diff --git a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
    index 9b5fa2fcf5..ce22eb5ed2 100644
    --- a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
    +++ b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
    @@ -15,19 +15,18 @@
      */
     package com.diffplug.spotless.protobuf;
     
    -import java.io.File;
    -
     import org.junit.jupiter.api.Test;
     
    +import com.diffplug.spotless.ResourceHarness;
     import com.diffplug.spotless.StepHarnessWithFile;
     import com.diffplug.spotless.tag.BufTest;
     
     @BufTest
    -class BufStepTest {
    +class BufStepTest extends ResourceHarness {
     	@Test
     	void test() throws Exception {
    -		try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(BufStep.withVersion(BufStep.defaultVersion()).create())) {
    -			harness.testResource(new File("src/main/resources/protobuf/buf/buf.proto"), "protobuf/buf/buf.proto", "protobuf/buf/buf.proto.clean");
    +		try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(this, BufStep.withVersion(BufStep.defaultVersion()).create())) {
    +			harness.testResource("protobuf/buf/buf.proto", "protobuf/buf/buf.proto.clean");
     		}
     	}
     }
    
    From 0fc9036455f1b5090e484c3f7b34e69bdb86c80d Mon Sep 17 00:00:00 2001
    From: Ned Twigg 
    Date: Sat, 15 Jul 2023 23:26:40 -0700
    Subject: [PATCH 0829/1120] Add warnings that buf must be the first step.
    
    ---
     plugin-gradle/README.md                                        | 2 ++
     .../java/com/diffplug/gradle/spotless/ProtobufExtension.java   | 3 +++
     2 files changed, 5 insertions(+)
    
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index efec76a048..55b6e98a30 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -524,6 +524,8 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe')
     
     `com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java)
     
    +**WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem.
    +
     ```gradle
     spotless {
       protobuf {
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
    index 77e4fbc7c7..7b0a6bb30a 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
    @@ -66,6 +66,9 @@ public class BufFormatExtension {
     
     		BufFormatExtension(String version) {
     			this.step = BufStep.withVersion(version);
    +			if (!steps.isEmpty()) {
    +				throw new IllegalArgumentException("buf() must be the first step, move other steps after it. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem.");
    +			}
     			addStep(createStep());
     		}
     
    
    From 7be3ce04ad22517ad741c17cc02ba68a2fb5df9b Mon Sep 17 00:00:00 2001
    From: runner
     
    Date: Mon, 17 Jul 2023 22:07:27 +0000
    Subject: [PATCH 0830/1120] Published lib/2.40.0
    
    ---
     CHANGES.md | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 9c37d36604..cc6dcd7331 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -10,6 +10,8 @@ This document is intended for Spotless developers.
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    +
    +## [2.40.0] - 2023-07-17
     ### Added
     * Added support for Protobuf formatting based on [Buf](https://buf.build/). (#1208)
     * `enum OnMatch { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#1749](https://github.com/diffplug/spotless/pull/1749))
    
    From 654b093663701ef7dc7f28c93567e4d943683d39 Mon Sep 17 00:00:00 2001
    From: runner
     
    Date: Mon, 17 Jul 2023 22:08:40 +0000
    Subject: [PATCH 0831/1120] Published gradle/6.20.0
    
    ---
     plugin-gradle/CHANGES.md |  2 ++
     plugin-gradle/README.md  | 54 ++++++++++++++++++++--------------------
     2 files changed, 29 insertions(+), 27 deletions(-)
    
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 33bd1ede30..6d8bee7169 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -3,6 +3,8 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
     
     ## [Unreleased]
    +
    +## [6.20.0] - 2023-07-17
     ### Added
     * Add target option `targetExcludeIfContentContains` and `targetExcludeIfContentContainsRegex` to exclude files based on their text content. ([#1749](https://github.com/diffplug/spotless/pull/1749))
     * Add support for Protobuf formatting based on [Buf](https://buf.build/) ([#1208](https://github.com/diffplug/spotless/pull/1208)).
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 55b6e98a30..e04697766a 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -14,9 +14,9 @@ output = [
       ].join('\n');
     -->
     [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless)
    -[![Changelog](https://img.shields.io/badge/changelog-6.19.0-blue.svg)](CHANGES.md)
    +[![Changelog](https://img.shields.io/badge/changelog-6.20.0-blue.svg)](CHANGES.md)
     [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22)
    -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/index.html)
    +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/index.html)
     
     [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle)
     [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle)
    @@ -127,10 +127,10 @@ spotless {
     ```
     
     Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has:
    -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-)
    -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc.
    +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-)
    +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc.
     
    -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below.
    +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below.
     
     ### Requirements
     
    @@ -143,7 +143,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer.
     
     ## Java
     
    -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java)
    +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java)
     
     ```gradle
     spotless {
    @@ -300,8 +300,8 @@ spotless {
     
     ## Groovy
     
    -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java)
    -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java)
    +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java)
    +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java)
     
     Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`.
     
    @@ -351,8 +351,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T
     
     ## Kotlin
     
    -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java)
    -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java)
    +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java)
    +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java)
     
     ```gradle
     spotless { // if you are using build.gradle.kts, instead of 'spotless {' use:
    @@ -422,7 +422,7 @@ spotless {
     
     ## Scala
     
    -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java)
    +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java)
     
     ```gradle
     spotless {
    @@ -454,7 +454,7 @@ spotless {
     
     ## C/C++
     
    -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java)
    +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java)
     
     ```gradle
     spotless {
    @@ -486,7 +486,7 @@ spotles {
     
     ## Python
     
    -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java)
    +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java)
     
     ```gradle
     spotless {
    @@ -522,7 +522,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe')
     
     ### buf
     
    -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java)
    +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java)
     
     **WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem.
     
    @@ -554,7 +554,7 @@ buf {
     
     ## FreshMark
     
    -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java)
    +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java)
     
     [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown.  This helps to keep badges and links up-to-date (see the source for this file), and can
     also be helpful for generating complex tables (see the source for [the parent readme](../README.md)).
    @@ -575,7 +575,7 @@ spotless {
     
     ## Antlr4
     
    -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java)
    +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java)
     
     ```gradle
     spotless {
    @@ -600,7 +600,7 @@ antlr4formatter('1.2.1') // version is optional
     
     ## SQL
     
    -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java)
    +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java)
     
     ```gradle
     spotless {
    @@ -640,7 +640,7 @@ sql.formatter.indent.size=4
     
     ## Typescript
     
    -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java)
    +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java)
     
     ```gradle
     spotless {
    @@ -734,7 +734,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr
     
     ## Javascript
     
    -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java)
    +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java)
     
     ```gradle
     spotless {
    @@ -799,7 +799,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr
     
     ## JSON
     
    -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java)
    +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java)
     
     ```gradle
     spotless {
    @@ -875,7 +875,7 @@ spotless {
     
     ## YAML
     
    -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java)
    +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java)
     
     ```gradle
     spotless {
    @@ -906,7 +906,7 @@ spotless {
     
     ## Gherkin
     
    -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.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.20.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 {
    @@ -1294,7 +1294,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or
     * `2017` -> `2017-2020`
     * `2017-2019` -> `2017-2020`
     
    -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options.
    +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options.
     
     
     
    @@ -1367,9 +1367,9 @@ spotless {
         custom 'lowercase', { str -> str.toLowerCase() }
     ```
     
    -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully.
    +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully.
     
    -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-).  The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep).  If the step is generally-useful, we hope you'll open a PR to share it!
    +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-).  The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep).  If the step is generally-useful, we hope you'll open a PR to share it!
     
     
     ```gradle
    @@ -1402,11 +1402,11 @@ spotless {
       format 'foo', com.acme.FooLanguageExtension, {
     ```
     
    -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-).
    +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-).
     
     ## Inception (languages within languages within...)
     
    -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that.  You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so.  See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details.
    +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that.  You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so.  See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details.
     
     ```gradle
     import com.diffplug.gradle.spotless.JavaExtension
    
    From 0c0be38a31eafff3060faed169841256fabc652f Mon Sep 17 00:00:00 2001
    From: runner
     
    Date: Mon, 17 Jul 2023 22:10:19 +0000
    Subject: [PATCH 0832/1120] Published maven/2.38.0
    
    ---
     plugin-maven/CHANGES.md | 2 ++
     plugin-maven/README.md  | 4 ++--
     2 files changed, 4 insertions(+), 2 deletions(-)
    
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index 231cee0edb..72d40dfe10 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -3,6 +3,8 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    +
    +## [2.38.0] - 2023-07-17
     ### Added
     * Support pass skip (`-Dspotless.skip=true`) from command-line. ([#1729](https://github.com/diffplug/spotless/pull/1729))
     ### Fixed
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index dc450d7ddd..c1ffd31e40 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -8,8 +8,8 @@ output = [
       ].join('\n');
     -->
     [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22)
    -[![Changelog](https://img.shields.io/badge/changelog-2.37.0-blue.svg)](CHANGES.md)
    -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.37.0/index.html)
    +[![Changelog](https://img.shields.io/badge/changelog-2.38.0-blue.svg)](CHANGES.md)
    +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.38.0/index.html)
     
     
     
    +       
       
     
     ```
    
    From 41138c92343f823973b0c07ec4712a181138bc42 Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Tue, 18 Jul 2023 13:59:51 +0200
    Subject: [PATCH 0843/1120] docs: adapt for actual PR number
    
    ---
     CHANGES.md               | 6 +++---
     plugin-gradle/CHANGES.md | 6 +++---
     plugin-maven/CHANGES.md  | 6 +++---
     3 files changed, 9 insertions(+), 9 deletions(-)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 67cc01a40c..00241182b0 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -17,15 +17,15 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     * `enum OnMatch { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#1749](https://github.com/diffplug/spotless/pull/1749))
     ### Fixed
     * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728))
    -* Add support for `prettier` version `3.0.0` and newer. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1751](https://github.com/diffplug/spotless/issues/1751))
    -* Fix npm install calls when npm cache is not up-to-date. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1750](https://github.com/diffplug/spotless/issues/1750))
    +* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    +* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     
     ### Changes
     * Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734))
     * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741))
       * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time.
       * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property.
    -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999))
    +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
     
     ## [2.39.0] - 2023-05-24
     ### Added
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 658f65f420..4358e9f26c 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -18,14 +18,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
         }
       }
       ```
    -* Add support for `prettier` version `3.0.0` and newer. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1751](https://github.com/diffplug/spotless/issues/1751))
    -* Fix npm install calls when npm cache is not up-to-date. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1750](https://github.com/diffplug/spotless/issues/1750))
    +* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    +* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     ### Changes
     * Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734))
     * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741))
       * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time.
       * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property.
    -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999))
    +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
     
     ## [6.19.0] - 2023-05-24
     ### Added
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index 98655ba3fe..823841a328 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -9,14 +9,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     * Support pass skip (`-Dspotless.skip=true`) from command-line. ([#1729](https://github.com/diffplug/spotless/pull/1729))
     ### Fixed
     * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728))
    -* Add support for `prettier` version `3.0.0` and newer. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1751](https://github.com/diffplug/spotless/issues/1751))
    -* Fix npm install calls when npm cache is not up-to-date. ([#9999]https://github.com/diffplug/spotless/pull/9999), [#1750](https://github.com/diffplug/spotless/issues/1750))
    +* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    +* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     ### Changes
     * Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734))
     * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741))
       * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time.
       * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property.
    -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#9999](https://github.com/diffplug/spotless/pull/9999))
    +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
     
     ## [2.37.0] - 2023-05-24
     ### Added
    
    From 7a4268b7e6768c072527432b160e00d071c36c57 Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Tue, 18 Jul 2023 14:50:25 +0200
    Subject: [PATCH 0844/1120] fix: resolves spotbugs issue (serializability of
     exception)
    
    ---
     .../java/com/diffplug/spotless/npm/NpmProcessException.java     | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java
    index 33c6fb8d28..c2e8444bcc 100644
    --- a/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java
    +++ b/lib/src/main/java/com/diffplug/spotless/npm/NpmProcessException.java
    @@ -21,7 +21,7 @@
     
     public class NpmProcessException extends RuntimeException {
     	private static final long serialVersionUID = 6424331316676759525L;
    -	private final ProcessRunner.Result result;
    +	private final transient ProcessRunner.Result result;
     
     	public NpmProcessException(String message, ProcessRunner.Result result) {
     		super(message);
    
    From a24908528cb3c7c35f3eee576814ce067bc60e7a Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Tue, 18 Jul 2023 15:01:42 +0200
    Subject: [PATCH 0845/1120] docs: move to Unreleased
    
    ---
     CHANGES.md               | 9 +++++----
     plugin-gradle/CHANGES.md | 9 +++++----
     plugin-maven/CHANGES.md  | 8 +++++---
     3 files changed, 15 insertions(+), 11 deletions(-)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 00241182b0..e54f6f6108 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -10,6 +10,11 @@ This document is intended for Spotless developers.
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    +### Fixed
    +* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    +* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    +### Changes
    +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
     
     ## [2.40.0] - 2023-07-17
     ### Added
    @@ -17,15 +22,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     * `enum OnMatch { INCLUDE, EXCLUDE }` so that `FormatterStep.filterByContent` can not only include based on the pattern but also exclude. ([#1749](https://github.com/diffplug/spotless/pull/1749))
     ### Fixed
     * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728))
    -* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    -* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    -
     ### Changes
     * Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734))
     * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741))
       * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time.
       * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property.
    -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
     
     ## [2.39.0] - 2023-05-24
     ### Added
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 4358e9f26c..b2e3972bba 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -3,6 +3,11 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
     
     ## [Unreleased]
    +### Fixed
    +* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    +* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    +### Changes
    +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
     
     ## [6.20.0] - 2023-07-17
     ### Added
    @@ -18,15 +23,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
         }
       }
       ```
    -* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    -* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     ### Changes
     * Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734))
     * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741))
       * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time.
       * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property.
    -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
    -
     ## [6.19.0] - 2023-05-24
     ### Added
     * Support Rome as a formatter for JavaScript and TypeScript code. Adds a new `rome` step to `javascript` and `typescript` formatter configurations. ([#1663](https://github.com/diffplug/spotless/pull/1663))
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index 823841a328..dcccd5d2ba 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -3,20 +3,22 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    +### Fixed
    +* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    +* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    +### Changes
    +* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
     
     ## [2.38.0] - 2023-07-17
     ### Added
     * Support pass skip (`-Dspotless.skip=true`) from command-line. ([#1729](https://github.com/diffplug/spotless/pull/1729))
     ### Fixed
     * Update documented default `semanticSort` to `false`. ([#1728](https://github.com/diffplug/spotless/pull/1728))
    -* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    -* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     ### Changes
     * Bump default `cleanthat` version to latest `2.13` -> `2.17`. ([#1734](https://github.com/diffplug/spotless/pull/1734))
     * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741))
       * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time.
       * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property.
    -* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
     
     ## [2.37.0] - 2023-05-24
     ### Added
    
    From 3577f4e2d4d42b7bf055067827e36194a984afef Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Tue, 18 Jul 2023 15:27:13 +0200
    Subject: [PATCH 0846/1120] fix: provide "lower" default versions for
     ts_standard
    
    as the upstream package has incompatible version restrictions otherwise
    ---
     .../main/java/com/diffplug/spotless/npm/EslintStyleGuide.java | 4 +++-
     1 file changed, 3 insertions(+), 1 deletion(-)
    
    diff --git a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java
    index ad5cb2ba2e..cb6f1325df 100644
    --- a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java
    +++ b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java
    @@ -29,7 +29,9 @@ public enum EslintStyleGuide {
     		@Override
     		public @Nonnull Map devDependencies() {
     			Map dependencies = new LinkedHashMap<>();
    -			dependencies.put("eslint-config-standard-with-typescript", "^36.1.0");
    +			dependencies.put("@typescript-eslint/eslint-plugin", "^5.62.0");
    +			dependencies.put("@typescript-eslint/parser", "^5.62.0");
    +			dependencies.put("eslint-config-standard-with-typescript", "^36.0.1");
     			dependencies.put("eslint-plugin-import", "^2.27.5");
     			dependencies.put("eslint-plugin-n", "^16.0.1");
     			dependencies.put("eslint-plugin-promise", "^6.1.1");
    
    From 7be049efc08def31b0a3f98d75a9253e959da960 Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Tue, 18 Jul 2023 15:35:18 +0200
    Subject: [PATCH 0847/1120] fix: adapt tests to work with newer prettier
     versions
    
    ---
     .../NpmTestsWithoutNpmInstallationTest.java      | 16 ++++++++--------
     ...ationTest_gradle_node_plugin_example_1.gradle |  2 +-
     ...ationTest_gradle_node_plugin_example_2.gradle |  2 +-
     3 files changed, 10 insertions(+), 10 deletions(-)
    
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java
    index 03d14292e9..363d88c0c0 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java
    @@ -40,7 +40,7 @@ void useNodeAndNpmFromNodeGradlePlugin() throws Exception {
     					"    npmWorkDir = file(\"${buildDir}/npm\")",
     					"}",
     					"def prettierConfig = [:]",
    -					"prettierConfig['printWidth'] = 50",
    +					"prettierConfig['printWidth'] = 20",
     					"prettierConfig['parser'] = 'typescript'",
     					"def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'",
     					"def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'",
    @@ -59,7 +59,7 @@ void useNodeAndNpmFromNodeGradlePlugin() throws Exception {
     			// then run spotless using that node installation
     			final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
     			Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
    -			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
    +			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
     		} catch (Exception e) {
     			printContents();
     			throw e;
    @@ -79,7 +79,7 @@ void useNodeAndNpmFromNodeGradlePlugin_example1() throws Exception {
     			setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
     			final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
     			Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
    -			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
    +			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
     		} catch (Exception e) {
     			printContents();
     			throw e;
    @@ -93,7 +93,7 @@ void useNpmFromNodeGradlePlugin_example2() throws Exception {
     			setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
     			final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
     			Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
    -			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
    +			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
     		} catch (Exception e) {
     			printContents();
     			throw e;
    @@ -115,7 +115,7 @@ void useNpmFromNodeGradlePlugin() throws Exception {
     					"    workDir = file(\"${buildDir}/nodejs\")",
     					"}",
     					"def prettierConfig = [:]",
    -					"prettierConfig['printWidth'] = 50",
    +					"prettierConfig['printWidth'] = 20",
     					"prettierConfig['parser'] = 'typescript'",
     					"def npmExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/npm.cmd' : '/bin/npm'",
     					"spotless {",
    @@ -132,7 +132,7 @@ void useNpmFromNodeGradlePlugin() throws Exception {
     			// then run spotless using that node installation
     			final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
     			Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
    -			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
    +			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
     		} catch (Exception e) {
     			printContents();
     			throw e;
    @@ -154,7 +154,7 @@ void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception {
     					"    workDir = file(\"${buildDir}/nodejs\")",
     					"}",
     					"def prettierConfig = [:]",
    -					"prettierConfig['printWidth'] = 50",
    +					"prettierConfig['printWidth'] = 20",
     					"prettierConfig['parser'] = 'typescript'",
     					"def nodeExec = System.getProperty('os.name').toLowerCase().contains('windows') ? '/node.exe' : '/bin/node'",
     					"spotless {",
    @@ -171,7 +171,7 @@ void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception {
     			// then run spotless using that node installation
     			final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
     			Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
    -			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
    +			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
     		} catch (Exception e) {
     			printContents();
     			throw e;
    diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle
    index 7ec7a2c592..c5acf5bbc5 100644
    --- a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle
    +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle
    @@ -16,7 +16,7 @@ node {
         npmWorkDir = file("${buildDir}/npm")
     }
     def prettierConfig = [:]
    -prettierConfig['printWidth'] = 50
    +prettierConfig['printWidth'] = 20
     prettierConfig['parser'] = 'typescript'
     
     // the executable names
    diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle
    index eb59b85cf0..ef843a8475 100644
    --- a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle
    +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle
    @@ -14,7 +14,7 @@ node {
         workDir = file("${buildDir}/nodejs")
     }
     def prettierConfig = [:]
    -prettierConfig['printWidth'] = 50
    +prettierConfig['printWidth'] = 20
     prettierConfig['parser'] = 'typescript'
     
     // the executable name
    
    From aa4893b1942778c3d7b69dae89977cb0aba2b13c Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Tue, 18 Jul 2023 15:55:50 +0200
    Subject: [PATCH 0848/1120] fix: create valid poms when using eslint
     styleguides
    
    (and enable the missed and disabled xo test in maven part)
    ---
     .../spotless/maven/typescript/TypescriptFormatStepTest.java   | 2 --
     .../main/java/com/diffplug/spotless/npm/EslintStyleGuide.java | 4 ++--
     2 files changed, 2 insertions(+), 4 deletions(-)
    
    diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java
    index 911cfad201..a09111d30d 100644
    --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java
    +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/typescript/TypescriptFormatStepTest.java
    @@ -19,7 +19,6 @@
     
     import java.io.IOException;
     
    -import org.junit.jupiter.api.Disabled;
     import org.junit.jupiter.api.Test;
     
     import com.diffplug.spotless.ProcessRunner;
    @@ -211,7 +210,6 @@ void eslintStyleguideStandardWithTypescript() throws Exception {
     	}
     
     	@Test
    -	@Disabled("https://github.com/diffplug/spotless/issues/1756")
     	void eslintStyleguideXo() throws Exception {
     		writePomWithTypescriptSteps(
     				TEST_FILE_PATH,
    diff --git a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java
    index cb6f1325df..874ae1905d 100644
    --- a/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java
    +++ b/testlib/src/main/java/com/diffplug/spotless/npm/EslintStyleGuide.java
    @@ -115,8 +115,8 @@ public String asGradleMapStringMergedWith(Map devDependencies) {
     
     	public String asMavenXmlStringMergedWith(Map devDependencies) {
     		return mergedWith(devDependencies).entrySet().stream()
    -				.map(entry -> "<" + entry.getKey() + ">" + entry.getValue() + "")
    -				.collect(Collectors.joining("", "", ""));
    +				.map(entry -> String.format("%s%s", entry.getKey(), entry.getValue()))
    +				.collect(Collectors.joining("", "", ""));
     	}
     
     }
    
    From 98943c33a41db287054569cbf3cfcfb01ee9a0ba Mon Sep 17 00:00:00 2001
    From: David Gregory <2992938+DavidGregory084@users.noreply.github.com>
    Date: Tue, 18 Jul 2023 15:05:10 +0100
    Subject: [PATCH 0849/1120] Update changelogs and documentation
    
    ---
     CHANGES.md               |  2 ++
     README.md                |  2 ++
     plugin-gradle/CHANGES.md |  2 ++
     plugin-gradle/README.md  | 44 ++++++++++++++++++++++++++++++++++++++++
     plugin-maven/CHANGES.md  |  2 ++
     plugin-maven/README.md   | 24 ++++++++++++++++++----
     6 files changed, 72 insertions(+), 4 deletions(-)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index cc6dcd7331..c026b4a099 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -10,6 +10,8 @@ This document is intended for Spotless developers.
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    +### Added
    +* Add an `applyJsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     
     ## [2.40.0] - 2023-07-17
     ### Added
    diff --git a/README.md b/README.md
    index 3e0c4e17e1..255dbe6813 100644
    --- a/README.md
    +++ b/README.md
    @@ -89,6 +89,7 @@ lib('java.CleanthatJavaStep')                    +'{{yes}}       | {{yes}}
     lib('json.gson.GsonStep')                        +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('json.JacksonJsonStep')                      +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('json.JsonSimpleStep')                       +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
    +lib('json.ApplyJsonPatchStep')                   +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('kotlin.KtLintStep')                         +'{{yes}}       | {{yes}}      | {{yes}}      | {{no}}  |',
     lib('kotlin.KtfmtStep')                          +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('kotlin.DiktatStep')                         +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
    @@ -140,6 +141,7 @@ lib('yaml.JacksonYamlStep')                      +'{{yes}}       | {{yes}}
     | [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`json.JacksonJsonStep`](lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
    +| [`json.ApplyJsonPatchStep`](lib/src/main/java/com/diffplug/spotless/json/ApplyJsonPatchStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1:       | :+1:      | :+1:      | :white_large_square:  |
     | [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 6d8bee7169..27541bc568 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -3,6 +3,8 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
     
     ## [Unreleased]
    +### Added
    +* Add an `applyJsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     
     ## [6.20.0] - 2023-07-17
     ### Added
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index e04697766a..a8ebf45cbe 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -811,6 +811,7 @@ spotless {
         gson()                                // has its own section below
         jackson()                             // has its own section below
         rome()                                // has its own section below
    +    applyJsonPatch([])                    // has its own section below
       }
     }
     ```
    @@ -872,6 +873,49 @@ spotless {
     }
     ```
     
    +### applyJsonPatch
    +
    +Uses [zjsonpatch](https://github.com/flipkart-incubator/zjsonpatch) to apply [JSON Patches](https://jsonpatch.com/) as per [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902/) to JSON documents.
    +
    +This enables you to add, replace or remove properties at locations in the JSON document that you specify using [JSON Pointers](https://datatracker.ietf.org/doc/html/rfc6901/).
    +
    +In Spotless Gradle, these JSON patches are represented as a `List>`, or a list of patch operations.
    +
    +Each patch operation must be a map with the following properties:
    +
    +* `"op"` - the operation to apply, one of `"replace"`, `"add"` or `"remove"`.
    +* `"path"` - a JSON Pointer string, for example `"/foo"`
    +* `"value"` - the value to `"add"` or `"replace"` at the specified path. Not needed for `"remove"` operations.
    +
    +For example, to apply the patch from the [JSON Patch homepage](https://jsonpatch.com/#the-patch):
    +
    +```gradle
    +spotless {
    +  json {
    +    target 'src/**/*.json'
    +    applyJsonPatch([
    +      [op: 'replace', path: '/baz', value: 'boo'],
    +      [op: 'add', path: '/hello', value: ['world']],
    +      [op: 'remove', path: '/foo']
    +    ])
    +  }
    +}
    +```
    +
    +Or using the Kotlin DSL:
    +
    +```kotlin
    +spotless {
    +  json {
    +    target("src/**/*.json")
    +    applyJsonPatch(listOf(
    +      mapOf("op" to "replace", "path" to "/baz", "value" to "boo"),
    +      mapOf("op" to "add", "path" to "/hello", "value" to listOf("world")),
    +      mapOf("op" to "remove", "path" to "/foo")
    +    ))
    +  }
    +}
    +```
     
     ## YAML
     
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index 72d40dfe10..fd471afdcc 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -3,6 +3,8 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    +### Added
    +* Add an `applyJsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     
     ## [2.38.0] - 2023-07-17
     ### Added
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index c1ffd31e40..1332829dc2 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -897,10 +897,11 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr
           src/**/*.json
         
     
    -        
    -          
    -       
    -          
    +             
    +               
    +            
    +               
    +     
       
     
     ```
    @@ -957,6 +958,21 @@ Uses Jackson for formatting.
     
     
     
    +### applyJsonPatch
    +
    +Uses [zjsonpatch](https://github.com/flipkart-incubator/zjsonpatch) to apply [JSON Patches](https://jsonpatch.com/) as per [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902/) to JSON documents.
    +
    +This enables you to add, replace or remove properties at locations in the JSON document that you specify using [JSON Pointers](https://datatracker.ietf.org/doc/html/rfc6901/).
    +
    +For example, to apply the patch from the [JSON Patch homepage](https://jsonpatch.com/#the-patch):
    +
    +```xml
    +[
    +  { "op": "replace", "path": "/baz", "value": "boo" },
    +  { "op": "add", "path": "/hello", "value": ["world"] },
    +  { "op": "remove", "path": "/foo" }
    +]
    +```
     
     ## YAML
     
    
    From 217c56198d0997a62a56a38f6dfa6509085bed93 Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Tue, 18 Jul 2023 16:16:15 +0200
    Subject: [PATCH 0850/1120] fix: adapt for prettier upgrades
    
    ---
     .../NpmInstallCacheIntegrationTests.java      |  4 +-
     .../spotless/PrettierIntegrationTest.java     | 24 +++++-----
     .../prettier/PrettierFormatStepTest.java      | 12 ++---
     .../npm/prettier/plugins/java-test.clean      |  5 ++-
     .../resources/npm/prettier/plugins/php.clean  | 44 +++++++++----------
     .../npm/PrettierFormatterStepTest.java        |  2 +-
     6 files changed, 46 insertions(+), 45 deletions(-)
    
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java
    index 3a690fbc55..e7ad5f1654 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmInstallCacheIntegrationTests.java
    @@ -112,8 +112,8 @@ private BuildResult runPhpPrettierOnDir(File projDir, File cacheDir) throws IOEx
     				"prettierConfig['tabWidth'] = 3",
     				"prettierConfig['parser'] = 'php'",
     				"def prettierPackages = [:]",
    -				"prettierPackages['prettier'] = '2.0.5'",
    -				"prettierPackages['@prettier/plugin-php'] = '0.14.2'",
    +				"prettierPackages['prettier'] = '2.8.8'",
    +				"prettierPackages['@prettier/plugin-php'] = '0.19.6'",
     				"spotless {",
     				"    format 'php', {",
     				"        target 'php-example.php'",
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java
    index a6b2ea9dc8..4d5069c1b5 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java
    @@ -33,7 +33,7 @@ void useInlineConfig() throws IOException {
     				"}",
     				"repositories { mavenCentral() }",
     				"def prettierConfig = [:]",
    -				"prettierConfig['printWidth'] = 50",
    +				"prettierConfig['printWidth'] = 20",
     				"prettierConfig['parser'] = 'typescript'",
     				"spotless {",
     				"    format 'mytypescript', {",
    @@ -44,7 +44,7 @@ void useInlineConfig() throws IOException {
     		setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
     		final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
     		Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
    -		assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
    +		assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
     	}
     
     	@Test
    @@ -88,7 +88,7 @@ void useFileConfig() throws IOException {
     		setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
     		final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
     		Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
    -		assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
    +		assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
     	}
     
     	@Test
    @@ -121,8 +121,8 @@ void useJavaCommunityPlugin() throws IOException {
     				"prettierConfig['tabWidth'] = 4",
     				"prettierConfig['parser'] = 'java'",
     				"def prettierPackages = [:]",
    -				"prettierPackages['prettier'] = '2.0.5'",
    -				"prettierPackages['prettier-plugin-java'] = '0.8.0'",
    +				"prettierPackages['prettier'] = '2.8.8'",
    +				"prettierPackages['prettier-plugin-java'] = '2.2.0'",
     				"spotless {",
     				"    format 'java', {",
     				"        target 'JavaTest.java'",
    @@ -145,7 +145,7 @@ void suggestsMissingJavaCommunityPlugin() throws IOException {
     				"def prettierConfig = [:]",
     				"prettierConfig['tabWidth'] = 4",
     				"def prettierPackages = [:]",
    -				"prettierPackages['prettier'] = '2.0.5'",
    +				"prettierPackages['prettier'] = '2.8.8'",
     				"spotless {",
     				"    format 'java', {",
     				"        target 'JavaTest.java'",
    @@ -169,8 +169,8 @@ void usePhpCommunityPlugin() throws IOException {
     				"prettierConfig['tabWidth'] = 3",
     				"prettierConfig['parser'] = 'php'",
     				"def prettierPackages = [:]",
    -				"prettierPackages['prettier'] = '2.0.5'",
    -				"prettierPackages['@prettier/plugin-php'] = '0.14.2'",
    +				"prettierPackages['prettier'] = '2.8.8'",
    +				"prettierPackages['@prettier/plugin-php'] = '0.19.6'",
     				"spotless {",
     				"    format 'php', {",
     				"        target 'php-example.php'",
    @@ -199,14 +199,14 @@ void usePhpAndJavaCommunityPlugin() throws IOException {
     				"prettierConfigPhp['tabWidth'] = 3",
     				"prettierConfigPhp['parser'] = 'php'",
     				"def prettierPackagesPhp = [:]",
    -				"prettierPackagesPhp['prettier'] = '2.0.5'",
    -				"prettierPackagesPhp['@prettier/plugin-php'] = '0.14.2'",
    +				"prettierPackagesPhp['prettier'] = '2.8.8'",
    +				"prettierPackagesPhp['@prettier/plugin-php'] = '0.19.6'",
     				"def prettierConfigJava = [:]",
     				"prettierConfigJava['tabWidth'] = 4",
     				"prettierConfigJava['parser'] = 'java'",
     				"def prettierPackagesJava = [:]",
    -				"prettierPackagesJava['prettier'] = '2.0.5'",
    -				"prettierPackagesJava['prettier-plugin-java'] = '0.8.0'",
    +				"prettierPackagesJava['prettier'] = '2.8.8'",
    +				"prettierPackagesJava['prettier-plugin-java'] = '2.2.0'",
     				"spotless {",
     				"    format 'php', {",
     				"        target 'php-example.php'",
    diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java
    index 78a0fc30ff..9cd1a313eb 100644
    --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java
    +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java
    @@ -120,11 +120,11 @@ void multiple_prettier_configs() throws Exception {
     								"  ",
     								"    ",
     								"      prettier",
    -								"      2.0.5",
    +								"      2.8.8",
     								"    ",
     								"    ",
     								"      @prettier/plugin-php",
    -								"      0.14.2",
    +								"      0.19.6",
     								"    ",
     								"  ",
     								"  ",
    @@ -137,11 +137,11 @@ void multiple_prettier_configs() throws Exception {
     								"  ",
     								"    ",
     								"      prettier",
    -								"      2.0.5",
    +								"      2.8.8",
     								"    ",
     								"    ",
     								"      prettier-plugin-java",
    -								"      0.8.0",
    +								"      2.2.0",
     								"    ",
     								"  ",
     								"  ",
    @@ -166,11 +166,11 @@ void custom_plugin() throws Exception {
     				"  ",
     				"    ",
     				"      prettier",
    -				"      2.0.5",
    +				"      2.8.8",
     				"    ",
     				"    ",
     				"      @prettier/plugin-php",
    -				"      0.14.2",
    +				"      0.19.6",
     				"    ",
     				"  ",
     				"  ",
    diff --git a/testlib/src/main/resources/npm/prettier/plugins/java-test.clean b/testlib/src/main/resources/npm/prettier/plugins/java-test.clean
    index c45ffe5183..93cf43955f 100644
    --- a/testlib/src/main/resources/npm/prettier/plugins/java-test.clean
    +++ b/testlib/src/main/resources/npm/prettier/plugins/java-test.clean
    @@ -4,6 +4,7 @@ import java.util.List;
     import java.util.function.Consumer;
     
     public class JavaTest {
    +
         private static final String NAME = "JavaTest";
     
         private List strings = new ArrayList<>();
    @@ -30,8 +31,8 @@ public class JavaTest {
             JavaTest javaTest = new JavaTest("1", "2", "3");
             System.out.println("joined: " + javaTest.join(','));
             StringBuilder builder = new StringBuilder();
    -        javaTest.operateOn(
    -            strings -> builder.append(String.join("---", strings))
    +        javaTest.operateOn(strings ->
    +            builder.append(String.join("---", strings))
             );
         }
     }
    diff --git a/testlib/src/main/resources/npm/prettier/plugins/php.clean b/testlib/src/main/resources/npm/prettier/plugins/php.clean
    index 4c8710bbee..067647a029 100644
    --- a/testlib/src/main/resources/npm/prettier/plugins/php.clean
    +++ b/testlib/src/main/resources/npm/prettier/plugins/php.clean
    @@ -27,17 +27,17 @@ abstract class ReallyReallyReallyLongClassName
        // variable doc
        public $test;
        public $other = 1;
    -   public static $staticTest = ['hi'];
    +   public static $staticTest = ["hi"];
        static $cache;
        protected static $_instance;
    -   protected $fillable = ['title', 'requester_id', 'type', 'summary', 'proof'];
    +   protected $fillable = ["title", "requester_id", "type", "summary", "proof"];
        protected $fillable2 = [
    -      'title',
    -      'description',
    -      'requester_id',
    -      'type',
    -      'summary',
    -      'proof',
    +      "title",
    +      "description",
    +      "requester_id",
    +      "type",
    +      "summary",
    +      "proof",
        ];
        protected $test = [
           //test
    @@ -52,7 +52,7 @@ abstract class ReallyReallyReallyLongClassName
         *
         * @return \Some\Test
         */
    -   public function __construct($test, $test_int = null, $test_string = 'hi')
    +   public function __construct($test, $test_int = null, $test_string = "hi")
        {
           parent::__construct($test_int ?: 1);
           $this->other = $test_string;
    @@ -108,7 +108,7 @@ abstract class ReallyReallyReallyLongClassName
     
        public function returnTypeTest(): string
        {
    -      return 'hi';
    +      return "hi";
        }
     
        final public static function bar()
    @@ -125,17 +125,17 @@ abstract class ReallyReallyReallyLongClassName
     
        public function method1()
        {
    -      return 'hi';
    +      return "hi";
        }
     
        public function method2()
        {
    -      return 'hi';
    +      return "hi";
        }
     
        public function method3()
        {
    -      return 'hi';
    +      return "hi";
        }
     
        public function testReturn(?string $name): ?string
    @@ -164,7 +164,7 @@ abstract class ReallyReallyReallyLongClassName
           string $bar,
           int $baz
        ): string {
    -      return 'foo';
    +      return "foo";
        }
     
        public function longLongAnotherFunctionOther(
    @@ -172,7 +172,7 @@ abstract class ReallyReallyReallyLongClassName
           string $bar,
           int $baz
        ) {
    -      return 'foo';
    +      return "foo";
        }
     
        public function testReturnTypeDeclaration(): object
    @@ -297,13 +297,13 @@ class field extends \models\base
     {
        protected function pre_save($input, $fields)
        {
    -      $input['configs'] = json_encode(
    +      $input["configs"] = json_encode(
              array_merge(
                 $configs,
    -            $field_type->process_field_config_from_user($input['definition'])
    +            $field_type->process_field_config_from_user($input["definition"])
              )
           );
    -      unset($input['definition']);
    +      unset($input["definition"]);
        }
     }
     
    @@ -311,8 +311,8 @@ class test
     {
        public function test_method()
        {
    -      $customer = (object) ['name' => 'Bob'];
    -      $job = (object) ['customer' => $customer];
    +      $customer = (object) ["name" => "Bob"];
    +      $job = (object) ["customer" => $customer];
     
           return "The customer for that job, {$job->customer->name} has an error that shows up after the line gets waaaaay toooo long.";
        }
    @@ -488,9 +488,9 @@ class User
     {
        public int $id;
        public string $name;
    -   public ?string $b = 'foo';
    +   public ?string $b = "foo";
        private Foo $prop;
    -   protected static string $static = 'default';
    +   protected static string $static = "default";
     
        public function __construct(int $id, string $name)
        {
    diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java
    index 672aec740b..769d91bc01 100644
    --- a/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java
    +++ b/testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java
    @@ -128,7 +128,7 @@ void parserInferenceBasedOnFilenameIsWorking(String prettierVersion) throws Exce
     		@Test
     		void verifyPrettierErrorMessageIsRelayed() throws Exception {
     			FormatterStep formatterStep = PrettierFormatterStep.create(
    -					PrettierFormatterStep.defaultDevDependenciesWithPrettier("2.0.5"),
    +					PrettierFormatterStep.defaultDevDependenciesWithPrettier("2.8.8"),
     					TestProvisioner.mavenCentral(),
     					projectDir(),
     					buildDir(),
    
    From 6188a820f5ca18dd375164ccbcadc8a5a2f9e621 Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Tue, 18 Jul 2023 16:16:28 +0200
    Subject: [PATCH 0851/1120] docs: adapt for newer base versions
    
    ---
     plugin-gradle/README.md |  4 ++--
     plugin-maven/README.md  | 12 ++++++------
     2 files changed, 8 insertions(+), 8 deletions(-)
    
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 2334c3ff71..3484e3cd59 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -979,11 +979,11 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos
     ```gradle
     spotless {
       java {
    -    prettier(['prettier': '2.0.5', 'prettier-plugin-java': '0.8.0']).config(['parser': 'java', 'tabWidth': 4])
    +    prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0']).config(['parser': 'java', 'tabWidth': 4])
       }
       format 'php', {
         target 'src/**/*.php'
    -    prettier(['prettier': '2.0.5', '@prettier/plugin-php': '0.14.2']).config(['parser': 'php', 'tabWidth': 3])
    +    prettier(['prettier': '2.8.8', '@prettier/plugin-php': '0.19.6']).config(['parser': 'php', 'tabWidth': 3])
       }
     }
     ```
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index af32c092fd..62f2a4ea57 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -1047,11 +1047,11 @@ You can use prettier in any language-specific format, but usually you will be cr
             
               
                 prettier
    -            2.0.5
    +            2.8.8
               
               
                 @prettier/plugin-php 
    -            0.14.2
    +            0.19.6
               
             
             
    @@ -1097,8 +1097,8 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos
     
           
             
    -            2.0.5
    -            0.8.0
    +            2.8.8
    +            2.2.0
             
             
                 4
    @@ -1118,11 +1118,11 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos
             
               
                 prettier
    -            2.0.5
    +            2.8.8
               
               
                 @prettier/plugin-php
    -            0.14.2
    +            0.19.6
               
             
             
    
    From b4a118a41e8d0244d80c249bdcb74c9557c0f57c Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Tue, 18 Jul 2023 17:21:48 +0200
    Subject: [PATCH 0852/1120] fix: upgrade to newer npm version for maybe fixing
     windows build
    
    ---
     .../gradle/spotless/NpmTestsWithoutNpmInstallationTest.java | 6 +++---
     ...tNpmInstallationTest_gradle_node_plugin_example_1.gradle | 4 ++--
     ...tNpmInstallationTest_gradle_node_plugin_example_2.gradle | 2 +-
     3 files changed, 6 insertions(+), 6 deletions(-)
    
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java
    index 363d88c0c0..d01d1ab006 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java
    @@ -34,8 +34,8 @@ void useNodeAndNpmFromNodeGradlePlugin() throws Exception {
     					"repositories { mavenCentral() }",
     					"node {",
     					"    download = true",
    -					"    version = '18.13.0'",
    -					"    npmVersion = '8.19.2'",
    +					"    version = '18.16.1'",
    +					"    npmVersion = '9.5.1'",
     					"    workDir = file(\"${buildDir}/nodejs\")",
     					"    npmWorkDir = file(\"${buildDir}/npm\")",
     					"}",
    @@ -111,7 +111,7 @@ void useNpmFromNodeGradlePlugin() throws Exception {
     					"repositories { mavenCentral() }",
     					"node {",
     					"    download = true",
    -					"    version = '18.13.0'",
    +					"    version = '18.16.1'",
     					"    workDir = file(\"${buildDir}/nodejs\")",
     					"}",
     					"def prettierConfig = [:]",
    diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle
    index c5acf5bbc5..c0fa255bcc 100644
    --- a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle
    +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle
    @@ -9,8 +9,8 @@ plugins {
     repositories { mavenCentral() }
     node {
         download = true
    -    version = '18.13.0'
    -    npmVersion = '8.19.2'
    +    version = '18.16.1'
    +    npmVersion = '9.5.1'
     	// when setting both these directories, npm and node will be in separate directories
         workDir = file("${buildDir}/nodejs")
         npmWorkDir = file("${buildDir}/npm")
    diff --git a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle
    index ef843a8475..6d77bc3d69 100644
    --- a/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle
    +++ b/plugin-gradle/src/test/resources/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_2.gradle
    @@ -9,7 +9,7 @@ plugins {
     repositories { mavenCentral() }
     node {
         download = true
    -    version = '18.13.0'
    +    version = '18.16.1'
     	// when not setting an explicit `npmWorkDir`, the npm binary will be installed next to the node binary
         workDir = file("${buildDir}/nodejs")
     }
    
    From 0abd5c353d773c4118e29014b49a07e01c0c8a8c Mon Sep 17 00:00:00 2001
    From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
    Date: Wed, 26 Jul 2023 16:42:22 +0000
    Subject: [PATCH 0853/1120] chore(deps): update plugin com.gradle.enterprise to
     v3.14.1
    
    ---
     settings.gradle | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/settings.gradle b/settings.gradle
    index b6d227dab8..57c670b977 100644
    --- a/settings.gradle
    +++ b/settings.gradle
    @@ -23,7 +23,7 @@ plugins {
     	// https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags
     	id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false
     	// https://plugins.gradle.org/plugin/com.gradle.enterprise
    -	id 'com.gradle.enterprise' version '3.13.3'
    +	id 'com.gradle.enterprise' version '3.14.1'
     	// https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md
     	id 'dev.equo.ide' version '1.0.1' apply false
     }
    
    From e3e8cdb0928df14d3f93e2a69739af24133f363c Mon Sep 17 00:00:00 2001
    From: Magnus Ihse Bursie 
    Date: Fri, 28 Jul 2023 15:04:57 +0200
    Subject: [PATCH 0854/1120] Add information about using ratchetFrom on CI
     systems
    
    Add the important TL;DR from #710 to the documentation where it is pertinent.
    ---
     plugin-gradle/README.md | 9 +++++++++
     1 file changed, 9 insertions(+)
    
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 3484e3cd59..33d3ede9d6 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -1326,6 +1326,15 @@ However, we strongly recommend that you use a non-local branch, such as a tag or
     
     This is especially helpful for injecting accurate copyright dates using the [license step](#license-header).
     
    +### Using ratchetFrom on CI systems
    +
    +If you are running Spotless on a CI system, make sure you do not have a shallow clone, or `ratchetFrom` will fail with `No such reference`. Many CI systems use a shallow clone by default for performance reasons. Here is how you turn off shallow clones for some common CI systems:
    +
    +* **GitHub Actions**: Ad `fetch-depth: 0` to `.yml`
    +* **GitLab CI**: Add `GIT_DEPTH: 0` under the `variables:` section of `.gitlab-ci.yml`
    +* **BitBucket Pipelines**: Add `clone: depth: full` to the build step
    +* **Travis**: Add `git: depth: false` in `travis.yml`
    +
     ## `spotless:off` and `spotless:on`
     
     Sometimes there is a chunk of code  which you have carefully handcrafted, and you would like to exclude just this one little part from getting clobbered by the autoformat. Some formatters have a way to do this, many don't, but who cares.  If you setup your spotless like this:
    
    From 16f41e7d25a86913e5d0e97bc2265779466c59bb Mon Sep 17 00:00:00 2001
    From: Ned Twigg 
    Date: Fri, 28 Jul 2023 13:58:45 -0700
    Subject: [PATCH 0855/1120] Condense the `ratchetFrom` CI info.
    
    ---
     plugin-gradle/README.md | 10 ++++------
     plugin-maven/README.md  |  7 +++++++
     2 files changed, 11 insertions(+), 6 deletions(-)
    
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 33d3ede9d6..fc0aa45a3f 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -1326,14 +1326,12 @@ However, we strongly recommend that you use a non-local branch, such as a tag or
     
     This is especially helpful for injecting accurate copyright dates using the [license step](#license-header).
     
    -### Using ratchetFrom on CI systems
    +### Using `ratchetFrom` on CI systems
     
    -If you are running Spotless on a CI system, make sure you do not have a shallow clone, or `ratchetFrom` will fail with `No such reference`. Many CI systems use a shallow clone by default for performance reasons. Here is how you turn off shallow clones for some common CI systems:
    +Many popular CI systems (GitHub, GitLab, BitBucket, and Travis) use a "shallow clone". This means that `ratchetFrom 'origin/main'` will fail with `No such reference`. You can fix this by:
     
    -* **GitHub Actions**: Ad `fetch-depth: 0` to `.yml`
    -* **GitLab CI**: Add `GIT_DEPTH: 0` under the `variables:` section of `.gitlab-ci.yml`
    -* **BitBucket Pipelines**: Add `clone: depth: full` to the build step
    -* **Travis**: Add `git: depth: false` in `travis.yml`
    +- calling `git fetch origin main` before you call Spotless
    +- disabling the shallow clone [like so](https://github.com/diffplug/spotless/issues/710)
     
     ## `spotless:off` and `spotless:on`
     
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index 62f2a4ea57..2d14c6edc7 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -1526,6 +1526,13 @@ You can explicitly disable ratchet functionality by providing the value 'NONE':
     ```
     This is useful for disabling the ratchet functionality in child projects where the parent defines a ratchetFrom value.
     
    +### Using `ratchetFrom` on CI systems
    +
    +Many popular CI systems (GitHub, GitLab, BitBucket, and Travis) use a "shallow clone". This means that `origin/main` will fail with `No such reference`. You can fix this by:
    +
    +- calling `git fetch origin main` before you call Spotless
    +- disabling the shallow clone [like so](https://github.com/diffplug/spotless/issues/710)
    +
     ## `spotless:off` and `spotless:on`
     
     Sometimes there is a chunk of code  which you have carefully handcrafted, and you would like to exclude just this one little part from getting clobbered by the autoformat. Some formatters have a way to do this, many don't, but who cares. If you setup your spotless like this:
    
    From 1eb2a4f59ff3e9cd8a551cc79b312a2243a84b6d Mon Sep 17 00:00:00 2001
    From: David Gregory <2992938+DavidGregory084@users.noreply.github.com>
    Date: Mon, 31 Jul 2023 16:02:32 +0100
    Subject: [PATCH 0856/1120] Rename `applyJsonPatch` functionality to
     `jsonPatch`
    
    ---
     CHANGES.md                                    |  2 +-
     README.md                                     |  4 ++--
     ...yJsonPatchStep.java => JsonPatchStep.java} |  6 +++---
     ...rFunc.java => JsonPatchFormatterFunc.java} |  6 +++---
     plugin-gradle/CHANGES.md                      |  2 +-
     plugin-gradle/README.md                       |  8 ++++----
     .../gradle/spotless/JsonExtension.java        | 20 +++++++++----------
     .../gradle/spotless/JsonExtensionTest.java    |  8 ++++----
     plugin-maven/CHANGES.md                       |  2 +-
     plugin-maven/README.md                        |  8 ++++----
     .../diffplug/spotless/maven/json/Json.java    |  4 ++--
     .../{ApplyJsonPatch.java => JsonPatch.java}   |  8 ++++----
     .../spotless/maven/json/JsonTest.java         |  8 ++++----
     13 files changed, 43 insertions(+), 43 deletions(-)
     rename lib/src/main/java/com/diffplug/spotless/json/{ApplyJsonPatchStep.java => JsonPatchStep.java} (96%)
     rename lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/{ApplyJsonPatchFormatterFunc.java => JsonPatchFormatterFunc.java} (88%)
     rename plugin-maven/src/main/java/com/diffplug/spotless/maven/json/{ApplyJsonPatch.java => JsonPatch.java} (80%)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index f65f4f23fc..2b60913d67 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     
     ## [Unreleased]
     ### Added
    -* Add an `applyJsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    +* Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     ### Fixed
     * Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756))
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    diff --git a/README.md b/README.md
    index 255dbe6813..cd1e736014 100644
    --- a/README.md
    +++ b/README.md
    @@ -89,7 +89,7 @@ lib('java.CleanthatJavaStep')                    +'{{yes}}       | {{yes}}
     lib('json.gson.GsonStep')                        +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('json.JacksonJsonStep')                      +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('json.JsonSimpleStep')                       +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
    -lib('json.ApplyJsonPatchStep')                   +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
    +lib('json.JsonPatchStep')                        +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('kotlin.KtLintStep')                         +'{{yes}}       | {{yes}}      | {{yes}}      | {{no}}  |',
     lib('kotlin.KtfmtStep')                          +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('kotlin.DiktatStep')                         +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
    @@ -141,7 +141,7 @@ lib('yaml.JacksonYamlStep')                      +'{{yes}}       | {{yes}}
     | [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`json.JacksonJsonStep`](lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
    -| [`json.ApplyJsonPatchStep`](lib/src/main/java/com/diffplug/spotless/json/ApplyJsonPatchStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
    +| [`json.JsonPatchStep`](lib/src/main/java/com/diffplug/spotless/json/JsonPatchStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1:       | :+1:      | :+1:      | :white_large_square:  |
     | [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
    diff --git a/lib/src/main/java/com/diffplug/spotless/json/ApplyJsonPatchStep.java b/lib/src/main/java/com/diffplug/spotless/json/JsonPatchStep.java
    similarity index 96%
    rename from lib/src/main/java/com/diffplug/spotless/json/ApplyJsonPatchStep.java
    rename to lib/src/main/java/com/diffplug/spotless/json/JsonPatchStep.java
    index 84f39f5b23..71f4380264 100644
    --- a/lib/src/main/java/com/diffplug/spotless/json/ApplyJsonPatchStep.java
    +++ b/lib/src/main/java/com/diffplug/spotless/json/JsonPatchStep.java
    @@ -28,12 +28,12 @@
     import com.diffplug.spotless.JarState;
     import com.diffplug.spotless.Provisioner;
     
    -public class ApplyJsonPatchStep {
    +public class JsonPatchStep {
     	// https://mvnrepository.com/artifact/com.flipkart.zjsonpatch/zjsonpatch
     	static final String MAVEN_COORDINATE = "com.flipkart.zjsonpatch:zjsonpatch";
     	static final String DEFAULT_VERSION = "0.4.14";
     
    -	private ApplyJsonPatchStep() {}
    +	private JsonPatchStep() {}
     
     	public static FormatterStep create(String patchString, Provisioner provisioner) {
     		return create(DEFAULT_VERSION, patchString, provisioner);
    @@ -77,7 +77,7 @@ private State(String zjsonPatchVersion, String patchString, Provisioner provisio
     		}
     
     		FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
    -			Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.json.ApplyJsonPatchFormatterFunc");
    +			Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.json.JsonPatchFormatterFunc");
     			if (this.patch != null) {
     				Constructor constructor = formatterFunc.getConstructor(List.class);
     				return (FormatterFunc) constructor.newInstance(patch);
    diff --git a/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java b/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/JsonPatchFormatterFunc.java
    similarity index 88%
    rename from lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java
    rename to lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/JsonPatchFormatterFunc.java
    index 1ba6084a67..dd2f053791 100644
    --- a/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/ApplyJsonPatchFormatterFunc.java
    +++ b/lib/src/zjsonPatch/java/com/diffplug/spotless/glue/json/JsonPatchFormatterFunc.java
    @@ -23,18 +23,18 @@
     
     import com.diffplug.spotless.FormatterFunc;
     
    -public class ApplyJsonPatchFormatterFunc implements FormatterFunc {
    +public class JsonPatchFormatterFunc implements FormatterFunc {
     	private final ObjectMapper objectMapper;
     	private final List> patch;
     	private final String patchString;
     
    -	public ApplyJsonPatchFormatterFunc(String patchString) {
    +	public JsonPatchFormatterFunc(String patchString) {
     		this.objectMapper = new ObjectMapper();
     		this.patch = null;
     		this.patchString = patchString;
     	}
     
    -	public ApplyJsonPatchFormatterFunc(List> patch) {
    +	public JsonPatchFormatterFunc(List> patch) {
     		this.objectMapper = new ObjectMapper();
     		this.patch = patch;
     		this.patchString = null;
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index ee7ea85658..b21debb36f 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     
     ## [Unreleased]
     ### Added
    -* Add an `applyJsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    +* Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 0edd2a893a..b08c8b85bc 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -811,7 +811,7 @@ spotless {
         gson()                                // has its own section below
         jackson()                             // has its own section below
         rome()                                // has its own section below
    -    applyJsonPatch([])                    // has its own section below
    +    jsonPatch([])                         // has its own section below
       }
     }
     ```
    @@ -873,7 +873,7 @@ spotless {
     }
     ```
     
    -### applyJsonPatch
    +### jsonPatch
     
     Uses [zjsonpatch](https://github.com/flipkart-incubator/zjsonpatch) to apply [JSON Patches](https://jsonpatch.com/) as per [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902/) to JSON documents.
     
    @@ -893,7 +893,7 @@ For example, to apply the patch from the [JSON Patch homepage](https://jsonpatch
     spotless {
       json {
         target 'src/**/*.json'
    -    applyJsonPatch([
    +    jsonPatch([
           [op: 'replace', path: '/baz', value: 'boo'],
           [op: 'add', path: '/hello', value: ['world']],
           [op: 'remove', path: '/foo']
    @@ -908,7 +908,7 @@ Or using the Kotlin DSL:
     spotless {
       json {
         target("src/**/*.json")
    -    applyJsonPatch(listOf(
    +    jsonPatch(listOf(
           mapOf("op" to "replace", "path" to "/baz", "value" to "boo"),
           mapOf("op" to "add", "path" to "/hello", "value" to listOf("world")),
           mapOf("op" to "remove", "path" to "/foo")
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java
    index 5e587dbd9f..8648cacea9 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java
    @@ -22,9 +22,9 @@
     import javax.inject.Inject;
     
     import com.diffplug.spotless.FormatterStep;
    -import com.diffplug.spotless.json.ApplyJsonPatchStep;
     import com.diffplug.spotless.json.JacksonJsonConfig;
     import com.diffplug.spotless.json.JacksonJsonStep;
    +import com.diffplug.spotless.json.JsonPatchStep;
     import com.diffplug.spotless.json.JsonSimpleStep;
     import com.diffplug.spotless.json.gson.GsonStep;
     
    @@ -75,12 +75,12 @@ public RomeJson rome(String version) {
     		return romeConfig;
     	}
     
    -	public ApplyJsonPatchConfig applyJsonPatch(List> patch) {
    -		return new ApplyJsonPatchConfig(patch);
    +	public JsonPatchConfig jsonPatch(List> patch) {
    +		return new JsonPatchConfig(patch);
     	}
     
    -	public ApplyJsonPatchConfig applyJsonPatch(String zjsonPatchVersion, List> patch) {
    -		return new ApplyJsonPatchConfig(zjsonPatchVersion, patch);
    +	public JsonPatchConfig jsonPatch(String zjsonPatchVersion, List> patch) {
    +		return new JsonPatchConfig(zjsonPatchVersion, patch);
     	}
     
     	public class SimpleConfig {
    @@ -204,28 +204,28 @@ protected RomeJson getThis() {
     		}
     	}
     
    -	public class ApplyJsonPatchConfig {
    +	public class JsonPatchConfig {
     		private String zjsonPatchVersion;
     		private List> patch;
     
    -		public ApplyJsonPatchConfig(List> patch) {
    +		public JsonPatchConfig(List> patch) {
     			this(DEFAULT_ZJSONPATCH_VERSION, patch);
     		}
     
    -		public ApplyJsonPatchConfig(String zjsonPatchVersion, List> patch) {
    +		public JsonPatchConfig(String zjsonPatchVersion, List> patch) {
     			this.zjsonPatchVersion = zjsonPatchVersion;
     			this.patch = patch;
     			addStep(createStep());
     		}
     
    -		public ApplyJsonPatchConfig version(String zjsonPatchVersion) {
    +		public JsonPatchConfig version(String zjsonPatchVersion) {
     			this.zjsonPatchVersion = zjsonPatchVersion;
     			replaceStep(createStep());
     			return this;
     		}
     
     		private FormatterStep createStep() {
    -			return ApplyJsonPatchStep.create(zjsonPatchVersion, patch, provisioner());
    +			return JsonPatchStep.create(zjsonPatchVersion, patch, provisioner());
     		}
     	}
     }
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java
    index ea1358ccee..73e443b915 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/JsonExtensionTest.java
    @@ -158,7 +158,7 @@ void jacksonFormattingWithSortingByKeys() throws IOException {
     	}
     
     	@Test
    -	void applyJsonPatchReplaceString() throws IOException {
    +	void jsonPatchReplaceString() throws IOException {
     		setFile("build.gradle").toLines(
     				"plugins {",
     				"    id 'java'",
    @@ -168,7 +168,7 @@ void applyJsonPatchReplaceString() throws IOException {
     				"spotless {",
     				"    json {",
     				"        target 'src/**/*.json'",
    -				"        applyJsonPatch([[op: 'replace', path: '/abc', value: 'ghi']])",
    +				"        jsonPatch([[op: 'replace', path: '/abc', value: 'ghi']])",
     				"        gson()",
     				"    }",
     				"}");
    @@ -178,7 +178,7 @@ void applyJsonPatchReplaceString() throws IOException {
     	}
     
     	@Test
    -	void applyJsonPatchReplaceWithObject() throws IOException {
    +	void jsonPatchReplaceWithObject() throws IOException {
     		setFile("build.gradle").toLines(
     				"plugins {",
     				"    id 'java'",
    @@ -188,7 +188,7 @@ void applyJsonPatchReplaceWithObject() throws IOException {
     				"spotless {",
     				"    json {",
     				"        target 'src/**/*.json'",
    -				"        applyJsonPatch([[op: 'replace', path: '/abc', value: [def: 'ghi']]])",
    +				"        jsonPatch([[op: 'replace', path: '/abc', value: [def: 'ghi']]])",
     				"        gson()",
     				"    }",
     				"}");
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index 06f8cc1e46..bab8fca7b3 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     
     ## [Unreleased]
     ### Added
    -* Add an `applyJsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    +* Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index 5892a401c9..8c56aaefa1 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -901,7 +901,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr
                    
                 
                    
    -     
    +          
       
     
     ```
    @@ -958,7 +958,7 @@ Uses Jackson for formatting.
     
     
     
    -### applyJsonPatch
    +### jsonPatch
     
     Uses [zjsonpatch](https://github.com/flipkart-incubator/zjsonpatch) to apply [JSON Patches](https://jsonpatch.com/) as per [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902/) to JSON documents.
     
    @@ -967,11 +967,11 @@ This enables you to add, replace or remove properties at locations in the JSON d
     For example, to apply the patch from the [JSON Patch homepage](https://jsonpatch.com/#the-patch):
     
     ```xml
    -[
    +[
       { "op": "replace", "path": "/baz", "value": "boo" },
       { "op": "add", "path": "/hello", "value": ["world"] },
       { "op": "remove", "path": "/foo" }
    -]
    +]
     ```
     
     ## YAML
    diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java
    index 76a5c43221..be5782b651 100644
    --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java
    +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java
    @@ -54,7 +54,7 @@ public void addRome(RomeJson rome) {
     		addStepFactory(rome);
     	}
     
    -	public void addApplyJsonPatch(ApplyJsonPatch applyJsonPatch) {
    -		addStepFactory(applyJsonPatch);
    +	public void addJsonPatch(JsonPatch jsonPatch) {
    +		addStepFactory(jsonPatch);
     	}
     }
    diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/ApplyJsonPatch.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JsonPatch.java
    similarity index 80%
    rename from plugin-maven/src/main/java/com/diffplug/spotless/maven/json/ApplyJsonPatch.java
    rename to plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JsonPatch.java
    index 6e18ea9388..a822ad09e2 100644
    --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/ApplyJsonPatch.java
    +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/JsonPatch.java
    @@ -18,14 +18,14 @@
     import org.apache.maven.plugins.annotations.Parameter;
     
     import com.diffplug.spotless.FormatterStep;
    -import com.diffplug.spotless.json.ApplyJsonPatchStep;
    +import com.diffplug.spotless.json.JsonPatchStep;
     import com.diffplug.spotless.maven.FormatterStepConfig;
     import com.diffplug.spotless.maven.FormatterStepFactory;
     
     /**
    - * A {@link FormatterStepFactory} implementation that corresponds to {@code ...} configuration element.
    + * A {@link FormatterStepFactory} implementation that corresponds to {@code ...} configuration element.
      */
    -public class ApplyJsonPatch implements FormatterStepFactory {
    +public class JsonPatch implements FormatterStepFactory {
     	private static final String DEFAULT_ZJSONPATCH_VERSION = "0.4.14";
     
     	@Parameter
    @@ -36,6 +36,6 @@ public class ApplyJsonPatch implements FormatterStepFactory {
     
     	@Override
     	public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
    -		return ApplyJsonPatchStep.create(zjsonPatchVersion, patch, stepConfig.getProvisioner());
    +		return JsonPatchStep.create(zjsonPatchVersion, patch, stepConfig.getProvisioner());
     	}
     }
    diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java
    index 49becde33a..4c2f05532c 100644
    --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java
    +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/json/JsonTest.java
    @@ -91,8 +91,8 @@ public void testFormatJson_WithJackson_sortByKeys_spaceAfterKeySeparator() throw
     	}
     
     	@Test
    -	public void testFormatJson_ApplyJsonPatch_replaceString() throws Exception {
    -		writePomWithJsonSteps("[{\"op\":\"replace\",\"path\":\"/abc\",\"value\":\"ghi\"}]");
    +	public void testFormatJson_JsonPatch_replaceString() throws Exception {
    +		writePomWithJsonSteps("[{\"op\":\"replace\",\"path\":\"/abc\",\"value\":\"ghi\"}]");
     
     		setFile("json_test.json").toResource("json/patchObjectBefore.json");
     
    @@ -101,8 +101,8 @@ public void testFormatJson_ApplyJsonPatch_replaceString() throws Exception {
     	}
     
     	@Test
    -	public void testFormatJson_ApplyJsonPatch_replaceWithObject() throws Exception {
    -		writePomWithJsonSteps("[{\"op\":\"replace\",\"path\":\"/abc\",\"value\":{\"def\":\"ghi\"}}]");
    +	public void testFormatJson_JsonPatch_replaceWithObject() throws Exception {
    +		writePomWithJsonSteps("[{\"op\":\"replace\",\"path\":\"/abc\",\"value\":{\"def\":\"ghi\"}}]");
     
     		setFile("json_test.json").toResource("json/patchObjectBefore.json");
     
    
    From 8b1713d88bf575730da921c910da72718b5da4e0 Mon Sep 17 00:00:00 2001
    From: Ned Twigg 
    Date: Mon, 31 Jul 2023 12:35:10 -0700
    Subject: [PATCH 0857/1120] Update README index at plugin-gradle and
     plugin-maven.
    
    ---
     plugin-gradle/README.md | 2 +-
     plugin-maven/README.md  | 2 +-
     2 files changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 852aed2bc7..325093796e 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -66,7 +66,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), [ESLint](#eslint-typescript), [Rome](#rome))
       - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Rome](#rome))
    -  - [JSON](#json)
    +  - [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [rome](#rome), [jsonPatch](#jsonPatch))
       - [YAML](#yaml)
       - [Gherkin](#gherkin)
       - Multiple languages
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index eb9bc35c1f..cb770099ac 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -51,7 +51,7 @@ user@machine repo % mvn spotless:check
       - [Markdown](#markdown) ([flexmark](#flexmark))
       - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome))
       - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Rome](#rome))
    -  - [JSON](#json)
    +  - [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [rome](#rome), [jsonPatch](#jsonPatch))
       - [YAML](#yaml)
       - [Gherkin](#gherkin)
       - Multiple languages
    
    From b2db0f55af0d5e20435355f2232c6f54ad7458ae Mon Sep 17 00:00:00 2001
    From: jochenberger 
    Date: Wed, 2 Aug 2023 15:42:51 +0200
    Subject: [PATCH 0858/1120] Add support for Eclipse 4.28
    
    ---
     .../spotless/extra/groovy/GrEclipseFormatterStep.java         | 4 +++-
     1 file changed, 3 insertions(+), 1 deletion(-)
    
    diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java
    index 3b57df889b..0d6287caea 100644
    --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java
    +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java
    @@ -50,7 +50,9 @@ protected P2Model model(String version) {
     					throw new IllegalArgumentException("4.8 is the oldest version we support, this was " + version);
     				}
     				String greclipseVersion;
    -				if (eVersion >= 18) {
    +				if (eVersion >= 28) {
    +					greclipseVersion = "5." + (eVersion - 28) + ".0";
    +				} else if (eVersion >= 18) {
     					greclipseVersion = "4." + (eVersion - 18) + ".0";
     				} else {
     					greclipseVersion = "3." + (eVersion - 8) + ".0";
    
    From 74d840dc06f8e10cc622cf6b0bd1799e7aa91860 Mon Sep 17 00:00:00 2001
    From: jochenberger 
    Date: Thu, 3 Aug 2023 08:08:51 +0200
    Subject: [PATCH 0859/1120] Update CHANGES.md
    
    ---
     CHANGES.md | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 2b60913d67..c64220d445 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
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))  
     ### Fixed
     * Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756))
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    
    From effba12acd62aebb8ed66eaed3067289aa556893 Mon Sep 17 00:00:00 2001
    From: jochenberger 
    Date: Thu, 3 Aug 2023 08:09:11 +0200
    Subject: [PATCH 0860/1120] Update CHANGES.md
    
    ---
     plugin-gradle/CHANGES.md | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index b21debb36f..4fef72db7e 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ## [Unreleased]
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))  
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    
    From 4c568b4f1da656771e5b95d6d77e74d3eedb5d0d Mon Sep 17 00:00:00 2001
    From: jochenberger 
    Date: Thu, 3 Aug 2023 08:09:45 +0200
    Subject: [PATCH 0861/1120] Update CHANGES.md
    
    ---
     plugin-maven/CHANGES.md | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index bab8fca7b3..e4f3441357 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ## [Unreleased]
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))  
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    
    From d1c663a7ad83e1c9b6a2df0e5bf10f2f8053035d Mon Sep 17 00:00:00 2001
    From: jochenberger 
    Date: Thu, 3 Aug 2023 08:18:12 +0200
    Subject: [PATCH 0862/1120] Fix formatting
    
    ---
     CHANGES.md | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index c64220d445..566d13cf94 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -12,7 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ## [Unreleased]
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    -* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))  
    +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))
     ### Fixed
     * Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756))
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    
    From 4c48360ef0b02af8494ea06ac47d382d259fd10e Mon Sep 17 00:00:00 2001
    From: jochenberger 
    Date: Thu, 3 Aug 2023 08:18:31 +0200
    Subject: [PATCH 0863/1120] Fix formatting
    
    ---
     plugin-gradle/CHANGES.md | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 4fef72db7e..bef3d961f8 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ## [Unreleased]
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    -* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))  
    +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    
    From 413cac88aa17a435ed55d1de89739fcfc6968e65 Mon Sep 17 00:00:00 2001
    From: jochenberger 
    Date: Thu, 3 Aug 2023 08:18:49 +0200
    Subject: [PATCH 0864/1120] Fix formatting
    
    ---
     plugin-maven/CHANGES.md | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index e4f3441357..d0977c05bf 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ## [Unreleased]
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    -* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))  
    +* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    
    From 595cecdb97437e3b7440ac1ec9cab2c7567c1c12 Mon Sep 17 00:00:00 2001
    From: Tyler Bertrand 
    Date: Tue, 1 Aug 2023 19:54:44 -0500
    Subject: [PATCH 0865/1120] Utilize providers for line endings
    
    This way the external git processes are launched at execution time and not during configuration
    ---
     .../com/diffplug/gradle/spotless/FormatExtension.java    | 4 +++-
     .../java/com/diffplug/gradle/spotless/SpotlessTask.java  | 9 +++++----
     .../gradle/spotless/DiffMessageFormatterTest.java        | 4 ++--
     .../com/diffplug/gradle/spotless/FormatTaskTest.java     | 2 +-
     .../com/diffplug/gradle/spotless/PaddedCellTaskTest.java | 2 +-
     5 files changed, 12 insertions(+), 9 deletions(-)
    
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    index e28ec13dcd..7a62f8cabf 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    @@ -40,6 +40,7 @@
     import org.gradle.api.GradleException;
     import org.gradle.api.Project;
     import org.gradle.api.file.ConfigurableFileTree;
    +import org.gradle.api.file.Directory;
     import org.gradle.api.file.FileCollection;
     import org.gradle.api.plugins.BasePlugin;
     import org.gradle.api.tasks.TaskProvider;
    @@ -925,7 +926,8 @@ protected void setupTask(SpotlessTask task) {
     			steps.replaceAll(formatterStep -> formatterStep.filterByContent(OnMatch.EXCLUDE, targetExcludeContentPattern));
     		}
     		task.setSteps(steps);
    -		task.setLineEndingsPolicy(getLineEndings().createPolicy(getProject().getProjectDir(), () -> totalTarget));
    +		Directory projectDir = getProject().getLayout().getProjectDirectory();
    +		task.setLineEndingsPolicy(getProject().provider(() -> getLineEndings().createPolicy(projectDir.getAsFile(), () -> totalTarget)));
     		spotless.getRegisterDependenciesTask().hookSubprojectTask(task);
     		task.setupRatchet(getRatchetFrom() != null ? getRatchetFrom() : "");
     	}
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java
    index c23cea0845..2af9a80b7a 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java
    @@ -28,6 +28,7 @@
     import org.gradle.api.file.DirectoryProperty;
     import org.gradle.api.file.FileCollection;
     import org.gradle.api.provider.Property;
    +import org.gradle.api.provider.Provider;
     import org.gradle.api.tasks.Input;
     import org.gradle.api.tasks.InputFiles;
     import org.gradle.api.tasks.Internal;
    @@ -64,14 +65,14 @@ public void setEncoding(String encoding) {
     		this.encoding = Objects.requireNonNull(encoding);
     	}
     
    -	protected final LiveCache lineEndingsPolicy = createLive("lineEndingsPolicy");
    +	protected final LiveCache> lineEndingsPolicy = createLive("lineEndingsPolicy");
     
     	@Input
    -	public LineEnding.Policy getLineEndingsPolicy() {
    +	public Provider getLineEndingsPolicy() {
     		return lineEndingsPolicy.get();
     	}
     
    -	public void setLineEndingsPolicy(LineEnding.Policy lineEndingsPolicy) {
    +	public void setLineEndingsPolicy(Provider lineEndingsPolicy) {
     		this.lineEndingsPolicy.set(lineEndingsPolicy);
     	}
     
    @@ -185,7 +186,7 @@ String formatName() {
     	Formatter buildFormatter() {
     		return Formatter.builder()
     				.name(formatName())
    -				.lineEndingsPolicy(lineEndingsPolicy.get())
    +				.lineEndingsPolicy(lineEndingsPolicy.get().get())
     				.encoding(Charset.forName(encoding))
     				.rootDir(getProjectDir().get().getAsFile().toPath())
     				.steps(steps.get())
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java
    index ef72043a47..c564664f10 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java
    @@ -62,7 +62,7 @@ public BuildServiceParameters.None getParameters() {
     		private SpotlessTaskImpl createFormatTask(String name) {
     			SpotlessTaskImpl task = project.getTasks().create("spotless" + SpotlessPlugin.capitalize(name), SpotlessTaskImpl.class);
     			task.init(taskService);
    -			task.setLineEndingsPolicy(LineEnding.UNIX.createPolicy());
    +			task.setLineEndingsPolicy(project.provider(LineEnding.UNIX::createPolicy));
     			task.setTarget(Collections.singletonList(file));
     			return task;
     		}
    @@ -100,7 +100,7 @@ private Bundle create(File... files) throws IOException {
     
     	private Bundle create(List files) throws IOException {
     		Bundle bundle = new Bundle("underTest");
    -		bundle.task.setLineEndingsPolicy(LineEnding.UNIX.createPolicy());
    +		bundle.task.setLineEndingsPolicy(bundle.project.provider(LineEnding.UNIX::createPolicy));
     		bundle.task.setTarget(files);
     		return bundle;
     	}
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java
    index 8985cd7a14..c4c055c799 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java
    @@ -35,7 +35,7 @@ class FormatTaskTest extends ResourceHarness {
     	void createTask() {
     		Project project = TestProvisioner.gradleProject(rootFolder());
     		spotlessTask = project.getTasks().create("spotlessTaskUnderTest", SpotlessTaskImpl.class);
    -		spotlessTask.setLineEndingsPolicy(LineEnding.UNIX.createPolicy());
    +		spotlessTask.setLineEndingsPolicy(project.provider(LineEnding.UNIX::createPolicy));
     		spotlessTask.init(GradleIntegrationHarness.providerOf(new SpotlessTaskService() {
     			@Override
     			public BuildServiceParameters.None getParameters() {
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java
    index bc7a2fdc96..db55077d00 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java
    @@ -66,7 +66,7 @@ private SpotlessTaskImpl createFormatTask(String name, FormatterStep step) {
     			SpotlessTaskImpl task = project.getTasks().create("spotless" + SpotlessPlugin.capitalize(name), SpotlessTaskImpl.class);
     			task.init(taskService);
     			task.addStep(step);
    -			task.setLineEndingsPolicy(LineEnding.UNIX.createPolicy());
    +			task.setLineEndingsPolicy(project.provider(LineEnding.UNIX::createPolicy));
     			task.setTarget(Collections.singletonList(file));
     			return task;
     		}
    
    From 2c33cd319b73f1aa5b86cef2414ebd6656f8f6f1 Mon Sep 17 00:00:00 2001
    From: Tyler Bertrand 
    Date: Wed, 2 Aug 2023 15:29:22 -0500
    Subject: [PATCH 0866/1120] Update plugin-gradle changelog
    
    ---
     plugin-gradle/CHANGES.md | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index b21debb36f..5ffc7912ba 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -8,6 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    +* Fix configuration cache failure when using LineEnding.GIT_ATTRIBUTES ([#1644](https://github.com/diffplug/spotless/issues/1644))
     ### Changes
     * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
     * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
    
    From 35be272b300d9a3a4a939b706728050cbf1b9c69 Mon Sep 17 00:00:00 2001
    From: Tyler Bertrand 
    Date: Thu, 3 Aug 2023 20:17:56 -0500
    Subject: [PATCH 0867/1120] spotlessApply
    
    ---
     .../com/diffplug/gradle/spotless/DiffMessageFormatterTest.java  | 2 +-
     .../test/java/com/diffplug/gradle/spotless/FormatTaskTest.java  | 2 +-
     .../java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java   | 2 +-
     3 files changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java
    index c564664f10..bc556ac06e 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2016-2022 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.
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java
    index c4c055c799..ddd813468d 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FormatTaskTest.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.
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java
    index db55077d00..4fe78d884d 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PaddedCellTaskTest.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.
    
    From 14e4e62aa76768e8d9110478731668fe73dec843 Mon Sep 17 00:00:00 2001
    From: jochenberger 
    Date: Fri, 4 Aug 2023 07:12:36 +0200
    Subject: [PATCH 0868/1120] Update default to 4.28
    
    ---
     .../diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java  | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java
    index 0d6287caea..b79918d555 100644
    --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java
    +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java
    @@ -32,7 +32,7 @@ public final class GrEclipseFormatterStep {
     	private GrEclipseFormatterStep() {}
     
     	private static final String NAME = "eclipse groovy formatter";
    -	private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26").add(17, "4.27");
    +	private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26").add(17, "4.28");
     
     	public static String defaultVersion() {
     		return JVM_SUPPORT.getRecommendedFormatterVersion();
    
    From 696a3c628117aca1608ebbf111768ba0411a4b0f Mon Sep 17 00:00:00 2001
    From: Simon Le Bras 
    Date: Tue, 8 Aug 2023 12:09:53 +0200
    Subject: [PATCH 0869/1120] Fix configuration cache issue with BufStep
    
    ---
     .../diffplug/spotless/protobuf/BufStep.java   | 30 +++++++++++--------
     1 file changed, 17 insertions(+), 13 deletions(-)
    
    diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    index c9b9efa543..acddff85cf 100644
    --- a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    @@ -21,6 +21,7 @@
     import java.nio.charset.StandardCharsets;
     import java.util.Arrays;
     import java.util.List;
    +import java.util.Objects;
     import java.util.regex.Pattern;
     
     import javax.annotation.Nullable;
    @@ -61,13 +62,12 @@ public FormatterStep create() {
     		return FormatterStep.createLazy(name(), this::createState, State::toFunc);
     	}
     
    -	private State createState() throws IOException, InterruptedException {
    +	private State createState() {
     		String instructions = "https://docs.buf.build/installation";
    -		String exeAbsPath = ForeignExe.nameAndVersion("buf", version)
    -				.pathToExe(pathToExe)
    -				.versionRegex(Pattern.compile("(\\S*)"))
    -				.fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}")
    -				.confirmVersionAndGetAbsolutePath();
    +		ForeignExe exeAbsPath = ForeignExe.nameAndVersion("buf", version)
    +			.pathToExe(pathToExe)
    +			.versionRegex(Pattern.compile("(\\S*)"))
    +			.fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}");
     		return new State(this, exeAbsPath);
     	}
     
    @@ -76,19 +76,23 @@ static class State implements Serializable {
     		private static final long serialVersionUID = -1825662356883926318L;
     		// used for up-to-date checks and caching
     		final String version;
    +		final transient ForeignExe exe;
     		// used for executing
    -		final transient List args;
    +		private transient @Nullable List args;
     
    -		State(BufStep step, String exeAbsPath) {
    +		State(BufStep step, ForeignExe exeAbsPath) {
     			this.version = step.version;
    -			this.args = Arrays.asList(exeAbsPath, "format");
    +			this.exe = Objects.requireNonNull(exeAbsPath);
     		}
     
     		String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException {
    -			String[] processArgs = args.toArray(new String[args.size() + 1]);
    -			// add an argument to the end
    -			processArgs[args.size()] = file.getAbsolutePath();
    -			return runner.exec(input.getBytes(StandardCharsets.UTF_8), processArgs).assertExitZero(StandardCharsets.UTF_8);
    +			if (args == null) {
    +				args = Arrays.asList(
    +					exe.confirmVersionAndGetAbsolutePath(),
    +					"format",
    +					file.getAbsolutePath());
    +			}
    +			return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8);
     		}
     
     		FormatterFunc.Closeable toFunc() {
    
    From 7878351838617e58959df3b47528a77f17efd4fa Mon Sep 17 00:00:00 2001
    From: Simon Le Bras 
    Date: Tue, 8 Aug 2023 12:20:17 +0200
    Subject: [PATCH 0870/1120] Update CHANGES.md
    
    ---
     plugin-gradle/CHANGES.md | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 5ffc7912ba..907f1a1cb0 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     * Fix configuration cache failure when using LineEnding.GIT_ATTRIBUTES ([#1644](https://github.com/diffplug/spotless/issues/1644))
    +* Fix configuration cache failure when formatting proto files with Buf. ([#1779]https://github.com/diffplug/spotless/pull/1779))
     ### Changes
     * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
     * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
    
    From 19f68d6763969e289591a82c353b3638f1c40210 Mon Sep 17 00:00:00 2001
    From: Ned Twigg 
    Date: Tue, 8 Aug 2023 09:11:17 -0700
    Subject: [PATCH 0871/1120] spotlessApply
    
    ---
     .../java/com/diffplug/spotless/protobuf/BufStep.java | 12 ++++++------
     1 file changed, 6 insertions(+), 6 deletions(-)
    
    diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    index acddff85cf..a5a6a6cdef 100644
    --- a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
    @@ -65,9 +65,9 @@ public FormatterStep create() {
     	private State createState() {
     		String instructions = "https://docs.buf.build/installation";
     		ForeignExe exeAbsPath = ForeignExe.nameAndVersion("buf", version)
    -			.pathToExe(pathToExe)
    -			.versionRegex(Pattern.compile("(\\S*)"))
    -			.fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}");
    +				.pathToExe(pathToExe)
    +				.versionRegex(Pattern.compile("(\\S*)"))
    +				.fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}");
     		return new State(this, exeAbsPath);
     	}
     
    @@ -88,9 +88,9 @@ static class State implements Serializable {
     		String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException {
     			if (args == null) {
     				args = Arrays.asList(
    -					exe.confirmVersionAndGetAbsolutePath(),
    -					"format",
    -					file.getAbsolutePath());
    +						exe.confirmVersionAndGetAbsolutePath(),
    +						"format",
    +						file.getAbsolutePath());
     			}
     			return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8);
     		}
    
    From 012c13569c101086137cee96ac2ec4e5c5398749 Mon Sep 17 00:00:00 2001
    From: Goooler 
    Date: Wed, 9 Aug 2023 09:22:34 +0800
    Subject: [PATCH 0872/1120] Support GJF own import order
    
    ---
     CHANGES.md                                    |  1 +
     .../java/GoogleJavaFormatFormatterFunc.java   | 12 ++++++----
     .../spotless/java/GoogleJavaFormatStep.java   | 23 ++++++++++++++-----
     plugin-gradle/CHANGES.md                      |  1 +
     plugin-gradle/README.md                       |  2 +-
     .../gradle/spotless/JavaExtension.java        |  9 +++++++-
     plugin-maven/CHANGES.md                       |  1 +
     .../spotless/maven/java/GoogleJavaFormat.java |  8 +++++--
     8 files changed, 42 insertions(+), 15 deletions(-)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 2b60913d67..81af46a526 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
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    +* Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
     ### Fixed
     * Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756))
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    diff --git a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java
    index 87e086b440..8c6aa42575 100644
    --- a/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java
    +++ b/lib/src/googleJavaFormat/java/com/diffplug/spotless/glue/java/GoogleJavaFormatFormatterFunc.java
    @@ -29,6 +29,8 @@
     
     import com.diffplug.spotless.FormatterFunc;
     
    +// Used via reflection by the Gradle plugin.
    +@SuppressWarnings("unused")
     public class GoogleJavaFormatFormatterFunc implements FormatterFunc {
     
     	@Nonnull
    @@ -42,10 +44,13 @@ public class GoogleJavaFormatFormatterFunc implements FormatterFunc {
     
     	private final boolean reflowStrings;
     
    -	public GoogleJavaFormatFormatterFunc(@Nonnull String version, @Nonnull String style, boolean reflowStrings) {
    +	private final boolean reorderImports;
    +
    +	public GoogleJavaFormatFormatterFunc(@Nonnull String version, @Nonnull String style, boolean reflowStrings, boolean reorderImports) {
     		this.version = Objects.requireNonNull(version);
     		this.formatterStyle = Style.valueOf(Objects.requireNonNull(style));
     		this.reflowStrings = reflowStrings;
    +		this.reorderImports = reorderImports;
     
     		this.formatter = new Formatter(JavaFormatterOptions.builder()
     				.style(formatterStyle)
    @@ -57,10 +62,7 @@ public GoogleJavaFormatFormatterFunc(@Nonnull String version, @Nonnull String st
     	public String apply(@Nonnull String input) throws Exception {
     		String formatted = formatter.formatSource(input);
     		String removedUnused = RemoveUnusedImports.removeUnusedImports(formatted);
    -		// Issue #1679: we used to call ImportOrderer.reorderImports(String) here, but that is deprecated.
    -		// Replacing the call with (the correct) reorderImports(String, Style) causes issues for Style.AOSP,
    -		// so we force the style to GOOGLE for now (which is what the deprecated method did)
    -		String sortedImports = ImportOrderer.reorderImports(removedUnused, Style.GOOGLE);
    +		String sortedImports = ImportOrderer.reorderImports(removedUnused, reorderImports ? formatterStyle : Style.GOOGLE);
     		return reflowLongStrings(sortedImports);
     	}
     
    diff --git a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java
    index 321d05420f..a0f796af4d 100644
    --- a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java
    +++ b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java
    @@ -32,6 +32,7 @@ private GoogleJavaFormatStep() {}
     
     	private static final String DEFAULT_STYLE = "GOOGLE";
     	private static final boolean DEFAULT_REFLOW_LONG_STRINGS = false;
    +	private static final boolean DEFAULT_REORDER_IMPORTS = false;
     	static final String NAME = "google-java-format";
     	static final String MAVEN_COORDINATE = "com.google.googlejavaformat:google-java-format";
     
    @@ -55,8 +56,12 @@ public static FormatterStep create(String version, String style, Provisioner pro
     		return create(MAVEN_COORDINATE, version, style, provisioner, reflowLongStrings);
     	}
     
    -	/** Creates a step which formats everything - groupArtifact, code, import order, and unused imports - and optionally reflows long strings. */
     	public static FormatterStep create(String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings) {
    +		return create(groupArtifact, version, style, provisioner, reflowLongStrings, false);
    +	}
    +
    +	/** Creates a step which formats everything - groupArtifact, code, import order, and unused imports - and optionally reflows long strings. */
    +	public static FormatterStep create(String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings, boolean reorderImports) {
     		Objects.requireNonNull(groupArtifact, "groupArtifact");
     		if (groupArtifact.chars().filter(ch -> ch == ':').count() != 1) {
     			throw new IllegalArgumentException("groupArtifact must be in the form 'groupId:artifactId'");
    @@ -65,7 +70,7 @@ public static FormatterStep create(String groupArtifact, String version, String
     		Objects.requireNonNull(style, "style");
     		Objects.requireNonNull(provisioner, "provisioner");
     		return FormatterStep.createLazy(NAME,
    -				() -> new State(NAME, groupArtifact, version, style, provisioner, reflowLongStrings),
    +				() -> new State(NAME, groupArtifact, version, style, provisioner, reflowLongStrings, reorderImports),
     				State::createFormat);
     	}
     
    @@ -92,6 +97,10 @@ public static boolean defaultReflowLongStrings() {
     		return DEFAULT_REFLOW_LONG_STRINGS;
     	}
     
    +	public static boolean defaultReorderImports() {
    +		return DEFAULT_REORDER_IMPORTS;
    +	}
    +
     	static final class State implements Serializable {
     		private static final long serialVersionUID = 1L;
     
    @@ -101,6 +110,7 @@ static final class State implements Serializable {
     		final String version;
     		final String style;
     		final boolean reflowLongStrings;
    +		final boolean reorderImports;
     
     		State(String stepName, String version, Provisioner provisioner) throws Exception {
     			this(stepName, version, DEFAULT_STYLE, provisioner);
    @@ -111,10 +121,10 @@ static final class State implements Serializable {
     		}
     
     		State(String stepName, String version, String style, Provisioner provisioner, boolean reflowLongStrings) throws Exception {
    -			this(stepName, MAVEN_COORDINATE, version, style, provisioner, reflowLongStrings);
    +			this(stepName, MAVEN_COORDINATE, version, style, provisioner, reflowLongStrings, DEFAULT_REORDER_IMPORTS);
     		}
     
    -		State(String stepName, String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings) throws Exception {
    +		State(String stepName, String groupArtifact, String version, String style, Provisioner provisioner, boolean reflowLongStrings, boolean reorderImports) throws Exception {
     			JVM_SUPPORT.assertFormatterSupported(version);
     			ModuleHelper.doOpenInternalPackagesIfRequired();
     			this.jarState = JarState.from(groupArtifact + ":" + version, provisioner);
    @@ -122,13 +132,14 @@ static final class State implements Serializable {
     			this.version = version;
     			this.style = style;
     			this.reflowLongStrings = reflowLongStrings;
    +			this.reorderImports = reorderImports;
     		}
     
     		FormatterFunc createFormat() throws Exception {
     			final ClassLoader classLoader = jarState.getClassLoader();
     			Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.java.GoogleJavaFormatFormatterFunc");
    -			Constructor constructor = formatterFunc.getConstructor(String.class, String.class, boolean.class);
    -			FormatterFunc googleJavaFormatFormatterFunc = (FormatterFunc) constructor.newInstance(version, style, reflowLongStrings);
    +			Constructor constructor = formatterFunc.getConstructor(String.class, String.class, boolean.class, boolean.class);
    +			FormatterFunc googleJavaFormatFormatterFunc = (FormatterFunc) constructor.newInstance(version, style, reflowLongStrings, reorderImports);
     
     			return JVM_SUPPORT.suggestLaterVersionOnError(version, googleJavaFormatFormatterFunc);
     		}
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 907f1a1cb0..1ce2f06a42 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ## [Unreleased]
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    +* Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 325093796e..dbc61207e5 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -206,7 +206,7 @@ spotless {
         // optional: you can specify a specific version (>= 1.8) and/or switch to AOSP style
         //   and/or reflow long strings
         //   and/or use custom group artifact (you probably don't need this)
    -    googleJavaFormat('1.8').aosp().reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
    +    googleJavaFormat('1.8').aosp().reflowLongStrings().reorderImports(false).groupArtifact('com.google.googlejavaformat:google-java-format')
     ```
     
     ### palantir-java-format
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java
    index 13fe674168..fcd1a0d105 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java
    @@ -173,6 +173,7 @@ public class GoogleJavaFormatConfig {
     		String groupArtifact;
     		String style;
     		boolean reflowLongStrings;
    +		boolean reorderImports;
     
     		GoogleJavaFormatConfig(String version) {
     			this.version = Objects.requireNonNull(version);
    @@ -207,13 +208,19 @@ public GoogleJavaFormatConfig reflowLongStrings(boolean reflowLongStrings) {
     			return this;
     		}
     
    +		public GoogleJavaFormatConfig reorderImports(boolean reorderImports) {
    +			this.reorderImports = reorderImports;
    +			return this;
    +		}
    +
     		private FormatterStep createStep() {
     			return GoogleJavaFormatStep.create(
     					groupArtifact,
     					version,
     					style,
     					provisioner(),
    -					reflowLongStrings);
    +					reflowLongStrings,
    +					reorderImports);
     		}
     	}
     
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index bab8fca7b3..65a557b14f 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ## [Unreleased]
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    +* Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/GoogleJavaFormat.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/GoogleJavaFormat.java
    index 3597e84e25..98296beb5f 100644
    --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/GoogleJavaFormat.java
    +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/GoogleJavaFormat.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.
    @@ -35,12 +35,16 @@ public class GoogleJavaFormat implements FormatterStepFactory {
     	@Parameter
     	private Boolean reflowLongStrings;
     
    +	@Parameter
    +	private Boolean reorderImports;
    +
     	@Override
     	public FormatterStep newFormatterStep(FormatterStepConfig config) {
     		String groupArtifact = this.groupArtifact != null ? this.groupArtifact : GoogleJavaFormatStep.defaultGroupArtifact();
     		String version = this.version != null ? this.version : GoogleJavaFormatStep.defaultVersion();
     		String style = this.style != null ? this.style : GoogleJavaFormatStep.defaultStyle();
     		boolean reflowLongStrings = this.reflowLongStrings != null ? this.reflowLongStrings : GoogleJavaFormatStep.defaultReflowLongStrings();
    -		return GoogleJavaFormatStep.create(groupArtifact, version, style, config.getProvisioner(), reflowLongStrings);
    +		boolean reorderImports = this.reorderImports != null ? this.reorderImports : GoogleJavaFormatStep.defaultReorderImports();
    +		return GoogleJavaFormatStep.create(groupArtifact, version, style, config.getProvisioner(), reflowLongStrings, reorderImports);
     	}
     }
    
    From 4dd5b5fb616e82cb09c329458edaee019219b092 Mon Sep 17 00:00:00 2001
    From: Dimitrii Lipiridi 
    Date: Wed, 16 Aug 2023 23:10:53 +0300
    Subject: [PATCH 0873/1120] feat: Introduce "spotlessIdeHook" argument for
     maven plugin
    
    ---
     plugin-maven/CHANGES.md                          |  1 +
     plugin-maven/README.md                           | 15 ++++++++++++---
     .../spotless/maven/AbstractSpotlessMojo.java     | 16 ++++++++++++++++
     3 files changed, 29 insertions(+), 3 deletions(-)
    
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index 65a557b14f..62d0f8c500 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 (
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
    +* `-DspotlessIdeHook` provides the ability to apply Spotless exclusively to a specified file. It accepts the absolute path of the file.
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index cb770099ac..aa324627f9 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -1601,14 +1601,23 @@ By default, `spotless:check` is bound to the `verify` phase.  You might want to
     
     ## Can I apply Spotless to specific files?
     
    -You can target specific files by setting the `spotlessFiles` project property to a comma-separated list of file patterns:
    +There are two options:
     
    +### Pattern
    +You can target specific files by setting the `spotlessFiles` project property to a comma-separated list of file patterns:
     ```
    -cmd> mvn spotless:apply -DspotlessFiles=my/file/pattern.java,more/generic/.*-pattern.java
    +cmd> mvn spotless:apply -DspotlessFiles="my/file/pattern\.java, more/generic/.*-pattern\.java"
     ```
    -
     The patterns are matched using `String#matches(String)` against the absolute file path.
     
    +### IDE Hook
    +You can specify a single file by providing the `spotlessIdeHook` argument, which accepts the absolute path of the file.
    +```
    +cmd> mvn spotless:apply -DspotlessIdeHook="C:\my-project\src\main\java\com\example\Application.java"
    +
    +```
    +This option ignores the ratchetFrom property.
    +
     
     
     ## Example configurations (from real-world projects)
    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 2c295cef27..ea66e921e5 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
    @@ -187,6 +187,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {
     	@Parameter(property = "spotlessFiles")
     	private String filePatterns;
     
    +	@Parameter(property = "spotlessIdeHook")
    +	private String spotlessIdeHook;
    +
     	@Parameter(property = LicenseHeaderStep.spotlessSetLicenseHeaderYearsFromGitHistory)
     	private String setLicenseHeaderYearsFromGitHistory;
     
    @@ -251,6 +254,10 @@ private boolean shouldSkip() {
     	}
     
     	private List collectFiles(FormatterFactory formatterFactory, FormatterConfig config) {
    +		if (!(spotlessIdeHook == null || spotlessIdeHook.isEmpty())) {
    +			return fetchFileFromIdeHook();
    +		}
    +
     		Optional ratchetFrom = formatterFactory.ratchetFrom(config);
     		try {
     			final List files;
    @@ -279,6 +286,15 @@ private List collectFiles(FormatterFactory formatterFactory, FormatterConf
     		}
     	}
     
    +	private List fetchFileFromIdeHook() {
    +		File file = new File(spotlessIdeHook);
    +		if (!file.isAbsolute()) {
    +			throw new PluginException("Argument passed to spotlessIdeHook must be an absolute path");
    +		}
    +
    +		return List.of(file);
    +	}
    +
     	private List collectFilesFromGit(FormatterFactory formatterFactory, String ratchetFrom) {
     		MatchPatterns includePatterns = MatchPatterns.from(
     				withNormalizedFileSeparators(getIncludes(formatterFactory)));
    
    From a76401b9ce82340498a20bb36065fcc7f691046b Mon Sep 17 00:00:00 2001
    From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
    Date: Thu, 17 Aug 2023 07:43:38 +0000
    Subject: [PATCH 0874/1120] chore(deps): update dependency gradle to v8
    
    ---
     gradle/wrapper/gradle-wrapper.jar        | Bin 61624 -> 63721 bytes
     gradle/wrapper/gradle-wrapper.properties |   3 ++-
     gradlew                                  |  19 ++++++++++++-------
     3 files changed, 14 insertions(+), 8 deletions(-)
    
    diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
    index afba109285af78dbd2a1d187e33ac4f87c76e392..7f93135c49b765f8051ef9d0a6055ff8e46073d8 100755
    GIT binary patch
    delta 41204
    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
    
    delta 39055
    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 /dev/null && pwd -P ) || exit
     
     # Use the maximum available, or set MAX_FD != -1 to use that value.
     MAX_FD=maximum
    @@ -133,10 +131,13 @@ location of your Java installation."
         fi
     else
         JAVACMD=java
    -    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
    +    if ! command -v java >/dev/null 2>&1
    +    then
    +        die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
     
     Please set the JAVA_HOME variable in your environment to match the
     location of your Java installation."
    +    fi
     fi
     
     # Increase the maximum file descriptors if we can.
    @@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
         case $MAX_FD in #(
           max*)
             # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
    -        # shellcheck disable=SC3045 
    +        # shellcheck disable=SC3045
             MAX_FD=$( ulimit -H -n ) ||
                 warn "Could not query maximum file descriptor limit"
         esac
    @@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
           '' | soft) :;; #(
           *)
             # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
    -        # shellcheck disable=SC3045 
    +        # shellcheck disable=SC3045
             ulimit -n "$MAX_FD" ||
                 warn "Could not set maximum file descriptor limit to $MAX_FD"
         esac
    @@ -197,6 +198,10 @@ if "$cygwin" || "$msys" ; then
         done
     fi
     
    +
    +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
    +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
    +
     # Collect all arguments for the java command;
     #   * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
     #     shell script including quotes and variable substitutions, so put them in
    
    From b83d1de4dd231eba868919d2c9662ddbdad51f06 Mon Sep 17 00:00:00 2001
    From: Dimitrii Lipiridi 
    Date: Thu, 17 Aug 2023 19:12:08 +0300
    Subject: [PATCH 0875/1120] fix: Update example of spotlessFiles argument
    
    ---
     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 aa324627f9..956dbf385e 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -1606,7 +1606,7 @@ There are two options:
     ### Pattern
     You can target specific files by setting the `spotlessFiles` project property to a comma-separated list of file patterns:
     ```
    -cmd> mvn spotless:apply -DspotlessFiles="my/file/pattern\.java, more/generic/.*-pattern\.java"
    +cmd> mvn spotless:apply -DspotlessFiles="src.main.java.com.example.*, .+Config.*\.java"
     ```
     The patterns are matched using `String#matches(String)` against the absolute file path.
     
    
    From cb5cb6adc6306d3673a64370f4f1920d6626cde6 Mon Sep 17 00:00:00 2001
    From: Dimitrii Lipiridi 
    Date: Thu, 17 Aug 2023 21:28:23 +0300
    Subject: [PATCH 0876/1120] feat: Add issue link to CHANGES.md
    
    ---
     plugin-maven/CHANGES.md | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index 62d0f8c500..972e0bf6e2 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 (
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
    -* `-DspotlessIdeHook` provides the ability to apply Spotless exclusively to a specified file. It accepts the absolute path of the file.
    +* Add `-DspotlessIdeHook` that provides the ability to apply Spotless exclusively to a specified file. It accepts the absolute path of the file. ([#200](https://github.com/diffplug/spotless/issues/200))
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    
    From 1d6b717c44f8d25e3b33936e280a06428c143a55 Mon Sep 17 00:00:00 2001
    From: Dimitrii Lipiridi 
    Date: Sun, 20 Aug 2023 21:31:08 +0300
    Subject: [PATCH 0877/1120] feat: Prepare Maven's IDE hook
    
    ---
     .../gradle/spotless/FormatExtension.java      |  2 +-
     plugin-maven/build.gradle                     |  1 +
     .../spotless/maven/AbstractSpotlessMojo.java  | 36 +++-----
     .../com/diffplug/spotless/maven/IdeHook.java  | 87 +++++++++++++++++++
     .../spotless/maven/SpotlessApplyMojo.java     | 31 +++++++
     5 files changed, 132 insertions(+), 25 deletions(-)
     create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/IdeHook.java
    
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    index 7a62f8cabf..0e4e4395c3 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    @@ -124,7 +124,7 @@ public void setEncoding(String name) {
     
     	/** @see #setRatchetFrom(String) */
     	public String getRatchetFrom() {
    -		return ratchetFrom == RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL ? spotless.getRatchetFrom() : ratchetFrom;
    +		return ratchetFrom.equals(RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL) ? spotless.getRatchetFrom() : ratchetFrom;
     	}
     
     	/**
    diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle
    index 7cfb38c2e9..74a76ddcb1 100644
    --- a/plugin-maven/build.gradle
    +++ b/plugin-maven/build.gradle
    @@ -39,6 +39,7 @@ dependencies {
     	compileOnly "org.eclipse.aether:aether-api:${VER_ECLIPSE_AETHER}"
     
     	implementation "com.diffplug.durian:durian-core:${VER_DURIAN}"
    +	implementation "com.diffplug.durian:durian-io:${VER_DURIAN}"
     	implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}"
     	implementation("org.codehaus.plexus:plexus-resources:${VER_PLEXUS_RESOURCES}")
     	implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}"
    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 ea66e921e5..825859716f 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
    @@ -187,9 +187,6 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo {
     	@Parameter(property = "spotlessFiles")
     	private String filePatterns;
     
    -	@Parameter(property = "spotlessIdeHook")
    -	private String spotlessIdeHook;
    -
     	@Parameter(property = LicenseHeaderStep.spotlessSetLicenseHeaderYearsFromGitHistory)
     	private String setLicenseHeaderYearsFromGitHistory;
     
    @@ -254,10 +251,6 @@ private boolean shouldSkip() {
     	}
     
     	private List collectFiles(FormatterFactory formatterFactory, FormatterConfig config) {
    -		if (!(spotlessIdeHook == null || spotlessIdeHook.isEmpty())) {
    -			return fetchFileFromIdeHook();
    -		}
    -
     		Optional ratchetFrom = formatterFactory.ratchetFrom(config);
     		try {
     			final List files;
    @@ -271,30 +264,21 @@ private List collectFiles(FormatterFactory formatterFactory, FormatterConf
     			}
     			final String[] includePatterns = this.filePatterns.split(",");
     			final List compiledIncludePatterns = Arrays.stream(includePatterns)
    -					.map(Pattern::compile)
    -					.collect(Collectors.toList());
    +				.map(Pattern::compile)
    +				.collect(Collectors.toList());
     			final Predicate shouldInclude = file -> compiledIncludePatterns
    -					.stream()
    -					.anyMatch(filePattern -> filePattern.matcher(file.getAbsolutePath())
    -							.matches());
    +				.stream()
    +				.anyMatch(filePattern -> filePattern.matcher(file.getAbsolutePath())
    +					.matches());
     			return files
    -					.stream()
    -					.filter(shouldInclude)
    -					.collect(toList());
    +				.stream()
    +				.filter(shouldInclude)
    +				.collect(toList());
     		} catch (IOException e) {
     			throw new PluginException("Unable to scan file tree rooted at " + baseDir, e);
     		}
     	}
     
    -	private List fetchFileFromIdeHook() {
    -		File file = new File(spotlessIdeHook);
    -		if (!file.isAbsolute()) {
    -			throw new PluginException("Argument passed to spotlessIdeHook must be an absolute path");
    -		}
    -
    -		return List.of(file);
    -	}
    -
     	private List collectFilesFromGit(FormatterFactory formatterFactory, String ratchetFrom) {
     		MatchPatterns includePatterns = MatchPatterns.from(
     				withNormalizedFileSeparators(getIncludes(formatterFactory)));
    @@ -400,4 +384,8 @@ private UpToDateChecker createUpToDateChecker(Iterable formatters) {
     		}
     		return UpToDateChecker.wrapWithBuildContext(checker, buildContext);
     	}
    +
    +	protected File getBaseDir() {
    +		return baseDir;
    +	}
     }
    diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/IdeHook.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/IdeHook.java
    new file mode 100644
    index 0000000000..dba9bcc547
    --- /dev/null
    +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/IdeHook.java
    @@ -0,0 +1,87 @@
    +/*
    + * 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.spotless.maven;
    +
    +import com.diffplug.common.base.Errors;
    +import com.diffplug.common.io.ByteStreams;
    +import com.diffplug.spotless.Formatter;
    +import com.diffplug.spotless.PaddedCell;
    +
    +import java.io.File;
    +import java.io.IOException;
    +import java.nio.file.Files;
    +import java.util.List;
    +
    +class IdeHook {
    +
    +	private static void dumpIsClean() {
    +		System.err.println("IS CLEAN");
    +	}
    +
    +	static void performHook(Iterable projectFiles, String path, Formatter formatter, File projectDir, String ratchetFrom, boolean spotlessIdeHookUseStdIn, boolean spotlessIdeHookUseStdOut) {
    +		File file = new File(path);
    +		if (!file.isAbsolute()) {
    +			System.err.println("Argument passed to spotlessIdeHook must be an absolute path");
    +			return;
    +		}
    +		if (projectContainsFile(projectFiles, file)) {
    +			try {
    +				if (ratchetFrom != null) {
    +					GitRatchetMaven ratchet = GitRatchetMaven.instance();
    +					if (ratchet.isClean(projectDir, ratchet.rootTreeShaOf(projectDir, ratchetFrom), file)) {
    +						dumpIsClean();
    +						return;
    +					}
    +				}
    +				byte[] bytes;
    +				if (spotlessIdeHookUseStdIn) {
    +					bytes = ByteStreams.toByteArray(System.in);
    +				} else {
    +					bytes = Files.readAllBytes(file.toPath());
    +				}
    +				PaddedCell.DirtyState dirty = PaddedCell.calculateDirtyState(formatter, file, bytes);
    +				if (dirty.isClean()) {
    +					dumpIsClean();
    +				} else if (dirty.didNotConverge()) {
    +					System.err.println("DID NOT CONVERGE");
    +					System.err.println("Run 'spotlessDiagnose' for details https://github.com/diffplug/spotless/blob/main/PADDEDCELL.md");
    +				} else {
    +					System.err.println("IS DIRTY");
    +					if (spotlessIdeHookUseStdOut) {
    +						dirty.writeCanonicalTo(System.out);
    +					} else {
    +						dirty.writeCanonicalTo(file);
    +					}
    +				}
    +			} catch (IOException e) {
    +				e.printStackTrace(System.err);
    +				throw Errors.asRuntime(e);
    +			} finally {
    +				System.err.close();
    +				System.out.close();
    +			}
    +		}
    +	}
    +
    +	private static boolean projectContainsFile(Iterable projectFiles, File file) {
    +		for (File projectFile : projectFiles) {
    +			if (projectFile.equals(file)) {
    +				return true;
    +			}
    +		}
    +		return false;
    +	}
    +}
    diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java
    index 5ebe2885c9..9d5e3f9b14 100644
    --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java
    +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java
    @@ -18,6 +18,8 @@
     import java.io.File;
     import java.io.IOException;
     
    +import java.util.List;
    +
     import org.apache.maven.plugin.MojoExecutionException;
     import org.apache.maven.plugins.annotations.Mojo;
     
    @@ -25,14 +27,30 @@
     import com.diffplug.spotless.PaddedCell;
     import com.diffplug.spotless.maven.incremental.UpToDateChecker;
     
    +import org.apache.maven.plugins.annotations.Parameter;
    +
     /**
      * Performs formatting of all source files according to configured formatters.
      */
     @Mojo(name = AbstractSpotlessMojo.GOAL_APPLY, threadSafe = true)
     public class SpotlessApplyMojo extends AbstractSpotlessMojo {
     
    +	@Parameter(property = "spotlessIdeHook")
    +	private String spotlessIdeHook;
    +
    +	@Parameter(property = "spotlessIdeHookUseStdIn")
    +	private boolean spotlessIdeHookUseStdIn;
    +
    +	@Parameter(property = "spotlessIdeHookUseStdOut")
    +	private boolean spotlessIdeHookUseStdOut;
    +
     	@Override
     	protected void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException {
    +		if(isIdeHook()) {
    +			IdeHook.performHook(files, spotlessIdeHook, formatter, getBaseDir(), null, spotlessIdeHookUseStdIn, spotlessIdeHookUseStdOut);
    +			return;
    +		}
    +
     		ImpactedFilesTracker counter = new ImpactedFilesTracker();
     
     		for (File file : files) {
    @@ -69,4 +87,17 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke
     			getLog().debug(String.format("Spotless.%s has no target files. Examine your ``: https://github.com/diffplug/spotless/tree/main/plugin-maven#quickstart", formatter.getName()));
     		}
     	}
    +
    +	private boolean isIdeHook() {
    +		return !(spotlessIdeHook == null || spotlessIdeHook.isEmpty());
    +	}
    +
    +	private List fetchFileFromIdeHook() {
    +		File file = new File(spotlessIdeHook);
    +		if (!file.isAbsolute()) {
    +			throw new PluginException("Argument passed to spotlessIdeHook must be an absolute path");
    +		}
    +
    +		return List.of(file);
    +	}
     }
    
    From 959fd854c36080caa13123de2089ebcb7396adb4 Mon Sep 17 00:00:00 2001
    From: Goooler 
    Date: Thu, 24 Aug 2023 09:42:44 +0800
    Subject: [PATCH 0878/1120] Check if EditorConfig file exist for Ktlint
    
    ---
     plugin-gradle/CHANGES.md                      |  1 +
     .../gradle/spotless/KotlinExtension.java      | 10 +++++---
     .../gradle/spotless/KotlinExtensionTest.java  | 24 +++++++++++++++++++
     3 files changed, 32 insertions(+), 3 deletions(-)
    
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 1ce2f06a42..27d60e7270 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -6,6 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
    +* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788)
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java
    index f2c3a29d75..27d93717f4 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java
    @@ -85,11 +85,15 @@ public class KotlinFormatExtension {
     			addStep(createStep());
     		}
     
    -		public KotlinFormatExtension setEditorConfigPath(Object editorConfigFile) throws IOException {
    -			if (editorConfigFile == null) {
    +		public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException {
    +			if (editorConfigPath == null) {
     				this.editorConfigPath = null;
     			} else {
    -				this.editorConfigPath = FileSignature.signAsList(getProject().file(editorConfigFile));
    +				File editorConfigFile = getProject().file(editorConfigPath);
    +				if (!editorConfigFile.exists()) {
    +					throw new IllegalArgumentException("EditorConfig file does not exist: " + editorConfigFile);
    +				}
    +				this.editorConfigPath = FileSignature.signAsList(editorConfigFile);
     			}
     			replaceStep(createStep());
     			return this;
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java
    index 10fbe5bd90..98e2259be4 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java
    @@ -15,6 +15,9 @@
      */
     package com.diffplug.gradle.spotless;
     
    +import static org.junit.jupiter.api.Assertions.assertTrue;
    +
    +import java.io.File;
     import java.io.IOException;
     
     import org.junit.jupiter.api.Test;
    @@ -81,6 +84,27 @@ void withExperimentalEditorConfigOverride() throws IOException {
     		assertFile("src/main/kotlin/Main.kt").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean");
     	}
     
    +	@Test
    +	void testWithInvalidEditorConfigFile() throws IOException {
    +		String invalidPath = "invalid/path/to/.editorconfig".replace('/', File.separatorChar);
    +
    +		setFile("build.gradle").toLines(
    +				"plugins {",
    +				"    id 'org.jetbrains.kotlin.jvm' version '1.5.31'",
    +				"    id 'com.diffplug.spotless'",
    +				"}",
    +				"repositories { mavenCentral() }",
    +				"spotless {",
    +				"    kotlin {",
    +				"        ktlint().setEditorConfigPath('" + invalidPath + "')",
    +				"    }",
    +				"}");
    +		setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
    +		String buildOutput = gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput();
    +		assertTrue(buildOutput.contains("EditorConfig file does not exist: "));
    +		assertTrue(buildOutput.contains(invalidPath));
    +	}
    +
     	@Test
     	void testWithHeader() throws IOException {
     		setFile("build.gradle").toLines(
    
    From ca026b868bce06f942f5f984aea279ae012437b2 Mon Sep 17 00:00:00 2001
    From: Dimitrii Lipiridi 
    Date: Thu, 24 Aug 2023 09:52:42 +0300
    Subject: [PATCH 0879/1120] feat: Remove checking ratchetFrom from IDE hook
    
    ---
     .../gradle/spotless/FormatExtension.java      |  2 +-
     .../spotless/maven/AbstractSpotlessMojo.java  | 20 ++---
     .../com/diffplug/spotless/maven/IdeHook.java  | 76 +++++++++----------
     .../spotless/maven/SpotlessApplyMojo.java     | 18 +----
     4 files changed, 48 insertions(+), 68 deletions(-)
    
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    index 0e4e4395c3..7a62f8cabf 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    @@ -124,7 +124,7 @@ public void setEncoding(String name) {
     
     	/** @see #setRatchetFrom(String) */
     	public String getRatchetFrom() {
    -		return ratchetFrom.equals(RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL) ? spotless.getRatchetFrom() : ratchetFrom;
    +		return ratchetFrom == RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL ? spotless.getRatchetFrom() : ratchetFrom;
     	}
     
     	/**
    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 825859716f..2c295cef27 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
    @@ -264,16 +264,16 @@ private List collectFiles(FormatterFactory formatterFactory, FormatterConf
     			}
     			final String[] includePatterns = this.filePatterns.split(",");
     			final List compiledIncludePatterns = Arrays.stream(includePatterns)
    -				.map(Pattern::compile)
    -				.collect(Collectors.toList());
    +					.map(Pattern::compile)
    +					.collect(Collectors.toList());
     			final Predicate shouldInclude = file -> compiledIncludePatterns
    -				.stream()
    -				.anyMatch(filePattern -> filePattern.matcher(file.getAbsolutePath())
    -					.matches());
    +					.stream()
    +					.anyMatch(filePattern -> filePattern.matcher(file.getAbsolutePath())
    +							.matches());
     			return files
    -				.stream()
    -				.filter(shouldInclude)
    -				.collect(toList());
    +					.stream()
    +					.filter(shouldInclude)
    +					.collect(toList());
     		} catch (IOException e) {
     			throw new PluginException("Unable to scan file tree rooted at " + baseDir, e);
     		}
    @@ -384,8 +384,4 @@ private UpToDateChecker createUpToDateChecker(Iterable formatters) {
     		}
     		return UpToDateChecker.wrapWithBuildContext(checker, buildContext);
     	}
    -
    -	protected File getBaseDir() {
    -		return baseDir;
    -	}
     }
    diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/IdeHook.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/IdeHook.java
    index dba9bcc547..0001046871 100644
    --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/IdeHook.java
    +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/IdeHook.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.
    @@ -15,64 +15,60 @@
      */
     package com.diffplug.spotless.maven;
     
    +import java.io.File;
    +import java.io.IOException;
    +import java.nio.file.Files;
    +
     import com.diffplug.common.base.Errors;
     import com.diffplug.common.io.ByteStreams;
     import com.diffplug.spotless.Formatter;
     import com.diffplug.spotless.PaddedCell;
     
    -import java.io.File;
    -import java.io.IOException;
    -import java.nio.file.Files;
    -import java.util.List;
    -
     class IdeHook {
     
     	private static void dumpIsClean() {
     		System.err.println("IS CLEAN");
     	}
     
    -	static void performHook(Iterable projectFiles, String path, Formatter formatter, File projectDir, String ratchetFrom, boolean spotlessIdeHookUseStdIn, boolean spotlessIdeHookUseStdOut) {
    +	//No need to check ratchet (using isClean()) as it is performed in Gradle's IDE hook, since we have already gathered the available git files from ratchet.
    +	static void performHook(Iterable projectFiles, Formatter formatter, String path, boolean spotlessIdeHookUseStdIn, boolean spotlessIdeHookUseStdOut) {
     		File file = new File(path);
     		if (!file.isAbsolute()) {
     			System.err.println("Argument passed to spotlessIdeHook must be an absolute path");
     			return;
     		}
    -		if (projectContainsFile(projectFiles, file)) {
    -			try {
    -				if (ratchetFrom != null) {
    -					GitRatchetMaven ratchet = GitRatchetMaven.instance();
    -					if (ratchet.isClean(projectDir, ratchet.rootTreeShaOf(projectDir, ratchetFrom), file)) {
    -						dumpIsClean();
    -						return;
    -					}
    -				}
    -				byte[] bytes;
    -				if (spotlessIdeHookUseStdIn) {
    -					bytes = ByteStreams.toByteArray(System.in);
    -				} else {
    -					bytes = Files.readAllBytes(file.toPath());
    -				}
    -				PaddedCell.DirtyState dirty = PaddedCell.calculateDirtyState(formatter, file, bytes);
    -				if (dirty.isClean()) {
    -					dumpIsClean();
    -				} else if (dirty.didNotConverge()) {
    -					System.err.println("DID NOT CONVERGE");
    -					System.err.println("Run 'spotlessDiagnose' for details https://github.com/diffplug/spotless/blob/main/PADDEDCELL.md");
    +
    +		if (!projectContainsFile(projectFiles, file)) {
    +			return;
    +		}
    +
    +		try {
    +			byte[] bytes;
    +			if (spotlessIdeHookUseStdIn) {
    +				bytes = ByteStreams.toByteArray(System.in);
    +			} else {
    +				bytes = Files.readAllBytes(file.toPath());
    +			}
    +			PaddedCell.DirtyState dirty = PaddedCell.calculateDirtyState(formatter, file, bytes);
    +			if (dirty.isClean()) {
    +				dumpIsClean();
    +			} else if (dirty.didNotConverge()) {
    +				System.err.println("DID NOT CONVERGE");
    +				System.err.println("See details https://github.com/diffplug/spotless/blob/main/PADDEDCELL.md");
    +			} else {
    +				System.err.println("IS DIRTY");
    +				if (spotlessIdeHookUseStdOut) {
    +					dirty.writeCanonicalTo(System.out);
     				} else {
    -					System.err.println("IS DIRTY");
    -					if (spotlessIdeHookUseStdOut) {
    -						dirty.writeCanonicalTo(System.out);
    -					} else {
    -						dirty.writeCanonicalTo(file);
    -					}
    +					dirty.writeCanonicalTo(file);
     				}
    -			} catch (IOException e) {
    -				e.printStackTrace(System.err);
    -				throw Errors.asRuntime(e);
    -			} finally {
    -				System.err.close();
    -				System.out.close();
     			}
    +		} catch (IOException e) {
    +			e.printStackTrace(System.err);
    +			throw Errors.asRuntime(e);
    +		} finally {
    +			System.err.close();
    +			System.out.close();
     		}
     	}
     
    diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java
    index 9d5e3f9b14..07cc2cbc85 100644
    --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java
    +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/SpotlessApplyMojo.java
    @@ -18,17 +18,14 @@
     import java.io.File;
     import java.io.IOException;
     
    -import java.util.List;
    -
     import org.apache.maven.plugin.MojoExecutionException;
     import org.apache.maven.plugins.annotations.Mojo;
    +import org.apache.maven.plugins.annotations.Parameter;
     
     import com.diffplug.spotless.Formatter;
     import com.diffplug.spotless.PaddedCell;
     import com.diffplug.spotless.maven.incremental.UpToDateChecker;
     
    -import org.apache.maven.plugins.annotations.Parameter;
    -
     /**
      * Performs formatting of all source files according to configured formatters.
      */
    @@ -46,8 +43,8 @@ public class SpotlessApplyMojo extends AbstractSpotlessMojo {
     
     	@Override
     	protected void process(Iterable files, Formatter formatter, UpToDateChecker upToDateChecker) throws MojoExecutionException {
    -		if(isIdeHook()) {
    -			IdeHook.performHook(files, spotlessIdeHook, formatter, getBaseDir(), null, spotlessIdeHookUseStdIn, spotlessIdeHookUseStdOut);
    +		if (isIdeHook()) {
    +			IdeHook.performHook(files, formatter, spotlessIdeHook, spotlessIdeHookUseStdIn, spotlessIdeHookUseStdOut);
     			return;
     		}
     
    @@ -91,13 +88,4 @@ protected void process(Iterable files, Formatter formatter, UpToDateChecke
     	private boolean isIdeHook() {
     		return !(spotlessIdeHook == null || spotlessIdeHook.isEmpty());
     	}
    -
    -	private List fetchFileFromIdeHook() {
    -		File file = new File(spotlessIdeHook);
    -		if (!file.isAbsolute()) {
    -			throw new PluginException("Argument passed to spotlessIdeHook must be an absolute path");
    -		}
    -
    -		return List.of(file);
    -	}
     }
    
    From 39c24abaa543e46f549409f16605052fca68a83f Mon Sep 17 00:00:00 2001
    From: Dimitrii Lipiridi 
    Date: Thu, 24 Aug 2023 09:52:51 +0300
    Subject: [PATCH 0880/1120] feat: Add IDE hook tests
    
    ---
     .../diffplug/spotless/maven/IdeHookTest.java  | 85 +++++++++++++++++++
     1 file changed, 85 insertions(+)
     create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/IdeHookTest.java
    
    diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/IdeHookTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/IdeHookTest.java
    new file mode 100644
    index 0000000000..3c9a1a17d6
    --- /dev/null
    +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/IdeHookTest.java
    @@ -0,0 +1,85 @@
    +/*
    + * 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.
    + * 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;
    +
    +import java.io.File;
    +import java.io.IOException;
    +
    +import org.assertj.core.api.Assertions;
    +import org.junit.jupiter.api.BeforeEach;
    +import org.junit.jupiter.api.Test;
    +
    +import com.diffplug.spotless.ProcessRunner;
    +
    +class IdeHookTest extends MavenIntegrationHarness {
    +	private String output, error;
    +	private File dirty, clean, diverge, outofbounds;
    +
    +	@BeforeEach
    +	void before() throws IOException {
    +		writePomWithFormatSteps("\n" +
    +				"                                DIRTY.md\n" +
    +				"                                CLEAN.md\n" +
    +				"                            \n" +
    +				"                            \n" +
    +				"                                Greetings to Mars\n" +
    +				"                                World\n" +
    +				"                                Mars\n" +
    +				"                            ");
    +
    +		dirty = setFile("DIRTY.md").toContent("World");
    +		clean = setFile("CLEAN.md").toContent("Mars");
    +		outofbounds = setFile("OUTOFBOUNDS.md").toContent("Mars");
    +		;
    +	}
    +
    +	private void runWith(String... arguments) throws IOException, InterruptedException {
    +		ProcessRunner.Result result = mavenRunner()
    +				.withArguments(arguments)
    +				.runNoError();
    +
    +		this.output = result.stdOutUtf8();
    +		this.error = result.stdErrUtf8();
    +	}
    +
    +	@Test
    +	void dirty() throws IOException, InterruptedException {
    +		runWith("spotless:apply", "--quiet", "-DspotlessIdeHook=\"" + dirty.getAbsolutePath() + "\"", "-DspotlessIdeHookUseStdOut=true");
    +		Assertions.assertThat(output).isEqualTo("Mars");
    +		Assertions.assertThat(error).startsWith("IS DIRTY");
    +	}
    +
    +	@Test
    +	void clean() throws IOException, InterruptedException {
    +		runWith("spotless:apply", "--quiet", "-DspotlessIdeHook=" + clean.getAbsolutePath(), "-DspotlessIdeHookUseStdOut=true");
    +		Assertions.assertThat(output).isEmpty();
    +		Assertions.assertThat(error).startsWith("IS CLEAN");
    +	}
    +
    +	@Test
    +	void outofbounds() throws IOException, InterruptedException {
    +		runWith("spotless:apply", "--quiet", "-DspotlessIdeHook=" + outofbounds.getAbsolutePath(), "-DspotlessIdeHookUseStdOut=true");
    +		Assertions.assertThat(output).isEmpty();
    +		Assertions.assertThat(error).isEmpty();
    +	}
    +
    +	@Test
    +	void notAbsolute() throws IOException, InterruptedException {
    +		runWith("spotless:apply", "--quiet", "-DspotlessIdeHook=\"pom.xml\"", "-DspotlessIdeHookUseStdOut=true");
    +		Assertions.assertThat(output).isEmpty();
    +		Assertions.assertThat(error).contains("Argument passed to spotlessIdeHook must be an absolute path");
    +	}
    +}
    
    From c6e55bd4fe07fc1668c4d3727bbb83054c15ed08 Mon Sep 17 00:00:00 2001
    From: Dimitrii Lipiridi 
    Date: Thu, 24 Aug 2023 09:57:31 +0300
    Subject: [PATCH 0881/1120] feat: Revert README.md
    
    ---
     plugin-maven/README.md | 15 +++------------
     1 file changed, 3 insertions(+), 12 deletions(-)
    
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index 956dbf385e..cb770099ac 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -1601,22 +1601,13 @@ By default, `spotless:check` is bound to the `verify` phase.  You might want to
     
     ## Can I apply Spotless to specific files?
     
    -There are two options:
    -
    -### Pattern
     You can target specific files by setting the `spotlessFiles` project property to a comma-separated list of file patterns:
    -```
    -cmd> mvn spotless:apply -DspotlessFiles="src.main.java.com.example.*, .+Config.*\.java"
    -```
    -The patterns are matched using `String#matches(String)` against the absolute file path.
     
    -### IDE Hook
    -You can specify a single file by providing the `spotlessIdeHook` argument, which accepts the absolute path of the file.
     ```
    -cmd> mvn spotless:apply -DspotlessIdeHook="C:\my-project\src\main\java\com\example\Application.java"
    -
    +cmd> mvn spotless:apply -DspotlessFiles=my/file/pattern.java,more/generic/.*-pattern.java
     ```
    -This option ignores the ratchetFrom property.
    +
    +The patterns are matched using `String#matches(String)` against the absolute file path.
     
     
     
    
    From b3c59f7d4b9e214c3f4c14d9333b816e3a90a34b Mon Sep 17 00:00:00 2001
    From: Ned Twigg 
    Date: Thu, 24 Aug 2023 12:31:36 -0700
    Subject: [PATCH 0882/1120] Fix on windows.
    
    ---
     .../com/diffplug/gradle/spotless/KotlinExtensionTest.java | 8 ++++----
     1 file changed, 4 insertions(+), 4 deletions(-)
    
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java
    index 98e2259be4..1c23728244 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java
    @@ -15,7 +15,7 @@
      */
     package com.diffplug.gradle.spotless;
     
    -import static org.junit.jupiter.api.Assertions.assertTrue;
    +import static org.assertj.core.api.Assertions.assertThat;
     
     import java.io.File;
     import java.io.IOException;
    @@ -96,13 +96,13 @@ void testWithInvalidEditorConfigFile() throws IOException {
     				"repositories { mavenCentral() }",
     				"spotless {",
     				"    kotlin {",
    -				"        ktlint().setEditorConfigPath('" + invalidPath + "')",
    +				"        ktlint().setEditorConfigPath('" + invalidPath.replace("\\", "\\\\") + "')",
     				"    }",
     				"}");
     		setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
     		String buildOutput = gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput();
    -		assertTrue(buildOutput.contains("EditorConfig file does not exist: "));
    -		assertTrue(buildOutput.contains(invalidPath));
    +		assertThat(buildOutput).contains("EditorConfig file does not exist: ");
    +		assertThat(buildOutput).contains(invalidPath);
     	}
     
     	@Test
    
    From 62a957e51b723b3572bbe4beef9255e910d9c036 Mon Sep 17 00:00:00 2001
    From: Ned Twigg 
    Date: Thu, 24 Aug 2023 12:31:48 -0700
    Subject: [PATCH 0883/1120] Categorize as fix rather than new feature.
    
    ---
     plugin-gradle/CHANGES.md | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 27d60e7270..2a5bd5db46 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -6,12 +6,12 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
    -* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788)
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     * Fix configuration cache failure when using LineEnding.GIT_ATTRIBUTES ([#1644](https://github.com/diffplug/spotless/issues/1644))
     * Fix configuration cache failure when formatting proto files with Buf. ([#1779]https://github.com/diffplug/spotless/pull/1779))
    +* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788)
     ### Changes
     * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
     * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
    
    From 83aace9d39b7037a430945e152b72580797c2a8a Mon Sep 17 00:00:00 2001
    From: Goooler 
    Date: Fri, 25 Aug 2023 09:35:35 +0800
    Subject: [PATCH 0884/1120] Fix changelog link formats
    
    ---
     CHANGES.md               | 4 ++--
     plugin-gradle/CHANGES.md | 8 ++++----
     plugin-maven/CHANGES.md  | 4 ++--
     3 files changed, 8 insertions(+), 8 deletions(-)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 81af46a526..905a78b8e6 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -15,8 +15,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
     ### Fixed
     * Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756))
    -* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    -* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    +* Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    +* Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     ### Changes
     * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
     * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 2a5bd5db46..4e7f0d21be 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -7,11 +7,11 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
     ### Fixed
    -* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    -* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    +* Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    +* Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     * Fix configuration cache failure when using LineEnding.GIT_ATTRIBUTES ([#1644](https://github.com/diffplug/spotless/issues/1644))
    -* Fix configuration cache failure when formatting proto files with Buf. ([#1779]https://github.com/diffplug/spotless/pull/1779))
    -* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788)
    +* Fix configuration cache failure when formatting proto files with Buf. ([#1779](https://github.com/diffplug/spotless/pull/1779))
    +* Check if EditorConfig file exist for Ktlint. ([#1788](https://github.com/diffplug/spotless/pull/1788))
     ### Changes
     * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
     * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index 65a557b14f..d5526dd3c6 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -7,8 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
     ### Fixed
    -* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    -* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    +* Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    +* Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     ### Changes
     * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
     * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
    
    From c23f89b5f01c2f8366ef127665351bc83bf10bd7 Mon Sep 17 00:00:00 2001
    From: Ned Twigg 
    Date: Mon, 28 Aug 2023 23:16:54 -0700
    Subject: [PATCH 0885/1120] Update changelogs.
    
    ---
     CHANGES.md               | 2 +-
     plugin-gradle/CHANGES.md | 2 +-
     plugin-maven/CHANGES.md  | 3 ++-
     3 files changed, 4 insertions(+), 3 deletions(-)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index fd8bbb4875..12b8609f82 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -20,7 +20,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ### Changes
     * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
     * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
    -* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))
    +* Bump default `greclipse` version to latest `4.27` -> `4.28`. ([#1775](https://github.com/diffplug/spotless/pull/1775))
     
     ## [2.40.0] - 2023-07-17
     ### Added
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index a04bf7987b..4d9832ebf5 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 (
     ### Changes
     * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
     * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
    -* Add support for Eclipse 4.28 to the Groovy formatter. ([#1775](https://github.com/diffplug/spotless/pull/1775))
    +* Bump default `greclipse` version to latest `4.27` -> `4.28`. ([#1775](https://github.com/diffplug/spotless/pull/1775))
     
     ## [6.20.0] - 2023-07-17
     ### Added
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index 5da66951fd..8278e16792 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -5,12 +5,14 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ## [Unreleased]
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    +* Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
     ### Changes
     * Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
     * Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
    +* Bump default `greclipse` version to latest `4.27` -> `4.28`. ([#1775](https://github.com/diffplug/spotless/pull/1775))
     
     ## [2.38.0] - 2023-07-17
     ### Added
    @@ -22,7 +24,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     * Bump default `ktlint` version to latest `0.49.1` -> `0.50.0`. ([#1741](https://github.com/diffplug/spotless/issues/1741))
       * Dropped support for `ktlint 0.47.x` following our policy of supporting two breaking changes at a time.
       * Dropped support for deprecated `useExperimental` parameter in favor of the `ktlint_experimental` property.
    -* Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
     
     ## [2.37.0] - 2023-05-24
     ### Added
    
    From 7e574c6159954115ced357f0e5e1f0adcf9e3e24 Mon Sep 17 00:00:00 2001
    From: runner
     
    Date: Tue, 29 Aug 2023 06:44:20 +0000
    Subject: [PATCH 0886/1120] Published lib/2.41.0
    
    ---
     CHANGES.md | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 12b8609f82..1d78e8d932 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -10,6 +10,8 @@ This document is intended for Spotless developers.
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    +
    +## [2.41.0] - 2023-08-29
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
    
    From f19cc96927fb50364cbc384ce5e8e2832f0f9ff8 Mon Sep 17 00:00:00 2001
    From: runner
     
    Date: Tue, 29 Aug 2023 06:47:16 +0000
    Subject: [PATCH 0887/1120] Published gradle/6.21.0
    
    ---
     plugin-gradle/CHANGES.md |  2 ++
     plugin-gradle/README.md  | 54 ++++++++++++++++++++--------------------
     2 files changed, 29 insertions(+), 27 deletions(-)
    
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 4d9832ebf5..eab7e32b2d 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -3,6 +3,8 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
     
     ## [Unreleased]
    +
    +## [6.21.0] - 2023-08-29
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index dbc61207e5..944c07bb6e 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -14,9 +14,9 @@ output = [
       ].join('\n');
     -->
     [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless)
    -[![Changelog](https://img.shields.io/badge/changelog-6.20.0-blue.svg)](CHANGES.md)
    +[![Changelog](https://img.shields.io/badge/changelog-6.21.0-blue.svg)](CHANGES.md)
     [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22)
    -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/index.html)
    +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/index.html)
     
     [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle)
     [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle)
    @@ -127,10 +127,10 @@ spotless {
     ```
     
     Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has:
    -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-)
    -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc.
    +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-)
    +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc.
     
    -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below.
    +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below.
     
     ### Requirements
     
    @@ -143,7 +143,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer.
     
     ## Java
     
    -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java)
    +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java)
     
     ```gradle
     spotless {
    @@ -300,8 +300,8 @@ spotless {
     
     ## Groovy
     
    -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java)
    -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java)
    +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java)
    +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java)
     
     Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`.
     
    @@ -351,8 +351,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T
     
     ## Kotlin
     
    -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java)
    -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java)
    +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java)
    +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java)
     
     ```gradle
     spotless { // if you are using build.gradle.kts, instead of 'spotless {' use:
    @@ -422,7 +422,7 @@ spotless {
     
     ## Scala
     
    -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java)
    +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java)
     
     ```gradle
     spotless {
    @@ -454,7 +454,7 @@ spotless {
     
     ## C/C++
     
    -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java)
    +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java)
     
     ```gradle
     spotless {
    @@ -486,7 +486,7 @@ spotles {
     
     ## Python
     
    -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java)
    +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java)
     
     ```gradle
     spotless {
    @@ -522,7 +522,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe')
     
     ### buf
     
    -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java)
    +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java)
     
     **WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem.
     
    @@ -554,7 +554,7 @@ buf {
     
     ## FreshMark
     
    -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java)
    +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java)
     
     [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown.  This helps to keep badges and links up-to-date (see the source for this file), and can
     also be helpful for generating complex tables (see the source for [the parent readme](../README.md)).
    @@ -575,7 +575,7 @@ spotless {
     
     ## Antlr4
     
    -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java)
    +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java)
     
     ```gradle
     spotless {
    @@ -600,7 +600,7 @@ antlr4formatter('1.2.1') // version is optional
     
     ## SQL
     
    -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java)
    +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java)
     
     ```gradle
     spotless {
    @@ -640,7 +640,7 @@ sql.formatter.indent.size=4
     
     ## Typescript
     
    -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java)
    +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java)
     
     ```gradle
     spotless {
    @@ -734,7 +734,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr
     
     ## Javascript
     
    -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java)
    +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java)
     
     ```gradle
     spotless {
    @@ -799,7 +799,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr
     
     ## JSON
     
    -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java)
    +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java)
     
     ```gradle
     spotless {
    @@ -919,7 +919,7 @@ spotless {
     
     ## YAML
     
    -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java)
    +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java)
     
     ```gradle
     spotless {
    @@ -951,7 +951,7 @@ spotless {
     
     ## Gherkin
     
    -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.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.21.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 {
    @@ -1339,7 +1339,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or
     * `2017` -> `2017-2020`
     * `2017-2019` -> `2017-2020`
     
    -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options.
    +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options.
     
     
     
    @@ -1419,9 +1419,9 @@ spotless {
         custom 'lowercase', { str -> str.toLowerCase() }
     ```
     
    -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully.
    +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully.
     
    -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-).  The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep).  If the step is generally-useful, we hope you'll open a PR to share it!
    +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-).  The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep).  If the step is generally-useful, we hope you'll open a PR to share it!
     
     
     ```gradle
    @@ -1454,11 +1454,11 @@ spotless {
       format 'foo', com.acme.FooLanguageExtension, {
     ```
     
    -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-).
    +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-).
     
     ## Inception (languages within languages within...)
     
    -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that.  You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so.  See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.20.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details.
    +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that.  You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so.  See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details.
     
     ```gradle
     import com.diffplug.gradle.spotless.JavaExtension
    
    From c360e81278d909cbe86630df29cfb9d253f38e41 Mon Sep 17 00:00:00 2001
    From: runner
     
    Date: Tue, 29 Aug 2023 06:49:30 +0000
    Subject: [PATCH 0888/1120] Published maven/2.39.0
    
    ---
     plugin-maven/CHANGES.md | 2 ++
     plugin-maven/README.md  | 4 ++--
     2 files changed, 4 insertions(+), 2 deletions(-)
    
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index 8278e16792..f932806fcc 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -3,6 +3,8 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    +
    +## [2.39.0] - 2023-08-29
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index cb770099ac..74872ef61f 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -8,8 +8,8 @@ output = [
       ].join('\n');
     -->
     [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22)
    -[![Changelog](https://img.shields.io/badge/changelog-2.38.0-blue.svg)](CHANGES.md)
    -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.38.0/index.html)
    +[![Changelog](https://img.shields.io/badge/changelog-2.39.0-blue.svg)](CHANGES.md)
    +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.39.0/index.html)
     
     
     
                              
       true 
    +  false        
       
       com.google.googlejavaformat:google-java-format
     
    
    From 493a3b6097773167751c711d8efaade9651a4bc9 Mon Sep 17 00:00:00 2001
    From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
    Date: Fri, 1 Sep 2023 13:52:03 +0000
    Subject: [PATCH 0894/1120] Update plugin com.gradle.plugin-publish to v1.2.1
    
    ---
     settings.gradle | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/settings.gradle b/settings.gradle
    index 57c670b977..a24c6d24d5 100644
    --- a/settings.gradle
    +++ b/settings.gradle
    @@ -8,7 +8,7 @@ pluginManagement {
     plugins {
     	id 'com.diffplug.spotless' version '6.18.0' apply false
     	// https://plugins.gradle.org/plugin/com.gradle.plugin-publish
    -	id 'com.gradle.plugin-publish' version '1.2.0' apply false
    +	id 'com.gradle.plugin-publish' version '1.2.1' apply false
     	// https://github.com/gradle-nexus/publish-plugin/releases
     	id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false
     	// https://github.com/spotbugs/spotbugs-gradle-plugin/releases
    
    From ef8829e4d13d7f335d5178209ca85410376432ce Mon Sep 17 00:00:00 2001
    From: samypr100 <3933065+samypr100@users.noreply.github.com>
    Date: Sat, 2 Sep 2023 15:32:54 -0400
    Subject: [PATCH 0895/1120] feat: add flexmark gradle support
    
    ---
     CHANGES.md                                    |  3 +
     README.md                                     |  4 +-
     .../spotless/markdown/FlexmarkStep.java       |  2 +-
     plugin-gradle/CHANGES.md                      |  3 +
     plugin-gradle/README.md                       | 20 +++++
     .../gradle/spotless/FlexmarkExtension.java    | 74 +++++++++++++++++++
     .../gradle/spotless/SpotlessExtension.java    |  6 ++
     .../spotless/FlexmarkExtensionTest.java       | 41 ++++++++++
     8 files changed, 150 insertions(+), 3 deletions(-)
     create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java
     create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 1d78e8d932..8150fefcbb 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     
     ## [Unreleased]
     
    +### Changes
    +* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`.
    +
     ## [2.41.0] - 2023-08-29
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    diff --git a/README.md b/README.md
    index cd1e736014..5c3221b1b4 100644
    --- a/README.md
    +++ b/README.md
    @@ -94,7 +94,7 @@ lib('kotlin.KtLintStep')                         +'{{yes}}       | {{yes}}
     lib('kotlin.KtfmtStep')                          +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('kotlin.DiktatStep')                         +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('markdown.FreshMarkStep')                    +'{{yes}}       | {{no}}       | {{no}}       | {{no}}  |',
    -lib('markdown.FlexmarkStep')                     +'{{no}}        | {{yes}}      | {{no}}       | {{no}}  |',
    +lib('markdown.FlexmarkStep')                     +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('npm.EslintFormatterStep')                   +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('npm.PrettierFormatterStep')                 +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
     lib('npm.TsFmtFormatterStep')                    +'{{yes}}       | {{yes}}      | {{no}}       | {{no}}  |',
    @@ -146,7 +146,7 @@ lib('yaml.JacksonYamlStep')                      +'{{yes}}       | {{yes}}
     | [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`markdown.FreshMarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FreshMarkStep.java) | :+1:       | :white_large_square:       | :white_large_square:       | :white_large_square:  |
    -| [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :white_large_square:        | :+1:      | :white_large_square:       | :white_large_square:  |
    +| [`markdown.FlexmarkStep`](lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`npm.EslintFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/EslintFormatterStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
     | [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1:       | :+1:      | :white_large_square:       | :white_large_square:  |
    diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java
    index 263931693e..b4159830e7 100644
    --- a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java
    +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java
    @@ -29,7 +29,7 @@ public class FlexmarkStep {
     	// prevent direct instantiation
     	private FlexmarkStep() {}
     
    -	private static final String DEFAULT_VERSION = "0.64.0";
    +	private static final String DEFAULT_VERSION = "0.64.6";
     	private static final String NAME = "flexmark-java";
     	private static final String MAVEN_COORDINATE = "com.vladsch.flexmark:flexmark-all:";
     
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index eab7e32b2d..791b27dafe 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
    +* Support `flexmark` in gradle. Previously only Maven was supported.
    +
     ## [6.21.0] - 2023-08-29
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 944c07bb6e..367634e63e 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -62,6 +62,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
       - [Protobuf](#protobuf) ([buf](#buf), [clang-format](#clang-format))
       - [Python](#python) ([black](#black))
       - [FreshMark](#freshmark) aka markdown
    +  - [FlexMark](#flexmark) aka markdown
       - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter))
       - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier))
       - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome))
    @@ -573,6 +574,25 @@ spotless {
     }
     ```
     
    +## Flexmark
    +
    +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java)
    +
    +[homepage](https://github.com/vsch/flexmark-java). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Flexmark.java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options).
    +
    +Currently, none of the available options can be configured yet. It uses only the default options together with `COMMONMARK` as `FORMATTER_EMULATION_PROFILE`.
    +
    +To apply flexmark to all of the `.md` files in your project, use this snippet:
    +
    +```gradle
    +spotless {
    +  flexmark {
    +    target '**/*.md' // you have to set the target manually
    +    flexmarkFormatter() // or flexmarkFormatter('0.64.6') // version is optional
    +  }
    +}
    +```
    +
     ## Antlr4
     
     `com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java)
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java
    new file mode 100644
    index 0000000000..feee2c4801
    --- /dev/null
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java
    @@ -0,0 +1,74 @@
    +/*
    + * 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.gradle.spotless;
    +
    +import java.util.Objects;
    +
    +import javax.inject.Inject;
    +
    +import com.diffplug.spotless.FormatterStep;
    +import com.diffplug.spotless.markdown.FlexmarkStep;
    +
    +public class FlexmarkExtension extends FormatExtension implements HasBuiltinDelimiterForLicense {
    +	static final String NAME = "flexmark";
    +
    +	@Inject
    +	public FlexmarkExtension(SpotlessExtension spotless) {
    +		super(spotless);
    +	}
    +
    +	@Override
    +	public LicenseHeaderConfig licenseHeader(String licenseHeader) {
    +		return licenseHeader(licenseHeader, null);
    +	}
    +
    +	@Override
    +	public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) {
    +		return licenseHeaderFile(licenseHeaderFile, null);
    +	}
    +
    +	public FlexmarkFormatterConfig flexmarkFormatter() {
    +		return flexmarkFormatter(FlexmarkStep.defaultVersion());
    +	}
    +
    +	public FlexmarkFormatterConfig flexmarkFormatter(String version) {
    +		return new FlexmarkFormatterConfig(version);
    +	}
    +
    +	@Override
    +	protected void setupTask(SpotlessTask task) {
    +		// defaults to all markdown files
    +		if (target == null) {
    +			throw noDefaultTargetException();
    +		}
    +		super.setupTask(task);
    +	}
    +
    +	public class FlexmarkFormatterConfig {
    +
    +		private final String version;
    +
    +		FlexmarkFormatterConfig(String version) {
    +			this.version = Objects.requireNonNull(version);
    +			addStep(createStep());
    +		}
    +
    +		private FormatterStep createStep() {
    +			return FlexmarkStep.create(this.version, 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 c3cf5123c0..838231c9f8 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
    @@ -147,6 +147,12 @@ public void freshmark(Action closure) {
     		format(FreshMarkExtension.NAME, FreshMarkExtension.class, closure);
     	}
     
    +	/** Configures the special flexmark-specific extension. */
    +	public void flexmark(Action closure) {
    +		requireNonNull(closure);
    +		format(FlexmarkExtension.NAME, FlexmarkExtension.class, closure);
    +	}
    +
     	/** Configures the special groovy-specific extension. */
     	public void groovy(Action closure) {
     		format(GroovyExtension.NAME, GroovyExtension.class, closure);
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java
    new file mode 100644
    index 0000000000..873baba744
    --- /dev/null
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java
    @@ -0,0 +1,41 @@
    +/*
    + * 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.gradle.spotless;
    +
    +import java.io.IOException;
    +
    +import org.junit.jupiter.api.Test;
    +
    +class FlexmarkExtensionTest extends GradleIntegrationHarness {
    +	@Test
    +	void integration() throws IOException {
    +		setFile("build.gradle").toLines(
    +				"plugins {",
    +				"    id 'java'",
    +				"    id 'com.diffplug.spotless'",
    +				"}",
    +				"repositories { mavenCentral() }",
    +				"spotless {",
    +				"    flexmark {",
    +				"        target '*.md'",
    +				"        flexmarkFormatter()",
    +				"    }",
    +				"}");
    +		setFile("markdown_test.md").toResource("markdown/flexmark/FlexmarkUnformatted.md");
    +		gradleRunner().withArguments("spotlessApply").build();
    +		assertFile("markdown_test.md").sameAsResource("markdown/flexmark/FlexmarkFormatted.md");
    +	}
    +}
    
    From ad04a62362ccec2cd8d5975f0326bb57b0bbbf5b Mon Sep 17 00:00:00 2001
    From: samypr100 <3933065+samypr100@users.noreply.github.com>
    Date: Sat, 2 Sep 2023 15:37:32 -0400
    Subject: [PATCH 0896/1120] docs: update docs/changes
    
    ---
     CHANGES.md               | 2 +-
     plugin-gradle/CHANGES.md | 2 +-
     plugin-gradle/README.md  | 2 +-
     3 files changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 8150fefcbb..711bcf819c 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -12,7 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ## [Unreleased]
     
     ### Changes
    -* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`.
    +* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`. ([#1801](https://github.com/diffplug/spotless/pull/1801))
     
     ## [2.41.0] - 2023-08-29
     ### Added
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 791b27dafe..736909025e 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ## [Unreleased]
     
     ### Added
    -* Support `flexmark` in gradle. Previously only Maven was supported.
    +* Support `flexmark` in gradle. Previously only Maven was supported. ([#1801](https://github.com/diffplug/spotless/pull/1801))
     
     ## [6.21.0] - 2023-08-29
     ### Added
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 367634e63e..f2781561a0 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -576,7 +576,7 @@ spotless {
     
     ## Flexmark
     
    -`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java)
    +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java)
     
     [homepage](https://github.com/vsch/flexmark-java). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Flexmark.java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options).
     
    
    From 9be41217c90032ecb2960e35fd9bef8c189b10d8 Mon Sep 17 00:00:00 2001
    From: samypr100 <3933065+samypr100@users.noreply.github.com>
    Date: Sat, 2 Sep 2023 15:43:27 -0400
    Subject: [PATCH 0897/1120] docs: remove copy/paste reference
    
    ---
     plugin-gradle/README.md | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index f2781561a0..91def5ad5f 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -578,7 +578,7 @@ spotless {
     
     `com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java)
     
    -[homepage](https://github.com/vsch/flexmark-java). [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/markdown/Flexmark.java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options).
    +[homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options).
     
     Currently, none of the available options can be configured yet. It uses only the default options together with `COMMONMARK` as `FORMATTER_EMULATION_PROFILE`.
     
    
    From d469a3548b6e85dda82d15e466d48f4e0c12fade Mon Sep 17 00:00:00 2001
    From: samypr100 <3933065+samypr100@users.noreply.github.com>
    Date: Sat, 2 Sep 2023 23:19:04 -0400
    Subject: [PATCH 0898/1120] feat: add support for prettier v3 plugin changes
    
    ---
     CHANGES.md                                    |   3 +
     .../spotless/npm/PrettierRestService.java     |  12 ++
     plugin-gradle/CHANGES.md                      |   3 +
     plugin-gradle/README.md                       |   2 +
     .../spotless/PrettierIntegrationTest.java     | 184 ++++++++++++++----
     plugin-maven/CHANGES.md                       |   3 +
     plugin-maven/README.md                        |   2 +
     .../spotless/maven/generic/Prettier.java      |   5 +
     .../prettier/PrettierFormatStepTest.java      |  50 +++++
     .../config/.prettierrc_java_plugin.yml        |   3 +
     10 files changed, 228 insertions(+), 39 deletions(-)
     create mode 100644 testlib/src/main/resources/npm/prettier/config/.prettierrc_java_plugin.yml
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 1d78e8d932..652e4ce38c 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     
     ## [Unreleased]
     
    +### Fixed
    +* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
    +
     ## [2.41.0] - 2023-08-29
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java
    index ccdc189d27..a517a7219b 100644
    --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java
    +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java
    @@ -17,7 +17,9 @@
     
     import java.io.File;
     import java.util.LinkedHashMap;
    +import java.util.List;
     import java.util.Map;
    +import java.util.stream.Collectors;
     
     public class PrettierRestService extends BaseNpmRestService {
     
    @@ -31,6 +33,16 @@ public String resolveConfig(File prettierConfigPath, Map prettie
     			jsonProperties.put("prettier_config_path", prettierConfigPath.getAbsolutePath());
     		}
     		if (prettierConfigOptions != null) {
    +			// Prettier 3.x plugins support
    +			if (prettierConfigOptions.get("plugins") instanceof List) {
    +				try {
    +					var pluginArray = (List) prettierConfigOptions.get("plugins");
    +					var pluginsJson = pluginArray.stream().map(e -> '"' + e + '"').collect(Collectors.joining(",", "[", "]"));
    +					prettierConfigOptions.put("plugins", JsonRawValue.wrap(pluginsJson));
    +				} catch (ClassCastException e) {
    +					throw new IllegalArgumentException("Only values of type 'List' are supported for plugins.");
    +				}
    +			}
     			jsonProperties.put("prettier_config_options", SimpleJsonWriter.of(prettierConfigOptions).toJsonRawValue());
     
     		}
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index eab7e32b2d..989b4ece12 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]
     
    +### Fixed
    +* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
    +
     ## [6.21.0] - 2023-08-29
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 944c07bb6e..2253557f3a 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -1024,10 +1024,12 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos
     spotless {
       java {
         prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0']).config(['parser': 'java', 'tabWidth': 4])
    +    // prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']).config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) // Prettier v3
       }
       format 'php', {
         target 'src/**/*.php'
         prettier(['prettier': '2.8.8', '@prettier/plugin-php': '0.19.6']).config(['parser': 'php', 'tabWidth': 3])
    +    // prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']).config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) // Prettier v3
       }
     }
     ```
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java
    index 4d5069c1b5..ed32900db0 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java
    @@ -19,14 +19,22 @@
     
     import org.assertj.core.api.Assertions;
     import org.gradle.testkit.runner.BuildResult;
    -import org.junit.jupiter.api.Test;
    +import org.junit.jupiter.params.ParameterizedTest;
    +import org.junit.jupiter.params.provider.ValueSource;
     
    +import com.diffplug.spotless.npm.PrettierFormatterStep;
     import com.diffplug.spotless.tag.NpmTest;
     
     @NpmTest
     class PrettierIntegrationTest extends GradleIntegrationHarness {
    -	@Test
    -	void useInlineConfig() throws IOException {
    +
    +	private static final String PRETTIER_VERSION_2 = PrettierFormatterStep.DEFAULT_VERSION;
    +
    +	private static final String PRETTIER_VERSION_3 = "3.0.3";
    +
    +	@ParameterizedTest(name = "{index}: useInlineConfig with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void useInlineConfig(String prettierVersion) throws IOException {
     		setFile("build.gradle").toLines(
     				"plugins {",
     				"    id 'com.diffplug.spotless'",
    @@ -38,17 +46,25 @@ void useInlineConfig() throws IOException {
     				"spotless {",
     				"    format 'mytypescript', {",
     				"        target 'test.ts'",
    -				"        prettier().config(prettierConfig)",
    +				"        prettier('" + prettierVersion + "').config(prettierConfig)",
     				"    }",
     				"}");
     		setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
    -		final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
    +		BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
     		Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
    -		assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
    +		switch (prettierVersion) {
    +		case PRETTIER_VERSION_2:
    +			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
    +			break;
    +		case PRETTIER_VERSION_3:
    +			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_3.clean");
    +			break;
    +		}
     	}
     
    -	@Test
    -	void verifyCleanSpotlessCheckWorks() throws IOException {
    +	@ParameterizedTest(name = "{index}: verifyCleanSpotlessCheckWorks with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void verifyCleanSpotlessCheckWorks(String prettierVersion) throws IOException {
     		setFile("build.gradle").toLines(
     				"plugins {",
     				"    id 'com.diffplug.spotless'",
    @@ -60,7 +76,7 @@ void verifyCleanSpotlessCheckWorks() throws IOException {
     				"spotless {",
     				"    format 'mytypescript', {",
     				"        target 'test.ts'",
    -				"        prettier().config(prettierConfig)",
    +				"        prettier('" + prettierVersion + "').config(prettierConfig)",
     				"    }",
     				"}");
     		setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
    @@ -71,8 +87,9 @@ void verifyCleanSpotlessCheckWorks() throws IOException {
     		gradleRunner().withArguments("--stacktrace", "spotlessCheck").build();
     	}
     
    -	@Test
    -	void useFileConfig() throws IOException {
    +	@ParameterizedTest(name = "{index}: useFileConfig with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void useFileConfig(String prettierVersion) throws IOException {
     		setFile(".prettierrc.yml").toResource("npm/prettier/config/.prettierrc.yml");
     		setFile("build.gradle").toLines(
     				"plugins {",
    @@ -82,17 +99,25 @@ void useFileConfig() throws IOException {
     				"spotless {",
     				"    format 'mytypescript', {",
     				"        target 'test.ts'",
    -				"        prettier().configFile('.prettierrc.yml')",
    +				"        prettier('" + prettierVersion + "').configFile('.prettierrc.yml')",
     				"    }",
     				"}");
     		setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
     		final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
     		Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
    -		assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
    +		switch (prettierVersion) {
    +		case PRETTIER_VERSION_2:
    +			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
    +			break;
    +		case PRETTIER_VERSION_3:
    +			assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_3.clean");
    +			break;
    +		}
     	}
     
    -	@Test
    -	void chooseParserBasedOnFilename() throws IOException {
    +	@ParameterizedTest(name = "{index}: chooseParserBasedOnFilename with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void chooseParserBasedOnFilename(String prettierVersion) throws IOException {
     		setFile("build.gradle").toLines(
     				"plugins {",
     				"    id 'com.diffplug.spotless'",
    @@ -101,7 +126,7 @@ void chooseParserBasedOnFilename() throws IOException {
     				"spotless {",
     				"    format 'webResources', {",
     				"        target 'dirty.*'",
    -				"        prettier()",
    +				"        prettier('" + prettierVersion + "')",
     				"    }",
     				"}");
     		setFile("dirty.json").toResource("npm/prettier/filename/dirty.json");
    @@ -110,8 +135,20 @@ void chooseParserBasedOnFilename() throws IOException {
     		assertFile("dirty.json").sameAsResource("npm/prettier/filename/clean.json");
     	}
     
    -	@Test
    -	void useJavaCommunityPlugin() throws IOException {
    +	@ParameterizedTest(name = "{index}: useJavaCommunityPlugin with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void useJavaCommunityPlugin(String prettierVersion) throws IOException {
    +		var prettierPluginJava = "";
    +		var prettierConfigPluginsStr = "";
    +		switch (prettierVersion) {
    +		case PRETTIER_VERSION_2:
    +			prettierPluginJava = "2.1.0"; // last version to support v2
    +			break;
    +		case PRETTIER_VERSION_3:
    +			prettierPluginJava = "2.3.0"; // latest to support v3
    +			prettierConfigPluginsStr = "prettierConfig['plugins'] = ['prettier-plugin-java']";
    +			break;
    +		}
     		setFile("build.gradle").toLines(
     				"plugins {",
     				"    id 'com.diffplug.spotless'",
    @@ -120,9 +157,10 @@ void useJavaCommunityPlugin() throws IOException {
     				"def prettierConfig = [:]",
     				"prettierConfig['tabWidth'] = 4",
     				"prettierConfig['parser'] = 'java'",
    +				prettierConfigPluginsStr,
     				"def prettierPackages = [:]",
    -				"prettierPackages['prettier'] = '2.8.8'",
    -				"prettierPackages['prettier-plugin-java'] = '2.2.0'",
    +				"prettierPackages['prettier'] = '" + prettierVersion + "'",
    +				"prettierPackages['prettier-plugin-java'] = '" + prettierPluginJava + "'",
     				"spotless {",
     				"    format 'java', {",
     				"        target 'JavaTest.java'",
    @@ -135,8 +173,42 @@ void useJavaCommunityPlugin() throws IOException {
     		assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean");
     	}
     
    -	@Test
    -	void suggestsMissingJavaCommunityPlugin() throws IOException {
    +	@ParameterizedTest(name = "{index}: useJavaCommunityPluginFileConfig with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void useJavaCommunityPluginFileConfig(String prettierVersion) throws IOException {
    +		var prettierPluginJava = "";
    +		switch (prettierVersion) {
    +		case PRETTIER_VERSION_2:
    +			prettierPluginJava = "2.1.0"; // last version to support v2
    +			break;
    +		case PRETTIER_VERSION_3:
    +			prettierPluginJava = "2.3.0"; // latest to support v3
    +			break;
    +		}
    +		setFile(".prettierrc.yml").toResource("npm/prettier/config/.prettierrc_java_plugin.yml");
    +		setFile("build.gradle").toLines(
    +				"plugins {",
    +				"    id 'com.diffplug.spotless'",
    +				"}",
    +				"repositories { mavenCentral() }",
    +				"def prettierPackages = [:]",
    +				"prettierPackages['prettier'] = '" + prettierVersion + "'",
    +				"prettierPackages['prettier-plugin-java'] = '" + prettierPluginJava + "'",
    +				"spotless {",
    +				"    format 'java', {",
    +				"        target 'JavaTest.java'",
    +				"        prettier(prettierPackages).configFile('.prettierrc.yml')",
    +				"    }",
    +				"}");
    +		setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty");
    +		final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
    +		Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
    +		assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean");
    +	}
    +
    +	@ParameterizedTest(name = "{index}: suggestsMissingJavaCommunityPlugin with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void suggestsMissingJavaCommunityPlugin(String prettierVersion) throws IOException {
     		setFile("build.gradle").toLines(
     				"plugins {",
     				"    id 'com.diffplug.spotless'",
    @@ -145,7 +217,7 @@ void suggestsMissingJavaCommunityPlugin() throws IOException {
     				"def prettierConfig = [:]",
     				"prettierConfig['tabWidth'] = 4",
     				"def prettierPackages = [:]",
    -				"prettierPackages['prettier'] = '2.8.8'",
    +				"prettierPackages['prettier'] = '" + prettierVersion + "'",
     				"spotless {",
     				"    format 'java', {",
     				"        target 'JavaTest.java'",
    @@ -158,8 +230,20 @@ void suggestsMissingJavaCommunityPlugin() throws IOException {
     		Assertions.assertThat(spotlessApply.getOutput()).contains("prettier-plugin-java");
     	}
     
    -	@Test
    -	void usePhpCommunityPlugin() throws IOException {
    +	@ParameterizedTest(name = "{index}: usePhpCommunityPlugin with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void usePhpCommunityPlugin(String prettierVersion) throws IOException {
    +		var prettierPluginPhp = "";
    +		var prettierConfigPluginsStr = "";
    +		switch (prettierVersion) {
    +		case PRETTIER_VERSION_2:
    +			prettierPluginPhp = "0.19.7"; // last version to support v2
    +			break;
    +		case PRETTIER_VERSION_3:
    +			prettierPluginPhp = "0.20.1"; // latest to support v3
    +			prettierConfigPluginsStr = "prettierConfig['plugins'] = ['@prettier/plugin-php']";
    +			break;
    +		}
     		setFile("build.gradle").toLines(
     				"plugins {",
     				"    id 'com.diffplug.spotless'",
    @@ -168,9 +252,10 @@ void usePhpCommunityPlugin() throws IOException {
     				"def prettierConfig = [:]",
     				"prettierConfig['tabWidth'] = 3",
     				"prettierConfig['parser'] = 'php'",
    +				prettierConfigPluginsStr,
     				"def prettierPackages = [:]",
    -				"prettierPackages['prettier'] = '2.8.8'",
    -				"prettierPackages['@prettier/plugin-php'] = '0.19.6'",
    +				"prettierPackages['prettier'] = '" + prettierVersion + "'",
    +				"prettierPackages['@prettier/plugin-php'] = '" + prettierPluginPhp + "'",
     				"spotless {",
     				"    format 'php', {",
     				"        target 'php-example.php'",
    @@ -188,8 +273,25 @@ void usePhpCommunityPlugin() throws IOException {
     	 *
     	 * @see Issue #1162 on github
     	 */
    -	@Test
    -	void usePhpAndJavaCommunityPlugin() throws IOException {
    +	@ParameterizedTest(name = "{index}: usePhpAndJavaCommunityPlugin with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void usePhpAndJavaCommunityPlugin(String prettierVersion) throws IOException {
    +		var prettierPluginJava = "";
    +		var prettierPluginPhp = "";
    +		var prettierConfigPluginsJavaStr = "";
    +		var prettierConfigPluginsPhpStr = "";
    +		switch (prettierVersion) {
    +		case PRETTIER_VERSION_2:
    +			prettierPluginJava = "2.1.0"; // last version to support v2
    +			prettierPluginPhp = "0.19.7"; // last version to support v2
    +			break;
    +		case PRETTIER_VERSION_3:
    +			prettierPluginJava = "2.3.0"; // latest to support v3
    +			prettierPluginPhp = "0.20.1"; // latest to support v3
    +			prettierConfigPluginsJavaStr = "prettierConfigJava['plugins'] = ['prettier-plugin-java']";
    +			prettierConfigPluginsPhpStr = "prettierConfigPhp['plugins'] = ['@prettier/plugin-php']";
    +			break;
    +		}
     		setFile("build.gradle").toLines(
     				"plugins {",
     				"    id 'com.diffplug.spotless'",
    @@ -198,15 +300,17 @@ void usePhpAndJavaCommunityPlugin() throws IOException {
     				"def prettierConfigPhp = [:]",
     				"prettierConfigPhp['tabWidth'] = 3",
     				"prettierConfigPhp['parser'] = 'php'",
    +				prettierConfigPluginsPhpStr,
     				"def prettierPackagesPhp = [:]",
    -				"prettierPackagesPhp['prettier'] = '2.8.8'",
    -				"prettierPackagesPhp['@prettier/plugin-php'] = '0.19.6'",
    +				"prettierPackagesPhp['prettier'] = '" + prettierVersion + "'",
    +				"prettierPackagesPhp['@prettier/plugin-php'] = '" + prettierPluginPhp + "'",
     				"def prettierConfigJava = [:]",
     				"prettierConfigJava['tabWidth'] = 4",
     				"prettierConfigJava['parser'] = 'java'",
    +				prettierConfigPluginsJavaStr,
     				"def prettierPackagesJava = [:]",
    -				"prettierPackagesJava['prettier'] = '2.8.8'",
    -				"prettierPackagesJava['prettier-plugin-java'] = '2.2.0'",
    +				"prettierPackagesJava['prettier'] = '" + prettierVersion + "'",
    +				"prettierPackagesJava['prettier-plugin-java'] = '" + prettierPluginJava + "'",
     				"spotless {",
     				"    format 'php', {",
     				"        target 'php-example.php'",
    @@ -227,8 +331,9 @@ void usePhpAndJavaCommunityPlugin() throws IOException {
     		assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean");
     	}
     
    -	@Test
    -	void autodetectNpmrcFileConfig() throws IOException {
    +	@ParameterizedTest(name = "{index}: autodetectNpmrcFileConfig with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void autodetectNpmrcFileConfig(String prettierVersion) throws IOException {
     		setFile(".npmrc").toLines(
     				"registry=https://i.do.not.exist.com",
     				"fetch-timeout=250",
    @@ -245,7 +350,7 @@ void autodetectNpmrcFileConfig() throws IOException {
     				"spotless {",
     				"    format 'mytypescript', {",
     				"        target 'test.ts'",
    -				"        prettier().config(prettierConfig)",
    +				"        prettier('" + prettierVersion + "').config(prettierConfig)",
     				"    }",
     				"}");
     		setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
    @@ -253,8 +358,9 @@ void autodetectNpmrcFileConfig() throws IOException {
     		Assertions.assertThat(spotlessApply.getOutput()).containsPattern("Running npm command.*npm install.* failed with exit code: 1");
     	}
     
    -	@Test
    -	void pickupNpmrcFileConfig() throws IOException {
    +	@ParameterizedTest(name = "{index}: autodetectNpmrcFileConfig with prettier {0}")
    +	@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
    +	void pickupNpmrcFileConfig(String prettierVersion) throws IOException {
     		setFile(".custom_npmrc").toLines(
     				"registry=https://i.do.not.exist.com",
     				"fetch-timeout=250",
    @@ -271,7 +377,7 @@ void pickupNpmrcFileConfig() throws IOException {
     				"spotless {",
     				"    format 'mytypescript', {",
     				"        target 'test.ts'",
    -				"        prettier().npmrc('.custom_npmrc').config(prettierConfig)",
    +				"        prettier('" + prettierVersion + "').npmrc('.custom_npmrc').config(prettierConfig)",
     				"    }",
     				"}");
     		setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index f932806fcc..b624299e71 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     
     ## [Unreleased]
     
    +### Fixed
    +* Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
    +
     ## [2.39.0] - 2023-08-29
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index 74872ef61f..1dc78a5667 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -1074,6 +1074,8 @@ You can use prettier in any language-specific format, but usually you will be cr
             ${project.basedir}/path/to/configfile
             
                 true
    +            
    +            @prettier/plugin-php
             
           
         
    diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java
    index e92b2814bd..c6b3e46e3c 100644
    --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java
    +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java
    @@ -85,6 +85,11 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
     						if (Boolean.TRUE.toString().equalsIgnoreCase(entry.getValue()) || Boolean.FALSE.toString().equalsIgnoreCase(entry.getValue())) {
     							return new AbstractMap.SimpleEntry<>(entry.getKey(), Boolean.parseBoolean(entry.getValue()));
     						}
    +						// Prettier v3 - plugins config will be a comma delimited list of plugins
    +						if (entry.getKey().equals("plugins")) {
    +							List values = entry.getValue().isEmpty() ? List.of() : Arrays.asList(entry.getValue().split(","));
    +							return new AbstractMap.SimpleEntry<>(entry.getKey(), values);
    +						}
     						return entry;
     					})
     					.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, LinkedHashMap::new));
    diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java
    index 9cd1a313eb..abba35e72c 100644
    --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java
    +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/prettier/PrettierFormatStepTest.java
    @@ -184,6 +184,56 @@ void custom_plugin() throws Exception {
     		assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean");
     	}
     
    +	@Test
    +	void custom_plugin_prettier3() throws Exception {
    +		writePomWithFormatSteps(
    +				"php-example.php",
    +				"",
    +				"  ",
    +				"    ",
    +				"      prettier",
    +				"      3.0.3",
    +				"    ",
    +				"    ",
    +				"      @prettier/plugin-php",
    +				"      0.20.1",
    +				"    ",
    +				"  ",
    +				"  ",
    +				"    3",
    +				"    php",
    +				"    @prettier/plugin-php",
    +				"  ",
    +				"");
    +
    +		setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty");
    +		mavenRunner().withArguments("spotless:apply").runNoError();
    +		assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean");
    +	}
    +
    +	@Test
    +	void custom_plugin_prettier3_file_config() throws Exception {
    +		writePomWithFormatSteps(
    +				"JavaTest.java",
    +				"",
    +				"  ",
    +				"    ",
    +				"      prettier",
    +				"      3.0.3",
    +				"    ",
    +				"    ",
    +				"      prettier-plugin-java",
    +				"      2.3.0",
    +				"    ",
    +				"  ",
    +				"  .prettierrc.yml",
    +				"");
    +		setFile(".prettierrc.yml").toResource("npm/prettier/config/.prettierrc_java_plugin.yml");
    +		setFile("JavaTest.java").toResource("npm/prettier/plugins/java-test.dirty");
    +		mavenRunner().withArguments("spotless:apply").runNoError();
    +		assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean");
    +	}
    +
     	@Test
     	void autodetect_parser_based_on_filename() throws Exception {
     		writePomWithFormatSteps(
    diff --git a/testlib/src/main/resources/npm/prettier/config/.prettierrc_java_plugin.yml b/testlib/src/main/resources/npm/prettier/config/.prettierrc_java_plugin.yml
    new file mode 100644
    index 0000000000..3f7a801335
    --- /dev/null
    +++ b/testlib/src/main/resources/npm/prettier/config/.prettierrc_java_plugin.yml
    @@ -0,0 +1,3 @@
    +parser: java
    +tabWidth: 4
    +plugins: ['prettier-plugin-java']
    
    From d5db9148e47a61e4f814af58b90228414cd2b833 Mon Sep 17 00:00:00 2001
    From: samypr100 <3933065+samypr100@users.noreply.github.com>
    Date: Sat, 2 Sep 2023 23:27:21 -0400
    Subject: [PATCH 0899/1120] fix: add final back to BuildResult
    
    ---
     .../com/diffplug/gradle/spotless/PrettierIntegrationTest.java | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java
    index ed32900db0..74b6db9167 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java
    @@ -50,7 +50,7 @@ void useInlineConfig(String prettierVersion) throws IOException {
     				"    }",
     				"}");
     		setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
    -		BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
    +		final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
     		Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
     		switch (prettierVersion) {
     		case PRETTIER_VERSION_2:
    @@ -80,7 +80,7 @@ void verifyCleanSpotlessCheckWorks(String prettierVersion) throws IOException {
     				"    }",
     				"}");
     		setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
    -		BuildResult spotlessCheckFailsGracefully = gradleRunner().withArguments("--stacktrace", "spotlessCheck").buildAndFail();
    +		final BuildResult spotlessCheckFailsGracefully = gradleRunner().withArguments("--stacktrace", "spotlessCheck").buildAndFail();
     		Assertions.assertThat(spotlessCheckFailsGracefully.getOutput()).contains("> The following files had format violations:");
     
     		gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
    
    From 3226165b74c32c00dcdce8deeecbf7c23283fe3c Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Sun, 3 Sep 2023 20:22:00 +0200
    Subject: [PATCH 0900/1120] feat: add support for nested lists in json writer
    
    opt for supporting lists/arrays as first level citizen in json serialization for configs in npm-based formatters.
    ---
     .../diffplug/spotless/npm/JsonEscaper.java    | 18 +++++-
     ...{SimpleJsonWriter.java => JsonWriter.java} | 33 +++++++----
     .../spotless/npm/ListableAdapter.java         | 58 +++++++++++++++++++
     .../spotless/npm/PrettierRestService.java     | 15 +----
     .../spotless/npm/SimpleRestClient.java        |  4 +-
     .../spotless/npm/TsFmtFormatterStep.java      |  2 +-
     .../spotless/npm/TsFmtRestService.java        |  2 +-
     ...sonWriterTest.java => JsonWriterTest.java} |  6 +-
     8 files changed, 106 insertions(+), 32 deletions(-)
     rename lib/src/main/java/com/diffplug/spotless/npm/{SimpleJsonWriter.java => JsonWriter.java} (77%)
     create mode 100644 lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java
     rename testlib/src/test/java/com/diffplug/spotless/npm/{SimpleJsonWriterTest.java => JsonWriterTest.java} (93%)
    
    diff --git a/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java b/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java
    index 163818d0e7..3ac20d892b 100644
    --- a/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java
    +++ b/lib/src/main/java/com/diffplug/spotless/npm/JsonEscaper.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2016-2020 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.
    @@ -34,6 +34,22 @@ public static String jsonEscape(Object val) {
     		if (val instanceof String) {
     			return jsonEscape((String) val);
     		}
    +		if (ListableAdapter.canAdapt(val)) {
    +			// create an array
    +			StringBuilder sb = new StringBuilder();
    +			sb.append('[');
    +			boolean first = true;
    +			for (Object o : ListableAdapter.adapt(val)) {
    +				if (first) {
    +					first = false;
    +				} else {
    +					sb.append(", ");
    +				}
    +				sb.append(jsonEscape(o));
    +			}
    +			sb.append(']');
    +			return sb.toString();
    +		}
     		return val.toString();
     	}
     
    diff --git a/lib/src/main/java/com/diffplug/spotless/npm/SimpleJsonWriter.java b/lib/src/main/java/com/diffplug/spotless/npm/JsonWriter.java
    similarity index 77%
    rename from lib/src/main/java/com/diffplug/spotless/npm/SimpleJsonWriter.java
    rename to lib/src/main/java/com/diffplug/spotless/npm/JsonWriter.java
    index 846f7f1cf3..bbdf9b63d4 100644
    --- a/lib/src/main/java/com/diffplug/spotless/npm/SimpleJsonWriter.java
    +++ b/lib/src/main/java/com/diffplug/spotless/npm/JsonWriter.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2016-2020 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.
    @@ -28,33 +28,46 @@
     
     import com.diffplug.spotless.ThrowingEx;
     
    -public class SimpleJsonWriter {
    +class JsonWriter {
     
     	private final LinkedHashMap valueMap = new LinkedHashMap<>();
     
    -	public static SimpleJsonWriter of(Map values) {
    -		SimpleJsonWriter writer = new SimpleJsonWriter();
    +	public static JsonWriter of(Map values) {
    +		JsonWriter writer = new JsonWriter();
     		writer.putAll(values);
     		return writer;
     	}
     
    -	SimpleJsonWriter putAll(Map values) {
    +	JsonWriter putAll(Map values) {
     		verifyValues(values);
     		this.valueMap.putAll(values);
     		return this;
     	}
     
    -	SimpleJsonWriter put(String name, Object value) {
    +	JsonWriter put(String name, Object value) {
     		verifyValues(Collections.singletonMap(name, value));
     		this.valueMap.put(name, value);
     		return this;
     	}
     
     	private void verifyValues(Map values) {
    -		if (values.values()
    -				.stream()
    -				.anyMatch(val -> !(val instanceof String || val instanceof JsonRawValue || val instanceof Number || val instanceof Boolean))) {
    -			throw new IllegalArgumentException("Only values of type 'String', 'JsonRawValue', 'Number' and 'Boolean' are supported. You provided: " + values.values());
    +		for (Object value : values.values()) {
    +			verifyValue(value);
    +		}
    +	}
    +
    +	private void verifyValue(Object val) {
    +		if (val == null) {
    +			return;
    +		}
    +		if (ListableAdapter.canAdapt(val)) {
    +			for (Object o : ListableAdapter.adapt(val)) {
    +				verifyValue(o);
    +			}
    +			return;
    +		}
    +		if (!(val instanceof String || val instanceof JsonRawValue || val instanceof Number || val instanceof Boolean)) {
    +			throw new IllegalArgumentException("Only values of type 'String', 'JsonRawValue', 'Number' and 'Boolean' are supported. You provided: " + val);
     		}
     	}
     
    diff --git a/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java b/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java
    new file mode 100644
    index 0000000000..3e05e8e51c
    --- /dev/null
    +++ b/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java
    @@ -0,0 +1,58 @@
    +/*
    + * 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.npm;
    +
    +import javax.annotation.Nonnull;
    +
    +import java.util.Arrays;
    +import java.util.Iterator;
    +import java.util.List;
    +import java.util.Objects;
    +
    +class ListableAdapter implements Iterable {
    +
    +	private final List delegate;
    +
    +	@SuppressWarnings("unchecked")
    +	private ListableAdapter(Object delegate) {
    +		Objects.requireNonNull(delegate);
    +		if (!canAdapt(delegate)) {
    +			throw new IllegalArgumentException("Cannot create ListableAdapter from " + delegate.getClass() + ". Use canAdapt() to check first.");
    +		}
    +		if (delegate instanceof List) {
    +			this.delegate = (List) delegate;
    +		} else if (delegate.getClass().isArray()) {
    +			this.delegate = Arrays.asList((T[]) delegate);
    +		} else {
    +			throw new IllegalArgumentException("Cannot create IterableAdapter from " + delegate.getClass());
    +		}
    +	}
    +
    +	static  Iterable adapt(Object delegate) {
    +		return new ListableAdapter<>(delegate);
    +	}
    +
    +	@Override
    +	@Nonnull
    +	public Iterator iterator() {
    +		return delegate.iterator();
    +	}
    +
    +	static boolean canAdapt(Object delegate) {
    +		Objects.requireNonNull(delegate);
    +		return delegate instanceof List || delegate.getClass().isArray();
    +	}
    +}
    diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java
    index a517a7219b..11fd29c68a 100644
    --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java
    +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierRestService.java
    @@ -17,9 +17,7 @@
     
     import java.io.File;
     import java.util.LinkedHashMap;
    -import java.util.List;
     import java.util.Map;
    -import java.util.stream.Collectors;
     
     public class PrettierRestService extends BaseNpmRestService {
     
    @@ -33,18 +31,7 @@ public String resolveConfig(File prettierConfigPath, Map prettie
     			jsonProperties.put("prettier_config_path", prettierConfigPath.getAbsolutePath());
     		}
     		if (prettierConfigOptions != null) {
    -			// Prettier 3.x plugins support
    -			if (prettierConfigOptions.get("plugins") instanceof List) {
    -				try {
    -					var pluginArray = (List) prettierConfigOptions.get("plugins");
    -					var pluginsJson = pluginArray.stream().map(e -> '"' + e + '"').collect(Collectors.joining(",", "[", "]"));
    -					prettierConfigOptions.put("plugins", JsonRawValue.wrap(pluginsJson));
    -				} catch (ClassCastException e) {
    -					throw new IllegalArgumentException("Only values of type 'List' are supported for plugins.");
    -				}
    -			}
    -			jsonProperties.put("prettier_config_options", SimpleJsonWriter.of(prettierConfigOptions).toJsonRawValue());
    -
    +			jsonProperties.put("prettier_config_options", JsonWriter.of(prettierConfigOptions).toJsonRawValue());
     		}
     		return restClient.postJson("/prettier/config-options", jsonProperties);
     	}
    diff --git a/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java b/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java
    index 561839c757..2f413e4b3a 100644
    --- a/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java
    +++ b/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.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.
    @@ -40,7 +40,7 @@ static SimpleRestClient forBaseUrl(String baseUrl) {
     	}
     
     	String postJson(String endpoint, Map jsonParams) throws SimpleRestException {
    -		final SimpleJsonWriter jsonWriter = SimpleJsonWriter.of(jsonParams);
    +		final JsonWriter jsonWriter = JsonWriter.of(jsonParams);
     		final String jsonString = jsonWriter.toJsonString();
     
     		return postJson(endpoint, jsonString);
    diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java
    index a83c3e202a..6b55610be0 100644
    --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java
    +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java
    @@ -107,7 +107,7 @@ private Map unifyOptions() {
     			Map unified = new HashMap<>();
     			if (!this.inlineTsFmtSettings.isEmpty()) {
     				File targetFile = new File(this.buildDir, "inline-tsfmt.json");
    -				SimpleJsonWriter.of(this.inlineTsFmtSettings).toJsonFile(targetFile);
    +				JsonWriter.of(this.inlineTsFmtSettings).toJsonFile(targetFile);
     				unified.put("tsfmt", true);
     				unified.put("tsfmtFile", targetFile.getAbsolutePath());
     			} else if (this.configFile != null) {
    diff --git a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java
    index 704d2b47af..61a53b4637 100644
    --- a/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java
    +++ b/lib/src/main/java/com/diffplug/spotless/npm/TsFmtRestService.java
    @@ -28,7 +28,7 @@ public String format(String fileContent, Map configOptions) {
     		Map jsonProperties = new LinkedHashMap<>();
     		jsonProperties.put("file_content", fileContent);
     		if (configOptions != null && !configOptions.isEmpty()) {
    -			jsonProperties.put("config_options", SimpleJsonWriter.of(configOptions).toJsonRawValue());
    +			jsonProperties.put("config_options", JsonWriter.of(configOptions).toJsonRawValue());
     		}
     
     		return restClient.postJson("/tsfmt/format", jsonProperties);
    diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/SimpleJsonWriterTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/JsonWriterTest.java
    similarity index 93%
    rename from testlib/src/test/java/com/diffplug/spotless/npm/SimpleJsonWriterTest.java
    rename to testlib/src/test/java/com/diffplug/spotless/npm/JsonWriterTest.java
    index 34d7966709..cb1719c0f3 100644
    --- a/testlib/src/test/java/com/diffplug/spotless/npm/SimpleJsonWriterTest.java
    +++ b/testlib/src/test/java/com/diffplug/spotless/npm/JsonWriterTest.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.
    @@ -26,9 +26,9 @@
     import com.diffplug.common.collect.ImmutableMap;
     import com.diffplug.spotless.ResourceHarness;
     
    -class SimpleJsonWriterTest extends ResourceHarness {
    +class JsonWriterTest extends ResourceHarness {
     
    -	private SimpleJsonWriter jsonWriter = new SimpleJsonWriter();
    +	private JsonWriter jsonWriter = new JsonWriter();
     
     	@Test
     	void itWritesAValidEmptyObject() {
    
    From 6fbb6505790be5103a96a4385eb33095046e1163 Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Sun, 3 Sep 2023 20:32:58 +0200
    Subject: [PATCH 0901/1120] docs: make explicit and add maven doc
    
    ---
     plugin-gradle/README.md | 4 ++--
     plugin-maven/README.md  | 2 ++
     2 files changed, 4 insertions(+), 2 deletions(-)
    
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 2253557f3a..fcdcfc213a 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -1024,12 +1024,12 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos
     spotless {
       java {
         prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0']).config(['parser': 'java', 'tabWidth': 4])
    -    // prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']).config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) // Prettier v3
    +    // prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']).config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) // Prettier v3 requires additional 'plugins' config
       }
       format 'php', {
         target 'src/**/*.php'
         prettier(['prettier': '2.8.8', '@prettier/plugin-php': '0.19.6']).config(['parser': 'php', 'tabWidth': 3])
    -    // prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']).config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) // Prettier v3
    +    // prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']).config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) // Prettier v3 requires additional 'plugins' config
       }
     }
     ```
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index 1dc78a5667..8f91d8b08b 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -1121,6 +1121,7 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos
             
                 4
                 java
    +            prettier-plugin-java
             
           
         
    @@ -1146,6 +1147,7 @@ Since spotless uses the actual npm prettier package behind the scenes, it is pos
             
                 3
                 php
    +            @prettier/plugin-php
             
           
         
    
    From 3754eb12d3da00be2da0cdadd3123e11ae63af9b Mon Sep 17 00:00:00 2001
    From: Simon Gamma 
    Date: Mon, 4 Sep 2023 15:02:11 +0200
    Subject: [PATCH 0902/1120] style: fix import order
    
    ---
     .../main/java/com/diffplug/spotless/npm/ListableAdapter.java  | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java b/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java
    index 3e05e8e51c..24ae62fde6 100644
    --- a/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java
    +++ b/lib/src/main/java/com/diffplug/spotless/npm/ListableAdapter.java
    @@ -15,13 +15,13 @@
      */
     package com.diffplug.spotless.npm;
     
    -import javax.annotation.Nonnull;
    -
     import java.util.Arrays;
     import java.util.Iterator;
     import java.util.List;
     import java.util.Objects;
     
    +import javax.annotation.Nonnull;
    +
     class ListableAdapter implements Iterable {
     
     	private final List delegate;
    
    From 7da08c7fbc5b8b908edd6bd36a2fd7272a7c4998 Mon Sep 17 00:00:00 2001
    From: samypr100 <3933065+samypr100@users.noreply.github.com>
    Date: Mon, 4 Sep 2023 17:25:08 -0400
    Subject: [PATCH 0903/1120] fix: remove HasBuiltinDelimiterForLicense as it's
     not quite applicable
    
    ---
     plugin-gradle/README.md                              |  2 +-
     .../diffplug/gradle/spotless/FlexmarkExtension.java  | 12 +-----------
     2 files changed, 2 insertions(+), 12 deletions(-)
    
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 91def5ad5f..a2a3ac948e 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -62,7 +62,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui
       - [Protobuf](#protobuf) ([buf](#buf), [clang-format](#clang-format))
       - [Python](#python) ([black](#black))
       - [FreshMark](#freshmark) aka markdown
    -  - [FlexMark](#flexmark) aka markdown
    +  - [Flexmark](#flexmark) aka markdown
       - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter))
       - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier))
       - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome))
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java
    index feee2c4801..047b0eda73 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java
    @@ -22,7 +22,7 @@
     import com.diffplug.spotless.FormatterStep;
     import com.diffplug.spotless.markdown.FlexmarkStep;
     
    -public class FlexmarkExtension extends FormatExtension implements HasBuiltinDelimiterForLicense {
    +public class FlexmarkExtension extends FormatExtension {
     	static final String NAME = "flexmark";
     
     	@Inject
    @@ -30,16 +30,6 @@ public FlexmarkExtension(SpotlessExtension spotless) {
     		super(spotless);
     	}
     
    -	@Override
    -	public LicenseHeaderConfig licenseHeader(String licenseHeader) {
    -		return licenseHeader(licenseHeader, null);
    -	}
    -
    -	@Override
    -	public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) {
    -		return licenseHeaderFile(licenseHeaderFile, null);
    -	}
    -
     	public FlexmarkFormatterConfig flexmarkFormatter() {
     		return flexmarkFormatter(FlexmarkStep.defaultVersion());
     	}
    
    From 0948c3e2323895efc7d6574d5e20f9ce358d8708 Mon Sep 17 00:00:00 2001
    From: Goooler 
    Date: Fri, 8 Sep 2023 16:12:10 +0800
    Subject: [PATCH 0904/1120] Support ktlint 1.0.0
    
    https://github.com/pinterest/ktlint/releases/tag/1.0.0
    ---
     lib/build.gradle                              |   7 +-
     .../compat/KtLintCompat1Dot0Dot0Adapter.java  | 165 ++++++++++++++++++
     .../glue/ktlint/KtlintFormatterFunc.java      |  36 ++--
     .../diffplug/spotless/kotlin/KtLintStep.java  |   9 +-
     .../KtLintCompat1Dot0Dot0AdapterTest.java     |  71 ++++++++
     .../resources/EmptyClassBody.kt               |   3 +
     .../resources/FailsNoSemicolons.kt            |   3 +
     plugin-gradle/README.md                       |   2 +-
     .../spotless/maven/kotlin/KtlintTest.java     |  10 +-
     .../spotless/kotlin/KtLintStepTest.java       |  10 ++
     10 files changed, 293 insertions(+), 23 deletions(-)
     create mode 100644 lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java
     create mode 100644 lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java
     create mode 100644 lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt
     create mode 100644 lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt
    
    diff --git a/lib/build.gradle b/lib/build.gradle
    index 01591e557d..0288277c78 100644
    --- a/lib/build.gradle
    +++ b/lib/build.gradle
    @@ -48,6 +48,7 @@ versionCompatibility {
     				'0.48.0',
     				'0.49.0',
     				'0.50.0',
    +				'1.0.0',
     			]
     			targetSourceSetName = 'ktlint'
     		}
    @@ -104,10 +105,14 @@ dependencies {
     	compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.49.0'
     	compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.49.0'
     	compatKtLint0Dot49Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0'
    -	// ktlint latest supported version
    +	// ktlint previous supported version
     	compatKtLint0Dot50Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.50.0'
     	compatKtLint0Dot50Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.50.0'
     	compatKtLint0Dot50Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0'
    +	// ktlint latest supported version
    +	compatKtLint1Dot0Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:1.0.0'
    +	compatKtLint1Dot0Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:1.0.0'
    +	compatKtLint1Dot0Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0'
     	// palantirJavaFormat
     	palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' 	// this version needs to stay compilable against Java 8 for CI Job testNpm
     	// scalafmt
    diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java
    new file mode 100644
    index 0000000000..7b12169400
    --- /dev/null
    +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java
    @@ -0,0 +1,165 @@
    +/*
    + * 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.ktlint.compat;
    +
    +import java.nio.file.Files;
    +import java.nio.file.Path;
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Objects;
    +import java.util.ServiceLoader;
    +import java.util.Set;
    +import java.util.stream.Collectors;
    +import java.util.stream.Stream;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3;
    +import com.pinterest.ktlint.rule.engine.api.Code;
    +import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults;
    +import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride;
    +import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine;
    +import com.pinterest.ktlint.rule.engine.api.LintError;
    +import com.pinterest.ktlint.rule.engine.core.api.Rule;
    +import com.pinterest.ktlint.rule.engine.core.api.RuleId;
    +import com.pinterest.ktlint.rule.engine.core.api.RuleProvider;
    +import com.pinterest.ktlint.rule.engine.core.api.RuleSetId;
    +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleEditorConfigPropertyKt;
    +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty;
    +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EndOfLinePropertyKt;
    +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentSizeEditorConfigPropertyKt;
    +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentStyleEditorConfigPropertyKt;
    +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt;
    +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt;
    +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution;
    +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt;
    +
    +import kotlin.Pair;
    +import kotlin.Unit;
    +import kotlin.jvm.functions.Function2;
    +
    +public class KtLintCompat1Dot0Dot0Adapter implements KtLintCompatAdapter {
    +
    +	private static final Logger logger = LoggerFactory.getLogger(KtLintCompat1Dot0Dot0Adapter.class);
    +
    +	private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES;
    +
    +	static {
    +		List> list = new ArrayList<>();
    +		list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY());
    +		list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY());
    +		list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY());
    +		list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY());
    +		list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY());
    +		list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY());
    +		list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY());
    +		DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list);
    +	}
    +
    +	static class FormatterCallback implements Function2 {
    +
    +		@Override
    +		public Unit invoke(LintError lint, Boolean corrected) {
    +			if (!corrected) {
    +				KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId().getValue(), lint.getDetail());
    +			}
    +			return Unit.INSTANCE;
    +		}
    +	}
    +
    +	@Override
    +	public String format(final String text, Path path, final boolean isScript,
    +			Path editorConfigPath, final Map userData,
    +			final Map editorConfigOverrideMap) {
    +		final FormatterCallback formatterCallback = new FormatterCallback();
    +
    +		Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader())
    +				.stream()
    +				.flatMap(loader -> loader.get().getRuleProviders().stream())
    +				.collect(Collectors.toUnmodifiableSet());
    +
    +		EditorConfigOverride editorConfigOverride;
    +		if (editorConfigOverrideMap.isEmpty()) {
    +			editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE();
    +		} else {
    +			editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map(
    +					RuleProvider::createNewRuleInstance).collect(Collectors.toList()),
    +					editorConfigOverrideMap);
    +		}
    +		EditorConfigDefaults editorConfig;
    +		if (editorConfigPath == null || !Files.exists(editorConfigPath)) {
    +			editorConfig = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS();
    +		} else {
    +			editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath, Collections.emptySet());
    +		}
    +
    +		return new KtLintRuleEngine(
    +				allRuleProviders,
    +				editorConfig,
    +				editorConfigOverride,
    +				false,
    +				path.getFileSystem())
    +				.format(Code.Companion.fromPath(path), formatterCallback);
    +	}
    +
    +	/**
    +	 * Create EditorConfigOverride from user provided parameters.
    +	 */
    +	private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) {
    +		// Get properties from rules in the rule sets
    +		Stream> ruleProperties = rules.stream()
    +				.flatMap(rule -> rule.getUsesEditorConfigProperties().stream());
    +
    +		// Create a mapping of properties to their names based on rule properties and default properties
    +		Map> supportedProperties = Stream
    +				.concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream())
    +				.distinct()
    +				.collect(Collectors.toMap(EditorConfigProperty::getName, property -> property));
    +
    +		// Create config properties based on provided property names and values
    +		@SuppressWarnings("unchecked")
    +		Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream()
    +				.map(entry -> {
    +					EditorConfigProperty property = supportedProperties.get(entry.getKey());
    +
    +					if (property == null && entry.getKey().startsWith("ktlint_")) {
    +						String[] parts = entry.getKey().substring(7).split("_", 2);
    +						if (parts.length == 1) {
    +							// convert ktlint_{ruleset} to RuleSetId
    +							RuleSetId id = new RuleSetId(parts[0]);
    +							property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(id, RuleExecution.enabled);
    +						} else {
    +							// convert ktlint_{ruleset}_{rulename} to RuleId
    +							RuleId id = new RuleId(parts[0] + ":" + parts[1]);
    +							property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(id, RuleExecution.enabled);
    +						}
    +					}
    +
    +					if (property == null) {
    +						return null;
    +					} else {
    +						return new Pair<>(property, entry.getValue());
    +					}
    +				})
    +				.filter(Objects::nonNull)
    +				.toArray(Pair[]::new);
    +
    +		return EditorConfigOverride.Companion.from(properties);
    +	}
    +}
    diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java
    index 1a11e8bcce..7ae0222566 100644
    --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java
    +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java
    @@ -33,22 +33,28 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile {
     
     	public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath, Map userData,
     			Map editorConfigOverrideMap) {
    -		int minorVersion = Integer.parseInt(version.split("\\.")[1]);
    -		if (minorVersion >= 50) {
    -			// Fixed `RuleId` and `RuleSetId` issues
    -			// New argument to `EditorConfigDefaults.Companion.load(...)` for custom property type parsing
    -			// New argument to `new KtLintRuleEngine(...)` to fail on usage of `treeCopyHandler` extension point
    -			this.adapter = new KtLintCompat0Dot50Dot0Adapter();
    -		} else if (minorVersion == 49) {
    -			// Packages and modules moved around (`ktlint-core` -> `ktlint-rule-engine`)
    -			// Experimental ruleset was replaced by implementing `Rule.Experimental` and checking the `ktlint_experimental` `.editorconfig` property
    -			// `RuleId` and `RuleSetId` became inline classes (mangled to be unrepresentable in Java source code, so reflection is needed), tracked here: https://github.com/pinterest/ktlint/issues/2041
    -			this.adapter = new KtLintCompat0Dot49Dot0Adapter();
    -		} else if (minorVersion == 48) {
    -			// ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class
    -			this.adapter = new KtLintCompat0Dot48Dot0Adapter();
    +		String[] versions = version.split("\\.");
    +		int majorVersion = Integer.parseInt(versions[0]);
    +		int minorVersion = Integer.parseInt(versions[1]);
    +		if (majorVersion == 1) {
    +			this.adapter = new KtLintCompat1Dot0Dot0Adapter();
     		} else {
    -			throw new IllegalStateException("Ktlint versions < 0.48.0 not supported!");
    +			if (minorVersion >= 50) {
    +				// Fixed `RuleId` and `RuleSetId` issues
    +				// New argument to `EditorConfigDefaults.Companion.load(...)` for custom property type parsing
    +				// New argument to `new KtLintRuleEngine(...)` to fail on usage of `treeCopyHandler` extension point
    +				this.adapter = new KtLintCompat0Dot50Dot0Adapter();
    +			} else if (minorVersion == 49) {
    +				// Packages and modules moved around (`ktlint-core` -> `ktlint-rule-engine`)
    +				// Experimental ruleset was replaced by implementing `Rule.Experimental` and checking the `ktlint_experimental` `.editorconfig` property
    +				// `RuleId` and `RuleSetId` became inline classes (mangled to be unrepresentable in Java source code, so reflection is needed), tracked here: https://github.com/pinterest/ktlint/issues/2041
    +				this.adapter = new KtLintCompat0Dot49Dot0Adapter();
    +			} else if (minorVersion == 48) {
    +				// ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class
    +				this.adapter = new KtLintCompat0Dot48Dot0Adapter();
    +			} else {
    +				throw new IllegalStateException("Ktlint versions < 0.48.0 not supported!");
    +			}
     		}
     		this.editorConfigPath = editorConfigPath;
     		this.editorConfigOverrideMap = editorConfigOverrideMap;
    diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java
    index 8f3fde5731..d08c59b839 100644
    --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java
    +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java
    @@ -36,10 +36,10 @@ public class KtLintStep {
     	// prevent direct instantiation
     	private KtLintStep() {}
     
    -	private static final String DEFAULT_VERSION = "0.50.0";
    +	private static final String DEFAULT_VERSION = "1.0.0";
     	static final String NAME = "ktlint";
    -	static final String PACKAGE = "com.pinterest";
    -	static final String MAVEN_COORDINATE = PACKAGE + ":ktlint:";
    +	static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:";
    +	static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:";
     
     	public static FormatterStep create(Provisioner provisioner) {
     		return create(defaultVersion(), provisioner);
    @@ -110,7 +110,8 @@ static final class State implements Serializable {
     			this.version = version;
     			this.userData = new TreeMap<>(userData);
     			this.editorConfigOverride = new TreeMap<>(editorConfigOverride);
    -			this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner);
    +			this.jarState = JarState.from((version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version,
    +					provisioner);
     			this.editorConfigPath = editorConfigPath;
     			this.isScript = isScript;
     		}
    diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java
    new file mode 100644
    index 0000000000..5ed2517c6f
    --- /dev/null
    +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java
    @@ -0,0 +1,71 @@
    +/*
    + * 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.ktlint.compat;
    +
    +import static org.junit.jupiter.api.Assertions.assertEquals;
    +
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.nio.charset.StandardCharsets;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
    +import java.nio.file.Paths;
    +import java.util.HashMap;
    +import java.util.Map;
    +
    +import org.junit.jupiter.api.Test;
    +import org.junit.jupiter.api.io.TempDir;
    +
    +public class KtLintCompat1Dot0Dot0AdapterTest {
    +	@Test
    +	public void testDefaults(@TempDir Path path) throws IOException {
    +		KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter();
    +		String text = loadAndWriteText(path, "EmptyClassBody.kt");
    +		final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");
    +
    +		Map userData = new HashMap<>();
    +
    +		Map editorConfigOverrideMap = new HashMap<>();
    +
    +		String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap);
    +		assertEquals("class EmptyClassBody\n", formatted);
    +	}
    +
    +	@Test
    +	public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
    +		KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter();
    +		String text = loadAndWriteText(path, "FailsNoSemicolons.kt");
    +		final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");
    +
    +		Map userData = new HashMap<>();
    +
    +		Map editorConfigOverrideMap = new HashMap<>();
    +		editorConfigOverrideMap.put("indent_style", "tab");
    +		editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea");
    +		editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");
    +
    +		String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap);
    +		assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted);
    +	}
    +
    +	private static String loadAndWriteText(Path path, String name) throws IOException {
    +		try (InputStream is = KtLintCompat1Dot0Dot0AdapterTest.class.getResourceAsStream("/" + name)) {
    +			Files.copy(is, path.resolve(name));
    +		}
    +		return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8);
    +	}
    +
    +}
    diff --git a/lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt b/lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt
    new file mode 100644
    index 0000000000..7da53fb78d
    --- /dev/null
    +++ b/lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt
    @@ -0,0 +1,3 @@
    +class EmptyClassBody {
    +
    +}
    diff --git a/lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt b/lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt
    new file mode 100644
    index 0000000000..4cf05ceacf
    --- /dev/null
    +++ b/lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt
    @@ -0,0 +1,3 @@
    +class FailsNoSemicolons {
    +	val i = 0;
    +}
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 944c07bb6e..9cc5019f57 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -399,7 +399,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `.
     spotless {
       kotlin {
         // version, userData and editorConfigOverride are all optional
    -    ktlint("0.50.0")
    +    ktlint("1.0.0")
           .userData(mapOf("android" to "true"))
           .setEditorConfigPath("$projectDir/config/.editorconfig")  // sample unusual placement
           .editorConfigOverride(mapOf("indent_size" to 2))
    diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java
    index ba6f1d8e2c..f3f360dc5d 100644
    --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java
    +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2016-2022 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.
    @@ -32,7 +32,13 @@ void testKtlint() throws Exception {
     
     	@Test
     	void testKtlintEditorConfigOverride() throws Exception {
    -		writePomWithKotlinSteps("truetrue");
    +		writePomWithKotlinSteps("\n" +
    +				"  \n" +
    +				"    true\n" +
    +				"    true\n" +
    +				"    intellij_idea\n" +
    +				"  \n" +
    +				"");
     
     		String path = "src/main/kotlin/Main.kt";
     		setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty");
    diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java
    index 5b62eeed48..0ccb47d1ed 100644
    --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java
    +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java
    @@ -74,6 +74,16 @@ void works0_50_0() {
     						"Wildcard import");
     	}
     
    +	@Test
    +	void works1_0_0() {
    +		FormatterStep step = KtLintStep.create("1.0.0", TestProvisioner.mavenCentral());
    +		StepHarnessWithFile.forStep(this, step)
    +				.testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean")
    +				.testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" +
    +						"rule: standard:no-wildcard-imports\n" +
    +						"Wildcard import");
    +	}
    +
     	@Test
     	void behavior() {
     		FormatterStep step = KtLintStep.create(TestProvisioner.mavenCentral());
    
    From 0224d3575f35e537f2cbc93e0903b984df389f44 Mon Sep 17 00:00:00 2001
    From: Goooler 
    Date: Sun, 10 Sep 2023 02:00:45 +0800
    Subject: [PATCH 0905/1120] Update changelogs
    
    ---
     CHANGES.md               | 2 ++
     plugin-gradle/CHANGES.md | 3 +++
     plugin-gradle/README.md  | 7 ++++++-
     plugin-maven/CHANGES.md  | 3 +++
     plugin-maven/README.md   | 3 ++-
     5 files changed, 16 insertions(+), 2 deletions(-)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 1d78e8d932..c2d379a874 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -10,6 +10,8 @@ This document is intended for Spotless developers.
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    +### Added
    +* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)).
     
     ## [2.41.0] - 2023-08-29
     ### Added
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index eab7e32b2d..b66fcbc262 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -3,6 +3,9 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
     
     ## [Unreleased]
    +### Added
    +* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)).
    +  The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`.
     
     ## [6.21.0] - 2023-08-29
     ### Added
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index 9cc5019f57..9a4b84c4dd 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -402,7 +402,12 @@ spotless {
         ktlint("1.0.0")
           .userData(mapOf("android" to "true"))
           .setEditorConfigPath("$projectDir/config/.editorconfig")  // sample unusual placement
    -      .editorConfigOverride(mapOf("indent_size" to 2))
    +      .editorConfigOverride(
    +        mapOf(
    +          "indent_size" to 2,
    +          "ktlint_code_style" to "intellij_idea",
    +        )
    +      )
       }
     }
     ```
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index f932806fcc..54f92898a1 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -3,6 +3,9 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    +### Added
    +* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)).
    +The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`.
     
     ## [2.39.0] - 2023-08-29
     ### Added
    diff --git a/plugin-maven/README.md b/plugin-maven/README.md
    index 74872ef61f..9419490d3e 100644
    --- a/plugin-maven/README.md
    +++ b/plugin-maven/README.md
    @@ -409,10 +409,11 @@ Additionally, `editorConfigOverride` options will override what's supplied in `.
     
     ```xml
     
    -  0.43.2 
    +  1.0.0 
        
         true
         true
    +    intellij_idea
       
     
     ```
    
    From f32701212bf8d327c67d10c35316cb80dcdf577b Mon Sep 17 00:00:00 2001
    From: Goooler 
    Date: Sun, 10 Sep 2023 19:58:18 +0800
    Subject: [PATCH 0906/1120] Migrate deprecated buildDir usages
    
    https://docs.gradle.org/8.3/userguide/upgrading_version_8.html#project_builddir
    ---
     plugin-gradle/README.md                                   | 2 +-
     .../com/diffplug/gradle/spotless/FormatExtension.java     | 8 ++++----
     .../com/diffplug/gradle/spotless/JavascriptExtension.java | 2 +-
     .../gradle/spotless/RegisterDependenciesTask.java         | 2 +-
     .../diffplug/gradle/spotless/SpotlessDiagnoseTask.java    | 5 +++--
     .../java/com/diffplug/gradle/spotless/SpotlessTask.java   | 2 +-
     .../com/diffplug/gradle/spotless/TypescriptExtension.java | 4 ++--
     7 files changed, 13 insertions(+), 12 deletions(-)
    
    diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
    index fcdcfc213a..f81b897a4a 100644
    --- a/plugin-gradle/README.md
    +++ b/plugin-gradle/README.md
    @@ -1243,7 +1243,7 @@ To use a fixed binary, omit the `version` and specify a `pathToExe`:
     spotless {
       format 'rome', {
         target '**/*.js','**/*.ts','**/*.json'
    -    rome().pathToExe("${project.buildDir.absolutePath}/bin/rome")
    +    rome().pathToExe("${project.layout.buildDirectory.asFile.get().absolutePath}/bin/rome")
       }
     }
     ```
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    index 7a62f8cabf..1f8b0c95b2 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
    @@ -280,9 +280,9 @@ private final FileCollection parseTargetIsExclude(Object target, boolean isExclu
     					excludes.add(".gradle");
     				}
     				// no build folders (flatInclude means that subproject might not be subfolders, see https://github.com/diffplug/spotless/issues/121)
    -				relativizeIfSubdir(excludes, dir, getProject().getBuildDir());
    +				relativizeIfSubdir(excludes, dir, getProject().getLayout().getBuildDirectory().getAsFile().get());
     				for (Project subproject : getProject().getSubprojects()) {
    -					relativizeIfSubdir(excludes, dir, subproject.getBuildDir());
    +					relativizeIfSubdir(excludes, dir, subproject.getLayout().getBuildDirectory().getAsFile().get());
     				}
     				matchedFiles.exclude(excludes);
     			}
    @@ -606,7 +606,7 @@ public T npmInstallCache(final Object npmInstallCache) {
     		}
     
     		public T npmInstallCache() {
    -			this.npmInstallCache = new File(project.getBuildDir(), SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME);
    +			this.npmInstallCache = new File(project.getLayout().getBuildDirectory().getAsFile().get(), SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME);
     			replaceStep();
     			return (T) this;
     		}
    @@ -673,7 +673,7 @@ protected FormatterStep createStep() {
     					devDependencies,
     					provisioner(),
     					project.getProjectDir(),
    -					project.getBuildDir(),
    +					project.getLayout().getBuildDirectory().getAsFile().get(),
     					npmModulesCacheOrNull(),
     					new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())),
     					new com.diffplug.spotless.npm.PrettierConfig(
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java
    index 76ad5650ca..cd2682e971 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java
    @@ -107,7 +107,7 @@ public FormatterStep createStep() {
     					devDependencies,
     					provisioner(),
     					project.getProjectDir(),
    -					project.getBuildDir(),
    +					project.getLayout().getBuildDirectory().getAsFile().get(),
     					npmModulesCacheOrNull(),
     					new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())),
     					eslintConfig());
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java
    index bdeb9d7d94..b7ffd0a295 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java
    @@ -68,7 +68,7 @@ void setup() {
     		taskService = buildServices.registerIfAbsent("SpotlessTaskService" + compositeBuildSuffix, SpotlessTaskService.class, spec -> {});
     		usesService(taskService);
     		getBuildEventsListenerRegistry().onTaskCompletion(taskService);
    -		unitOutput = new File(getProject().getBuildDir(), "tmp/spotless-register-dependencies");
    +		unitOutput = new File(getProject().getLayout().getBuildDirectory().getAsFile().get(), "tmp/spotless-register-dependencies");
     	}
     
     	List steps = new ArrayList<>();
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessDiagnoseTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessDiagnoseTask.java
    index f20957e650..6dcba72864 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessDiagnoseTask.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessDiagnoseTask.java
    @@ -1,5 +1,5 @@
     /*
    - * Copyright 2016 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.
    @@ -43,7 +43,8 @@ public SpotlessTask getSource() {
     	@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
     	public void performAction() throws IOException {
     		Path srcRoot = getProject().getProjectDir().toPath();
    -		Path diagnoseRoot = getProject().getBuildDir().toPath().resolve("spotless-diagnose-" + source.formatName());
    +		Path diagnoseRoot = getProject().getLayout().getBuildDirectory().getAsFile().get()
    +				.toPath().resolve("spotless-diagnose-" + source.formatName());
     		getProject().delete(diagnoseRoot.toFile());
     		try (Formatter formatter = source.buildFormatter()) {
     			for (File file : source.target) {
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java
    index 2af9a80b7a..7b225eacd0 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTask.java
    @@ -148,7 +148,7 @@ public void setTarget(Iterable target) {
     		}
     	}
     
    -	protected File outputDirectory = new File(getProject().getBuildDir(), "spotless/" + getName());
    +	protected File outputDirectory = new File(getProject().getLayout().getBuildDirectory().getAsFile().get(), "spotless/" + getName());
     
     	@OutputDirectory
     	public File getOutputDirectory() {
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java
    index ddb7fbfc10..929ea4423b 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java
    @@ -118,7 +118,7 @@ public FormatterStep createStep() {
     					devDependencies,
     					provisioner(),
     					project.getProjectDir(),
    -					project.getBuildDir(),
    +					project.getLayout().getBuildDirectory().getAsFile().get(),
     					npmModulesCacheOrNull(),
     					new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())),
     					typedConfigFile(),
    @@ -215,7 +215,7 @@ public FormatterStep createStep() {
     					devDependencies,
     					provisioner(),
     					project.getProjectDir(),
    -					project.getBuildDir(),
    +					project.getLayout().getBuildDirectory().getAsFile().get(),
     					npmModulesCacheOrNull(),
     					new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())),
     					eslintConfig());
    
    From 49a64c43601f047c817f3d85ad132948d9bd799a Mon Sep 17 00:00:00 2001
    From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
    Date: Sun, 10 Sep 2023 17:33:25 +0000
    Subject: [PATCH 0907/1120] chore(deps): update plugin com.github.spotbugs to
     v5.1.3
    
    ---
     settings.gradle | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/settings.gradle b/settings.gradle
    index a24c6d24d5..11ac98ec93 100644
    --- a/settings.gradle
    +++ b/settings.gradle
    @@ -12,7 +12,7 @@ plugins {
     	// https://github.com/gradle-nexus/publish-plugin/releases
     	id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false
     	// https://github.com/spotbugs/spotbugs-gradle-plugin/releases
    -	id 'com.github.spotbugs' version '5.0.14' apply false
    +	id 'com.github.spotbugs' version '5.1.3' apply false
     	// https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md
     	id 'com.diffplug.spotless-changelog' version '3.0.2' apply false
     	// https://github.com/diffplug/goomph/blob/main/CHANGES.md
    
    From c3f286224947ae53a94d6618a877c564866852e6 Mon Sep 17 00:00:00 2001
    From: Ned Twigg 
    Date: Wed, 13 Sep 2023 22:31:29 -0700
    Subject: [PATCH 0908/1120] Move the changelog entries to the right place.
    
    ---
     CHANGES.md               | 4 ++--
     plugin-gradle/CHANGES.md | 4 ++--
     plugin-maven/CHANGES.md  | 4 ++--
     3 files changed, 6 insertions(+), 6 deletions(-)
    
    diff --git a/CHANGES.md b/CHANGES.md
    index 52db59e7bd..2112f3aa2c 100644
    --- a/CHANGES.md
    +++ b/CHANGES.md
    @@ -10,7 +10,8 @@ This document is intended for Spotless developers.
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    -
    +### Added
    +* Added support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793))
     ### Fixed
     * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
     
    @@ -18,7 +19,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
    -* Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793))
     ### Fixed
     * Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756))
     * Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
    diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
    index 7ca1fd168e..e4360b02bb 100644
    --- a/plugin-gradle/CHANGES.md
    +++ b/plugin-gradle/CHANGES.md
    @@ -3,7 +3,8 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
     
     ## [Unreleased]
    -
    +### Added
    +* Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793))
     ### Fixed
     * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
     
    @@ -11,7 +12,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
    -* Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793))
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
    index e8e4081019..3bcc396f8d 100644
    --- a/plugin-maven/CHANGES.md
    +++ b/plugin-maven/CHANGES.md
    @@ -3,7 +3,8 @@
     We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
     
     ## [Unreleased]
    -
    +### Added
    +* Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793))
     ### Fixed
     * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
     
    @@ -11,7 +12,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
     ### Added
     * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
     * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780))
    -* Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793))
     ### Fixed
     * Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
     * Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
    
    From 919b4811448e1ec11ceadfebc8bcfc8f48137ad4 Mon Sep 17 00:00:00 2001
    From: Goooler 
    Date: Fri, 15 Sep 2023 13:41:57 +0800
    Subject: [PATCH 0909/1120] Fix ktlint tests
    
    ---
     .../com/diffplug/spotless/kotlin/KtLintStep.java     |  2 +-
     .../diffplug/gradle/spotless/GradleProvisioner.java  | 10 +++++++++-
     .../gradle/spotless/KotlinExtensionTest.java         |  1 +
     .../gradle/spotless/KotlinGradleExtensionTest.java   |  1 +
     .../java/com/diffplug/spotless/TestProvisioner.java  | 12 ++++++++++--
     .../com/diffplug/spotless/kotlin/KtLintStepTest.java |  8 ++++----
     6 files changed, 26 insertions(+), 8 deletions(-)
    
    diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java
    index d08c59b839..bedbb4a071 100644
    --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java
    +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java
    @@ -39,7 +39,7 @@ private KtLintStep() {}
     	private static final String DEFAULT_VERSION = "1.0.0";
     	static final String NAME = "ktlint";
     	static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:";
    -	static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:";
    +	public static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:";
     
     	public static FormatterStep create(Provisioner provisioner) {
     		return create(defaultVersion(), provisioner);
    diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java
    index e1129b3b0b..a92d583596 100644
    --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java
    +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java
    @@ -34,6 +34,7 @@
     import com.diffplug.common.base.Unhandled;
     import com.diffplug.common.collect.ImmutableList;
     import com.diffplug.spotless.Provisioner;
    +import com.diffplug.spotless.kotlin.KtLintStep;
     
     /** Should be package-private. */
     class GradleProvisioner {
    @@ -121,7 +122,14 @@ private static Provisioner forConfigurationContainer(Project project, Configurat
     				config.setCanBeConsumed(false);
     				config.setVisible(false);
     				config.attributes(attr -> {
    -					attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL));
    +					final String type;
    +					// See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984.
    +					if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) {
    +						type = Bundling.SHADOWED;
    +					} else {
    +						type = Bundling.EXTERNAL;
    +					}
    +					attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type));
     				});
     				return config.resolve();
     			} catch (Exception e) {
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java
    index 1c23728244..a2fa7c16e7 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java
    @@ -73,6 +73,7 @@ void withExperimentalEditorConfigOverride() throws IOException {
     				"spotless {",
     				"    kotlin {",
     				"        ktlint().editorConfigOverride([",
    +				"            ktlint_code_style: \"intellij_idea\",",
     				"            ktlint_experimental: \"enabled\",",
     				"            ij_kotlin_allow_trailing_comma: true,",
     				"            ij_kotlin_allow_trailing_comma_on_call_site: true",
    diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java
    index 7dade5f2ff..6d7bdf351a 100644
    --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java
    +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java
    @@ -52,6 +52,7 @@ void withExperimentalEditorConfigOverride() throws IOException {
     				"spotless {",
     				"    kotlinGradle {",
     				"        ktlint().editorConfigOverride([",
    +				"            ktlint_code_style: \"intellij_idea\",",
     				"            ktlint_experimental: \"enabled\",",
     				"            ij_kotlin_allow_trailing_comma: true,",
     				"            ij_kotlin_allow_trailing_comma_on_call_site: true",
    diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java
    index 0d9ced4c9e..6a942d8ca3 100644
    --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java
    +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.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.
    @@ -39,6 +39,7 @@
     import com.diffplug.common.base.Suppliers;
     import com.diffplug.common.collect.ImmutableSet;
     import com.diffplug.common.io.Files;
    +import com.diffplug.spotless.kotlin.KtLintStep;
     
     public class TestProvisioner {
     	public static Project gradleProject(File dir) {
    @@ -70,7 +71,14 @@ private static Provisioner createWithRepositories(Consumer re
     			config.setTransitive(withTransitives);
     			config.setDescription(mavenCoords.toString());
     			config.attributes(attr -> {
    -				attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL));
    +				final String type;
    +				// See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984.
    +				if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) {
    +					type = Bundling.SHADOWED;
    +				} else {
    +					type = Bundling.EXTERNAL;
    +				}
    +				attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type));
     			});
     			try {
     				return config.resolve();
    diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java
    index 0ccb47d1ed..02526b46e6 100644
    --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java
    +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java
    @@ -80,8 +80,8 @@ void works1_0_0() {
     		StepHarnessWithFile.forStep(this, step)
     				.testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean")
     				.testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" +
    -						"rule: standard:no-wildcard-imports\n" +
    -						"Wildcard import");
    +						"rule: standard:no-empty-file\n" +
    +						"File 'unsolvable.dirty' should not be empty");
     	}
     
     	@Test
    @@ -90,8 +90,8 @@ void behavior() {
     		StepHarnessWithFile.forStep(this, step)
     				.testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean")
     				.testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" +
    -						"rule: standard:no-wildcard-imports\n" +
    -						"Wildcard import");
    +						"rule: standard:no-empty-file\n" +
    +						"File 'unsolvable.dirty' should not be empty");
     	}
     
     	@Test
    
    From a333813a787b38a604683a92e566a54c1051d34e Mon Sep 17 00:00:00 2001
    From: Andre Wachsmuth 
    Date: Fri, 15 Sep 2023 19:45:54 +0100
    Subject: [PATCH 0910/1120] Add support for biome, #1804
    
    ---
     .../diffplug/spotless/rome/EBiomeFlavor.java  |  80 +++
     .../rome/RomeExecutableDownloader.java        | 101 ++-
     .../com/diffplug/spotless/rome/RomeStep.java  | 174 ++---
     .../gradle/spotless/FormatExtension.java      | 368 +++++++---
     .../gradle/spotless/JavascriptExtension.java  |  86 ++-
     .../gradle/spotless/JsonExtension.java        |  61 +-
     .../gradle/spotless/RomeStepConfig.java       | 100 +--
     .../gradle/spotless/TypescriptExtension.java  | 104 ++-
     .../gradle/spotless/BiomeIntegrationTest.java | 343 +++++++++
     .../gradle/spotless/RomeIntegrationTest.java  |   4 +-
     .../spotless/maven/generic/Biome.java         |  60 ++
     .../spotless/maven/generic/Format.java        |  14 +
     .../diffplug/spotless/maven/generic/Rome.java |  10 +-
     .../spotless/maven/javascript/BiomeJs.java    |  33 +
     .../spotless/maven/javascript/Javascript.java |   5 +
     .../spotless/maven/javascript/RomeJs.java     |   7 +
     .../spotless/maven/json/BiomeJson.java        |  33 +
     .../diffplug/spotless/maven/json/Json.java    |   5 +
     .../spotless/maven/json/RomeJson.java         |   7 +
     .../spotless/maven/rome/AbstractRome.java     |  68 +-
     .../spotless/maven/typescript/BiomeTs.java    |  33 +
     .../spotless/maven/typescript/RomeTs.java     |   7 +
     .../spotless/maven/typescript/Typescript.java |   5 +
     .../maven/MavenIntegrationHarness.java        |   5 +
     .../spotless/maven/biome/BiomeMavenTest.java  | 202 ++++++
     .../spotless/maven/rome/RomeMavenTest.java    |   3 +-
     .../biome/config/line-width-120.json          |  11 +
     .../resources/biome/config/line-width-80.json |  11 +
     .../src/main/resources/biome/js/fileAfter.cjs |   3 +
     .../src/main/resources/biome/js/fileAfter.js  |   3 +
     .../src/main/resources/biome/js/fileAfter.jsx |   3 +
     .../src/main/resources/biome/js/fileAfter.mjs |   3 +
     .../main/resources/biome/js/fileBefore.cjs    |   3 +
     .../src/main/resources/biome/js/fileBefore.js |   3 +
     .../main/resources/biome/js/fileBefore.jsx    |   4 +
     .../main/resources/biome/js/fileBefore.mjs    |   3 +
     .../resources/biome/js/longLineAfter120.js    |   1 +
     .../resources/biome/js/longLineAfter80.js     |  13 +
     .../main/resources/biome/js/longLineBefore.js |   1 +
     .../main/resources/biome/json/fileAfter.json  |   5 +
     .../main/resources/biome/json/fileBefore.json |   7 +
     .../src/main/resources/biome/ts/fileAfter.cts |   4 +
     .../src/main/resources/biome/ts/fileAfter.mts |   4 +
     .../src/main/resources/biome/ts/fileAfter.ts  |   4 +
     .../src/main/resources/biome/ts/fileAfter.tsx |   7 +
     .../main/resources/biome/ts/fileBefore.cts    |   4 +
     .../main/resources/biome/ts/fileBefore.mts    |   5 +
     .../src/main/resources/biome/ts/fileBefore.ts |   5 +
     .../main/resources/biome/ts/fileBefore.tsx    |   8 +
     .../diffplug/spotless/rome/RomeStepTest.java  | 657 ++++++++++++------
     50 files changed, 2114 insertions(+), 576 deletions(-)
     create mode 100644 lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java
     create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java
     create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java
     create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java
     create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java
     create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java
     create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/biome/BiomeMavenTest.java
     create mode 100644 testlib/src/main/resources/biome/config/line-width-120.json
     create mode 100644 testlib/src/main/resources/biome/config/line-width-80.json
     create mode 100644 testlib/src/main/resources/biome/js/fileAfter.cjs
     create mode 100644 testlib/src/main/resources/biome/js/fileAfter.js
     create mode 100644 testlib/src/main/resources/biome/js/fileAfter.jsx
     create mode 100644 testlib/src/main/resources/biome/js/fileAfter.mjs
     create mode 100644 testlib/src/main/resources/biome/js/fileBefore.cjs
     create mode 100644 testlib/src/main/resources/biome/js/fileBefore.js
     create mode 100644 testlib/src/main/resources/biome/js/fileBefore.jsx
     create mode 100644 testlib/src/main/resources/biome/js/fileBefore.mjs
     create mode 100644 testlib/src/main/resources/biome/js/longLineAfter120.js
     create mode 100644 testlib/src/main/resources/biome/js/longLineAfter80.js
     create mode 100644 testlib/src/main/resources/biome/js/longLineBefore.js
     create mode 100644 testlib/src/main/resources/biome/json/fileAfter.json
     create mode 100644 testlib/src/main/resources/biome/json/fileBefore.json
     create mode 100644 testlib/src/main/resources/biome/ts/fileAfter.cts
     create mode 100644 testlib/src/main/resources/biome/ts/fileAfter.mts
     create mode 100644 testlib/src/main/resources/biome/ts/fileAfter.ts
     create mode 100644 testlib/src/main/resources/biome/ts/fileAfter.tsx
     create mode 100644 testlib/src/main/resources/biome/ts/fileBefore.cts
     create mode 100644 testlib/src/main/resources/biome/ts/fileBefore.mts
     create mode 100644 testlib/src/main/resources/biome/ts/fileBefore.ts
     create mode 100644 testlib/src/main/resources/biome/ts/fileBefore.tsx
    
    diff --git a/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java b/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java
    new file mode 100644
    index 0000000000..e47662f154
    --- /dev/null
    +++ b/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java
    @@ -0,0 +1,80 @@
    +package com.diffplug.spotless.rome;
    +
    +/**
    + * The flavor of Biome to use. Exists for compatibility reason, may be removed
    + * shortly.
    + * 

    + * Will be removed once the old Rome project is not supported anymore. + */ +public enum EBiomeFlavor { + /** The new forked Biome project. */ + BIOME("biome", "1.2.0", "biome.json", "biome-%s-%s-%s", + "https://github.com/biomejs/biome/releases/download/cli%%2Fv%s/biome-%s"), + + /** + * The old deprecated Rome project. + * + * @deprecated Will be removed once the old Rome project is not supported + * anymore. + */ + @Deprecated + ROME("rome", "12.0.0", "rome.json", "rome-%s-%s-%s", + "https://github.com/rome/tools/releases/download/cli%%2Fv%s/rome-%s"); + + private final String configName; + private final String defaultVersion; + private final String downloadFilePattern; + private final String shortName; + private final String urlPattern; + + EBiomeFlavor(String shortName, String defaultVersion, String configName, String downloadFilePattern, + String urlPattern) { + this.shortName = shortName; + this.defaultVersion = defaultVersion; + this.configName = configName; + this.downloadFilePattern = downloadFilePattern; + this.urlPattern = urlPattern; + } + + /** + * @return The name of the default config file. + */ + public String configName() { + return configName; + } + + /** + * @return Default version to use when no version was set explicitly. + */ + public String defaultVersion() { + return defaultVersion; + } + + /** + * @return The pattern for {@link String#format(String, Object...) + * String.format()} for the file name of a Biome executable for a + * certain version and architecure. The first parameter is the platform, + * the second is the OS, the third is the architecture. + */ + public String getDownloadFilePattern() { + return downloadFilePattern; + } + + /** + * @return The pattern for {@link String#format(String, Object...) + * String.format()} for the URL where the executables can be downloaded. + * The first parameter is the version, the second parameter is the OS / + * platform. + */ + public String getUrlPattern() { + return urlPattern; + } + + /** + * @return The short name of this flavor, i.e. rome or + * biome. + */ + public String shortName() { + return shortName; + } +} \ No newline at end of file diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java index 578916a54b..7ff0bdb622 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java @@ -38,8 +38,8 @@ import org.slf4j.LoggerFactory; /** - * Downloader for the Rome executable: - * https://github.com/rome/tools. + * Downloader for the Biome executable: + * https://github.com/biomejs/biome. */ final class RomeExecutableDownloader { private static final Logger logger = LoggerFactory.getLogger(RomeExecutableDownloader.class); @@ -51,15 +51,7 @@ final class RomeExecutableDownloader { /** * The pattern for {@link String#format(String, Object...) String.format()} for - * the file name of a Rome executable for a certain version and architecure. The - * first parameter is the platform, the second is the OS, the third is the - * architecture. - */ - private static final String DOWNLOAD_FILE_PATTERN = "rome-%s-%s-%s"; - - /** - * The pattern for {@link String#format(String, Object...) String.format()} for - * the platform part of the Rome executable download URL. First parameter is the + * the platform part of the Biome executable download URL. First parameter is the * OS, second parameter the architecture, the third the file extension. */ private static final String PLATFORM_PATTERN = "%s-%s%s"; @@ -70,13 +62,6 @@ final class RomeExecutableDownloader { */ private static final OpenOption[] READ_OPTIONS = {StandardOpenOption.READ}; - /** - * The pattern for {@link String#format(String, Object...) String.format()} for - * the URL where the Rome executables can be downloaded. The first parameter is - * the version, the second parameter is the OS / platform. - */ - private static final String URL_PATTERN = "https://github.com/rome/tools/releases/download/cli%%2Fv%s/rome-%s"; - /** * {@link OpenOption Open options} for creating a new file, overwriting the * existing file if present. @@ -84,25 +69,29 @@ final class RomeExecutableDownloader { private static final OpenOption[] WRITE_OPTIONS = {StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE}; - private Path downloadDir; + private final Path downloadDir; + + private final EBiomeFlavor flavor; /** - * Creates a new downloader for the Rome executable. The executable files are + * Creates a new downloader for the Biome executable. The executable files are * stored in the given download directory. * - * @param downloadDir Directory where + * @param flavor Flavor of Biome to use. + * @param downloadDir Directory where to store the downloaded executable. */ - public RomeExecutableDownloader(Path downloadDir) { + public RomeExecutableDownloader(EBiomeFlavor flavor, Path downloadDir) { + this.flavor = flavor; this.downloadDir = downloadDir; } /** - * Downloads the Rome executable for the current platform from the network to + * Downloads the Biome executable for the current platform from the network to * the download directory. When the executable exists already, it is * overwritten. * - * @param version Desired Rome version. - * @return The path to the Rome executable. + * @param version Desired Biome version. + * @return The path to the Biome executable. * @throws IOException When the executable cannot be downloaded from * the network or the file system could not be * accessed. @@ -121,7 +110,7 @@ public Path download(String version) throws IOException, InterruptedException { if (executableDir != null) { Files.createDirectories(executableDir); } - logger.info("Attempting to download Rome from '{}' to '{}'", url, executablePath); + logger.info("Attempting to download Biome from '{}' to '{}'", url, executablePath); var request = HttpRequest.newBuilder(URI.create(url)).GET().build(); var handler = BodyHandlers.ofFile(executablePath, WRITE_OPTIONS); var response = HttpClient.newBuilder().followRedirects(Redirect.NORMAL).build().send(request, handler); @@ -133,19 +122,19 @@ public Path download(String version) throws IOException, InterruptedException { throw new IOException("Failed to download file from " + url + ", file is empty or does not exist"); } writeChecksumFile(downloadedFile, checksumPath); - logger.debug("Rome was downloaded successfully to '{}'", downloadedFile); + logger.debug("Biome was downloaded successfully to '{}'", downloadedFile); return downloadedFile; } /** - * Ensures that the Rome executable for the current platform exists in the + * Ensures that the Biome executable for the current platform exists in the * download directory. When the executable does not exist in the download - * directory, an attempt is made to download the Rome executable from the + * directory, an attempt is made to download the Biome executable from the * network. When the executable exists already, no attempt to download it again * is made. * - * @param version Desired Rome version. - * @return The path to the Rome executable. + * @param version Desired Biome version. + * @return The path to the Biome executable. * @throws IOException When the executable cannot be downloaded from * the network or the file system could not be * accessed. @@ -157,23 +146,23 @@ public Path download(String version) throws IOException, InterruptedException { */ public Path ensureDownloaded(String version) throws IOException, InterruptedException { var platform = Platform.guess(); - logger.debug("Ensuring that Rome for platform '{}' is downloaded", platform); + logger.debug("Ensuring that Biome for platform '{}' is downloaded", platform); var existing = findDownloaded(version); if (existing.isPresent()) { - logger.debug("Rome was already downloaded, using executable at '{}'", existing.get()); + logger.debug("Biome was already downloaded, using executable at '{}'", existing.get()); return existing.get(); } else { - logger.debug("Rome was not yet downloaded, attempting to download executable"); + logger.debug("Biome was not yet downloaded, attempting to download executable"); return download(version); } } /** - * Attempts to find the Rome executable for the current platform in the download + * Attempts to find the Biome executable for the current platform in the download * directory. No attempt is made to download the executable from the network. * - * @param version Desired Rome version. - * @return The path to the Rome executable. + * @param version Desired Biome version. + * @return The path to the Biome executable. * @throws IOException When the executable does not exists in the * download directory, or when the file system * could not be accessed. @@ -184,7 +173,7 @@ public Path ensureDownloaded(String version) throws IOException, InterruptedExce public Optional findDownloaded(String version) throws IOException { var platform = Platform.guess(); var executablePath = getExecutablePath(version, platform); - logger.debug("Checking rome executable at {}", executablePath); + logger.debug("Checking Biome executable at {}", executablePath); return checkFileWithChecksum(executablePath) ? Optional.ofNullable(executablePath) : Optional.empty(); } @@ -248,12 +237,12 @@ private String computeChecksum(Path file, String algorithm) throws IOException { } /** - * Finds the code name for the given operating system used by the Rome + * Finds the code name for the given operating system used by the Biome * executable download URL. * * @param os Desired operating system. - * @return Code name for the Rome download URL. - * @throws IOException When the given OS is not supported by Rome. + * @return Code name for the Biome download URL. + * @throws IOException When the given OS is not supported by Biome. */ private String getArchitectureCodeName(Architecture architecture) throws IOException { switch (architecture) { @@ -281,28 +270,28 @@ private Path getChecksumPath(Path file) { } /** - * Finds the URL from which the Rome executable can be downloaded. + * Finds the URL from which the Biome executable can be downloaded. * - * @param version Desired Rome version. + * @param version Desired Biome version. * @param platform Desired platform. - * @return The URL for the Rome executable. - * @throws IOException When the platform is not supported by Rome. + * @return The URL for the Biome executable. + * @throws IOException When the platform is not supported by Biome. */ private String getDownloadUrl(String version, Platform platform) throws IOException { var osCodeName = getOsCodeName(platform.getOs()); var architectureCodeName = getArchitectureCodeName(platform.getArchitecture()); var extension = getDownloadUrlExtension(platform.getOs()); var platformString = String.format(PLATFORM_PATTERN, osCodeName, architectureCodeName, extension); - return String.format(URL_PATTERN, version, platformString); + return String.format(flavor.getUrlPattern(), version, platformString); } /** - * Finds the file extension of the Rome download URL for the given operating + * Finds the file extension of the Biome download URL for the given operating * system. * * @param os Desired operating system. - * @return Extension for the Rome download URL. - * @throws IOException When the given OS is not supported by Rome. + * @return Extension for the Biome download URL. + * @throws IOException When the given OS is not supported by Biome. */ private String getDownloadUrlExtension(OS os) throws IOException { switch (os) { @@ -318,27 +307,27 @@ private String getDownloadUrlExtension(OS os) throws IOException { } /** - * Finds the path on the file system for the Rome executable with a given + * Finds the path on the file system for the Biome executable with a given * version and platform. * - * @param version Desired Rome version. + * @param version Desired Biome version. * @param platform Desired platform. - * @return The path for the Rome executable. + * @return The path for the Biome executable. */ private Path getExecutablePath(String version, Platform platform) { var os = platform.getOs().name().toLowerCase(Locale.ROOT); var arch = platform.getArchitecture().name().toLowerCase(Locale.ROOT); - var fileName = String.format(DOWNLOAD_FILE_PATTERN, os, arch, version); + var fileName = String.format(flavor.getDownloadFilePattern(), os, arch, version); return downloadDir.resolve(fileName); } /** - * Finds the code name for the given operating system used by the Rome + * Finds the code name for the given operating system used by the Biome * executable download URL. * * @param os Desired operating system. - * @return Code name for the Rome download URL. - * @throws IOException When the given OS is not supported by Rome. + * @return Code name for the Biome download URL. + * @throws IOException When the given OS is not supported by Biome. */ private String getOsCodeName(OS os) throws IOException { switch (os) { diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java index d6a3e62669..88c35c8662 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java @@ -38,16 +38,16 @@ import com.diffplug.spotless.ProcessRunner; /** - * formatter step that formats JavaScript and TypeScript code with Rome: - * https://github.com/rome/tools. - * It delegates to the Rome executable. The Rome executable is downloaded from + * formatter step that formats JavaScript and TypeScript code with Biome: + * https://github.com/biomejs/biome. + * It delegates to the Biome executable. The Rome executable is downloaded from * the network when no executable path is provided explicitly. */ public class RomeStep { private static final Logger logger = LoggerFactory.getLogger(RomeStep.class); /** - * Path to the directory with the {@code rome.json} config file, can be + * Path to the directory with the {@code biome.json} config file, can be * null, in which case the defaults are used. */ private String configPath; @@ -55,7 +55,7 @@ public class RomeStep { /** * The language (syntax) of the input files to format. When null or * the empty string, the language is detected automatically from the file name. - * Currently the following languages are supported by Rome: + * Currently the following languages are supported by Biome: *

      *
    • js (JavaScript)
    • *
    • jsx (JavaScript + JSX)
    • @@ -71,7 +71,13 @@ public class RomeStep { private String language; /** - * Path to the Rome executable. Can be null, but either a path to + * Biome flavor to use. Will be removed once we stop supporting the deprecated Rome project. + */ + @Deprecated + private final EBiomeFlavor flavor; + + /** + * Path to the Biome executable. Can be null, but either a path to * the executable of a download directory and version must be given. The path * must be either an absolute path, or a file name without path separators. If * the latter, it is interpreted as a command in the user's path. @@ -79,46 +85,48 @@ public class RomeStep { private final String pathToExe; /** - * Absolute path to the download directory for storing the download Rome + * Absolute path to the download directory for storing the download Biome * executable. Can be null, but either a path to the executable of * a download directory and version must be given. */ private final String downloadDir; /** - * Version of Rome to download. Can be null, but either a path to + * Version of Biome to download. Can be null, but either a path to * the executable of a download directory and version must be given. */ private final String version; /** - * @return The name of this format step, i.e. {@code rome}. + * @return The name of this format step, i.e. biome or rome. */ - public static String name() { - return "rome"; + public String name() { + return flavor.shortName(); } /** - * Creates a Rome step that format code by downloading to the given Rome + * Creates a Biome step that format code by downloading to the given Biome * version. The executable is downloaded from the network. * - * @param version Version of the Rome executable to download. + * @param flavor Flavor of Biome to use. + * @param version Version of the Biome executable to download. * @param downloadDir Directory where to place the downloaded executable. - * @return A new Rome step that download the executable from the network. + * @return A new Biome step that download the executable from the network. */ - public static RomeStep withExeDownload(String version, String downloadDir) { - return new RomeStep(version, null, downloadDir); + public static RomeStep withExeDownload(EBiomeFlavor flavor, String version, String downloadDir) { + return new RomeStep(flavor, version, null, downloadDir); } /** - * Creates a Rome step that formats code by delegating to the Rome executable + * Creates a Biome step that formats code by delegating to the Biome executable * located at the given path. * - * @param pathToExe Path to the Rome executable to use. - * @return A new Rome step that format with the given executable. + * @param flavor Flavor of Biome to use. + * @param pathToExe Path to the Biome executable to use. + * @return A new Biome step that format with the given executable. */ - public static RomeStep withExePath(String pathToExe) { - return new RomeStep(null, pathToExe, null); + public static RomeStep withExePath(EBiomeFlavor flavor, String pathToExe) { + return new RomeStep(flavor, null, pathToExe, null); } /** @@ -140,21 +148,21 @@ private static void attemptToAddPosixPermission(Path file, PosixFilePermission p } /** - * Finds the default version for Rome when no version is specified explicitly. + * Finds the default version for Biome when no version is specified explicitly. * Over time this will become outdated -- people should always specify the * version explicitly! * - * @return The default version for Rome. + * @return The default version for Biome. */ - private static String defaultVersion() { - return "12.0.0"; + private static String defaultVersion(EBiomeFlavor flavor) { + return flavor.defaultVersion(); } /** * Attempts to make the given file executable. This is a best-effort attempt, * any errors are swallowed. Depending on the OS, the file might still be * executable even if this method fails. The user will get a descriptive error - * later when we attempt to execute the Rome executable. + * later when we attempt to execute the Biome executable. * * @param filePath Path to the file to make executable. */ @@ -187,60 +195,64 @@ private static String resolveNameAgainstPath(String name) throws IOException, In } /** - * Checks the Rome config path. When the config path does not exist or when it - * does not contain a file named {@code rome.json}, an error is thrown. + * Checks the Biome config path. When the config path does not exist or when it + * does not contain a file named {@code biome.json}, an error is thrown. */ - private static void validateRomeConfigPath(String configPath) { + private static void validateBiomeConfigPath(EBiomeFlavor flavor, String configPath) { if (configPath == null) { return; } var path = Paths.get(configPath); - var config = path.resolve("rome.json"); + var config = path.resolve(flavor.configName()); if (!Files.exists(path)) { - throw new IllegalArgumentException("Rome config directory does not exist: " + path); + throw new IllegalArgumentException("Biome config directory does not exist: " + path); } if (!Files.exists(config)) { - throw new IllegalArgumentException("Rome config does not exist: " + config); + throw new IllegalArgumentException("Biome config does not exist: " + config); } } /** - * Checks the Rome executable file. When the file does not exist, an error is + * Checks the Biome executable file. When the file does not exist, an error is * thrown. */ - private static void validateRomeExecutable(String resolvedPathToExe) { + private static void validateBiomeExecutable(String resolvedPathToExe) { if (!new File(resolvedPathToExe).isFile()) { - throw new IllegalArgumentException("Rome executable does not exist: " + resolvedPathToExe); + throw new IllegalArgumentException("Biome executable does not exist: " + resolvedPathToExe); } } /** - * Creates a new Rome step with the configuration from the given builder. + * Creates a new Biome step with the configuration from the given builder. * - * @param builder Builder with the configuration to use. + * @param flavor Flavor of Biome to use. + * @param version Version of the Biome executable to download. + * @param pathToExe Path to the Biome executable to use. + * @param downloadDir Directory where to place the downloaded executable. */ - private RomeStep(String version, String pathToExe, String downloadDir) { - this.version = version != null && !version.isBlank() ? version : defaultVersion(); + private RomeStep(EBiomeFlavor flavor, String version, String pathToExe, String downloadDir) { + this.flavor = flavor; + this.version = version != null && !version.isBlank() ? version : defaultVersion(flavor); this.pathToExe = pathToExe; this.downloadDir = downloadDir; } /** * Creates a formatter step with the current configuration, which formats code - * by passing it to the Rome executable. + * by passing it to the Biome executable. * - * @return A new formatter step for formatting with Rome. + * @return A new formatter step for formatting with Biome. */ public FormatterStep create() { return FormatterStep.createLazy(name(), this::createState, State::toFunc); } /** - * Sets the path to the directory with the {@code rome.json} config file. When + * Sets the path to the directory with the {@code biome.json} config file. When * no config path is set, the default configuration is used. * - * @param configPath Config path to use. Must point to a directory which contain - * a file named {@code rome.json}. + * @param configPath Config path to use. Must point to a directory which contains + * a file named {@code biome.json}. * @return This builder instance for chaining method calls. */ public RomeStep withConfigPath(String configPath) { @@ -251,7 +263,7 @@ public RomeStep withConfigPath(String configPath) { /** * Sets the language of the files to format When no language is set, it is * determined automatically from the file name. The following languages are - * currently supported by Rome. + * currently supported by Biome. * *
        *
      • js (JavaScript)
      • @@ -274,41 +286,41 @@ public RomeStep withLanguage(String language) { } /** - * Resolves the Rome executable, possibly downloading it from the network, and + * Resolves the Biome executable, possibly downloading it from the network, and * creates a new state instance with the resolved executable that can format - * code via Rome. + * code via Biome. * - * @return The state instance for formatting code via Rome. + * @return The state instance for formatting code via Biome. * @throws IOException When any file system or network operations - * failed, such as when the Rome executable could + * failed, such as when the Biome executable could * not be downloaded, or when the given executable * does not exist. - * @throws InterruptedException When the Rome executable needs to be downloaded + * @throws InterruptedException When the Biome executable needs to be downloaded * and this thread was interrupted while waiting * for the download to complete. */ private State createState() throws IOException, InterruptedException { var resolvedPathToExe = resolveExe(); - validateRomeExecutable(resolvedPathToExe); - validateRomeConfigPath(configPath); - logger.debug("Using Rome executable located at '{}'", resolvedPathToExe); + validateBiomeExecutable(resolvedPathToExe); + validateBiomeConfigPath(flavor, configPath); + logger.debug("Using Biome executable located at '{}'", resolvedPathToExe); var exeSignature = FileSignature.signAsList(Collections.singleton(new File(resolvedPathToExe))); makeExecutable(resolvedPathToExe); return new State(resolvedPathToExe, exeSignature, configPath, language); } /** - * Resolves the path to the Rome executable, given the configuration of this - * step. When the path to the Rome executable is given explicitly, that path is - * used as-is. Otherwise, at attempt is made to download the Rome executable for + * Resolves the path to the Biome executable, given the configuration of this + * step. When the path to the Biome executable is given explicitly, that path is + * used as-is. Otherwise, at attempt is made to download the Biome executable for * the configured version from the network, unless it was already downloaded and * is available in the cache. * - * @return The path to the resolved Rome executable. + * @return The path to the resolved Biome executable. * @throws IOException When any file system or network operations - * failed, such as when the Rome executable could + * failed, such as when the Biome executable could * not be downloaded. - * @throws InterruptedException When the Rome executable needs to be downloaded + * @throws InterruptedException When the Biome executable needs to be downloaded * and this thread was interrupted while waiting * for the download to complete. */ @@ -321,7 +333,7 @@ private String resolveExe() throws IOException, InterruptedException { return pathToExe; } } else { - var downloader = new RomeExecutableDownloader(Paths.get(downloadDir)); + var downloader = new RomeExecutableDownloader(flavor, Paths.get(downloadDir)); var downloaded = downloader.ensureDownloaded(version).toString(); makeExecutable(downloaded); return downloaded; @@ -329,7 +341,7 @@ private String resolveExe() throws IOException, InterruptedException { } /** - * The internal state used by the Rome formatter. A state instance is created + * The internal state used by the Biome formatter. A state instance is created * when the spotless plugin for Maven or Gradle is executed, and reused for all * formatting requests for different files. The lifetime of the instance ends * when the Maven or Gradle plugin was successfully executed. @@ -349,7 +361,7 @@ private static class State implements Serializable { private final FileSignature exeSignature; /** - * The optional path to the directory with the {@code rome.json} config file. + * The optional path to the directory with the {@code biome.json} config file. */ private final String configPath; @@ -360,12 +372,12 @@ private static class State implements Serializable { private final String language; /** - * Creates a new state for instance which can format code with the given Rome + * Creates a new state for instance which can format code with the given Biome * executable. * - * @param exe Path to the Rome executable. - * @param exeSignature Signature (e.g. SHA-256 checksum) of the Rome executable. - * @param configPath Path to the optional directory with the {@code rome.json} + * @param exe Path to the Biome executable. + * @param exeSignature Signature (e.g. SHA-256 checksum) of the Biome executable. + * @param configPath Path to the optional directory with the {@code biome.json} * config file, can be null, in which case the * defaults are used. */ @@ -377,13 +389,13 @@ private State(String exe, FileSignature exeSignature, String configPath, String } /** - * Builds the list of arguments for the command that executes Rome to format a + * Builds the list of arguments for the command that executes Biome to format a * piece of code passed via stdin. * * @param file File to format. - * @return The Rome command to use for formatting code. + * @return The Biome command to use for formatting code. */ - private String[] buildRomeCommand(File file) { + private String[] buildBiomeCommand(File file) { var fileName = resolveFileName(file); var argList = new ArrayList(); argList.add(pathToExe); @@ -398,37 +410,37 @@ private String[] buildRomeCommand(File file) { } /** - * Formats the given piece of code by delegating to the Rome executable. The - * code is passed to Rome via stdin, the file name is used by Rome only to + * Formats the given piece of code by delegating to the Biome executable. The + * code is passed to Biome via stdin, the file name is used by Biome only to * determine the code syntax (e.g. JavaScript or TypeScript). * - * @param runner Process runner for invoking the Rome executable. + * @param runner Process runner for invoking the Biome executable. * @param input Code to format. * @param file File to format. * @return The formatted code. * @throws IOException When a file system error occurred while - * executing Rome. + * executing Biome. * @throws InterruptedException When this thread was interrupted while waiting - * for Rome to finish formatting. + * for Biome to finish formatting. */ private String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException { var stdin = input.getBytes(StandardCharsets.UTF_8); - var args = buildRomeCommand(file); + var args = buildBiomeCommand(file); if (logger.isDebugEnabled()) { - logger.debug("Running Rome comand to format code: '{}'", String.join(", ", args)); + logger.debug("Running Biome comand to format code: '{}'", String.join(", ", args)); } return runner.exec(stdin, args).assertExitZero(StandardCharsets.UTF_8); } /** - * The Rome executable currently does not have a parameter to specify the - * expected language / syntax. Rome always determined the language from the file + * The Biome executable currently does not have a parameter to specify the + * expected language / syntax. Biome always determined the language from the file * extension. This method returns the file name for the desired language when a * language was requested explicitly, or the file name of the input file for * auto detection. * * @param file File to be formatted. - * @return The file name to pass to the Rome executable. + * @return The file name to pass to the Biome executable. */ private String resolveFileName(File file) { var name = file.getName(); @@ -454,7 +466,7 @@ private String resolveFileName(File file) { return "tsx".equals(ext) ? name : "file.tsx"; case "json": return "json".equals(ext) ? name : "file.json"; - // so that we can support new languages such as css or yaml when Rome adds + // so that we can support new languages such as css or yaml when Biome adds // support for them without having to change the code default: return "file." + language; @@ -463,7 +475,7 @@ private String resolveFileName(File file) { /** * Creates a new formatter function for formatting a piece of code by delegating - * to the Rome executable. + * to the Biome executable. * * @return A formatter function for formatting code. */ diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 1f8b0c95b2..61fb0a6e5b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -67,6 +67,7 @@ import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; +import com.diffplug.spotless.rome.EBiomeFlavor; import groovy.lang.Closure; @@ -95,29 +96,44 @@ private String formatName() { LineEnding lineEndings; - /** Returns the line endings to use (defaults to {@link SpotlessExtensionImpl#getLineEndings()}. */ + /** + * Returns the line endings to use (defaults to + * {@link SpotlessExtensionImpl#getLineEndings()}. + */ public LineEnding getLineEndings() { return lineEndings == null ? spotless.getLineEndings() : lineEndings; } - /** Sets the line endings to use (defaults to {@link SpotlessExtensionImpl#getLineEndings()}. */ + /** + * Sets the line endings to use (defaults to + * {@link SpotlessExtensionImpl#getLineEndings()}. + */ public void setLineEndings(LineEnding lineEndings) { this.lineEndings = requireNonNull(lineEndings); } Charset encoding; - /** Returns the encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}. */ + /** + * Returns the encoding to use (defaults to + * {@link SpotlessExtensionImpl#getEncoding()}. + */ public Charset getEncoding() { return encoding == null ? spotless.getEncoding() : encoding; } - /** Sets the encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}. */ + /** + * Sets the encoding to use (defaults to + * {@link SpotlessExtensionImpl#getEncoding()}. + */ public void setEncoding(String name) { setEncoding(Charset.forName(requireNonNull(name))); } - /** Sentinel to distinguish between "don't ratchet this format" and "use spotless parent format". */ + /** + * Sentinel to distinguish between "don't ratchet this format" and "use spotless + * parent format". + */ private static final String RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL = " not set at format level "; private String ratchetFrom = RATCHETFROM_NOT_SET_AT_FORMAT_LEVEL; @@ -128,8 +144,8 @@ public String getRatchetFrom() { } /** - * Allows you to override the value from the parent {@link SpotlessExtension#setRatchetFrom(String)} - * for this specific format. + * Allows you to override the value from the parent + * {@link SpotlessExtension#setRatchetFrom(String)} for this specific format. */ public void setRatchetFrom(String ratchetFrom) { this.ratchetFrom = ratchetFrom; @@ -140,7 +156,10 @@ public void ratchetFrom(String ratchetFrom) { setRatchetFrom(ratchetFrom); } - /** Sets the encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}. */ + /** + * Sets the encoding to use (defaults to + * {@link SpotlessExtensionImpl#getEncoding()}. + */ public void setEncoding(Charset charset) { encoding = requireNonNull(charset); } @@ -157,7 +176,10 @@ public void ignoreErrorForPath(String relativePath) { exceptionPolicy.excludePath(requireNonNull(relativePath)); } - /** Sets encoding to use (defaults to {@link SpotlessExtensionImpl#getEncoding()}). */ + /** + * Sets encoding to use (defaults to + * {@link SpotlessExtensionImpl#getEncoding()}). + */ public void encoding(String charset) { setEncoding(charset); } @@ -180,31 +202,33 @@ protected boolean isLicenseHeaderStep(FormatterStep formatterStep) { } /** - * Sets which files should be formatted. Files to be formatted = (target - targetExclude). + * Sets which files should be formatted. Files to be formatted = (target - + * targetExclude). * * When this method is called multiple times, only the last call has any effect. * - * FileCollections pass through raw. - * Strings are treated as the 'include' arg to fileTree, with project.rootDir as the dir. - * List are treated as the 'includes' arg to fileTree, with project.rootDir as the dir. - * Anything else gets passed to getProject().files(). + * FileCollections pass through raw. Strings are treated as the 'include' arg to + * fileTree, with project.rootDir as the dir. List are treated as the + * 'includes' arg to fileTree, with project.rootDir as the dir. Anything else + * gets passed to getProject().files(). * - * If you pass any strings that start with "**\/*", this method will automatically filter out - * "build", ".gradle", and ".git" folders. + * If you pass any strings that start with "**\/*", this method will + * automatically filter out "build", ".gradle", and ".git" folders. */ public void target(Object... targets) { this.target = parseTargetsIsExclude(targets, false); } /** - * Sets which files will be excluded from formatting. Files to be formatted = (target - targetExclude). + * Sets which files will be excluded from formatting. Files to be formatted = + * (target - targetExclude). * * When this method is called multiple times, only the last call has any effect. * - * FileCollections pass through raw. - * Strings are treated as the 'include' arg to fileTree, with project.rootDir as the dir. - * List are treated as the 'includes' arg to fileTree, with project.rootDir as the dir. - * Anything else gets passed to getProject().files(). + * FileCollections pass through raw. Strings are treated as the 'include' arg to + * fileTree, with project.rootDir as the dir. List are treated as the + * 'includes' arg to fileTree, with project.rootDir as the dir. Anything else + * gets passed to getProject().files(). */ public void targetExclude(Object... targets) { this.targetExclude = parseTargetsIsExclude(targets, true); @@ -244,10 +268,10 @@ private FileCollection parseTargetsIsExclude(Object[] targets, boolean isExclude } /** - * FileCollections pass through raw. - * Strings are treated as the 'include' arg to fileTree, with project.rootDir as the dir. - * List are treated as the 'includes' arg to fileTree, with project.rootDir as the dir. - * Anything else gets passed to getProject().files(). + * FileCollections pass through raw. Strings are treated as the 'include' arg to + * fileTree, with project.rootDir as the dir. List are treated as the + * 'includes' arg to fileTree, with project.rootDir as the dir. Anything else + * gets passed to getProject().files(). */ protected final FileCollection parseTarget(Object target) { return parseTargetIsExclude(target, false); @@ -264,7 +288,8 @@ private final FileCollection parseTargetIsExclude(Object target, boolean isExclu String targetString = (String) target; matchedFiles.include(targetString); - // since people are likely to do '**/*.md', we want to make sure to exclude folders + // since people are likely to do '**/*.md', we want to make sure to exclude + // folders // they don't want to format which will slow down the operation greatly // but we only want to do that if they are *including* - if they are specifying // what they want to exclude, we shouldn't filter at all @@ -279,7 +304,8 @@ private final FileCollection parseTargetIsExclude(Object target, boolean isExclu if (getProject() == getProject().getRootProject()) { excludes.add(".gradle"); } - // no build folders (flatInclude means that subproject might not be subfolders, see https://github.com/diffplug/spotless/issues/121) + // no build folders (flatInclude means that subproject might not be subfolders, + // see https://github.com/diffplug/spotless/issues/121) relativizeIfSubdir(excludes, dir, getProject().getLayout().getBuildDirectory().getAsFile().get()); for (Project subproject : getProject().getSubprojects()) { relativizeIfSubdir(excludes, dir, subproject.getLayout().getBuildDirectory().getAsFile().get()); @@ -300,8 +326,8 @@ private static void relativizeIfSubdir(List relativePaths, File root, Fi } /** - * Returns the relative path between root and dest, - * or null if dest is not a child of root. + * Returns the relative path between root and dest, or null if dest is not a + * child of root. */ static @Nullable String relativize(File root, File dest) { String rootPath = root.getAbsolutePath(); @@ -321,7 +347,8 @@ public void addStep(FormatterStep newStep) { requireNonNull(newStep); int existingIdx = getExistingStepIdx(newStep.getName()); if (existingIdx != -1) { - throw new GradleException("Multiple steps with name '" + newStep.getName() + "' for spotless format '" + formatName() + "'"); + throw new GradleException( + "Multiple steps with name '" + newStep.getName() + "' for spotless format '" + formatName() + "'"); } steps.add(newStep); } @@ -333,7 +360,10 @@ public void addStep(Function createStepFn) { addStep(newStep); } - /** Returns the index of the existing step with the given name, or -1 if no such step exists. */ + /** + * Returns the index of the existing step with the given name, or -1 if no such + * step exists. + */ protected int getExistingStepIdx(String stepName) { for (int i = 0; i < steps.size(); ++i) { if (steps.get(i).getName().equals(stepName)) { @@ -347,7 +377,8 @@ protected int getExistingStepIdx(String stepName) { protected void replaceStep(FormatterStep replacementStep) { int existingIdx = getExistingStepIdx(replacementStep.getName()); if (existingIdx == -1) { - throw new GradleException("Cannot replace step '" + replacementStep.getName() + "' for spotless format '" + formatName() + "' because it hasn't been added yet."); + throw new GradleException("Cannot replace step '" + replacementStep.getName() + "' for spotless format '" + + formatName() + "' because it hasn't been added yet."); } steps.set(existingIdx, replacementStep); } @@ -358,20 +389,21 @@ public void clearSteps() { } /** - * An optional performance optimization if you are using any of the {@code custom} - * methods. If you aren't explicitly calling {@code custom}, then this method - * has no effect. + * An optional performance optimization if you are using any of the + * {@code custom} methods. If you aren't explicitly calling {@code custom}, then + * this method has no effect. * - * Spotless tracks what files have changed from run to run, so that it can run faster - * by only checking files which have changed, or whose formatting steps have changed. - * If you use the {@code custom} methods, then gradle can never mark - * your files as {@code up-to-date}, because it can't know if perhaps the behavior of your - * custom function has changed. + * Spotless tracks what files have changed from run to run, so that it can run + * faster by only checking files which have changed, or whose formatting steps + * have changed. If you use the {@code custom} methods, then gradle can never + * mark your files as {@code up-to-date}, because it can't know if perhaps the + * behavior of your custom function has changed. * - * If you set {@code bumpThisNumberIfACustomStepChanges( )}, then spotless will - * assume that the custom rules have not changed if the number has not changed. If a - * custom rule does change, then you must bump the number so that spotless will know - * that it must recheck the files it has already checked. + * If you set {@code bumpThisNumberIfACustomStepChanges( )}, then + * spotless will assume that the custom rules have not changed if the number has + * not changed. If a custom rule does change, then you must bump the number so + * that spotless will know that it must recheck the files it has already + * checked. */ public void bumpThisNumberIfACustomStepChanges(int number) { globalState = number; @@ -389,13 +421,19 @@ protected Integer calculateState() throws Exception { } } - /** Adds a custom step. Receives a string with unix-newlines, must return a string with unix newlines. */ + /** + * Adds a custom step. Receives a string with unix-newlines, must return a + * string with unix newlines. + */ public void custom(String name, Closure formatter) { requireNonNull(formatter, "formatter"); custom(name, formatter::call); } - /** Adds a custom step. Receives a string with unix-newlines, must return a string with unix newlines. */ + /** + * Adds a custom step. Receives a string with unix-newlines, must return a + * string with unix newlines. + */ public void custom(String name, FormatterFunc formatter) { requireNonNull(formatter, "formatter"); addStep(FormatterStep.createLazy(name, () -> globalState, unusedState -> formatter)); @@ -447,9 +485,11 @@ public void nativeCmd(String name, String pathToExe, List arguments) { } /** - * Created by {@link FormatExtension#licenseHeader(String, String)} or {@link FormatExtension#licenseHeaderFile(Object, String)}. - * For most language-specific formats (e.g. java, scala, etc.) you can omit the second {@code delimiter} argument, because it is supplied - * automatically ({@link HasBuiltinDelimiterForLicense}). + * Created by {@link FormatExtension#licenseHeader(String, String)} or + * {@link FormatExtension#licenseHeaderFile(Object, String)}. For most + * language-specific formats (e.g. java, scala, etc.) you can omit the second + * {@code delimiter} argument, because it is supplied automatically + * ({@link HasBuiltinDelimiterForLicense}). */ public class LicenseHeaderConfig { LicenseHeaderStep builder; @@ -478,8 +518,8 @@ public LicenseHeaderConfig(LicenseHeaderStep builder) { } /** - * @param delimiter - * Spotless will look for a line that starts with this regular expression pattern to know what the "top" is. + * @param delimiter Spotless will look for a line that starts with this regular + * expression pattern to know what the "top" is. */ public LicenseHeaderConfig delimiter(String delimiter) { builder = builder.withDelimiter(delimiter); @@ -488,8 +528,8 @@ public LicenseHeaderConfig delimiter(String delimiter) { } /** - * @param yearSeparator - * The characters used to separate the first and last years in multi years patterns. + * @param yearSeparator The characters used to separate the first and last years + * in multi years patterns. */ public LicenseHeaderConfig yearSeparator(String yearSeparator) { builder = builder.withYearSeparator(yearSeparator); @@ -504,9 +544,11 @@ public LicenseHeaderConfig skipLinesMatching(String skipLinesMatching) { } /** - * @param updateYearWithLatest - * Will turn {@code 2004} into {@code 2004-2020}, and {@code 2004-2019} into {@code 2004-2020} - * Default value is false, unless {@link SpotlessExtensionImpl#ratchetFrom(String)} is used, in which case default value is true. + * @param updateYearWithLatest Will turn {@code 2004} into {@code 2004-2020}, + * and {@code 2004-2019} into {@code 2004-2020} + * Default value is false, unless + * {@link SpotlessExtensionImpl#ratchetFrom(String)} + * is used, in which case default value is true. */ public LicenseHeaderConfig updateYearWithLatest(boolean updateYearWithLatest) { this.updateYearWithLatest = updateYearWithLatest; @@ -516,7 +558,8 @@ public LicenseHeaderConfig updateYearWithLatest(boolean updateYearWithLatest) { FormatterStep createStep() { return builder.withYearModeLazy(() -> { - if ("true".equals(spotless.project.findProperty(LicenseHeaderStep.FLAG_SET_LICENSE_HEADER_YEARS_FROM_GIT_HISTORY()))) { + if ("true".equals(spotless.project + .findProperty(LicenseHeaderStep.FLAG_SET_LICENSE_HEADER_YEARS_FROM_GIT_HISTORY()))) { return YearMode.SET_FROM_GIT; } else { boolean updateYear = updateYearWithLatest == null ? getRatchetFrom() != null : updateYearWithLatest; @@ -527,22 +570,22 @@ FormatterStep createStep() { } /** - * @param licenseHeader - * Content that should be at the top of every file. - * @param delimiter - * Spotless will look for a line that starts with this regular expression pattern to know what the "top" is. + * @param licenseHeader Content that should be at the top of every file. + * @param delimiter Spotless will look for a line that starts with this + * regular expression pattern to know what the "top" is. */ public LicenseHeaderConfig licenseHeader(String licenseHeader, String delimiter) { - LicenseHeaderConfig config = new LicenseHeaderConfig(LicenseHeaderStep.headerDelimiter(licenseHeader, delimiter)); + LicenseHeaderConfig config = new LicenseHeaderConfig( + LicenseHeaderStep.headerDelimiter(licenseHeader, delimiter)); addStep(config.createStep()); return config; } /** - * @param licenseHeaderFile - * Content that should be at the top of every file. - * @param delimiter - * Spotless will look for a line that starts with this regular expression pattern to know what the "top" is. + * @param licenseHeaderFile Content that should be at the top of every file. + * @param delimiter Spotless will look for a line that starts with this + * regular expression pattern to know what the "top" + * is. */ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile, String delimiter) { LicenseHeaderConfig config = new LicenseHeaderConfig(LicenseHeaderStep.headerDelimiter(() -> { @@ -606,7 +649,8 @@ public T npmInstallCache(final Object npmInstallCache) { } public T npmInstallCache() { - this.npmInstallCache = new File(project.getLayout().getBuildDirectory().getAsFile().get(), SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME); + this.npmInstallCache = new File(project.getLayout().getBuildDirectory().getAsFile().get(), + SPOTLESS_NPM_INSTALL_CACHE_DEFAULT_NAME); replaceStep(); return (T) this; } @@ -669,34 +713,93 @@ public PrettierConfig config(final Map prettierConfig) { @Override protected FormatterStep createStep() { final Project project = getProject(); - return PrettierFormatterStep.create( - devDependencies, - provisioner(), - project.getProjectDir(), - project.getLayout().getBuildDirectory().getAsFile().get(), - npmModulesCacheOrNull(), - new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), + return PrettierFormatterStep.create(devDependencies, provisioner(), project.getProjectDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), + Arrays.asList(project.getProjectDir(), project.getRootDir())), new com.diffplug.spotless.npm.PrettierConfig( this.prettierConfigFile != null ? project.file(this.prettierConfigFile) : null, this.prettierConfig)); } } + /** + * Generic Biome formatter step that detects the language of the input file from + * the file name. It should be specified as a formatter step for a generic + * format{ ... }. + */ + public class BiomeGeneric extends RomeStepConfig { + @Nullable + String language; + + /** + * Creates a new Rome config that downloads the Rome executable for the given + * version from the network. + * + * @param version Rome version to use. The default version is used when + * null. + */ + public BiomeGeneric(String version) { + super(getProject(), FormatExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + } + + /** + * Sets the language (syntax) of the input files to format. When + * null or the empty string, the language is detected automatically + * from the file name. Currently the following languages are supported by Biome: + *
          + *
        • js (JavaScript)
        • + *
        • jsx (JavaScript + JSX)
        • + *
        • js? (JavaScript or JavaScript + JSX, depending on the file + * extension)
        • + *
        • ts (TypeScript)
        • + *
        • tsx (TypeScript + JSX)
        • + *
        • ts? (TypeScript or TypeScript + JSX, depending on the file + * extension)
        • + *
        • json (JSON)
        • + *
        + * + * @param language The language of the files to format. + * @return This step for further configuration. + */ + public BiomeGeneric language(String language) { + this.language = language; + replaceStep(); + return this; + } + + @Override + protected String getLanguage() { + return language; + } + + @Override + protected BiomeGeneric getThis() { + return this; + } + } + /** * Generic Rome formatter step that detects the language of the input file from * the file name. It should be specified as a formatter step for a generic * format{ ... }. + * + * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ + @Deprecated public class RomeGeneric extends RomeStepConfig { @Nullable String language; /** - * Creates a new Rome config that downloads the Rome executable for the given version from the network. - * @param version Rome version to use. The default version is used when null. + * Creates a new Rome config that downloads the Rome executable for the given + * version from the network. + * + * @param version Rome version to use. The default version is used when + * null. */ public RomeGeneric(String version) { - super(getProject(), FormatExtension.this::replaceStep, version); + super(getProject(), FormatExtension.this::replaceStep, EBiomeFlavor.ROME, version); } /** @@ -714,6 +817,7 @@ public RomeGeneric(String version) { * extension) *
      • json (JSON)
      • *
      + * * @param language The language of the files to format. * @return This step for further configuration. */ @@ -751,16 +855,40 @@ public PrettierConfig prettier(Map devDependencies) { return prettierConfig; } + /** + * Defaults to downloading the default Biome version from the network. To work + * offline, you can specify the path to the Biome executable via + * {@code biome().pathToExe(...)}. + */ + public RomeStepConfig biome() { + return biome(null); + } + + /** Downloads the given Biome version from the network. */ + public RomeStepConfig biome(String version) { + var biomeConfig = new BiomeGeneric(version); + addStep(biomeConfig.createStep()); + return biomeConfig; + } + /** * Defaults to downloading the default Rome version from the network. To work * offline, you can specify the path to the Rome executable via * {@code rome().pathToExe(...)}. + * + * @deprecated Use {@link #biome(String)}. */ + @Deprecated public RomeStepConfig rome() { return rome(null); } - /** Downloads the given Rome version from the network. */ + /** + * Downloads the given Rome version from the network. + * + * @deprecated Use {@link #biome(String)}. + */ + @Deprecated public RomeStepConfig rome(String version) { var romeConfig = new RomeGeneric(version); addStep(romeConfig.createStep()); @@ -844,8 +972,9 @@ public void withinBlocks(String name, String open, String close, Action * spotless { @@ -858,33 +987,44 @@ public void withinBlocks(String name, String open, String close, Action */ - public void withinBlocks(String name, String open, String close, Class clazz, Action configure) { + public void withinBlocks(String name, String open, String close, Class clazz, + Action configure) { withinBlocksHelper(PipeStepPair.named(name).openClose(open, close), clazz, configure); } - /** Same as {@link #withinBlocks(String, String, String, Action)}, except instead of an open/close pair, you specify a regex with exactly one capturing group. */ + /** + * Same as {@link #withinBlocks(String, String, String, Action)}, except instead + * of an open/close pair, you specify a regex with exactly one capturing group. + */ public void withinBlocksRegex(String name, String regex, Action configure) { withinBlocksRegex(name, regex, FormatExtension.class, configure); } - /** Same as {@link #withinBlocksRegex(String, String, Action)}, except you can specify any language-specific subclass of {@link FormatExtension} to get language-specific steps. */ - public void withinBlocksRegex(String name, String regex, Class clazz, Action configure) { + /** + * Same as {@link #withinBlocksRegex(String, String, Action)}, except you can + * specify any language-specific subclass of {@link FormatExtension} to get + * language-specific steps. + */ + public void withinBlocksRegex(String name, String regex, Class clazz, + Action configure) { withinBlocksHelper(PipeStepPair.named(name).regex(regex), clazz, configure); } - private void withinBlocksHelper(PipeStepPair.Builder builder, Class clazz, Action configure) { + private void withinBlocksHelper(PipeStepPair.Builder builder, Class clazz, + Action configure) { // create the sub-extension T formatExtension = spotless.instantiateFormatExtension(clazz); // configure it configure.execute(formatExtension); // create a step which applies all of those steps as sub-steps - FormatterStep step = builder.buildStepWhichAppliesSubSteps(spotless.project.getRootDir().toPath(), formatExtension.steps); + FormatterStep step = builder.buildStepWhichAppliesSubSteps(spotless.project.getRootDir().toPath(), + formatExtension.steps); addStep(step); } /** - * Given a regex with *exactly one capturing group*, disables formatting - * inside that captured group. + * Given a regex with *exactly one capturing group*, disables formatting inside + * that captured group. */ public void toggleOffOnRegex(String regex) { this.togglePair = PipeStepPair.named(PipeStepPair.defaultToggleName()).regex(regex).buildPair(); @@ -900,7 +1040,10 @@ public void toggleOffOn() { toggleOffOn(PipeStepPair.defaultToggleOff(), PipeStepPair.defaultToggleOn()); } - /** Undoes all previous calls to {@link #toggleOffOn()} and {@link #toggleOffOn(String, String)}. */ + /** + * Undoes all previous calls to {@link #toggleOffOn()} and + * {@link #toggleOffOn(String, String)}. + */ public void toggleOffOnDisable() { this.togglePair = null; } @@ -923,11 +1066,13 @@ protected void setupTask(SpotlessTask task) { steps = this.steps; } if (targetExcludeContentPattern != null) { - steps.replaceAll(formatterStep -> formatterStep.filterByContent(OnMatch.EXCLUDE, targetExcludeContentPattern)); + steps.replaceAll( + formatterStep -> formatterStep.filterByContent(OnMatch.EXCLUDE, targetExcludeContentPattern)); } task.setSteps(steps); Directory projectDir = getProject().getLayout().getProjectDirectory(); - task.setLineEndingsPolicy(getProject().provider(() -> getLineEndings().createPolicy(projectDir.getAsFile(), () -> totalTarget))); + task.setLineEndingsPolicy( + getProject().provider(() -> getLineEndings().createPolicy(projectDir.getAsFile(), () -> totalTarget))); spotless.getRegisterDependenciesTask().hookSubprojectTask(task); task.setupRatchet(getRatchetFrom() != null ? getRatchetFrom() : ""); } @@ -943,31 +1088,38 @@ public SpotlessApply createIndependentApplyTask(String taskName) { } /** - * Creates an independent {@link SpotlessApply} for (very) unusual circumstances. + * Creates an independent {@link SpotlessApply} for (very) unusual + * circumstances. * - * Most users will not want this method. In the rare case that you want to create - * a {@code SpotlessApply} which is independent of the normal Spotless machinery, this will - * let you do that. + * Most users will not want this method. In the rare case that you want to + * create a {@code SpotlessApply} which is independent of the normal Spotless + * machinery, this will let you do that. * - * The returned task will not be hooked up to the global {@code spotlessApply}, and there will be no corresponding {@code check} task. + * The returned task will not be hooked up to the global {@code spotlessApply}, + * and there will be no corresponding {@code check} task. * * The task name must not end with `Apply`. * - * NOTE: does not respect the rarely-used {@code spotlessFiles} property. + * NOTE: does not respect the rarely-used {@code spotlessFiles} + * property. */ public TaskProvider createIndependentApplyTaskLazy(String taskName) { - Preconditions.checkArgument(!taskName.endsWith(SpotlessExtension.APPLY), "Task name must not end with " + SpotlessExtension.APPLY); - TaskProvider spotlessTask = spotless.project.getTasks().register(taskName + SpotlessTaskService.INDEPENDENT_HELPER, SpotlessTaskImpl.class, task -> { - task.init(spotless.getRegisterDependenciesTask().getTaskService()); - setupTask(task); - // clean removes the SpotlessCache, so we have to run after clean - task.mustRunAfter(BasePlugin.CLEAN_TASK_NAME); - }); + Preconditions.checkArgument(!taskName.endsWith(SpotlessExtension.APPLY), + "Task name must not end with " + SpotlessExtension.APPLY); + TaskProvider spotlessTask = spotless.project.getTasks() + .register(taskName + SpotlessTaskService.INDEPENDENT_HELPER, SpotlessTaskImpl.class, task -> { + task.init(spotless.getRegisterDependenciesTask().getTaskService()); + setupTask(task); + // clean removes the SpotlessCache, so we have to run after clean + task.mustRunAfter(BasePlugin.CLEAN_TASK_NAME); + }); // create the apply task - TaskProvider applyTask = spotless.project.getTasks().register(taskName, SpotlessApply.class, task -> { - task.dependsOn(spotlessTask); - task.init(spotlessTask.get()); - }); + TaskProvider applyTask = spotless.project.getTasks().register(taskName, SpotlessApply.class, + task -> { + task.dependsOn(spotlessTask); + task.init(spotlessTask.get()); + }); return applyTask; } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index cd2682e971..c776004da3 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -34,6 +34,7 @@ import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; +import com.diffplug.spotless.rome.EBiomeFlavor; public class JavascriptExtension extends FormatExtension { @@ -58,7 +59,8 @@ public JavascriptEslintConfig eslint(Map devDependencies) { return eslint; } - public static abstract class EslintBaseConfig> extends NpmStepConfig> { + public static abstract class EslintBaseConfig> + extends NpmStepConfig> { Map devDependencies = new LinkedHashMap<>(); @Nullable @@ -67,7 +69,8 @@ public static abstract class EslintBaseConfig> ext @Nullable String configJs = null; - public EslintBaseConfig(Project project, Consumer replaceStep, Map devDependencies) { + public EslintBaseConfig(Project project, Consumer replaceStep, + Map devDependencies) { super(project, replaceStep); this.devDependencies.putAll(requireNonNull(devDependencies)); } @@ -103,13 +106,10 @@ public JavascriptEslintConfig(Map devDependencies) { public FormatterStep createStep() { final Project project = getProject(); - return EslintFormatterStep.create( - devDependencies, - provisioner(), - project.getProjectDir(), - project.getLayout().getBuildDirectory().getAsFile().get(), - npmModulesCacheOrNull(), - new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), + return EslintFormatterStep.create(devDependencies, provisioner(), project.getProjectDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), + Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); } @@ -138,16 +138,40 @@ public PrettierConfig prettier(Map devDependencies) { return prettierConfig; } + /** + * Defaults to downloading the default Biome version from the network. To work + * offline, you can specify the path to the Biome executable via + * {@code biome().pathToExe(...)}. + */ + public BiomeJs biome() { + return biome(null); + } + + /** Downloads the given Biome version from the network. */ + public BiomeJs biome(String version) { + var biomeConfig = new BiomeJs(version); + addStep(biomeConfig.createStep()); + return biomeConfig; + } + /** * Defaults to downloading the default Rome version from the network. To work * offline, you can specify the path to the Rome executable via * {@code rome().pathToExe(...)}. + * + * @deprecated Use {@link #biome()}. */ + @Deprecated public RomeJs rome() { return rome(null); } - /** Downloads the given Rome version from the network. */ + /** + * Downloads the given Rome version from the network. + * + * @deprecated Use {@link #biome(String)}. + */ + @Deprecated public RomeJs rome(String version) { var romeConfig = new RomeJs(version); addStep(romeConfig.createStep()); @@ -155,21 +179,49 @@ public RomeJs rome(String version) { } private static final String DEFAULT_PRETTIER_JS_PARSER = "babel"; - private static final ImmutableList PRETTIER_JS_PARSERS = ImmutableList.of(DEFAULT_PRETTIER_JS_PARSER, "babel-flow", "flow"); + private static final ImmutableList PRETTIER_JS_PARSERS = ImmutableList.of(DEFAULT_PRETTIER_JS_PARSER, + "babel-flow", "flow"); + + /** + * Biome formatter step for JavaScript. + */ + public class BiomeJs extends RomeStepConfig { + /** + * Creates a new Biome formatter step config for formatting JavaScript files. + * Unless overwritten, the given Biome version is downloaded from the network. + * + * @param version Biome version to use. + */ + public BiomeJs(String version) { + super(getProject(), JavascriptExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + } + + @Override + protected String getLanguage() { + return "js?"; + } + + @Override + protected BiomeJs getThis() { + return this; + } + } /** * Rome formatter step for JavaScript. + * + * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ + @Deprecated public class RomeJs extends RomeStepConfig { - /** - * Creates a new Rome formatter step config for formatting JavaScript files. Unless - * overwritten, the given Rome version is downloaded from the network. + * Creates a new Rome formatter step config for formatting JavaScript files. + * Unless overwritten, the given Rome version is downloaded from the network. * * @param version Rome version to use. */ public RomeJs(String version) { - super(getProject(), JavascriptExtension.this::replaceStep, version); + super(getProject(), JavascriptExtension.this::replaceStep, EBiomeFlavor.ROME, version); } @Override @@ -208,7 +260,9 @@ private void fixParserToJavascript() { } else { this.prettierConfig.put("parser", DEFAULT_PRETTIER_JS_PARSER); if (currentParser != null) { - getProject().getLogger().warn("Overriding parser option to '{}'. (Was set to '{}'.) Set it to another js parser if you have problems with '{}'.", DEFAULT_PRETTIER_JS_PARSER, currentParser, DEFAULT_PRETTIER_JS_PARSER); + getProject().getLogger().warn( + "Overriding parser option to '{}'. (Was set to '{}'.) Set it to another js parser if you have problems with '{}'.", + DEFAULT_PRETTIER_JS_PARSER, currentParser, DEFAULT_PRETTIER_JS_PARSER); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 8648cacea9..cc16b7ed35 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -27,6 +27,7 @@ import com.diffplug.spotless.json.JsonPatchStep; import com.diffplug.spotless.json.JsonSimpleStep; import com.diffplug.spotless.json.gson.GsonStep; +import com.diffplug.spotless.rome.EBiomeFlavor; public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; @@ -59,16 +60,40 @@ public JacksonJsonGradleConfig jackson() { return new JacksonJsonGradleConfig(this); } + /** + * Defaults to downloading the default Biome version from the network. To work + * offline, you can specify the path to the Biome executable via + * {@code biome().pathToExe(...)}. + */ + public BiomeJson biome() { + return biome(null); + } + + /** Downloads the given Biome version from the network. */ + public BiomeJson biome(String version) { + var biomeConfig = new BiomeJson(version); + addStep(biomeConfig.createStep()); + return biomeConfig; + } + /** * Defaults to downloading the default Rome version from the network. To work * offline, you can specify the path to the Rome executable via * {@code rome().pathToExe(...)}. + * + * @deprecated Use {@link #biome()}. */ + @Deprecated public RomeJson rome() { return rome(null); } - /** Downloads the given Rome version from the network. */ + /** + * Downloads the given Rome version from the network. + * + * @deprecated Use {@link #biome(String)}. + */ + @Deprecated public RomeJson rome(String version) { var romeConfig = new RomeJson(version); addStep(romeConfig.createStep()); @@ -140,7 +165,9 @@ public GsonConfig version(String version) { } private FormatterStep createStep() { - return GsonStep.create(new com.diffplug.spotless.json.gson.GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), provisioner()); + return GsonStep.create( + new com.diffplug.spotless.json.gson.GsonConfig(sortByKeys, escapeHtml, indentSpaces, version), + provisioner()); } } @@ -179,9 +206,37 @@ protected final FormatterStep createStep() { } } + /** + * Biome formatter step for JSON. + */ + public class BiomeJson extends RomeStepConfig { + /** + * Creates a new Biome formatter step config for formatting JSON files. Unless + * overwritten, the given Biome version is downloaded from the network. + * + * @param version Biome version to use. + */ + public BiomeJson(String version) { + super(getProject(), JsonExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + } + + @Override + protected String getLanguage() { + return "json"; + } + + @Override + protected BiomeJson getThis() { + return this; + } + } + /** * Rome formatter step for JSON. + * + * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ + @Deprecated public class RomeJson extends RomeStepConfig { /** * Creates a new Rome formatter step config for formatting JSON files. Unless @@ -190,7 +245,7 @@ public class RomeJson extends RomeStepConfig { * @param version Rome version to use. */ public RomeJson(String version) { - super(getProject(), JsonExtension.this::replaceStep, version); + super(getProject(), JsonExtension.this::replaceStep, EBiomeFlavor.ROME, version); } @Override diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java index f739e922d2..6b0ae893ac 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java @@ -28,12 +28,13 @@ import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.rome.EBiomeFlavor; import com.diffplug.spotless.rome.RomeStep; public abstract class RomeStepConfig> { /** - * Optional path to the directory with configuration file for Rome. The file - * must be named {@code rome.json}. When none is given, the default + * Optional path to the directory with configuration file for Biome. The file + * must be named {@code biome.json}. When none is given, the default * configuration is used. If this is a relative path, it is resolved against the * project's base directory. */ @@ -41,16 +42,22 @@ public abstract class RomeStepConfig> { private Object configPath; /** - * Optional directory where the downloaded Rome executable is placed. If this is - * a relative path, it is resolved against the project's base directory. + * Optional directory where the downloaded Biome executable is placed. If this + * is a relative path, it is resolved against the project's base directory. * Defaults to - * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + * ~/.m2/repository/com/diffplug/spotless/spotless-data/biome. */ @Nullable private Object downloadDir; /** - * Optional path to the Rome executable. Either a version or a + * The flavor of Biome to use. Will be removed when we stop support the + * deprecated Rome project. + */ + private final EBiomeFlavor flavor; + + /** + * Optional path to the Biome executable. Either a version or a * pathToExe should be specified. When not given, an attempt is * made to download the executable for the given version from the network. When * given, the executable is used and the version parameter is @@ -59,10 +66,10 @@ public abstract class RomeStepConfig> { * When an absolute path is given, that path is used as-is. When a relative path * is given, it is resolved against the project's base directory. When only a * file name (i.e. without any slashes or back slash path separators such as - * {@code rome}) is given, this is interpreted as the name of a command with - * executable that is in your {@code path} environment variable. Use - * {@code ./executable-name} if you want to use an executable in the project's - * base directory. + * biome) is given, this is interpreted as the name of a command + * with executable that is in your path environment variable. Use + * ./executable-name if you want to use an executable in the + * project's base directory. */ @Nullable private Object pathToExe; @@ -73,12 +80,12 @@ public abstract class RomeStepConfig> { private final Project project; /** - * Replaces the current Rome formatter step with the given step. + * Replaces the current Biome formatter step with the given step. */ private final Consumer replaceStep; /** - * Rome version to download, applies only when no pathToExe is + * Biome version to download, applies only when no pathToExe is * specified explicitly. Either a version or a * pathToExe should be specified. When not given, a default known * version is used. For stable builds, it is recommended that you always set the @@ -88,15 +95,17 @@ public abstract class RomeStepConfig> { @Nullable private String version; - protected RomeStepConfig(Project project, Consumer replaceStep, String version) { + protected RomeStepConfig(Project project, Consumer replaceStep, EBiomeFlavor flavor, + String version) { this.project = requireNonNull(project); this.replaceStep = requireNonNull(replaceStep); + this.flavor = flavor; this.version = version; } /** - * Optional path to the directory with configuration file for Rome. The file - * must be named {@code rome.json}. When none is given, the default + * Optional path to the directory with configuration file for Biome. The file + * must be named {@code biome.json}. When none is given, the default * configuration is used. If this is a relative path, it is resolved against the * project's base directory. * @@ -109,10 +118,10 @@ public Self configPath(Object configPath) { } /** - * Optional directory where the downloaded Rome executable is placed. If this is - * a relative path, it is resolved against the project's base directory. + * Optional directory where the downloaded Biome executable is placed. If this + * is a relative path, it is resolved against the project's base directory. * Defaults to - * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + * ~/.m2/repository/com/diffplug/spotless/spotless-data/biome. * * @return This step for further configuration. */ @@ -123,16 +132,16 @@ public Self downloadDir(Object downloadDir) { } /** - * Optional path to the Rome executable. Overwrites the configured version. No - * attempt is made to download the Rome executable from the network. + * Optional path to the Biome executable. Overwrites the configured version. No + * attempt is made to download the Biome executable from the network. *

      * When an absolute path is given, that path is used as-is. When a relative path * is given, it is resolved against the project's base directory. When only a * file name (i.e. without any slashes or back slash path separators such as - * {@code rome}) is given, this is interpreted as the name of a command with - * executable that is in your {@code path} environment variable. Use - * {@code ./executable-name} if you want to use an executable in the project's - * base directory. + * biome) is given, this is interpreted as the name of a command + * with executable that is in your path environment variable. Use + * ./executable-name if you want to use an executable in the + * project's base directory. * * @return This step for further configuration. */ @@ -143,10 +152,10 @@ public Self pathToExe(Object pathToExe) { } /** - * Creates a new formatter step that formats code by calling the Rome + * Creates a new formatter step that formats code by calling the Biome * executable, using the current configuration. * - * @return A new formatter step for the Rome formatter. + * @return A new formatter step for the Biome formatter. */ protected FormatterStep createStep() { var builder = newBuilder(); @@ -161,7 +170,7 @@ protected FormatterStep createStep() { /** * Gets the language (syntax) of the input files to format. When * null or the empty string, the language is detected automatically - * from the file name. Currently the following languages are supported by Rome: + * from the file name. Currently the following languages are supported by Biome: *

        *
      • js (JavaScript)
      • *
      • jsx (JavaScript + JSX)
      • @@ -179,12 +188,12 @@ protected FormatterStep createStep() { protected abstract String getLanguage(); /** - * @return This Rome config instance. + * @return This Biome config instance. */ protected abstract Self getThis(); /** - * Creates a new Rome step and replaces the existing Rome step in the list of + * Creates a new Biome step and replaces the existing Biome step in the list of * format steps. */ protected void replaceStep() { @@ -193,19 +202,18 @@ protected void replaceStep() { /** * Finds the data directory that can be used for storing shared data such as - * Rome executable globally. This is a directory in the local repository, e.g. + * Biome executable globally. This is a directory in the local repository, e.g. * ~/.m2/repository/com/diffplus/spotless/spotless-data. * * @return The directory for storing shared data. */ private File findDataDir() { - var currentRepo = project.getRepositories().stream() - .filter(r -> r instanceof MavenArtifactRepository) - .map(r -> (MavenArtifactRepository) r) - .filter(r -> "file".equals(r.getUrl().getScheme())) - .findAny().orElse(null); + var currentRepo = project.getRepositories().stream().filter(r -> r instanceof MavenArtifactRepository) + .map(r -> (MavenArtifactRepository) r).filter(r -> "file".equals(r.getUrl().getScheme())).findAny() + .orElse(null); // Temporarily add mavenLocal() repository to get its file URL - var localRepo = currentRepo != null ? (MavenArtifactRepository) currentRepo : project.getRepositories().mavenLocal(); + var localRepo = currentRepo != null ? (MavenArtifactRepository) currentRepo + : project.getRepositories().mavenLocal(); try { // e.g. ~/.m2/repository/ var repoPath = Path.of(localRepo.getUrl()); @@ -220,29 +228,29 @@ private File findDataDir() { } /** - * A new builder for configuring a Rome step that either downloads the Rome + * A new builder for configuring a Biome step that either downloads the Biome * executable with the given version from the network, or uses the executable * from the given path. * - * @return A builder for a Rome step. + * @return A builder for a Biome step. */ private RomeStep newBuilder() { if (pathToExe != null) { var resolvedPathToExe = resolvePathToExe(); - return RomeStep.withExePath(resolvedPathToExe); + return RomeStep.withExePath(flavor, resolvedPathToExe); } else { var downloadDir = resolveDownloadDir(); - return RomeStep.withExeDownload(version, downloadDir); + return RomeStep.withExeDownload(flavor, version, downloadDir); } } /** - * Resolves the path to the Rome executable. When the path is only a file name, + * Resolves the path to the Biome executable. When the path is only a file name, * do not perform any resolution and interpret it as a command that must be on * the user's path. Otherwise resolve the executable path against the project's * base directory. * - * @return The resolved path to the Rome executable. + * @return The resolved path to the Biome executable. */ private String resolvePathToExe() { var fileNameOnly = pathToExe instanceof String && Paths.get(pathToExe.toString()).getNameCount() == 1; @@ -254,18 +262,18 @@ private String resolvePathToExe() { } /** - * Resolves the directory to use for storing downloaded Rome executable. When a + * Resolves the directory to use for storing downloaded Biome executable. When a * {@link #downloadDir} is given, use that directory, resolved against the - * current project's directory. Otherwise, use the {@code Rome} sub folder in + * current project's directory. Otherwise, use the {@code biome} sub folder in * the shared data directory. * - * @return The download directory for the Rome executable. + * @return The download directory for the Biome executable. */ private String resolveDownloadDir() { if (downloadDir != null) { return project.file(downloadDir).toString(); } else { - return findDataDir().toPath().resolve("rome").toString(); + return findDataDir().toPath().resolve(flavor.shortName()).toString(); } } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 929ea4423b..ad9bcc832b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -38,6 +38,7 @@ import com.diffplug.spotless.npm.TsConfigFileType; import com.diffplug.spotless.npm.TsFmtFormatterStep; import com.diffplug.spotless.npm.TypedTsFmtConfigFile; +import com.diffplug.spotless.rome.EBiomeFlavor; public class TypescriptExtension extends FormatExtension { @@ -58,7 +59,10 @@ public TypescriptFormatExtension tsfmt(String version) { return tsfmt(TsFmtFormatterStep.defaultDevDependenciesWithTsFmt(version)); } - /** Creates a {@code TypescriptFormatExtension} using exactly the specified npm packages. */ + /** + * Creates a {@code TypescriptFormatExtension} using exactly the specified npm + * packages. + */ public TypescriptFormatExtension tsfmt(Map devDependencies) { TypescriptFormatExtension tsfmt = new TypescriptFormatExtension(devDependencies); addStep(tsfmt.createStep()); @@ -114,15 +118,12 @@ private TypescriptFormatExtension configFile(TsConfigFileType filetype, Object p public FormatterStep createStep() { final Project project = getProject(); - return TsFmtFormatterStep.create( - devDependencies, - provisioner(), - project.getProjectDir(), - project.getLayout().getBuildDirectory().getAsFile().get(), - npmModulesCacheOrNull(), - new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), - typedConfigFile(), - config); + return TsFmtFormatterStep + .create(devDependencies, provisioner(), project.getProjectDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), + Arrays.asList(project.getProjectDir(), project.getRootDir())), + typedConfigFile(), config); } private TypedTsFmtConfigFile typedConfigFile() { @@ -154,7 +155,8 @@ public PrettierConfig prettier(Map devDependencies) { } /** - * Overrides the parser to be set to typescript, no matter what the user's config says. + * Overrides the parser to be set to typescript, no matter what the user's + * config says. */ public class TypescriptPrettierConfig extends PrettierConfig { TypescriptPrettierConfig(Map devDependencies) { @@ -173,7 +175,8 @@ private void fixParserToTypescript() { } else { final Object replaced = this.prettierConfig.put("parser", "typescript"); if (replaced != null) { - getProject().getLogger().warn("overriding parser option to 'typescript'. Was set to '{}'", replaced); + getProject().getLogger().warn("overriding parser option to 'typescript'. Was set to '{}'", + replaced); } } } @@ -211,52 +214,99 @@ public TypescriptEslintConfig tsconfigFile(Object path) { public FormatterStep createStep() { final Project project = getProject(); - return EslintFormatterStep.create( - devDependencies, - provisioner(), - project.getProjectDir(), - project.getLayout().getBuildDirectory().getAsFile().get(), - npmModulesCacheOrNull(), - new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), Arrays.asList(project.getProjectDir(), project.getRootDir())), + return EslintFormatterStep.create(devDependencies, provisioner(), project.getProjectDir(), + project.getLayout().getBuildDirectory().getAsFile().get(), npmModulesCacheOrNull(), + new NpmPathResolver(npmFileOrNull(), nodeFileOrNull(), npmrcFileOrNull(), + Arrays.asList(project.getProjectDir(), project.getRootDir())), eslintConfig()); } protected EslintConfig eslintConfig() { - return new EslintTypescriptConfig( - configFilePath != null ? getProject().file(configFilePath) : null, - configJs, - typescriptConfigFilePath != null ? getProject().file(typescriptConfigFilePath) : null); + return new EslintTypescriptConfig(configFilePath != null ? getProject().file(configFilePath) : null, + configJs, typescriptConfigFilePath != null ? getProject().file(typescriptConfigFilePath) : null); } } + /** + * Defaults to downloading the default Biome version from the network. To work + * offline, you can specify the path to the Biome executable via + * {@code biome().pathToExe(...)}. + */ + public BiomeTs biome() { + return biome(null); + } + + /** Downloads the given Biome version from the network. */ + public BiomeTs biome(String version) { + var biomeConfig = new BiomeTs(version); + addStep(biomeConfig.createStep()); + return biomeConfig; + } + /** * Defaults to downloading the default Rome version from the network. To work * offline, you can specify the path to the Rome executable via * {@code rome().pathToExe(...)}. + * + * @deprecated Use {@link #biome()}. */ + @Deprecated public RomeTs rome() { return rome(null); } - /** Downloads the given Rome version from the network. */ + /** + * Downloads the given Rome version from the network. + * + * @deprecated Use {@link #biome(String)}. + */ + @Deprecated public RomeTs rome(String version) { var romeConfig = new RomeTs(version); addStep(romeConfig.createStep()); return romeConfig; } + /** + * Biome formatter step for TypeScript. + */ + public class BiomeTs extends RomeStepConfig { + /** + * Creates a new Biome formatter step config for formatting TypeScript files. + * Unless overwritten, the given Biome version is downloaded from the network. + * + * @param version Biome version to use. + */ + public BiomeTs(String version) { + super(getProject(), TypescriptExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + } + + @Override + protected String getLanguage() { + return "ts?"; + } + + @Override + protected BiomeTs getThis() { + return this; + } + } + /** * Rome formatter step for TypeScript. + * + * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ + @Deprecated public class RomeTs extends RomeStepConfig { /** - * Creates a new Rome formatter step config for formatting TypeScript files. Unless - * overwritten, the given Rome version is downloaded from the network. + * Creates a new Rome formatter step config for formatting TypeScript files. + * Unless overwritten, the given Rome version is downloaded from the network. * * @param version Rome version to use. */ public RomeTs(String version) { - super(getProject(), TypescriptExtension.this::replaceStep, version); + super(getProject(), TypescriptExtension.this::replaceStep, EBiomeFlavor.ROME, version); } @Override diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java new file mode 100644 index 0000000000..a2665a3bf1 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BiomeIntegrationTest.java @@ -0,0 +1,343 @@ +/* + * 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.gradle.spotless; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; +import org.owasp.encoder.Encode; + +class BiomeIntegrationTest extends GradleIntegrationHarness { + /** + * Tests that biome can be used as a generic formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asGenericStep() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + } + + /** + * Tests that biome can be used as a JavaScript formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asJavaScriptStep() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " javascript {", + " target '**/*.js'", + " biome('1.2.0')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + } + + /** + * Tests that biome can be used as a JSON formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asJsonStep() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " json {", + " target '**/*.json'", + " biome('1.2.0')", + " }", + "}"); + setFile("biome_test.json").toResource("biome/json/fileBefore.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.json").sameAsResource("biome/json/fileAfter.json"); + } + + /** + * Tests that biome can be used as a TypeScript formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asTypeScriptStep() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " typescript {", + " target '**/*.ts'", + " biome('1.2.0')", + " }", + "}"); + setFile("biome_test.ts").toResource("biome/ts/fileBefore.ts"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.ts").sameAsResource("biome/ts/fileAfter.ts"); + } + + /** + * Tests that the language can be specified for the generic format step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void canSetLanguageForGenericStep() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'mybiome', {", + " target '**/*.nosj'", + " biome('1.2.0').language('json')", + " }", + "}"); + setFile("biome_test.nosj").toResource("biome/json/fileBefore.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.nosj").sameAsResource("biome/json/fileAfter.json"); + } + + /** + * Tests that an absolute config path can be specified. + * + * @throws Exception When a test failure occurs. + */ + @Test + void configPathAbsolute() throws Exception { + var path = newFile("configs").getAbsolutePath(); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').configPath('" + Encode.forJava(path) + "')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-120.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the biome.json config file can be + * specified. Uses a config file with a line width of 120. + * + * @throws Exception When a test failure occurs. + */ + @Test + void configPathLineWidth120() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').configPath('configs')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-120.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the biome.json config file can be + * specified. Uses a config file with a line width of 80. + * + * @throws Exception When a test failure occurs. + */ + @Test + void configPathLineWidth80() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').configPath('configs')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-80.json"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/longLineAfter80.js"); + } + + /** + * Tests that the download directory can be an absolute path. + * + * @throws Exception When a test failure occurs. + */ + @Test + void downloadDirAbsolute() throws Exception { + var path = newFile("target/bin/biome").getAbsoluteFile().toString(); + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').downloadDir('" + Encode.forJava(path) + "')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/biome").exists() || newFile("target/bin/biome").list().length == 0); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/biome").list().length); + } + + /** + * Tests that the download directory can be changed to a path relative to the + * project's base directory. + * + * @throws Exception When a test failure occurs. + */ + @Test + void downloadDirRelative() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').downloadDir('target/bin/biome')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/biome").exists() || newFile("target/bin/biome").list().length == 0); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build(); + assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL"); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/biome").list().length); + } + + /** + * Tests that the build fails when given Biome executable does not exist. + * + * @throws Exception When a test failure occurs. + */ + @Test + void failureWhenExeNotFound() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').pathToExe('biome/is/missing')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + assertThat(spotlessApply.getOutput()).contains("Build failed with an exception"); + assertFile("biome_test.js").sameAsResource("biome/js/fileBefore.js"); + assertThat(spotlessApply.getOutput()).contains("Could not create task ':spotlessMybiomeApply'"); + assertThat(spotlessApply.getOutput()).contains("Biome executable does not exist"); + } + + /** + * Tests that the build fails when the input file could not be parsed. + * + * @throws Exception When a test failure occurs. + */ + @Test + void failureWhenNotParseable() throws Exception { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " format 'mybiome', {", + " target '**/*.js'", + " biome('1.2.0').language('json')", + " }", + "}"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + + var spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").buildAndFail(); + assertThat(spotlessApply.getOutput()).contains("spotlessMybiome FAILED"); + assertFile("biome_test.js").sameAsResource("biome/js/fileBefore.js"); + assertThat(spotlessApply.getOutput()).contains("Format with errors is disabled."); + assertThat(spotlessApply.getOutput()).contains("Step 'biome' found problem in 'biome_test.js'"); + } +} diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java index 4464b1cec7..0c12f9f500 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/RomeIntegrationTest.java @@ -288,7 +288,7 @@ void downloadDirRelative() throws Exception { } /** - * Tests that the build fails when given Rome executable does not exist. + * Tests that the build fails when given Biome executable does not exist. * * @throws Exception When a test failure occurs. */ @@ -311,7 +311,7 @@ void failureWhenExeNotFound() throws Exception { assertThat(spotlessApply.getOutput()).contains("Build failed with an exception"); assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); assertThat(spotlessApply.getOutput()).contains("Could not create task ':spotlessMyromeApply'"); - assertThat(spotlessApply.getOutput()).contains("Rome executable does not exist"); + assertThat(spotlessApply.getOutput()).contains("Biome executable does not exist"); } /** diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java new file mode 100644 index 0000000000..23b6637519 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java @@ -0,0 +1,60 @@ +/* + * 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. + * 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.generic; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; + +/** + * Generic Biome formatter step that detects the language of the input file from + * the file name. It should be specified as a formatter step for a generic + * {@code }. + */ +public class Biome extends AbstractRome { + public Biome() { + super(EBiomeFlavor.BIOME); + } + + /** + * Gets the language (syntax) of the input files to format. When + * null or the empty string, the language is detected automatically + * from the file name. Currently the following languages are supported by Biome: + *
          + *
            + *
          • js (JavaScript)
          • + *
          • jsx (JavaScript + JSX)
          • + *
          • js? (JavaScript or JavaScript + JSX, depending on the file + * extension)
          • + *
          • ts (TypeScript)
          • + *
          • tsx (TypeScript + JSX)
          • + *
          • ts? (TypeScript or TypeScript + JSX, depending on the file + * extension)
          • + *
          • json (JSON)
          • + *
          + *
        + * + * @return The language of the input files. + */ + @Parameter + private String language; + + @Override + protected String getLanguage() { + return language; + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java index ed08718c65..ce7db9b926 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Format.java @@ -41,6 +41,20 @@ public String licenseHeaderDelimiter() { return null; } + /** + * Adds a step to this format that format code with the Biome formatter. + * @param biome Biome configuration to use. + */ + public void addBiome(Biome biome) { + addStepFactory(biome); + } + + /** + * Adds a step to this format that format code with the Rome formatter. + * @param rome Rome configuration to use. + * @deprecated Rome has transitioned to Biome. Use {@link #addBiome(Biome)}. + */ + @Deprecated public void addRome(Rome rome) { addStepFactory(rome); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java index 62d9d3fdec..628c051699 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java @@ -18,13 +18,17 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; /** - * Generic Rome formatter step that detects the language of the input file from - * the file name. It should be specified as a formatter step for a generic - * {@code }. + * See {@link Biome}. + * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ public class Rome extends AbstractRome { + public Rome() { + super(EBiomeFlavor.ROME); + } + /** * Gets the language (syntax) of the input files to format. When * null or the empty string, the language is detected automatically diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java new file mode 100644 index 0000000000..07a341eee5 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java @@ -0,0 +1,33 @@ +/* + * 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. + * 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.javascript; + +import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; + +/** + * Biome formatter step for JavaScript. + */ +public class BiomeJs extends AbstractRome { + public BiomeJs() { + super(EBiomeFlavor.BIOME); + } + + @Override + protected String getLanguage() { + return "js?"; + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java index b254110486..3f0a3f959c 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/Javascript.java @@ -42,6 +42,11 @@ public void addEslint(EslintJs eslint) { addStepFactory(eslint); } + public void addBiome(BiomeJs biome) { + addStepFactory(biome); + } + + @Deprecated public void addRome(RomeJs rome) { addStepFactory(rome); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java index 60fb7077df..b5754f2b65 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java @@ -16,11 +16,18 @@ package com.diffplug.spotless.maven.javascript; import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; /** * Rome formatter step for JavaScript. + * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ +@Deprecated public class RomeJs extends AbstractRome { + public RomeJs() { + super(EBiomeFlavor.ROME); + } + @Override protected String getLanguage() { return "js?"; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java new file mode 100644 index 0000000000..13c2ab92f2 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java @@ -0,0 +1,33 @@ +/* + * 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. + * 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.json; + +import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; + +/** + * Biome formatter step for JSON. + */ +public class BiomeJson extends AbstractRome { + public BiomeJson() { + super(EBiomeFlavor.BIOME); + } + + @Override + protected String getLanguage() { + return "json"; + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java index be5782b651..8baf379a5e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/Json.java @@ -50,6 +50,11 @@ public void addJackson(JacksonJson jackson) { addStepFactory(jackson); } + public void addBiome(BiomeJson biome) { + addStepFactory(biome); + } + + @Deprecated public void addRome(RomeJson rome) { addStepFactory(rome); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java index 1cd044b759..7daab94afb 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java @@ -16,11 +16,18 @@ package com.diffplug.spotless.maven.json; import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; /** * Rome formatter step for JSON. + * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ +@Deprecated public class RomeJson extends AbstractRome { + public RomeJson() { + super(EBiomeFlavor.ROME); + } + @Override protected String getLanguage() { return "json"; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java index 33567b0a20..8b140ea381 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java @@ -22,19 +22,27 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; +import com.diffplug.spotless.rome.EBiomeFlavor; import com.diffplug.spotless.rome.RomeStep; /** - * Factory for creating the Rome formatter step that can format format code in - * various types of language with Rome. Currently Rome support JavaScript, - * TypeScript, JSX, TSX, and JSON. See also - * https://github.com/rome/tools. - * It delegates to the Rome CLI executable. + * Factory for creating the Biome formatter step that can format format code in + * various types of language with Biome. Currently Biome supports JavaScript, + * TypeScript, JSX, TSX, and JSON. See also https://github.com/biomejs/biome. It + * delegates to the Biome CLI executable. */ public abstract class AbstractRome implements FormatterStepFactory { + /** Biome flavor to use. */ + private EBiomeFlavor flavor; + + protected AbstractRome(EBiomeFlavor flavor) { + this.flavor = flavor; + } + /** - * Optional path to the directory with configuration file for Rome. The file - * must be named {@code rome.json}. When none is given, the default + * Optional path to the directory with configuration file for Biome. The file + * must be named {@code biome.json}. When none is given, the default * configuration is used. If this is a relative path, it is resolved against the * project's base directory. */ @@ -42,12 +50,12 @@ public abstract class AbstractRome implements FormatterStepFactory { private String configPath; /** - * Optional directory where the downloaded Rome executable is placed. If this is - * a relative path, it is resolved against the project's base directory. + * Optional directory where the downloaded Biome executable is placed. If this + * is a relative path, it is resolved against the project's base directory. * Defaults to - * ~/.m2/repository/com/diffplug/spotless/spotless-data/rome. + * ~/.m2/repository/com/diffplug/spotless/spotless-data/biome. *

        - * You can use an expression like ${user.home}/rome if you want to + * You can use an expression like ${user.home}/biome if you want to * use the home directory, or ${project.build.directory if you want * to use the target directory of the current project. */ @@ -55,7 +63,7 @@ public abstract class AbstractRome implements FormatterStepFactory { private String downloadDir; /** - * Optional path to the Rome executable. Either a version or a + * Optional path to the Biome executable. Either a version or a * pathToExe should be specified. When not given, an attempt is * made to download the executable for the given version from the network. When * given, the executable is used and the version parameter is @@ -64,16 +72,16 @@ public abstract class AbstractRome implements FormatterStepFactory { * When an absolute path is given, that path is used as-is. When a relative path * is given, it is resolved against the project's base directory. When only a * file name (i.e. without any slashes or back slash path separators such as - * {@code rome}) is given, this is interpreted as the name of a command with - * executable that is in your {@code path} environment variable. Use - * {@code ./executable-name} if you want to use an executable in the project's - * base directory. + * biome) is given, this is interpreted as the name of a command + * with executable that is in your path environment variable. Use + * ./executable-name if you want to use an executable in the + * project's base directory. */ @Parameter private String pathToExe; /** - * Rome version to download, applies only when no pathToExe is + * Biome version to download, applies only when no pathToExe is * specified explicitly. Either a version or a * pathToExe should be specified. When not given, a default known * version is used. For stable builds, it is recommended that you always set the @@ -99,7 +107,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { /** * Gets the language (syntax) of the input files to format. When * null or the empty string, the language is detected automatically - * from the file name. Currently the following languages are supported by Rome: + * from the file name. Currently the following languages are supported by Biome: *

          *
        • js (JavaScript)
        • *
        • jsx (JavaScript + JSX)
        • @@ -117,26 +125,26 @@ public FormatterStep newFormatterStep(FormatterStepConfig config) { protected abstract String getLanguage(); /** - * A new builder for configuring a Rome step that either downloads the Rome + * A new builder for configuring a Biome step that either downloads the Biome * executable with the given version from the network, or uses the executable * from the given path. * * @param config Configuration from the Maven Mojo execution with details about * the currently executed project. - * @return A builder for a Rome step. + * @return A builder for a Biome step. */ private RomeStep newBuilder(FormatterStepConfig config) { if (pathToExe != null) { var resolvedExePath = resolveExePath(config); - return RomeStep.withExePath(resolvedExePath); + return RomeStep.withExePath(flavor, resolvedExePath); } else { var downloadDir = resolveDownloadDir(config); - return RomeStep.withExeDownload(version, downloadDir); + return RomeStep.withExeDownload(flavor, version, downloadDir); } } /** - * Resolves the path to the configuration file for Rome. Relative paths are + * Resolves the path to the configuration file for Biome. Relative paths are * resolved against the project's base directory. * * @param config Configuration from the Maven Mojo execution with details about @@ -148,14 +156,14 @@ private String resolveConfigFile(FormatterStepConfig config) { } /** - * Resolves the path to the Rome executable. When the path is only a file name, + * Resolves the path to the Biome executable. When the path is only a file name, * do not perform any resolution and interpret it as a command that must be on * the user's path. Otherwise resolve the executable path against the project's * base directory. * * @param config Configuration from the Maven Mojo execution with details about * the currently executed project. - * @return The resolved path to the Rome executable. + * @return The resolved path to the Biome executable. */ private String resolveExePath(FormatterStepConfig config) { var path = Paths.get(pathToExe); @@ -167,20 +175,20 @@ private String resolveExePath(FormatterStepConfig config) { } /** - * Resolves the directory to use for storing downloaded Rome executable. When a + * Resolves the directory to use for storing downloaded Biome executable. When a * {@link #downloadDir} is given, use that directory, resolved against the - * current project's directory. Otherwise, use the {@code Rome} sub folder in - * the shared data directory. + * current project's directory. Otherwise, use the biome sub folder + * in the shared data directory. * * @param config Configuration for this step. - * @return The download directory for the Rome executable. + * @return The download directory for the Biome executable. */ private String resolveDownloadDir(FormatterStepConfig config) { final var fileLocator = config.getFileLocator(); if (downloadDir != null && !downloadDir.isBlank()) { return fileLocator.getBaseDir().toPath().resolve(downloadDir).toAbsolutePath().toString(); } else { - return fileLocator.getDataDir().toPath().resolve("rome").toString(); + return fileLocator.getDataDir().toPath().resolve(flavor.shortName()).toString(); } } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java new file mode 100644 index 0000000000..6fbcb31ee2 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java @@ -0,0 +1,33 @@ +/* + * 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. + * 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.typescript; + +import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; + +/** + * Biome formatter step for TypeScript. + */ +public class BiomeTs extends AbstractRome { + public BiomeTs() { + super(EBiomeFlavor.BIOME); + } + + @Override + protected String getLanguage() { + return "ts?"; + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java index ccee83744a..149d4208e3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java @@ -16,11 +16,18 @@ package com.diffplug.spotless.maven.typescript; import com.diffplug.spotless.maven.rome.AbstractRome; +import com.diffplug.spotless.rome.EBiomeFlavor; /** * Rome formatter step for TypeScript. + * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ +@Deprecated public class RomeTs extends AbstractRome { + public RomeTs() { + super(EBiomeFlavor.ROME); + } + @Override protected String getLanguage() { return "ts?"; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index ddae74db82..af25b8c773 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -46,6 +46,11 @@ public void addEslint(EslintTs eslint) { addStepFactory(eslint); } + public void addBiome(BiomeTs biome) { + addStepFactory(biome); + } + + @Deprecated public void addRome(RomeTs rome) { addStepFactory(rome); } 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 398932dd19..5fd59752e6 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 @@ -154,6 +154,11 @@ protected void writePomWithPrettierSteps(String includes, String... steps) throw writePom(formats(groupWithSteps("format", including(includes), steps))); } + protected void writePomWithBiomeSteps(String includes, String... steps) throws IOException { + writePom(formats(groupWithSteps("format", including(includes), steps))); + } + + @Deprecated protected void writePomWithRomeSteps(String includes, String... steps) throws IOException { writePom(formats(groupWithSteps("format", including(includes), steps))); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/biome/BiomeMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/biome/BiomeMavenTest.java new file mode 100644 index 0000000000..e015b934f5 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/biome/BiomeMavenTest.java @@ -0,0 +1,202 @@ +/* + * 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.biome; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.owasp.encoder.Encode.forXml; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +class BiomeMavenTest extends MavenIntegrationHarness { + /** + * Tests that Biome can be used as a generic formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asGenericStep() throws Exception { + writePomWithBiomeSteps("**/*.js", "1.2.0"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + } + + /** + * Tests that Biome can be used as a JavaScript formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asJavaScriptStep() throws Exception { + writePomWithJavascriptSteps("**/*.js", "1.2.0"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + } + + /** + * Tests that biome can be used as a JSON formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asJsonStep() throws Exception { + writePomWithJsonSteps("**/*.json", "1.2.0"); + setFile("biome_test.json").toResource("biome/json/fileBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.json").sameAsResource("biome/json/fileAfter.json"); + } + + /** + * Tests that biome can be used as a TypeScript formatting step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void asTypeScriptStep() throws Exception { + writePomWithTypescriptSteps("**/*.ts", "1.2.0"); + setFile("biome_test.ts").toResource("biome/ts/fileBefore.ts"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.ts").sameAsResource("biome/ts/fileAfter.ts"); + } + + /** + * Tests that the language can be specified for the generic format step. + * + * @throws Exception When a test failure occurs. + */ + @Test + void canSetLanguageForGenericStep() throws Exception { + writePomWithBiomeSteps("**/*.nosj", "1.2.0json"); + setFile("biome_test.nosj").toResource("biome/json/fileBefore.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.nosj").sameAsResource("biome/json/fileAfter.json"); + } + + /** + * Tests that an absolute config path can be specified. + * + * @throws Exception When a test failure occurs. + */ + @Test + void configPathAbsolute() throws Exception { + var path = newFile("configs").getAbsolutePath(); + writePomWithBiomeSteps("**/*.js", + "1.2.0" + forXml(path) + ""); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-120.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the biome.json config file can be + * specified. Uses a config file with a line width of 120. + * + * @throws Exception When a test failure occurs. + */ + @Test + void configPathLineWidth120() throws Exception { + writePomWithBiomeSteps("**/*.js", "1.2.0configs"); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-120.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/longLineAfter120.js"); + } + + /** + * Tests that a path to the directory with the biome.json config file can be + * specified. Uses a config file with a line width of 80. + * + * @throws Exception When a test failure occurs. + */ + @Test + void configPathLineWidth80() throws Exception { + writePomWithBiomeSteps("**/*.js", "1.2.0configs"); + setFile("biome_test.js").toResource("biome/js/longLineBefore.js"); + setFile("configs/biome.json").toResource("biome/config/line-width-80.json"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/longLineAfter80.js"); + } + + /** + * Tests that the download directory can be an absolute path. + * + * @throws Exception When a test failure occurs. + */ + @Test + void downloadDirAbsolute() throws Exception { + var path = newFile("target/bin/biome").getAbsoluteFile().toString(); + writePomWithBiomeSteps("**/*.js", + "1.2.0" + forXml(path) + ""); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/biome").exists() || newFile("target/bin/biome").list().length == 0); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/biome").list().length); + } + + /** + * Tests that the download directory can be changed to a path relative to the + * project's base directory. + * + * @throws Exception When a test failure occurs. + */ + @Test + void downloadDirRelative() throws Exception { + writePomWithBiomeSteps("**/*.js", + "1.2.0target/bin/biome"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + assertTrue(!newFile("target/bin/biome").exists() || newFile("target/bin/biome").list().length == 0); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("biome_test.js").sameAsResource("biome/js/fileAfter.js"); + assertEquals(2, newFile("target/bin/biome").list().length); + } + + /** + * Tests that the build fails when the input file could not be parsed. + * + * @throws Exception When a test failure occurs. + */ + @Test + void failureWhenExeNotFound() throws Exception { + writePomWithBiomeSteps("**/*.js", "1.2.0biome/is/missing"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + var result = mavenRunner().withArguments("spotless:apply").runHasError(); + assertFile("biome_test.js").sameAsResource("biome/js/fileBefore.js"); + assertThat(result.stdOutUtf8()).contains("Biome executable does not exist"); + } + + /** + * Tests that the build fails when the input file could not be parsed. + * + * @throws Exception When a test failure occurs. + */ + @Test + void failureWhenNotParseable() throws Exception { + writePomWithBiomeSteps("**/*.js", "1.2.0json"); + setFile("biome_test.js").toResource("biome/js/fileBefore.js"); + var result = mavenRunner().withArguments("spotless:apply").runHasError(); + assertFile("biome_test.js").sameAsResource("biome/js/fileBefore.js"); + assertThat(result.stdOutUtf8()).contains("Format with errors is disabled."); + assertThat(result.stdOutUtf8()).contains("Unable to format file"); + assertThat(result.stdOutUtf8()).contains("Step 'biome' found problem in 'biome_test.js'"); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java index 7ca3f7d981..f6a8107be1 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/rome/RomeMavenTest.java @@ -24,6 +24,7 @@ import com.diffplug.spotless.maven.MavenIntegrationHarness; +@Deprecated class RomeMavenTest extends MavenIntegrationHarness { /** * Tests that rome can be used as a generic formatting step. @@ -181,7 +182,7 @@ void failureWhenExeNotFound() throws Exception { setFile("rome_test.js").toResource("rome/js/fileBefore.js"); var result = mavenRunner().withArguments("spotless:apply").runHasError(); assertFile("rome_test.js").sameAsResource("rome/js/fileBefore.js"); - assertThat(result.stdOutUtf8()).contains("Rome executable does not exist"); + assertThat(result.stdOutUtf8()).contains("Biome executable does not exist"); } /** diff --git a/testlib/src/main/resources/biome/config/line-width-120.json b/testlib/src/main/resources/biome/config/line-width-120.json new file mode 100644 index 0000000000..8f14afa3f8 --- /dev/null +++ b/testlib/src/main/resources/biome/config/line-width-120.json @@ -0,0 +1,11 @@ +{ + "formatter": { + "enabled": true, + "indentStyle": "tab", + "lineWidth": 120, + "formatWithErrors": false + }, + "linter": { + "enabled": false + } + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/config/line-width-80.json b/testlib/src/main/resources/biome/config/line-width-80.json new file mode 100644 index 0000000000..5ec998bd97 --- /dev/null +++ b/testlib/src/main/resources/biome/config/line-width-80.json @@ -0,0 +1,11 @@ +{ + "formatter": { + "enabled": true, + "indentStyle": "tab", + "lineWidth": 80, + "formatWithErrors": false + }, + "linter": { + "enabled": false + } + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/js/fileAfter.cjs b/testlib/src/main/resources/biome/js/fileAfter.cjs new file mode 100644 index 0000000000..defc9c85eb --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileAfter.cjs @@ -0,0 +1,3 @@ +function foo(name = "World") { + return "Hello " + name; +} diff --git a/testlib/src/main/resources/biome/js/fileAfter.js b/testlib/src/main/resources/biome/js/fileAfter.js new file mode 100644 index 0000000000..defc9c85eb --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileAfter.js @@ -0,0 +1,3 @@ +function foo(name = "World") { + return "Hello " + name; +} diff --git a/testlib/src/main/resources/biome/js/fileAfter.jsx b/testlib/src/main/resources/biome/js/fileAfter.jsx new file mode 100644 index 0000000000..313aceb6ed --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileAfter.jsx @@ -0,0 +1,3 @@ +export function Panel(cfg = {}) { + return
          {1 + 2}
          ; +} diff --git a/testlib/src/main/resources/biome/js/fileAfter.mjs b/testlib/src/main/resources/biome/js/fileAfter.mjs new file mode 100644 index 0000000000..defc9c85eb --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileAfter.mjs @@ -0,0 +1,3 @@ +function foo(name = "World") { + return "Hello " + name; +} diff --git a/testlib/src/main/resources/biome/js/fileBefore.cjs b/testlib/src/main/resources/biome/js/fileBefore.cjs new file mode 100644 index 0000000000..92539ba751 --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileBefore.cjs @@ -0,0 +1,3 @@ +function foo ( name="World"){ + return "Hello "+name ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/js/fileBefore.js b/testlib/src/main/resources/biome/js/fileBefore.js new file mode 100644 index 0000000000..92539ba751 --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileBefore.js @@ -0,0 +1,3 @@ +function foo ( name="World"){ + return "Hello "+name ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/js/fileBefore.jsx b/testlib/src/main/resources/biome/js/fileBefore.jsx new file mode 100644 index 0000000000..8e5d9834bc --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileBefore.jsx @@ -0,0 +1,4 @@ +export function Panel ( cfg={}){ + return (
          {1+2}
          + ) ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/js/fileBefore.mjs b/testlib/src/main/resources/biome/js/fileBefore.mjs new file mode 100644 index 0000000000..92539ba751 --- /dev/null +++ b/testlib/src/main/resources/biome/js/fileBefore.mjs @@ -0,0 +1,3 @@ +function foo ( name="World"){ + return "Hello "+name ; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/js/longLineAfter120.js b/testlib/src/main/resources/biome/js/longLineAfter120.js new file mode 100644 index 0000000000..68addc4b65 --- /dev/null +++ b/testlib/src/main/resources/biome/js/longLineAfter120.js @@ -0,0 +1 @@ +const x = ["Hello", "World", "How", "Are", "You", "Doing", "Today", "Such", "A", "Wondrous", "Sunshine"]; diff --git a/testlib/src/main/resources/biome/js/longLineAfter80.js b/testlib/src/main/resources/biome/js/longLineAfter80.js new file mode 100644 index 0000000000..dbdbd157e9 --- /dev/null +++ b/testlib/src/main/resources/biome/js/longLineAfter80.js @@ -0,0 +1,13 @@ +const x = [ + "Hello", + "World", + "How", + "Are", + "You", + "Doing", + "Today", + "Such", + "A", + "Wondrous", + "Sunshine", +]; diff --git a/testlib/src/main/resources/biome/js/longLineBefore.js b/testlib/src/main/resources/biome/js/longLineBefore.js new file mode 100644 index 0000000000..fd59e429c2 --- /dev/null +++ b/testlib/src/main/resources/biome/js/longLineBefore.js @@ -0,0 +1 @@ +const x = ["Hello", "World", "How", "Are", "You", "Doing", "Today", "Such", "A", "Wondrous", "Sunshine"]; \ No newline at end of file diff --git a/testlib/src/main/resources/biome/json/fileAfter.json b/testlib/src/main/resources/biome/json/fileAfter.json new file mode 100644 index 0000000000..468dac3297 --- /dev/null +++ b/testlib/src/main/resources/biome/json/fileAfter.json @@ -0,0 +1,5 @@ +{ + "a": [1, 2, 3], + "b": 9, + "c": null +} diff --git a/testlib/src/main/resources/biome/json/fileBefore.json b/testlib/src/main/resources/biome/json/fileBefore.json new file mode 100644 index 0000000000..77182284c7 --- /dev/null +++ b/testlib/src/main/resources/biome/json/fileBefore.json @@ -0,0 +1,7 @@ + { + "a":[1,2,3 + +], + "b":9, + "c" : null + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/ts/fileAfter.cts b/testlib/src/main/resources/biome/ts/fileAfter.cts new file mode 100644 index 0000000000..f854953234 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileAfter.cts @@ -0,0 +1,4 @@ +type Name = "World" | "Maven" | "Gradle"; +const foo = (name: Name = "World", v: T): string => { + return "Hello " + name; +}; diff --git a/testlib/src/main/resources/biome/ts/fileAfter.mts b/testlib/src/main/resources/biome/ts/fileAfter.mts new file mode 100644 index 0000000000..e6563e3030 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileAfter.mts @@ -0,0 +1,4 @@ +export type Name = "World" | "Maven" | "Gradle"; +export const foo = (name: Name = "World", v: T): string => { + return "Hello " + name; +}; diff --git a/testlib/src/main/resources/biome/ts/fileAfter.ts b/testlib/src/main/resources/biome/ts/fileAfter.ts new file mode 100644 index 0000000000..e6563e3030 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileAfter.ts @@ -0,0 +1,4 @@ +export type Name = "World" | "Maven" | "Gradle"; +export const foo = (name: Name = "World", v: T): string => { + return "Hello " + name; +}; diff --git a/testlib/src/main/resources/biome/ts/fileAfter.tsx b/testlib/src/main/resources/biome/ts/fileAfter.tsx new file mode 100644 index 0000000000..15ef316142 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileAfter.tsx @@ -0,0 +1,7 @@ +export interface Cfg { + classname: string; + message: T; +} +const Panel = (cfg: Cfg): JSX.Element => { + return
          {String(cfg.message)}
          ; +}; diff --git a/testlib/src/main/resources/biome/ts/fileBefore.cts b/testlib/src/main/resources/biome/ts/fileBefore.cts new file mode 100644 index 0000000000..d4304287c0 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileBefore.cts @@ -0,0 +1,4 @@ +type Name = "World" | "Maven"|"Gradle"; +const foo = ( name: Name="World", v: T): string => { + return "Hello " + name; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/ts/fileBefore.mts b/testlib/src/main/resources/biome/ts/fileBefore.mts new file mode 100644 index 0000000000..96837762a3 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileBefore.mts @@ -0,0 +1,5 @@ +export + type Name = "World" | "Maven"|"Gradle"; +export const foo = ( name: Name="World", v: T): string => { + return "Hello " + name; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/ts/fileBefore.ts b/testlib/src/main/resources/biome/ts/fileBefore.ts new file mode 100644 index 0000000000..96837762a3 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileBefore.ts @@ -0,0 +1,5 @@ +export + type Name = "World" | "Maven"|"Gradle"; +export const foo = ( name: Name="World", v: T): string => { + return "Hello " + name; + } \ No newline at end of file diff --git a/testlib/src/main/resources/biome/ts/fileBefore.tsx b/testlib/src/main/resources/biome/ts/fileBefore.tsx new file mode 100644 index 0000000000..38f24f8440 --- /dev/null +++ b/testlib/src/main/resources/biome/ts/fileBefore.tsx @@ -0,0 +1,8 @@ +export interface Cfg{ +classname:string, +message:T, +} +const Panel = ( cfg:Cfg):JSX.Element =>{ + return (
          {String(cfg.message)}
          + ) ; + } \ No newline at end of file diff --git a/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java index 5c4801d50a..f1761498c3 100644 --- a/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java @@ -38,247 +38,498 @@ static void createDownloadDir() throws IOException { downloadDir = userHome.resolve(".gradle").resolve("rome-dl-test").toAbsolutePath().normalize().toString(); } - /** - * Tests that files can be formatted without setting the input language - * explicitly. - */ @Nested - class AutoDetectLanguage { + @Deprecated + class Rome { /** - * Tests that a *.cjs file can be formatted without setting the input language + * Tests that files can be formatted without setting the input language * explicitly. */ - @Test - void testAutoDetectCjs() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); - } + @Nested + class AutoDetectLanguage { + /** + * Tests that a *.cjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); + } - /** - * Tests that a *.cts file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectCts() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.cts", "rome/ts/fileAfter.cts"); - } + /** + * Tests that a *.cts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.cts", "rome/ts/fileAfter.cts"); + } - /** - * Tests that a *.js file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectJs() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.js", "rome/js/fileAfter.js"); - } + /** + * Tests that a *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.js", "rome/js/fileAfter.js"); + } - /** - * Tests that a *.js file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectJson() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/json/fileBefore.json", "rome/json/fileAfter.json"); - } + /** + * Tests that a *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJson() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/json/fileBefore.json", "rome/json/fileAfter.json"); + } - /** - * Tests that a *.jsx file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectJsx() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.jsx", "rome/js/fileAfter.jsx"); - } + /** + * Tests that a *.jsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.jsx", "rome/js/fileAfter.jsx"); + } - /** - * Tests that a *.mjs file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectMjs() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.mjs", "rome/js/fileAfter.mjs"); - } + /** + * Tests that a *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.mjs", "rome/js/fileAfter.mjs"); + } - /** - * Tests that a *.mts file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectMts() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.mts", "rome/ts/fileAfter.mts"); - } + /** + * Tests that a *.mts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.mts", "rome/ts/fileAfter.mts"); + } - /** - * Tests that a *.ts file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectTs() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.ts", "rome/ts/fileAfter.ts"); - } + /** + * Tests that a *.ts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectTs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.ts", "rome/ts/fileAfter.ts"); + } - /** - * Tests that a *.tsx file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectTsx() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); + /** + * Tests that a *.tsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectTsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); + } } - } - @Nested - class ConfigFile { - /** - * Test formatting with the line width in the config file set to 120. - */ - @Test - void testLineWidth120() { - var path = createRomeConfig("rome/config/line-width-120.json"); - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withConfigPath(path).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/longLineBefore.js", "rome/js/longLineAfter120.js"); + @Nested + class ConfigFile { + /** + * Test formatting with the line width in the config file set to 120. + */ + @Test + void testLineWidth120() { + var path = createRomeConfig("rome/config/line-width-120.json"); + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withConfigPath(path).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/longLineBefore.js", "rome/js/longLineAfter120.js"); + } + + /** + * Test formatting with the line width in the config file set to 120. + */ + @Test + void testLineWidth80() { + var path = createRomeConfig("rome/config/line-width-80.json"); + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withConfigPath(path).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/longLineBefore.js", "rome/js/longLineAfter80.js"); + } + + private String createRomeConfig(String name) { + var config = createTestFile(name).toPath(); + var dir = config.getParent(); + var rome = dir.resolve("rome.json"); + ThrowingEx.run(() -> Files.copy(config, rome)); + return dir.toString(); + } } /** - * Test formatting with the line width in the config file set to 120. + * Tests that files can be formatted when setting the input language explicitly. */ - @Test - void testLineWidth80() { - var path = createRomeConfig("rome/config/line-width-80.json"); - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withConfigPath(path).create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/longLineBefore.js", "rome/js/longLineAfter80.js"); - } + @Nested + class ExplicitLanguage { + /** + * Tests that a *.cjs file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); + } + + /** + * Tests that a *.cts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectCts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.cts", "rome/ts/fileAfter.cts"); + } + + /** + * Tests that a *.js file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.js", "rome/js/fileAfter.js"); + } + + /** + * Tests that a *.json file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJson() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("json").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/json/fileBefore.json", "rome/json/fileAfter.json"); + } + + /** + * Tests that a *.jsx file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("jsx").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.jsx", "rome/js/fileAfter.jsx"); + } - private String createRomeConfig(String name) { - var config = createTestFile(name).toPath(); - var dir = config.getParent(); - var rome = dir.resolve("rome.json"); - ThrowingEx.run(() -> Files.copy(config, rome)); - return dir.toString(); + /** + * Tests that a *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/js/fileBefore.mjs", "rome/js/fileAfter.mjs"); + } + + /** + * Tests that a *.mts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectMts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.mts", "rome/ts/fileAfter.mts"); + } + + /** + * Tests that a *.ts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectTs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.ts", "rome/ts/fileAfter.ts"); + } + + /** + * Tests that a *.tsx file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectTsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("tsx").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); + } } } - /** - * Tests that files can be formatted when setting the input language explicitly. - */ @Nested - class ExplicitLanguage { + class Biome { /** - * Tests that a *.cjs file can be formatted when setting the input language + * Tests that files can be formatted without setting the input language * explicitly. */ - @Test - void testAutoDetectCjs() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("js").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); - } + @Nested + class AutoDetectLanguage { + /** + * Tests that a *.cjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.cjs", "biome/js/fileAfter.cjs"); + } - /** - * Tests that a *.cts file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectCts() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("ts").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.cts", "rome/ts/fileAfter.cts"); - } + /** + * Tests that a *.cts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectCts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.cts", "biome/ts/fileAfter.cts"); + } - /** - * Tests that a *.js file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJs() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("js").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.js", "rome/js/fileAfter.js"); - } + /** + * Tests that a *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.js", "biome/js/fileAfter.js"); + } - /** - * Tests that a *.json file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJson() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("json").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/json/fileBefore.json", "rome/json/fileAfter.json"); - } + /** + * Tests that a *.js file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJson() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/json/fileBefore.json", "biome/json/fileAfter.json"); + } - /** - * Tests that a *.jsx file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectJsx() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("jsx").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.jsx", "rome/js/fileAfter.jsx"); - } + /** + * Tests that a *.jsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectJsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.jsx", "biome/js/fileAfter.jsx"); + } - /** - * Tests that a *.mjs file can be formatted without setting the input language - * explicitly. - */ - @Test - void testAutoDetectMjs() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("js").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/js/fileBefore.mjs", "rome/js/fileAfter.mjs"); - } + /** + * Tests that a *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.mjs", "biome/js/fileAfter.mjs"); + } - /** - * Tests that a *.mts file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectMts() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("ts").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.mts", "rome/ts/fileAfter.mts"); + /** + * Tests that a *.mts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.mts", "biome/ts/fileAfter.mts"); + } + + /** + * Tests that a *.ts file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectTs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.ts", "biome/ts/fileAfter.ts"); + } + + /** + * Tests that a *.tsx file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectTsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.tsx", "biome/ts/fileAfter.tsx"); + } } - /** - * Tests that a *.ts file can be formatted when setting the input language - * explicitly. - */ - @Test - void testAutoDetectTs() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("ts").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.ts", "rome/ts/fileAfter.ts"); + @Nested + class ConfigFile { + /** + * Test formatting with the line width in the config file set to 120. + */ + @Test + void testLineWidth120() { + var path = createBiomeConfig("biome/config/line-width-120.json"); + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/js/longLineBefore.js", "biome/js/longLineAfter120.js"); + } + + /** + * Test formatting with the line width in the config file set to 120. + */ + @Test + void testLineWidth80() { + var path = createBiomeConfig("biome/config/line-width-80.json"); + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/js/longLineBefore.js", "biome/js/longLineAfter80.js"); + } + + private String createBiomeConfig(String name) { + var config = createTestFile(name).toPath(); + var dir = config.getParent(); + var rome = dir.resolve("biome.json"); + ThrowingEx.run(() -> Files.copy(config, rome)); + return dir.toString(); + } } /** - * Tests that a *.tsx file can be formatted when setting the input language - * explicitly. + * Tests that files can be formatted when setting the input language explicitly. */ - @Test - void testAutoDetectTsx() { - var step = RomeStep.withExeDownload("12.0.0", downloadDir.toString()).withLanguage("tsx").create(); - var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); - stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); + @Nested + class ExplicitLanguage { + /** + * Tests that a *.cjs file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectCjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.cjs", "biome/js/fileAfter.cjs"); + } + + /** + * Tests that a *.cts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectCts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.cts", "biome/ts/fileAfter.cts"); + } + + /** + * Tests that a *.js file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.js", "biome/js/fileAfter.js"); + } + + /** + * Tests that a *.json file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJson() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("json").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/json/fileBefore.json", "biome/json/fileAfter.json"); + } + + /** + * Tests that a *.jsx file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectJsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("jsx").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.jsx", "biome/js/fileAfter.jsx"); + } + + /** + * Tests that a *.mjs file can be formatted without setting the input language + * explicitly. + */ + @Test + void testAutoDetectMjs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/js/fileBefore.mjs", "biome/js/fileAfter.mjs"); + } + + /** + * Tests that a *.mts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectMts() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.mts", "biome/ts/fileAfter.mts"); + } + + /** + * Tests that a *.ts file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectTs() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.ts", "biome/ts/fileAfter.ts"); + } + + /** + * Tests that a *.tsx file can be formatted when setting the input language + * explicitly. + */ + @Test + void testAutoDetectTsx() { + var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("tsx").create(); + var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); + stepHarness.testResource("biome/ts/fileBefore.tsx", "biome/ts/fileAfter.tsx"); + } } } } From 967825f76ea6d3f3541c63b457ba758fca2eb654 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Fri, 15 Sep 2023 19:46:13 +0100 Subject: [PATCH 0911/1120] Update readme and changes for biome, #1804 --- CHANGES.md | 4 ++ README.md | 4 +- plugin-gradle/CHANGES.md | 4 ++ plugin-gradle/README.md | 133 +++++++++++++++++++-------------------- plugin-maven/CHANGES.md | 4 ++ plugin-maven/README.md | 124 ++++++++++++++++++------------------ 6 files changed, 143 insertions(+), 130 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 652e4ce38c..36ca61af71 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] +* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). + The configuration is still the same, but you should switch to the new `biome` tag / function and adjust + the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). + ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) diff --git a/README.md b/README.md index cd1e736014..0bfa395a23 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', lib('protobuf.BufStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', -lib('rome.RomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', +lib('biome.BiomeStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', @@ -153,7 +153,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | [`pom.SortPomStepStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStepStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | | [`protobuf.BufStep`](lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | -| [`rome.RomeStep`](lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | +| [`biome.BiomeStep`](lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`wtp.EclipseWtpFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 989b4ece12..d7907f0b87 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). + The configuration is still the same, but you should switch to the new `biome(...)` function and adjust + the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). + ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f81b897a4a..9c37f16902 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -64,9 +64,9 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome)) - - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Rome](#rome)) - - [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [rome](#rome), [jsonPatch](#jsonPatch)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Biome](#biome)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Biome](#biome)) + - [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [Biome](#biome), [jsonPatch](#jsonPatch)) - [YAML](#yaml) - [Gherkin](#gherkin) - Multiple languages @@ -76,7 +76,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - c, c++, c#, objective-c, protobuf, javascript, java - [eclipse web tools platform](#eclipse-web-tools-platform) - css, html, js, json, xml - - [Rome](#rome) ([binary detection](#rome-binary), [config file](#rome-configuration-file), [input language](#rome-input-language)) + - [Biome](#biome) ([binary detection](#biome-binary), [config file](#biome-configuration-file), [input language](#biome-input-language)) - **Language independent** - [Generic steps](#generic-steps) - [License header](#license-header) ([slurp year from git](#retroactively-slurp-years-from-git-history)) @@ -650,7 +650,7 @@ spotless { tsfmt() // has its own section below prettier() // has its own section below eslint() // has its own section below - rome() // has its own section below + biome() // has its own section below licenseHeader '/* (C) $YEAR */', '(import|const|declare|export|var) ' // or licenseHeaderFile // note the '(import|const|...' argument - this is a regex which identifies the top @@ -743,7 +743,7 @@ spotless { prettier() // has its own section below eslint() // has its own section below - rome() // has its own section below + biome() // has its own section below licenseHeader '/* (C) $YEAR */', 'REGEX_TO_DEFINE_TOP_OF_FILE' // or licenseHeaderFile } @@ -810,7 +810,7 @@ spotless { eclipseWtp('json') // see Eclipse web tools platform section gson() // has its own section below jackson() // has its own section below - rome() // has its own section below + biome() // has its own section below jsonPatch([]) // has its own section below } } @@ -1150,15 +1150,20 @@ Unlike Eclipse, Spotless WTP ignores per default external URIs in schema locatio external entities. To allow the access of external URIs, set the property `resolveExternalURI` to true. -## Rome +## Biome -[homepage](https://rome.tools/). [changelog](https://github.com/rome/tools/blob/main/CHANGELOG.md). Rome is a formatter that for the Frontend written in Rust, which has a native binary, -does not require Node.js and as such, is pretty fast. It can currently format -JavaScript, TypeScript, JSX, and JSON, and may support -[more frontend languages](https://docs.rome.tools/internals/language_support/) -such as CSS in the future. +[homepage](https://biomejs.dev/). [changelog](https://github.com/biomejs/biome/blob/main/CHANGELOG.md). Biome is +a formatter that for the frontend written in Rust, which has a native binary, does not require Node.js and as such, +is pretty fast. It can currently format JavaScript, TypeScript, JSX, and JSON, and may support +[more frontend languages](https://biomejs.dev/internals/language-support/) such as CSS in the future. -You can use rome in any language-specific format for supported languages, but +Note: Biome [was formerly called Rome](https://biomejs.dev/blog/annoucing-biome/). Configurations with +the old `` tag and `rome(...)` function are still supported for the time being. This will be removed +in a future version, you should migrate to the new `` tag or `biome(...)` function. The configuration +remains the same, you only need to update the version. If you are using a custom `rome.json` configuration file, +you need to rename it to `biome.json`. + +You can use Biome in any language-specific format for supported languages, but usually you will be creating a generic format. ```gradle @@ -1167,72 +1172,73 @@ spotless { // you have to set the target manually target 'src/*/webapp/**/*.js' - // Download Rome from the network if not already downloaded, see below for more info - rome('12.0.0') + // Download Biome from the network if not already downloaded, see below for more info + biome('1.2.0') - // (optional) Path to the directory with the rome.json conig file - rome('12.0.0').configPath("path/config/dir") + // (optional) Path to the directory with the biome.json conig file + biome('1.2.0').configPath("path/config/dir") - // (optional) Rome will auto detect the language based on the file extension. + // (optional) Biome will auto detect the language based on the file extension. // See below for possible values. - rome('12.0.0').language("js") + biome('1.2.0').language("js") } } ``` **Limitations:** + - The auto-discovery of config files (up the file tree) will not work when using - Rome within spotless. + Biome within spotless. -To apply Rome to more kinds of files with a different configuration, just add +To apply Biome to more kinds of files with a different configuration, just add more formats: ```gradle spotless { - format 'rome-js', { + format 'biome-js', { target '**/*.js' - rome('12.0.0') + biome('1.2.0') } - format 'rome-ts', { + format 'biome-ts', { target '**/*.ts' - rome('12.0.0') + biome('1.2.0') } - format 'rome-json', { + format 'biome-json', { target '**/*.json' - rome('12.0.0') + biome('1.2.0') } } ``` -### Rome binary +### Biome binary -To format with Rome, spotless needs to find the Rome binary. By default, +To format with Biome, spotless needs to find the Biome binary. By default, spotless downloads the binary for the given version from the network. This should be fine in most cases, but may not work e.g. when there is not connection to the internet. -To download the Rome binary from the network, just specify a version: +To download the Biome binary from the network, just specify a version: ```gradle spotless { - format 'rome', { + format 'biome', { target '**/*.js','**/*.ts','**/*.json' - rome('12.0.0') + biome('1.2.0') } } ``` -Spotless uses a default version when you do not specfiy a version, but this -may change at any time, so we recommend that you always set the Rome version +Spotless uses a default version when you do not specify a version, but this +may change at any time, so we recommend that you always set the Biome version you want to use. Optionally, you can also specify a directory for the downloaded -Rome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/rome`): +Biome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/biome`): ```gradle spotless { - format 'rome', { + format 'biome', { target '**/*.js','**/*.ts','**/*.json' // Relative paths are resolved against the project's base directory - rome('12.0.0').downloadDir("${project.gradle.gradleUserHomeDir}/rome") + biome('1.2.0').downloadDir("${project.gradle.gradleUserHomeDir}/biome") } } ``` @@ -1241,68 +1247,59 @@ To use a fixed binary, omit the `version` and specify a `pathToExe`: ```gradle spotless { - format 'rome', { + format 'biome', { target '**/*.js','**/*.ts','**/*.json' - rome().pathToExe("${project.layout.buildDirectory.asFile.get().absolutePath}/bin/rome") + biome().pathToExe("${project.layout.buildDirectory.asFile.get().absolutePath}/bin/biome") } } ``` Absolute paths are used as-is. Relative paths are resolved against the project's -base directory. To use a pre-installed Rome binary on the user's path, specify +base directory. To use a pre-installed Biome binary on the user's path, specify just a name without any slashes / backslashes: ```gradle spotless { - format 'rome', { + format 'biome', { target '**/*.js','**/*.ts','**/*.json' - // Uses the "rome" command, which must be on the user's path. --> - rome().pathToExe('rome') + // Uses the "biome" command, which must be on the user's path. --> + biome().pathToExe('biome') } } ``` -### Rome configuration file +### Biome configuration file -Rome is a biased formatter and linter without many options, but there are a few -basic options. Rome uses a file named [rome.json](https://docs.rome.tools/configuration/) +Biome is a biased formatter and linter without many options, but there are a few +basic options. Biome uses a file named [biome.json](https://biomejs.dev/reference/configuration/) for its configuration. When none is specified, the default configuration from -Rome is used. To use a custom configuration: +Biome is used. To use a custom configuration: ```gradle spotless { - format 'rome', { + format 'biome', { target '**/*.js','**/*.ts','**/*.json' - // Must point to the directory with the "rome.json" config file --> + // Must point to the directory with the "biome.json" config file --> // Relative paths are resolved against the project's base directory --> - rome('12.0.0').configPath('./config') + biome('1.2.0').configPath('./config') } } ``` -### Rome input language +### Biome input language -By default, Rome detects the language / syntax of the files to format +By default, Biome detects the language / syntax of the files to format automatically from the file extension. This may fail if your source code files have unusual extensions for some reason. If you are using the generic format, you can force a certain language like this: ```xml - - - - - src/**/typescript/**/*.mjson - - - - 12.0.0 - json - - - - - +spotless { + format 'biome', { + target 'src/**/typescript/**/*.mjson' + biome('1.2.0').language('json') + } +} ``` The following languages are currently recognized: diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index b624299e71..22b77e4a7b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +* Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). + The configuration is still the same, but you should switch to the new `` tag and adjust + the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). + ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 8f91d8b08b..b6673b0221 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -49,15 +49,15 @@ user@machine repo % mvn spotless:check - [Sql](#sql) ([dbeaver](#dbeaver)) - [Maven Pom](#maven-pom) ([sortPom](#sortpom)) - [Markdown](#markdown) ([flexmark](#flexmark)) - - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Rome](#rome)) - - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Rome](#rome)) - - [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [rome](#rome), [jsonPatch](#jsonPatch)) + - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript), [Biome](#biome)) + - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript), [Biome](#biome)) + - [JSON](#json) ([simple](#simple), [gson](#gson), [jackson](#jackson), [Biome](#biome), [jsonPatch](#jsonPatch)) - [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) - - [Rome](#rome) ([binary detection](#rome-binary), [config file](#rome-configuration-file), [input language](#rome-input-language)) + - [Biome](#biome) ([binary detection](#biome-binary), [config file](#biome-configuration-file), [input language](#biome-input-language)) - **Language independent** - [Generic steps](#generic-steps) - [License header](#license-header) ([slurp year from git](#retroactively-slurp-years-from-git-history)) @@ -712,7 +712,7 @@ Currently, none of the available options can be configured yet. It uses only the - + /* (C)$YEAR */ @@ -823,7 +823,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr - + /* (C)$YEAR */ @@ -900,7 +900,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr - + @@ -1252,15 +1252,20 @@ to true. -## Rome +## Biome -[homepage](https://rome.tools/). [changelog](https://github.com/rome/tools/blob/main/CHANGELOG.md). Rome is a formatter that for the Frontend written in Rust, which has a native binary, -does not require Node.js and as such, is pretty fast. It can currently format -JavaScript, TypeScript, JSX, and JSON, and may support -[more frontend languages](https://docs.rome.tools/internals/language_support/) -such as CSS in the future. +[homepage](https://biomejs.dev/). [changelog](https://github.com/biomejs/biome/blob/main/CHANGELOG.md). Biome is +a formatter that for the frontend written in Rust, which has a native binary, does not require Node.js and as such, +is pretty fast. It can currently format JavaScript, TypeScript, JSX, and JSON, and may support +[more frontend languages](https://biomejs.dev/internals/language-support/) such as CSS in the future. -You can use rome in any language-specific format for supported languages, but +Note: Biome [was formerly called Rome](https://biomejs.dev/blog/annoucing-biome/). Configurations with +the old `` tag and `rome(...)` function are still supported for the time being. This will be removed +in a future version, you should migrate to the new `` tag or `biome(...)` function. The configuration +remains the same, you only need to update the version. If you are using a custom `rome.json` configuration file, +you need to rename it to `biome.json`. + +You can use Biome in any language-specific format for supported languages, but usually you will be creating a generic format. ```xml @@ -1271,18 +1276,18 @@ usually you will be creating a generic format. src/**/typescript/**/*.ts - - - 12.0.0 + + + 1.2.0 - + ${project.basedir}/path/to/config/dir - + ts - + @@ -1290,85 +1295,85 @@ usually you will be creating a generic format. **Limitations:** - The auto-discovery of config files (up the file tree) will not work when using - Rome within spotless. + Biome within spotless. -To apply Rome to more kinds of files with a different configuration, just add -more formats +To apply Biome to more kinds of files with a different configuration, just add +more formats: ```xml - src/**/*.ts - src/**/*.js + src/**/*.ts + src/**/*.js ``` -### Rome binary +### Biome binary -To format with Rome, spotless needs to find the Rome binary. By default, +To format with Biome, spotless needs to find the Biome binary. By default, spotless downloads the binary for the given version from the network. This should be fine in most cases, but may not work e.g. when there is not connection to the internet. -To download the Rome binary from the network, just specify a version: +To download the Biome binary from the network, just specify a version: ```xml - - 12.0.0 - + + 1.2.0 + ``` -Spotless uses a default version when you do not specfiy a version, but this -may change at any time, so we recommend that you always set the Rome version +Spotless uses a default version when you do not specify a version, but this +may change at any time, so we recommend that you always set the Biome version you want to use. Optionally, you can also specify a directory for the downloaded -Rome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/rome`): +Biome binaries (defaults to `~/.m2/repository/com/diffplug/spotless/spotless-data/biome`): ```xml - - 12.0.0 + + 1.2.0 - ${user.home}/rome - + ${user.home}/biome + ``` To use a fixed binary, omit the `version` and specify a `pathToExe`: ```xml - - ${project.basedir}/bin/rome - + + ${project.basedir}/bin/biome + ``` Absolute paths are used as-is. Relative paths are resolved against the project's -base directory. To use a pre-installed Rome binary on the user's path, specify +base directory. To use a pre-installed Biome binary on the user's path, specify just a name without any slashes / backslashes: ```xml - - - rome - + + + biome + ``` -### Rome configuration file +### Biome configuration file -Rome is a biased formatter and linter without many options, but there are a few -basic options. Rome uses a file named [rome.json](https://docs.rome.tools/configuration/) +Biome is a biased formatter and linter without many options, but there are a few +basic options. Biome uses a file named [biome.json](https://biomejs.dev/reference/configuration/) for its configuration. When none is specified, the default configuration from -Rome is used. To use a custom configuration: +Biome is used. To use a custom configuration: ```xml - - + + ${project.basedir} - + ``` -### Rome input language +### Biome input language -By default, Rome detects the language / syntax of the files to format +By default, Biome detects the language / syntax of the files to format automatically from the file extension. This may fail if your source code files have unusual extensions for some reason. If you are using the generic format, you can force a certain language like this: @@ -1381,12 +1386,11 @@ you can force a certain language like this: src/**/typescript/**/*.mjson - - 12.0.0 + + 1.2.0 json - - - + + ``` From 4a9e443bae171637e915a1b5bf11d90a21e74fa1 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Fri, 15 Sep 2023 20:37:56 +0100 Subject: [PATCH 0912/1120] Apply spotless --- .../diffplug/spotless/rome/EBiomeFlavor.java | 19 +++++++++++++++++-- .../gradle/spotless/FormatExtension.java | 14 +++++++------- .../gradle/spotless/JavascriptExtension.java | 6 +++--- .../gradle/spotless/JsonExtension.java | 6 +++--- .../gradle/spotless/TypescriptExtension.java | 6 +++--- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java b/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java index e47662f154..efe9a74807 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java @@ -1,3 +1,18 @@ +/* + * 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.rome; /** @@ -13,7 +28,7 @@ public enum EBiomeFlavor { /** * The old deprecated Rome project. - * + * * @deprecated Will be removed once the old Rome project is not supported * anymore. */ @@ -77,4 +92,4 @@ public String getUrlPattern() { public String shortName() { return shortName; } -} \ No newline at end of file +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 61fb0a6e5b..6c62469b04 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -735,7 +735,7 @@ public class BiomeGeneric extends RomeStepConfig { /** * Creates a new Rome config that downloads the Rome executable for the given * version from the network. - * + * * @param version Rome version to use. The default version is used when * null. */ @@ -758,7 +758,7 @@ public BiomeGeneric(String version) { * extension) *
        • json (JSON)
        • *
        - * + * * @param language The language of the files to format. * @return This step for further configuration. */ @@ -783,7 +783,7 @@ protected BiomeGeneric getThis() { * Generic Rome formatter step that detects the language of the input file from * the file name. It should be specified as a formatter step for a generic * format{ ... }. - * + * * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ @Deprecated @@ -794,7 +794,7 @@ public class RomeGeneric extends RomeStepConfig { /** * Creates a new Rome config that downloads the Rome executable for the given * version from the network. - * + * * @param version Rome version to use. The default version is used when * null. */ @@ -817,7 +817,7 @@ public RomeGeneric(String version) { * extension) *
      • json (JSON)
      • *
      - * + * * @param language The language of the files to format. * @return This step for further configuration. */ @@ -875,7 +875,7 @@ public RomeStepConfig biome(String version) { * Defaults to downloading the default Rome version from the network. To work * offline, you can specify the path to the Rome executable via * {@code rome().pathToExe(...)}. - * + * * @deprecated Use {@link #biome(String)}. */ @Deprecated @@ -885,7 +885,7 @@ public RomeStepConfig rome() { /** * Downloads the given Rome version from the network. - * + * * @deprecated Use {@link #biome(String)}. */ @Deprecated diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index c776004da3..4dc810ce6b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -158,7 +158,7 @@ public BiomeJs biome(String version) { * Defaults to downloading the default Rome version from the network. To work * offline, you can specify the path to the Rome executable via * {@code rome().pathToExe(...)}. - * + * * @deprecated Use {@link #biome()}. */ @Deprecated @@ -168,7 +168,7 @@ public RomeJs rome() { /** * Downloads the given Rome version from the network. - * + * * @deprecated Use {@link #biome(String)}. */ @Deprecated @@ -209,7 +209,7 @@ protected BiomeJs getThis() { /** * Rome formatter step for JavaScript. - * + * * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ @Deprecated diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index cc16b7ed35..8273d81e79 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -80,7 +80,7 @@ public BiomeJson biome(String version) { * Defaults to downloading the default Rome version from the network. To work * offline, you can specify the path to the Rome executable via * {@code rome().pathToExe(...)}. - * + * * @deprecated Use {@link #biome()}. */ @Deprecated @@ -90,7 +90,7 @@ public RomeJson rome() { /** * Downloads the given Rome version from the network. - * + * * @deprecated Use {@link #biome(String)}. */ @Deprecated @@ -233,7 +233,7 @@ protected BiomeJson getThis() { /** * Rome formatter step for JSON. - * + * * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ @Deprecated diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index ad9bcc832b..f21bd9ed39 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -247,7 +247,7 @@ public BiomeTs biome(String version) { * Defaults to downloading the default Rome version from the network. To work * offline, you can specify the path to the Rome executable via * {@code rome().pathToExe(...)}. - * + * * @deprecated Use {@link #biome()}. */ @Deprecated @@ -257,7 +257,7 @@ public RomeTs rome() { /** * Downloads the given Rome version from the network. - * + * * @deprecated Use {@link #biome(String)}. */ @Deprecated @@ -294,7 +294,7 @@ protected BiomeTs getThis() { /** * Rome formatter step for TypeScript. - * + * * @deprecated Rome has transitioned to Biome. This will be removed shortly. */ @Deprecated From ddaf8d47b044adb87580bdeb096ac15771d4fcf8 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 16 Sep 2023 09:31:41 +0100 Subject: [PATCH 0913/1120] Enum naming convention, EBiomeFlavor -> BiomeFlavor --- .../rome/{EBiomeFlavor.java => BiomeFlavor.java} | 4 ++-- .../spotless/rome/RomeExecutableDownloader.java | 4 ++-- .../java/com/diffplug/spotless/rome/RomeStep.java | 12 ++++++------ .../diffplug/gradle/spotless/FormatExtension.java | 6 +++--- .../gradle/spotless/JavascriptExtension.java | 6 +++--- .../com/diffplug/gradle/spotless/JsonExtension.java | 6 +++--- .../com/diffplug/gradle/spotless/RomeStepConfig.java | 6 +++--- .../gradle/spotless/TypescriptExtension.java | 6 +++--- .../com/diffplug/spotless/maven/generic/Biome.java | 4 ++-- .../com/diffplug/spotless/maven/generic/Rome.java | 4 ++-- .../diffplug/spotless/maven/javascript/BiomeJs.java | 4 ++-- .../diffplug/spotless/maven/javascript/RomeJs.java | 4 ++-- .../com/diffplug/spotless/maven/json/BiomeJson.java | 4 ++-- .../com/diffplug/spotless/maven/json/RomeJson.java | 4 ++-- .../diffplug/spotless/maven/rome/AbstractRome.java | 6 +++--- .../diffplug/spotless/maven/typescript/BiomeTs.java | 4 ++-- .../diffplug/spotless/maven/typescript/RomeTs.java | 4 ++-- 17 files changed, 44 insertions(+), 44 deletions(-) rename lib/src/main/java/com/diffplug/spotless/rome/{EBiomeFlavor.java => BiomeFlavor.java} (95%) diff --git a/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java b/lib/src/main/java/com/diffplug/spotless/rome/BiomeFlavor.java similarity index 95% rename from lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java rename to lib/src/main/java/com/diffplug/spotless/rome/BiomeFlavor.java index efe9a74807..dbfd43eee9 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/EBiomeFlavor.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/BiomeFlavor.java @@ -21,7 +21,7 @@ *

      * Will be removed once the old Rome project is not supported anymore. */ -public enum EBiomeFlavor { +public enum BiomeFlavor { /** The new forked Biome project. */ BIOME("biome", "1.2.0", "biome.json", "biome-%s-%s-%s", "https://github.com/biomejs/biome/releases/download/cli%%2Fv%s/biome-%s"), @@ -42,7 +42,7 @@ public enum EBiomeFlavor { private final String shortName; private final String urlPattern; - EBiomeFlavor(String shortName, String defaultVersion, String configName, String downloadFilePattern, + BiomeFlavor(String shortName, String defaultVersion, String configName, String downloadFilePattern, String urlPattern) { this.shortName = shortName; this.defaultVersion = defaultVersion; diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java index 7ff0bdb622..052f72def4 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeExecutableDownloader.java @@ -71,7 +71,7 @@ final class RomeExecutableDownloader { private final Path downloadDir; - private final EBiomeFlavor flavor; + private final BiomeFlavor flavor; /** * Creates a new downloader for the Biome executable. The executable files are @@ -80,7 +80,7 @@ final class RomeExecutableDownloader { * @param flavor Flavor of Biome to use. * @param downloadDir Directory where to store the downloaded executable. */ - public RomeExecutableDownloader(EBiomeFlavor flavor, Path downloadDir) { + public RomeExecutableDownloader(BiomeFlavor flavor, Path downloadDir) { this.flavor = flavor; this.downloadDir = downloadDir; } diff --git a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java index 88c35c8662..5ba33d593d 100644 --- a/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java +++ b/lib/src/main/java/com/diffplug/spotless/rome/RomeStep.java @@ -74,7 +74,7 @@ public class RomeStep { * Biome flavor to use. Will be removed once we stop supporting the deprecated Rome project. */ @Deprecated - private final EBiomeFlavor flavor; + private final BiomeFlavor flavor; /** * Path to the Biome executable. Can be null, but either a path to @@ -113,7 +113,7 @@ public String name() { * @param downloadDir Directory where to place the downloaded executable. * @return A new Biome step that download the executable from the network. */ - public static RomeStep withExeDownload(EBiomeFlavor flavor, String version, String downloadDir) { + public static RomeStep withExeDownload(BiomeFlavor flavor, String version, String downloadDir) { return new RomeStep(flavor, version, null, downloadDir); } @@ -125,7 +125,7 @@ public static RomeStep withExeDownload(EBiomeFlavor flavor, String version, Stri * @param pathToExe Path to the Biome executable to use. * @return A new Biome step that format with the given executable. */ - public static RomeStep withExePath(EBiomeFlavor flavor, String pathToExe) { + public static RomeStep withExePath(BiomeFlavor flavor, String pathToExe) { return new RomeStep(flavor, null, pathToExe, null); } @@ -154,7 +154,7 @@ private static void attemptToAddPosixPermission(Path file, PosixFilePermission p * * @return The default version for Biome. */ - private static String defaultVersion(EBiomeFlavor flavor) { + private static String defaultVersion(BiomeFlavor flavor) { return flavor.defaultVersion(); } @@ -198,7 +198,7 @@ private static String resolveNameAgainstPath(String name) throws IOException, In * Checks the Biome config path. When the config path does not exist or when it * does not contain a file named {@code biome.json}, an error is thrown. */ - private static void validateBiomeConfigPath(EBiomeFlavor flavor, String configPath) { + private static void validateBiomeConfigPath(BiomeFlavor flavor, String configPath) { if (configPath == null) { return; } @@ -230,7 +230,7 @@ private static void validateBiomeExecutable(String resolvedPathToExe) { * @param pathToExe Path to the Biome executable to use. * @param downloadDir Directory where to place the downloaded executable. */ - private RomeStep(EBiomeFlavor flavor, String version, String pathToExe, String downloadDir) { + private RomeStep(BiomeFlavor flavor, String version, String pathToExe, String downloadDir) { this.flavor = flavor; this.version = version != null && !version.isBlank() ? version : defaultVersion(flavor); this.pathToExe = pathToExe; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 6c62469b04..30fded9d5f 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -67,7 +67,7 @@ import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; import groovy.lang.Closure; @@ -740,7 +740,7 @@ public class BiomeGeneric extends RomeStepConfig { * null. */ public BiomeGeneric(String version) { - super(getProject(), FormatExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + super(getProject(), FormatExtension.this::replaceStep, BiomeFlavor.BIOME, version); } /** @@ -799,7 +799,7 @@ public class RomeGeneric extends RomeStepConfig { * null. */ public RomeGeneric(String version) { - super(getProject(), FormatExtension.this::replaceStep, EBiomeFlavor.ROME, version); + super(getProject(), FormatExtension.this::replaceStep, BiomeFlavor.ROME, version); } /** diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index 4dc810ce6b..b14bd29ab8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -34,7 +34,7 @@ import com.diffplug.spotless.npm.EslintFormatterStep; import com.diffplug.spotless.npm.NpmPathResolver; import com.diffplug.spotless.npm.PrettierFormatterStep; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; public class JavascriptExtension extends FormatExtension { @@ -193,7 +193,7 @@ public class BiomeJs extends RomeStepConfig { * @param version Biome version to use. */ public BiomeJs(String version) { - super(getProject(), JavascriptExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + super(getProject(), JavascriptExtension.this::replaceStep, BiomeFlavor.BIOME, version); } @Override @@ -221,7 +221,7 @@ public class RomeJs extends RomeStepConfig { * @param version Rome version to use. */ public RomeJs(String version) { - super(getProject(), JavascriptExtension.this::replaceStep, EBiomeFlavor.ROME, version); + super(getProject(), JavascriptExtension.this::replaceStep, BiomeFlavor.ROME, version); } @Override diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 8273d81e79..441e25b93d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -27,7 +27,7 @@ import com.diffplug.spotless.json.JsonPatchStep; import com.diffplug.spotless.json.JsonSimpleStep; import com.diffplug.spotless.json.gson.GsonStep; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; public class JsonExtension extends FormatExtension { private static final int DEFAULT_INDENTATION = 4; @@ -217,7 +217,7 @@ public class BiomeJson extends RomeStepConfig { * @param version Biome version to use. */ public BiomeJson(String version) { - super(getProject(), JsonExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + super(getProject(), JsonExtension.this::replaceStep, BiomeFlavor.BIOME, version); } @Override @@ -245,7 +245,7 @@ public class RomeJson extends RomeStepConfig { * @param version Rome version to use. */ public RomeJson(String version) { - super(getProject(), JsonExtension.this::replaceStep, EBiomeFlavor.ROME, version); + super(getProject(), JsonExtension.this::replaceStep, BiomeFlavor.ROME, version); } @Override diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java index 6b0ae893ac..98c4000a8b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RomeStepConfig.java @@ -28,7 +28,7 @@ import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; import com.diffplug.spotless.rome.RomeStep; public abstract class RomeStepConfig> { @@ -54,7 +54,7 @@ public abstract class RomeStepConfig> { * The flavor of Biome to use. Will be removed when we stop support the * deprecated Rome project. */ - private final EBiomeFlavor flavor; + private final BiomeFlavor flavor; /** * Optional path to the Biome executable. Either a version or a @@ -95,7 +95,7 @@ public abstract class RomeStepConfig> { @Nullable private String version; - protected RomeStepConfig(Project project, Consumer replaceStep, EBiomeFlavor flavor, + protected RomeStepConfig(Project project, Consumer replaceStep, BiomeFlavor flavor, String version) { this.project = requireNonNull(project); this.replaceStep = requireNonNull(replaceStep); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index f21bd9ed39..190a2f8e20 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -38,7 +38,7 @@ import com.diffplug.spotless.npm.TsConfigFileType; import com.diffplug.spotless.npm.TsFmtFormatterStep; import com.diffplug.spotless.npm.TypedTsFmtConfigFile; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; public class TypescriptExtension extends FormatExtension { @@ -278,7 +278,7 @@ public class BiomeTs extends RomeStepConfig { * @param version Biome version to use. */ public BiomeTs(String version) { - super(getProject(), TypescriptExtension.this::replaceStep, EBiomeFlavor.BIOME, version); + super(getProject(), TypescriptExtension.this::replaceStep, BiomeFlavor.BIOME, version); } @Override @@ -306,7 +306,7 @@ public class RomeTs extends RomeStepConfig { * @param version Rome version to use. */ public RomeTs(String version) { - super(getProject(), TypescriptExtension.this::replaceStep, EBiomeFlavor.ROME, version); + super(getProject(), TypescriptExtension.this::replaceStep, BiomeFlavor.ROME, version); } @Override diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java index 23b6637519..e096a14734 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Biome.java @@ -18,7 +18,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Generic Biome formatter step that detects the language of the input file from @@ -27,7 +27,7 @@ */ public class Biome extends AbstractRome { public Biome() { - super(EBiomeFlavor.BIOME); + super(BiomeFlavor.BIOME); } /** diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java index 628c051699..53080fe546 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Rome.java @@ -18,7 +18,7 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * See {@link Biome}. @@ -26,7 +26,7 @@ */ public class Rome extends AbstractRome { public Rome() { - super(EBiomeFlavor.ROME); + super(BiomeFlavor.ROME); } /** diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java index 07a341eee5..4d52f4cc80 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/BiomeJs.java @@ -16,14 +16,14 @@ package com.diffplug.spotless.maven.javascript; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Biome formatter step for JavaScript. */ public class BiomeJs extends AbstractRome { public BiomeJs() { - super(EBiomeFlavor.BIOME); + super(BiomeFlavor.BIOME); } @Override diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java index b5754f2b65..405809c7a7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/RomeJs.java @@ -16,7 +16,7 @@ package com.diffplug.spotless.maven.javascript; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Rome formatter step for JavaScript. @@ -25,7 +25,7 @@ @Deprecated public class RomeJs extends AbstractRome { public RomeJs() { - super(EBiomeFlavor.ROME); + super(BiomeFlavor.ROME); } @Override diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java index 13c2ab92f2..a8d329d725 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/BiomeJson.java @@ -16,14 +16,14 @@ package com.diffplug.spotless.maven.json; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Biome formatter step for JSON. */ public class BiomeJson extends AbstractRome { public BiomeJson() { - super(EBiomeFlavor.BIOME); + super(BiomeFlavor.BIOME); } @Override diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java index 7daab94afb..2959d5a055 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/json/RomeJson.java @@ -16,7 +16,7 @@ package com.diffplug.spotless.maven.json; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Rome formatter step for JSON. @@ -25,7 +25,7 @@ @Deprecated public class RomeJson extends AbstractRome { public RomeJson() { - super(EBiomeFlavor.ROME); + super(BiomeFlavor.ROME); } @Override diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java index 8b140ea381..da66bf37a0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/rome/AbstractRome.java @@ -22,7 +22,7 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; import com.diffplug.spotless.rome.RomeStep; /** @@ -34,9 +34,9 @@ */ public abstract class AbstractRome implements FormatterStepFactory { /** Biome flavor to use. */ - private EBiomeFlavor flavor; + private BiomeFlavor flavor; - protected AbstractRome(EBiomeFlavor flavor) { + protected AbstractRome(BiomeFlavor flavor) { this.flavor = flavor; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java index 6fbcb31ee2..a99e633a42 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/BiomeTs.java @@ -16,14 +16,14 @@ package com.diffplug.spotless.maven.typescript; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Biome formatter step for TypeScript. */ public class BiomeTs extends AbstractRome { public BiomeTs() { - super(EBiomeFlavor.BIOME); + super(BiomeFlavor.BIOME); } @Override diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java index 149d4208e3..f6ea80581d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/RomeTs.java @@ -16,7 +16,7 @@ package com.diffplug.spotless.maven.typescript; import com.diffplug.spotless.maven.rome.AbstractRome; -import com.diffplug.spotless.rome.EBiomeFlavor; +import com.diffplug.spotless.rome.BiomeFlavor; /** * Rome formatter step for TypeScript. @@ -25,7 +25,7 @@ @Deprecated public class RomeTs extends AbstractRome { public RomeTs() { - super(EBiomeFlavor.ROME); + super(BiomeFlavor.ROME); } @Override From a1b2e82f5cb23d8d52ef51450358c8fea198ceb8 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Sat, 16 Sep 2023 10:38:44 +0100 Subject: [PATCH 0914/1120] Fix test compilation --- .../diffplug/spotless/rome/RomeStepTest.java | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java index f1761498c3..f723a561c2 100644 --- a/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/rome/RomeStepTest.java @@ -53,7 +53,7 @@ class AutoDetectLanguage { */ @Test void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); } @@ -64,7 +64,7 @@ void testAutoDetectCjs() { */ @Test void testAutoDetectCts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/ts/fileBefore.cts", "rome/ts/fileAfter.cts"); } @@ -75,7 +75,7 @@ void testAutoDetectCts() { */ @Test void testAutoDetectJs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/js/fileBefore.js", "rome/js/fileAfter.js"); } @@ -86,7 +86,7 @@ void testAutoDetectJs() { */ @Test void testAutoDetectJson() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/json/fileBefore.json", "rome/json/fileAfter.json"); } @@ -97,7 +97,7 @@ void testAutoDetectJson() { */ @Test void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/js/fileBefore.jsx", "rome/js/fileAfter.jsx"); } @@ -108,7 +108,7 @@ void testAutoDetectJsx() { */ @Test void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/js/fileBefore.mjs", "rome/js/fileAfter.mjs"); } @@ -119,7 +119,7 @@ void testAutoDetectMjs() { */ @Test void testAutoDetectMts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/ts/fileBefore.mts", "rome/ts/fileAfter.mts"); } @@ -130,7 +130,7 @@ void testAutoDetectMts() { */ @Test void testAutoDetectTs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/ts/fileBefore.ts", "rome/ts/fileAfter.ts"); } @@ -141,7 +141,7 @@ void testAutoDetectTs() { */ @Test void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); } @@ -155,7 +155,7 @@ class ConfigFile { @Test void testLineWidth120() { var path = createRomeConfig("rome/config/line-width-120.json"); - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withConfigPath(path).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withConfigPath(path).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/js/longLineBefore.js", "rome/js/longLineAfter120.js"); } @@ -166,7 +166,7 @@ void testLineWidth120() { @Test void testLineWidth80() { var path = createRomeConfig("rome/config/line-width-80.json"); - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withConfigPath(path).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withConfigPath(path).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/js/longLineBefore.js", "rome/js/longLineAfter80.js"); } @@ -191,7 +191,7 @@ class ExplicitLanguage { */ @Test void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/js/fileBefore.cjs", "rome/js/fileAfter.cjs"); } @@ -202,7 +202,7 @@ void testAutoDetectCjs() { */ @Test void testAutoDetectCts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/ts/fileBefore.cts", "rome/ts/fileAfter.cts"); } @@ -213,7 +213,7 @@ void testAutoDetectCts() { */ @Test void testAutoDetectJs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/js/fileBefore.js", "rome/js/fileAfter.js"); } @@ -224,7 +224,7 @@ void testAutoDetectJs() { */ @Test void testAutoDetectJson() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("json").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("json").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/json/fileBefore.json", "rome/json/fileAfter.json"); } @@ -235,7 +235,7 @@ void testAutoDetectJson() { */ @Test void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("jsx").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("jsx").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/js/fileBefore.jsx", "rome/js/fileAfter.jsx"); } @@ -246,7 +246,7 @@ void testAutoDetectJsx() { */ @Test void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("js").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/js/fileBefore.mjs", "rome/js/fileAfter.mjs"); } @@ -257,7 +257,7 @@ void testAutoDetectMjs() { */ @Test void testAutoDetectMts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/ts/fileBefore.mts", "rome/ts/fileAfter.mts"); } @@ -268,7 +268,7 @@ void testAutoDetectMts() { */ @Test void testAutoDetectTs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("ts").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/ts/fileBefore.ts", "rome/ts/fileAfter.ts"); } @@ -279,7 +279,7 @@ void testAutoDetectTs() { */ @Test void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("tsx").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.ROME, "12.0.0", downloadDir.toString()).withLanguage("tsx").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("rome/ts/fileBefore.tsx", "rome/ts/fileAfter.tsx"); } @@ -300,7 +300,7 @@ class AutoDetectLanguage { */ @Test void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/js/fileBefore.cjs", "biome/js/fileAfter.cjs"); } @@ -311,7 +311,7 @@ void testAutoDetectCjs() { */ @Test void testAutoDetectCts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/ts/fileBefore.cts", "biome/ts/fileAfter.cts"); } @@ -322,7 +322,7 @@ void testAutoDetectCts() { */ @Test void testAutoDetectJs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/js/fileBefore.js", "biome/js/fileAfter.js"); } @@ -333,7 +333,7 @@ void testAutoDetectJs() { */ @Test void testAutoDetectJson() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/json/fileBefore.json", "biome/json/fileAfter.json"); } @@ -344,7 +344,7 @@ void testAutoDetectJson() { */ @Test void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/js/fileBefore.jsx", "biome/js/fileAfter.jsx"); } @@ -355,7 +355,7 @@ void testAutoDetectJsx() { */ @Test void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/js/fileBefore.mjs", "biome/js/fileAfter.mjs"); } @@ -366,7 +366,7 @@ void testAutoDetectMjs() { */ @Test void testAutoDetectMts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/ts/fileBefore.mts", "biome/ts/fileAfter.mts"); } @@ -377,7 +377,7 @@ void testAutoDetectMts() { */ @Test void testAutoDetectTs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/ts/fileBefore.ts", "biome/ts/fileAfter.ts"); } @@ -388,7 +388,7 @@ void testAutoDetectTs() { */ @Test void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/ts/fileBefore.tsx", "biome/ts/fileAfter.tsx"); } @@ -402,7 +402,7 @@ class ConfigFile { @Test void testLineWidth120() { var path = createBiomeConfig("biome/config/line-width-120.json"); - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/js/longLineBefore.js", "biome/js/longLineAfter120.js"); } @@ -413,7 +413,7 @@ void testLineWidth120() { @Test void testLineWidth80() { var path = createBiomeConfig("biome/config/line-width-80.json"); - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withConfigPath(path).create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/js/longLineBefore.js", "biome/js/longLineAfter80.js"); } @@ -438,7 +438,7 @@ class ExplicitLanguage { */ @Test void testAutoDetectCjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/js/fileBefore.cjs", "biome/js/fileAfter.cjs"); } @@ -449,7 +449,7 @@ void testAutoDetectCjs() { */ @Test void testAutoDetectCts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/ts/fileBefore.cts", "biome/ts/fileAfter.cts"); } @@ -460,7 +460,7 @@ void testAutoDetectCts() { */ @Test void testAutoDetectJs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/js/fileBefore.js", "biome/js/fileAfter.js"); } @@ -471,7 +471,7 @@ void testAutoDetectJs() { */ @Test void testAutoDetectJson() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("json").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("json").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/json/fileBefore.json", "biome/json/fileAfter.json"); } @@ -482,7 +482,7 @@ void testAutoDetectJson() { */ @Test void testAutoDetectJsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("jsx").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("jsx").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/js/fileBefore.jsx", "biome/js/fileAfter.jsx"); } @@ -493,7 +493,7 @@ void testAutoDetectJsx() { */ @Test void testAutoDetectMjs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("js").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/js/fileBefore.mjs", "biome/js/fileAfter.mjs"); } @@ -504,7 +504,7 @@ void testAutoDetectMjs() { */ @Test void testAutoDetectMts() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/ts/fileBefore.mts", "biome/ts/fileAfter.mts"); } @@ -515,7 +515,7 @@ void testAutoDetectMts() { */ @Test void testAutoDetectTs() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("ts").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/ts/fileBefore.ts", "biome/ts/fileAfter.ts"); } @@ -526,7 +526,7 @@ void testAutoDetectTs() { */ @Test void testAutoDetectTsx() { - var step = RomeStep.withExeDownload(EBiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("tsx").create(); + var step = RomeStep.withExeDownload(BiomeFlavor.BIOME, "1.2.0", downloadDir.toString()).withLanguage("tsx").create(); var stepHarness = StepHarnessWithFile.forStep(RomeStepTest.this, step); stepHarness.testResource("biome/ts/fileBefore.tsx", "biome/ts/fileAfter.tsx"); } From 7de7991d86f867ed7c528d915eec493c2699be25 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 19 Sep 2023 08:41:39 +0800 Subject: [PATCH 0915/1120] Compat old ktlint users --- CHANGES.md | 2 +- .../glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java | 5 +++++ .../glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java | 1 - plugin-gradle/CHANGES.md | 3 +-- plugin-gradle/README.md | 1 - .../com/diffplug/gradle/spotless/KotlinExtensionTest.java | 1 - .../diffplug/gradle/spotless/KotlinGradleExtensionTest.java | 1 - plugin-maven/CHANGES.md | 3 +-- plugin-maven/README.md | 1 - .../java/com/diffplug/spotless/maven/kotlin/KtlintTest.java | 1 - 10 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c2d379a874..4a831e9d0b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). +* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [2.41.0] - 2023-08-29 ### Added diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index 7b12169400..9c2792f769 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -132,6 +132,11 @@ private static EditorConfigOverride createEditorConfigOverride(final List .distinct() .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); + // The default style had been changed from intellij_idea to ktlint_official in version 1.0.0 + if (!editorConfigOverrideMap.containsKey("ktlint_code_style")) { + editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea"); + } + // Create config properties based on provided property names and values @SuppressWarnings("unchecked") Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java index 5ed2517c6f..1f8e6023b4 100644 --- a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -54,7 +54,6 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); - editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b66fcbc262..feb5c67844 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,8 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). - The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`. +* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [6.21.0] - 2023-08-29 ### Added diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 9a4b84c4dd..03a94e5004 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -405,7 +405,6 @@ spotless { .editorConfigOverride( mapOf( "indent_size" to 2, - "ktlint_code_style" to "intellij_idea", ) ) } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index a2fa7c16e7..1c23728244 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -73,7 +73,6 @@ void withExperimentalEditorConfigOverride() throws IOException { "spotless {", " kotlin {", " ktlint().editorConfigOverride([", - " ktlint_code_style: \"intellij_idea\",", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", " ij_kotlin_allow_trailing_comma_on_call_site: true", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 6d7bdf351a..7dade5f2ff 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -52,7 +52,6 @@ void withExperimentalEditorConfigOverride() throws IOException { "spotless {", " kotlinGradle {", " ktlint().editorConfigOverride([", - " ktlint_code_style: \"intellij_idea\",", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", " ij_kotlin_allow_trailing_comma_on_call_site: true", diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 54f92898a1..ef310b3ea2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,8 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). -The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`. +* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [2.39.0] - 2023-08-29 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 9419490d3e..f63d7faed9 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -413,7 +413,6 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. true true - intellij_idea ``` diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index f3f360dc5d..060e0de84f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -36,7 +36,6 @@ void testKtlintEditorConfigOverride() throws Exception { " \n" + " true\n" + " true\n" + - " intellij_idea\n" + " \n" + ""); From 80a83a8be5d5f585809da9cb5665e1dd529a0c64 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:09:16 +0000 Subject: [PATCH 0916/1120] chore(deps): update plugin dev.equo.ide to v1.7.3 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 11ac98ec93..1a9f631f20 100644 --- a/settings.gradle +++ b/settings.gradle @@ -25,7 +25,7 @@ plugins { // https://plugins.gradle.org/plugin/com.gradle.enterprise id 'com.gradle.enterprise' version '3.14.1' // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md - id 'dev.equo.ide' version '1.0.1' apply false + id 'dev.equo.ide' version '1.7.3' apply false } dependencyResolutionManagement { From 4047ae01329491b1f3d79f4f792f842d9b526ea8 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 19 Sep 2023 22:41:20 +0800 Subject: [PATCH 0917/1120] Add Category.LIBRARY attr to resolve ktlint deps --- .../com/diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../diffplug/gradle/spotless/GradleProvisioner.java | 12 +++--------- .../java/com/diffplug/spotless/TestProvisioner.java | 12 +++--------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index bedbb4a071..d08c59b839 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -39,7 +39,7 @@ private KtLintStep() {} private static final String DEFAULT_VERSION = "1.0.0"; static final String NAME = "ktlint"; static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; - public static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; + static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index a92d583596..288cc10c72 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -27,6 +27,7 @@ import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.dsl.DependencyHandler; import org.gradle.api.attributes.Bundling; +import org.gradle.api.attributes.Category; import org.gradle.api.initialization.dsl.ScriptHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +35,6 @@ import com.diffplug.common.base.Unhandled; import com.diffplug.common.collect.ImmutableList; import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.kotlin.KtLintStep; /** Should be package-private. */ class GradleProvisioner { @@ -122,14 +122,8 @@ private static Provisioner forConfigurationContainer(Project project, Configurat config.setCanBeConsumed(false); config.setVisible(false); config.attributes(attr -> { - final String type; - // See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984. - if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) { - type = Bundling.SHADOWED; - } else { - type = Bundling.EXTERNAL; - } - attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type)); + attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY)); + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); }); return config.resolve(); } catch (Exception e) { diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java index 6a942d8ca3..e06640ccfd 100644 --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java @@ -32,6 +32,7 @@ import org.gradle.api.artifacts.ResolveException; import org.gradle.api.artifacts.dsl.RepositoryHandler; import org.gradle.api.attributes.Bundling; +import org.gradle.api.attributes.Category; import org.gradle.testfixtures.ProjectBuilder; import com.diffplug.common.base.Errors; @@ -39,7 +40,6 @@ import com.diffplug.common.base.Suppliers; import com.diffplug.common.collect.ImmutableSet; import com.diffplug.common.io.Files; -import com.diffplug.spotless.kotlin.KtLintStep; public class TestProvisioner { public static Project gradleProject(File dir) { @@ -71,14 +71,8 @@ private static Provisioner createWithRepositories(Consumer re config.setTransitive(withTransitives); config.setDescription(mavenCoords.toString()); config.attributes(attr -> { - final String type; - // See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984. - if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) { - type = Bundling.SHADOWED; - } else { - type = Bundling.EXTERNAL; - } - attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type)); + attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY)); + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); }); try { return config.resolve(); From 196afc0f1be5f1171bed1eb8617554f59200db95 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 26 Sep 2023 12:36:59 +0800 Subject: [PATCH 0918/1120] Enable type-safe project accessors https://docs.gradle.org/7.6/userguide/declaring_dependencies.html#sec:type-safe-project-accessors --- _ext/gradle/java-setup.gradle | 2 +- lib-extra/build.gradle | 4 ++-- plugin-gradle/build.gradle | 6 +++--- plugin-maven/build.gradle | 4 ++-- settings.gradle | 1 + testlib/build.gradle | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/_ext/gradle/java-setup.gradle b/_ext/gradle/java-setup.gradle index 0d620a6519..d1a1075d84 100644 --- a/_ext/gradle/java-setup.gradle +++ b/_ext/gradle/java-setup.gradle @@ -19,7 +19,7 @@ tasks.withType(JavaCompile).configureEach { dependencies { testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" - testImplementation project(':testlib') + testImplementation projects.testlib } tasks.withType(Test).configureEach { diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 1158ca0893..35381f08a4 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -9,7 +9,7 @@ apply from: rootProject.file('gradle/java-publish.gradle') String VER_SOLSTICE = '1.3.1' dependencies { - api project(':lib') + api projects.lib // misc useful utilities implementation "com.diffplug.durian:durian-core:${VER_DURIAN}" implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}" @@ -20,7 +20,7 @@ dependencies { implementation "dev.equo.ide:solstice:${VER_SOLSTICE}" // testing - testImplementation project(':testlib') + testImplementation projects.testlib testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index 021155abfe..ba800173a2 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -10,8 +10,8 @@ apply from: rootProject.file('gradle/spotless-freshmark.gradle') dependencies { if (version.endsWith('-SNAPSHOT') || (rootProject.spotlessChangelog.versionNext == rootProject.spotlessChangelog.versionLast)) { - api project(':lib') - api project(':lib-extra') + api projects.lib + api projects.libExtra } else { api "com.diffplug.spotless:spotless-lib:${rootProject.spotlessChangelog.versionLast}" api "com.diffplug.spotless:spotless-lib-extra:${rootProject.spotlessChangelog.versionLast}" @@ -21,7 +21,7 @@ dependencies { implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}" implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}" - testImplementation project(':testlib') + testImplementation projects.testlib testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" testImplementation "com.diffplug.durian:durian-testlib:${VER_DURIAN}" diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index 7cfb38c2e9..3f46e6eba7 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -30,8 +30,8 @@ String VER_MAVEN_API = '3.0' String VER_ECLIPSE_AETHER = '1.1.0' String VER_PLEXUS_RESOURCES = '1.2.0' dependencies { - implementation project(':lib') - implementation project(':lib-extra') + implementation projects.lib + implementation projects.libExtra compileOnly "org.apache.maven:maven-plugin-api:${VER_MAVEN_API}" compileOnly "org.apache.maven.plugin-tools:maven-plugin-annotations:${VER_MAVEN_API}" diff --git a/settings.gradle b/settings.gradle index 11ac98ec93..3ef45ca2f0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -71,6 +71,7 @@ gradleEnterprise { } enableFeaturePreview("STABLE_CONFIGURATION_CACHE") +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") rootProject.name = 'spotless' diff --git a/testlib/build.gradle b/testlib/build.gradle index afa6a67a91..12b3bcd135 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -6,8 +6,8 @@ version = rootProject.spotlessChangelog.versionNext apply from: rootProject.file('gradle/java-setup.gradle') dependencies { - api project(':lib') - api files(project(':lib').sourceSets.sortPom.output.classesDirs) + api projects.lib + api files(projects.lib.dependencyProject.sourceSets.sortPom.output.classesDirs) api "com.diffplug.durian:durian-core:${VER_DURIAN}" api "com.diffplug.durian:durian-testlib:${VER_DURIAN}" api "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" From 68c78405aba32f3d7f1bff6e121e6877ce8d1f13 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Sep 2023 23:55:48 -0700 Subject: [PATCH 0919/1120] Fixup changelog. --- plugin-gradle/README.md | 2 +- plugin-maven/CHANGES.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index e0d6371236..d58d698303 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -592,7 +592,7 @@ To apply flexmark to all of the `.md` files in your project, use this snippet: spotless { flexmark { target '**/*.md' // you have to set the target manually - flexmarkFormatter() // or flexmarkFormatter('0.64.6') // version is optional + flexmark() // or flexmark('0.64.6') // version is optional } } ``` diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9d413397e2..bc31c30e4b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,9 +5,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). - ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) +### Changes +* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) ## [2.39.0] - 2023-08-29 ### Added From beed923037ffebd2a857a2e6dde1e6ee1837b99e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 27 Sep 2023 23:56:29 -0700 Subject: [PATCH 0920/1120] `flexmarkFormatter` -> `flexmark` --- .../com/diffplug/gradle/spotless/FlexmarkExtension.java | 6 +++--- .../com/diffplug/gradle/spotless/FlexmarkExtensionTest.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java index 047b0eda73..d1f941613b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java @@ -30,11 +30,11 @@ public FlexmarkExtension(SpotlessExtension spotless) { super(spotless); } - public FlexmarkFormatterConfig flexmarkFormatter() { - return flexmarkFormatter(FlexmarkStep.defaultVersion()); + public FlexmarkFormatterConfig flexmark() { + return flexmark(FlexmarkStep.defaultVersion()); } - public FlexmarkFormatterConfig flexmarkFormatter(String version) { + public FlexmarkFormatterConfig flexmark(String version) { return new FlexmarkFormatterConfig(version); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java index 873baba744..6264c0c230 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/FlexmarkExtensionTest.java @@ -31,7 +31,7 @@ void integration() throws IOException { "spotless {", " flexmark {", " target '*.md'", - " flexmarkFormatter()", + " flexmark()", " }", "}"); setFile("markdown_test.md").toResource("markdown/flexmark/FlexmarkUnformatted.md"); From 9ac3edca3fe802321fa68924a52ed3c595ecbd48 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 00:06:45 -0700 Subject: [PATCH 0921/1120] Bump 64.6 -> 64.8. --- CHANGES.md | 2 +- .../main/java/com/diffplug/spotless/markdown/FlexmarkStep.java | 2 +- plugin-gradle/README.md | 2 +- plugin-maven/CHANGES.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4ae2a3aafe..71cde3f643 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,7 +17,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes -* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) +* Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) * Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808)) ## [2.41.0] - 2023-08-29 diff --git a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java index b4159830e7..65d903cba3 100644 --- a/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java +++ b/lib/src/main/java/com/diffplug/spotless/markdown/FlexmarkStep.java @@ -29,7 +29,7 @@ public class FlexmarkStep { // prevent direct instantiation private FlexmarkStep() {} - private static final String DEFAULT_VERSION = "0.64.6"; + private static final String DEFAULT_VERSION = "0.64.8"; private static final String NAME = "flexmark-java"; private static final String MAVEN_COORDINATE = "com.vladsch.flexmark:flexmark-all:"; diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index c7303bbc9e..8aef3ac234 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -592,7 +592,7 @@ To apply flexmark to all of the `.md` files in your project, use this snippet: spotless { flexmark { target '**/*.md' // you have to set the target manually - flexmark() // or flexmark('0.64.6') // version is optional + flexmark() // or flexmark('0.64.8') // version is optional } } ``` diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e04a360e26..72d1e502a1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,7 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes -* Bump default `flexmark` version to latest `0.64.0` -> `0.64.6`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) +* Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) * Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808)) ## [2.39.0] - 2023-08-29 From 7faf344c98ac99b515a75515028a9060fba5f1dd Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 07:10:44 +0000 Subject: [PATCH 0922/1120] chore(deps): update plugin com.gradle.enterprise to v3.15 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 3ef45ca2f0..6387e3b2c2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,7 +23,7 @@ plugins { // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags id 'io.github.davidburstrom.version-compatibility' version '0.5.0' apply false // https://plugins.gradle.org/plugin/com.gradle.enterprise - id 'com.gradle.enterprise' version '3.14.1' + id 'com.gradle.enterprise' version '3.15' // https://github.com/equodev/equo-ide/blob/main/plugin-gradle/CHANGELOG.md id 'dev.equo.ide' version '1.0.1' apply false } From a35af334cec87aa26c7f4b9b8cfa91b0e5dd9fa1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mille Date: Thu, 21 Sep 2023 13:44:26 +0200 Subject: [PATCH 0923/1120] Support configuration of P2 mirrors in maven plugin (fixes #1697) --- .../spotless/extra/EquoBasedStepBuilder.java | 7 +++++ .../com/diffplug/spotless/extra/P2Mirror.java | 30 +++++++++++++++++++ .../spotless/maven/cpp/EclipseCdt.java | 7 +++++ .../spotless/maven/groovy/GrEclipse.java | 7 +++++ .../diffplug/spotless/maven/java/Eclipse.java | 7 +++++ 5 files changed, 58 insertions(+) create mode 100644 lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 586deeb5bf..22ba268426 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -15,10 +15,13 @@ */ package com.diffplug.spotless.extra; +import static java.util.stream.Collectors.toMap; + import java.io.File; import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Properties; @@ -76,6 +79,10 @@ public void setP2Mirrors(Map p2Mirrors) { this.p2Mirrors = Map.copyOf(p2Mirrors); } + public void setP2Mirrors(Collection p2Mirrors) { + this.p2Mirrors = p2Mirrors.stream().collect(toMap(P2Mirror::getPrefix, P2Mirror::getUrl)); + } + /** Returns the FormatterStep (whose state will be calculated lazily). */ public FormatterStep build() { return FormatterStep.createLazy(formatterName, this::get, stateToFormatter); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java new file mode 100644 index 0000000000..f6ce6727b2 --- /dev/null +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java @@ -0,0 +1,30 @@ +/* + * 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.extra; + +public class P2Mirror { + + private String prefix; + private String url; + + public String getPrefix() { + return prefix; + } + + public String getUrl() { + return url; + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java index a92e7b2423..92f4229ed3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/EclipseCdt.java @@ -16,12 +16,15 @@ package com.diffplug.spotless.maven.cpp; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.P2Mirror; import com.diffplug.spotless.extra.cpp.EclipseCdtFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -34,6 +37,9 @@ public class EclipseCdt implements FormatterStepFactory { @Parameter private String version; + @Parameter + private List p2Mirrors = new ArrayList<>(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { EquoBasedStepBuilder eclipseConfig = EclipseCdtFormatterStep.createBuilder(stepConfig.getProvisioner()); @@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File settingsFile = stepConfig.getFileLocator().locateFile(file); eclipseConfig.setPreferences(Arrays.asList(settingsFile)); } + eclipseConfig.setP2Mirrors(p2Mirrors); return eclipseConfig.build(); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java index 8836993cce..67ab40fbf2 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/GrEclipse.java @@ -16,12 +16,15 @@ package com.diffplug.spotless.maven.groovy; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.P2Mirror; import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -34,6 +37,9 @@ public class GrEclipse implements FormatterStepFactory { @Parameter private String version; + @Parameter + private List p2Mirrors = new ArrayList<>(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { EquoBasedStepBuilder grEclipseConfig = GrEclipseFormatterStep.createBuilder(stepConfig.getProvisioner()); @@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File settingsFile = stepConfig.getFileLocator().locateFile(file); grEclipseConfig.setPreferences(Arrays.asList(settingsFile)); } + grEclipseConfig.setP2Mirrors(p2Mirrors); return grEclipseConfig.build(); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java index e30a4faad9..8d5869cc8e 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java @@ -16,12 +16,15 @@ package com.diffplug.spotless.maven.java; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.P2Mirror; import com.diffplug.spotless.extra.java.EclipseJdtFormatterStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -34,6 +37,9 @@ public class Eclipse implements FormatterStepFactory { @Parameter private String version; + @Parameter + private List p2Mirrors = new ArrayList<>(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { EquoBasedStepBuilder eclipseConfig = EclipseJdtFormatterStep.createBuilder(stepConfig.getProvisioner()); @@ -42,6 +48,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { File settingsFile = stepConfig.getFileLocator().locateFile(file); eclipseConfig.setPreferences(Arrays.asList(settingsFile)); } + eclipseConfig.setP2Mirrors(p2Mirrors); return eclipseConfig.build(); } } From d0fca7a14d8513883c53f2f1a845fb6becc29267 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mille Date: Thu, 21 Sep 2023 13:54:23 +0200 Subject: [PATCH 0924/1120] Update changelog --- CHANGES.md | 1 + plugin-maven/CHANGES.md | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 71cde3f643..24dfc66c39 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). The configuration is still the same, but you should switch to the new `biome` tag / function and adjust the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). +* Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)). ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 72d1e502a1..5a75a717a0 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,19 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). The configuration is still the same, but you should switch to the new `` tag and adjust the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). +* Support configuration of mirrors for P2 repositories ([#1697](https://github.com/diffplug/spotless/issues/1697)): + ``` + + + + https://download.eclipse.org/ + https://some.internal.mirror/eclipse + + + + ``` + 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 `` and ``. ### Fixed * Added support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes From 34d92f2c892c942463d70fbdb30ca5651be8ff3d Mon Sep 17 00:00:00 2001 From: Goooler Date: Thu, 28 Sep 2023 17:11:23 +0800 Subject: [PATCH 0925/1120] Ignore Ktlint updates by Renovate https://docs.renovatebot.com/configuration-options/#ignoredeps --- renovate.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/renovate.json b/renovate.json index 7bd954555f..2b278dfe17 100644 --- a/renovate.json +++ b/renovate.json @@ -2,5 +2,14 @@ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:base" + ], + "packageRules": [ + { + "groupName": "Ktlint", + "enabled": false, + "matchPackagePatterns": [ + "com.pinterest.ktlint:*" + ] + } ] } From 56cea6d8bb12bd90a749e00cb7d4670a67604d1b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:52:12 +0000 Subject: [PATCH 0926/1120] fix(deps): update dependency org.eclipse.jgit:org.eclipse.jgit to v6.7.0.202309050840-r --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ce29bbfaeb..8312afaed3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -29,7 +29,7 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 -VER_JGIT=6.6.0.202305301015-r +VER_JGIT=6.7.0.202309050840-r VER_JUNIT=5.9.3 VER_ASSERTJ=3.24.2 VER_MOCKITO=5.3.1 From c86699083424701a3582d35c8f4e9adf0b889980 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:13:06 +0000 Subject: [PATCH 0927/1120] fix(deps): update dependency org.mockito:mockito-core to v5.5.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ce29bbfaeb..af3c2fd9c1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -32,4 +32,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.6.0.202305301015-r VER_JUNIT=5.9.3 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.3.1 +VER_MOCKITO=5.5.0 From 479248d566a0fd8a072ff383fa531a0b2ed4ebd9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 15:16:24 +0000 Subject: [PATCH 0928/1120] fix(deps): update dependency org.junit.jupiter:junit-jupiter to v5.10.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 8312afaed3..6d11931de2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,6 +30,6 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 VER_JGIT=6.7.0.202309050840-r -VER_JUNIT=5.9.3 +VER_JUNIT=5.10.0 VER_ASSERTJ=3.24.2 VER_MOCKITO=5.3.1 From 59fce9599d67ce21cc710e100ca1a8010d3220c7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:14:33 +0000 Subject: [PATCH 0929/1120] chore(deps): update actions/checkout action to v4 --- .github/workflows/changelog-print.yml | 2 +- .github/workflows/ci.yml | 4 ++-- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/deploy.yml | 2 +- .github/workflows/gradle-wrapper-validation.yml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/changelog-print.yml b/.github/workflows/changelog-print.yml index a3009e3a39..31b6c9aabc 100644 --- a/.github/workflows/changelog-print.yml +++ b/.github/workflows/changelog-print.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest name: changelogPrint steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: jdk 11 uses: actions/setup-java@v3 with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a8078339d..b6a2e612aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: buildcachepass: ${{ secrets.BUILDCACHE_PASS }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Install JDK 11 @@ -59,7 +59,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} uses: actions/setup-java@v3 with: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b2f2a259c3..7fb9daff0d 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -37,7 +37,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f139032cf6..0e36087855 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -36,7 +36,7 @@ jobs: ORG_GRADLE_PROJECT_gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} ORG_GRADLE_PROJECT_gpg_key64: ${{ secrets.GPG_KEY64 }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: jdk 11 uses: actions/setup-java@v3 with: diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 2c02ce0fc4..d8be29afda 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -19,5 +19,5 @@ jobs: name: "Validation" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: gradle/wrapper-validation-action@v1 From c48a180905566fd444ce03279863a5e5dffc6b6e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:14:38 +0000 Subject: [PATCH 0930/1120] chore(deps): update mikepenz/action-junit-report action to v4 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a8078339d..01379f3a91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,7 +79,7 @@ jobs: if: matrix.kind == 'npm' run: ./gradlew testNpm - name: junit result - uses: mikepenz/action-junit-report@v3 + uses: mikepenz/action-junit-report@v4 if: always() # always run even if the previous step fails with: check_name: JUnit ${{ matrix.kind }} ${{ matrix.jre }} ${{ matrix.os }} From 3562e49ef862e53678fdc02fd3280d5a4f249fb9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 09:19:51 -0700 Subject: [PATCH 0931/1120] Bump solstice to latest. --- .../java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 22ba268426..2d62e25355 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -117,7 +117,7 @@ EquoBasedStepBuilder.State get() throws Exception { } var classpath = new ArrayList(); var mavenDeps = new ArrayList(); - mavenDeps.add("dev.equo.ide:solstice:1.3.1"); + mavenDeps.add("dev.equo.ide:solstice:1.7.3"); mavenDeps.add("com.diffplug.durian:durian-swt.os:4.2.0"); mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); From 5404e027529dbdc9a50b264c3d2e8d7891bbfee5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 09:39:25 -0700 Subject: [PATCH 0932/1120] Bump gradle to 8.4-rc-2 for Java 21 --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.jar | Bin gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 gradle/wrapper/gradle-wrapper.jar diff --git a/build.gradle b/build.gradle index 0ae84bd9c4..dcef3b68b9 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'dev.equo.ide' equoIde { branding().title('Spotless').icon(file('_images/spotless_logo.png')) welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') - gradleBuildship().autoImport('.') + //gradleBuildship().autoImport('.') } repositories { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar old mode 100755 new mode 100644 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ac72c34e8a..98ea390909 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-rc-2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From deba3401369eb6e11ed720732b5a3701b36157ff Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 09:40:49 -0700 Subject: [PATCH 0933/1120] Revert accidental commit. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index dcef3b68b9..0ae84bd9c4 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'dev.equo.ide' equoIde { branding().title('Spotless').icon(file('_images/spotless_logo.png')) welcome().openUrl('https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md') - //gradleBuildship().autoImport('.') + gradleBuildship().autoImport('.') } repositories { From 6271c51fd85f4450e0cc0a0c7faa2a0f4e976ca6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 10:22:05 -0700 Subject: [PATCH 0934/1120] Fix findbugs warnings. --- .../src/main/java/com/diffplug/spotless/extra/P2Mirror.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java index f6ce6727b2..172857422b 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/P2Mirror.java @@ -15,6 +15,9 @@ */ package com.diffplug.spotless.extra; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +@SuppressFBWarnings("UWF_UNWRITTEN_FIELD") public class P2Mirror { private String prefix; From c320ffeab856dc4d335aabf7c3ffe4e7ab8b10dd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 14:25:00 -0700 Subject: [PATCH 0935/1120] Attempt a fix for #1806 by preventing JGit from finding the native git executable. --- CHANGES.md | 1 + .../gradle/spotless/GitRatchetGradle.java | 73 ++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 3d14044c7c..87eacf12a5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)). ### Fixed * Fix support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) +* Fix configuration cache issue around `external process started '/usr/bin/git --version'`. ([#1806](https://github.com/diffplug/spotless/issues/1806)) ### Changes * Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) * Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808)) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GitRatchetGradle.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GitRatchetGradle.java index 8c4f88e7da..b2c3adc459 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GitRatchetGradle.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GitRatchetGradle.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-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,10 +19,33 @@ import javax.annotation.Nullable; +import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.eclipse.jgit.util.FS; +import org.eclipse.jgit.util.SystemReader; + import com.diffplug.spotless.extra.GitRatchet; /** Gradle implementation of GitRatchet. */ public class GitRatchetGradle extends GitRatchet { + static { + preventJGitFromCallingExecutables(); + } + + static void preventJGitFromCallingExecutables() { + SystemReader reader = SystemReader.getInstance(); + SystemReader.setInstance(new DelegatingSystemReader(reader) { + @Override + public String getenv(String variable) { + if ("PATH".equals(variable)) { + return ""; + } else { + return super.getenv(variable); + } + } + }); + } + @Override protected File getDir(File project) { return project; @@ -32,4 +55,52 @@ protected File getDir(File project) { protected @Nullable File getParent(File project) { return project.getParentFile(); } + + static class DelegatingSystemReader extends SystemReader { + final SystemReader reader; + + DelegatingSystemReader(SystemReader reader) { + this.reader = reader; + } + + @Override + public String getHostname() { + return reader.getHostname(); + } + + @Override + public String getenv(String variable) { + return reader.getProperty(variable); + } + + @Override + public String getProperty(String key) { + return reader.getProperty(key); + } + + @Override + public FileBasedConfig openUserConfig(Config parent, FS fs) { + return reader.openUserConfig(parent, fs); + } + + @Override + public FileBasedConfig openSystemConfig(Config parent, FS fs) { + return reader.openSystemConfig(parent, fs); + } + + @Override + public FileBasedConfig openJGitConfig(Config parent, FS fs) { + return reader.openJGitConfig(parent, fs); + } + + @Override + public long getCurrentTime() { + return reader.getCurrentTime(); + } + + @Override + public int getTimezone(long when) { + return reader.getTimezone(when); + } + } } From 5ddf6e075323c53934a4f8c3ca98a346ec144f3c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 14:34:56 -0700 Subject: [PATCH 0936/1120] Update changelog. --- plugin-maven/CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ed6ce8fe49..1338d42ddb 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,6 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added +* Add `-DspotlessIdeHook` that provides the ability to apply Spotless exclusively to a specified file. It accepts the absolute path of the file. ([#1782](https://github.com/diffplug/spotless/pull/1782)) + * BETA, subject to change until we have proven compatibility with some IDE plugins. * Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793)) * Added support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). The configuration is still the same, but you should switch to the new `` tag and adjust @@ -31,7 +33,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753)) * Support GJF own import order. ([#1780](https://github.com/diffplug/spotless/pull/1780)) -* Add `-DspotlessIdeHook` that provides the ability to apply Spotless exclusively to a specified file. It accepts the absolute path of the file. ([#200](https://github.com/diffplug/spotless/issues/200)) ### Fixed * Add support for `prettier` version `3.0.0` and newer. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751)) * Fix npm install calls when npm cache is not up-to-date. ([#1760](https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750)) From 9c27d39f642fcee2afbd032d0179a30074ea96f9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 15:09:11 -0700 Subject: [PATCH 0937/1120] Create new GIT_ATTRIBUTES_FAST_ALLSAME which is the same as GIT_ATTRIBUTES, except that: - it is much faster - it assumes that every file in a given format has the same line endings --- .../com/diffplug/spotless/LineEnding.java | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/LineEnding.java b/lib/src/main/java/com/diffplug/spotless/LineEnding.java index 72b2532f2a..fa487a03b7 100644 --- a/lib/src/main/java/com/diffplug/spotless/LineEnding.java +++ b/lib/src/main/java/com/diffplug/spotless/LineEnding.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. @@ -37,6 +37,14 @@ public Policy createPolicy() { return super.createPolicy(); } }, + /** Uses the same line endings as Git, and assumes that every single file being formatted will have the same line ending. */ + GIT_ATTRIBUTES_FAST_ALLSAME { + /** .gitattributes is path-specific, so you must use {@link LineEnding#createPolicy(File, Supplier)}. */ + @Override @Deprecated + public Policy createPolicy() { + return super.createPolicy(); + } + }, /** {@code \n} on unix systems, {@code \r\n} on windows systems. */ PLATFORM_NATIVE, /** {@code \r\n} */ @@ -51,7 +59,7 @@ public Policy createPolicy() { public Policy createPolicy(File projectDir, Supplier> toFormat) { Objects.requireNonNull(projectDir, "projectDir"); Objects.requireNonNull(toFormat, "toFormat"); - if (this != GIT_ATTRIBUTES) { + if (this != GIT_ATTRIBUTES && this != GIT_ATTRIBUTES_FAST_ALLSAME) { return createPolicy(); } else { if (gitAttributesPolicyCreator == null) { @@ -64,7 +72,39 @@ public Policy createPolicy(File projectDir, Supplier> toFormat) { } } // gitAttributesPolicyCreator will always be nonnull at this point - return gitAttributesPolicyCreator.apply(projectDir, toFormat); + Policy policy = gitAttributesPolicyCreator.apply(projectDir, toFormat); + if (this == GIT_ATTRIBUTES) { + return policy; + } else if (this == GIT_ATTRIBUTES_FAST_ALLSAME) { + return new LazyAllTheSame(policy, toFormat); + } else { + throw new IllegalArgumentException("Unknown " + this); + } + } + } + + static class LazyAllTheSame extends LazyForwardingEquality implements Policy { + private transient Policy policy; + private transient Supplier> toFormat; + + public LazyAllTheSame(Policy policy, Supplier> toFormat) { + this.policy = policy; + this.toFormat = toFormat; + } + + @Override + protected String calculateState() throws Exception { + var files = toFormat.get().iterator(); + if (files.hasNext()) { + return policy.getEndingFor(files.next()); + } else { + return LineEnding.UNIX.str(); + } + } + + @Override + public String getEndingFor(File file) { + return state(); } } From 54c0af2bb701fc1b0756b8ff1bfd568d0c43bf65 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 15:13:52 -0700 Subject: [PATCH 0938/1120] Set the default line endings to be GIT_ATTRIBUTES_FAST_ALLSAME. --- .../java/com/diffplug/gradle/spotless/SpotlessExtension.java | 2 +- .../java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 838231c9f8..514945f22d 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 @@ -57,7 +57,7 @@ RegisterDependenciesTask getRegisterDependenciesTask() { } /** Line endings (if any). */ - LineEnding lineEndings = LineEnding.GIT_ATTRIBUTES; + LineEnding lineEndings = LineEnding.GIT_ATTRIBUTES_FAST_ALLSAME; public LineEnding getLineEndings() { return lineEndings; 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 2c295cef27..97a61ddaea 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 @@ -80,7 +80,7 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { private static final String DEFAULT_INDEX_FILE_NAME = "spotless-index"; private static final String DEFAULT_ENCODING = "UTF-8"; - private static final String DEFAULT_LINE_ENDINGS = "GIT_ATTRIBUTES"; + private static final String DEFAULT_LINE_ENDINGS = "GIT_ATTRIBUTES_FAST_ALLSAME"; /** Value to allow unsetting the ratchet inherited from parent pom configuration. */ static final String RATCHETFROM_NONE = "NONE"; From 809fb4b0785803d96b2acde585db747f86e89c04 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 15:28:26 -0700 Subject: [PATCH 0939/1120] Make GIT_ATTRIBUTES_FAST_ALLSAME faster. --- .../extra/GitAttributesLineEndings.java | 35 ++++++++++++ .../com/diffplug/spotless/LineEnding.java | 56 ++++--------------- 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java index fb54be4ba0..c53e9a3e92 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java @@ -68,6 +68,41 @@ public final class GitAttributesLineEndings { // prevent direct instantiation private GitAttributesLineEndings() {} + /** + * Creates a line-endings policy which matches {@link #create(File, Supplier)}, + * which is much faster at the cost that every file under the policy + * is assumed to have the same line endings as the first file. + */ + public static LineEnding.Policy createFastAllSame(File projectDir, Supplier> toFormat) { + return new LazyAllTheSame(projectDir, toFormat); + } + + static class LazyAllTheSame extends LazyForwardingEquality implements LineEnding.Policy { + transient File projectDir; + transient Supplier> toFormat; + + public LazyAllTheSame(File projectDir, Supplier> toFormat) { + this.projectDir = projectDir; + this.toFormat = toFormat; + } + + @Override + protected String calculateState() throws Exception { + var files = toFormat.get().iterator(); + if (files.hasNext()) { + Runtime runtime = new RuntimeInit(projectDir).atRuntime(); + return runtime.getEndingFor(files.next()); + } else { + return LineEnding.UNIX.str(); + } + } + + @Override + public String getEndingFor(File file) { + return state(); + } + } + /** * Creates a line-endings policy whose serialized state is relativized against projectDir, * at the cost of eagerly evaluating the line-ending state of every target file when the diff --git a/lib/src/main/java/com/diffplug/spotless/LineEnding.java b/lib/src/main/java/com/diffplug/spotless/LineEnding.java index fa487a03b7..708699904c 100644 --- a/lib/src/main/java/com/diffplug/spotless/LineEnding.java +++ b/lib/src/main/java/com/diffplug/spotless/LineEnding.java @@ -59,52 +59,20 @@ public Policy createPolicy() { public Policy createPolicy(File projectDir, Supplier> toFormat) { Objects.requireNonNull(projectDir, "projectDir"); Objects.requireNonNull(toFormat, "toFormat"); - if (this != GIT_ATTRIBUTES && this != GIT_ATTRIBUTES_FAST_ALLSAME) { - return createPolicy(); + String gitAttributesMethod; + if (this == GIT_ATTRIBUTES) { + gitAttributesMethod = "create"; + } else if (this == GIT_ATTRIBUTES_FAST_ALLSAME) { + gitAttributesMethod = "createFastAllSame"; } else { - if (gitAttributesPolicyCreator == null) { - try { - Class clazz = Class.forName("com.diffplug.spotless.extra.GitAttributesLineEndings"); - Method method = clazz.getMethod("create", File.class, Supplier.class); - gitAttributesPolicyCreator = (proj, target) -> ThrowingEx.get(() -> (Policy) method.invoke(null, proj, target)); - } catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) { - throw new IllegalStateException("LineEnding.GIT_ATTRIBUTES requires the spotless-lib-extra library, but it is not on the classpath", e); - } - } - // gitAttributesPolicyCreator will always be nonnull at this point - Policy policy = gitAttributesPolicyCreator.apply(projectDir, toFormat); - if (this == GIT_ATTRIBUTES) { - return policy; - } else if (this == GIT_ATTRIBUTES_FAST_ALLSAME) { - return new LazyAllTheSame(policy, toFormat); - } else { - throw new IllegalArgumentException("Unknown " + this); - } - } - } - - static class LazyAllTheSame extends LazyForwardingEquality implements Policy { - private transient Policy policy; - private transient Supplier> toFormat; - - public LazyAllTheSame(Policy policy, Supplier> toFormat) { - this.policy = policy; - this.toFormat = toFormat; - } - - @Override - protected String calculateState() throws Exception { - var files = toFormat.get().iterator(); - if (files.hasNext()) { - return policy.getEndingFor(files.next()); - } else { - return LineEnding.UNIX.str(); - } + return createPolicy(); } - - @Override - public String getEndingFor(File file) { - return state(); + try { + Class clazz = Class.forName("com.diffplug.spotless.extra.GitAttributesLineEndings"); + Method method = clazz.getMethod(gitAttributesMethod, File.class, Supplier.class); + return ThrowingEx.get(() -> (Policy) method.invoke(null, projectDir, toFormat)); + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) { + throw new IllegalStateException("LineEnding.GIT_ATTRIBUTES requires the spotless-lib-extra library, but it is not on the classpath", e); } } From d56acd51206381d68cc9112c16376d502478edd5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 15:47:24 -0700 Subject: [PATCH 0940/1120] Fix spotbugs. --- .../com/diffplug/spotless/extra/GitAttributesLineEndings.java | 1 + 1 file changed, 1 insertion(+) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java index c53e9a3e92..3be75637be 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java @@ -78,6 +78,7 @@ public static LineEnding.Policy createFastAllSame(File projectDir, Supplier implements LineEnding.Policy { + private static final long serialVersionUID = 727912266173243664L; transient File projectDir; transient Supplier> toFormat; From 0cfe58f1e9b7693cbddd177de95d8d1812d94cc0 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 15:47:32 -0700 Subject: [PATCH 0941/1120] Update docs. --- plugin-gradle/README.md | 4 ++-- plugin-maven/README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 6543d21b79..d4537d4b11 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -1425,12 +1425,12 @@ spotless { encoding 'Cp1252' // except java, which will be Cp1252 ``` -Line endings can also be set globally or per-format using the `lineEndings` property. Spotless supports four line ending modes: `UNIX`, `WINDOWS`, `MAC_CLASSIC`, `PLATFORM_NATIVE`, and `GIT_ATTRIBUTES`. The default value is `GIT_ATTRIBUTES`, and *we highly recommend that you* ***do not change*** *this value*. Git has opinions about line endings, and if Spotless and git disagree, then you're going to have a bad time. +Line endings can also be set globally or per-format using the `lineEndings` property. Spotless supports four line ending modes: `UNIX`, `WINDOWS`, `MAC_CLASSIC`, `PLATFORM_NATIVE`, `GIT_ATTRIBUTES`, and `GIT_ATTRIBUTES_FAST_ALLSAME`. The default value is `GIT_ATTRIBUTES_FAST_ALLSAME`, and *we highly recommend that you* ***do not change*** *this value*. Git has opinions about line endings, and if Spotless and git disagree, then you're going to have a bad time. `FAST_ALLSAME` just means that Spotless can assume that every file being formatted has the same line endings ([more info](https://github.com/diffplug/spotless/pull/1838)). You can easily set the line endings of different files using [a `.gitattributes` file](https://help.github.com/articles/dealing-with-line-endings/). Here's an example `.gitattributes` which sets all files to unix newlines: `* text eol=lf`. - + ## Custom steps diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 8942b6c059..919a05dfbb 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -1586,7 +1586,7 @@ Spotless uses UTF-8 by default, but you can use [any encoding which Java support ``` -Line endings can also be set globally or per-format using the `lineEndings` property. Spotless supports four line ending modes: `UNIX`, `WINDOWS`, `MAC_CLASSIC`, `PLATFORM_NATIVE`, and `GIT_ATTRIBUTES`. The default value is `GIT_ATTRIBUTES`, and *we highly recommend that you* ***do not change*** *this value*. Git has opinions about line endings, and if Spotless and git disagree, then you're going to have a bad time. +Line endings can also be set globally or per-format using the `lineEndings` property. Spotless supports four line ending modes: `UNIX`, `WINDOWS`, `MAC_CLASSIC`, `PLATFORM_NATIVE`, `GIT_ATTRIBUTES`, and `GIT_ATTRIBUTES_FAST_ALLSAME`. The default value is `GIT_ATTRIBUTES_FAST_ALLSAME`, and *we highly recommend that you* ***do not change*** *this value*. Git has opinions about line endings, and if Spotless and git disagree, then you're going to have a bad time. `FAST_ALLSAME` just means that Spotless can assume that every file being formatted has the same line endings ([more info](https://github.com/diffplug/spotless/pull/1838)). You can easily set the line endings of different files using [a `.gitattributes` file](https://help.github.com/articles/dealing-with-line-endings/). Here's an example `.gitattributes` which sets all files to unix newlines: `* text eol=lf`. From cdc0c7b3c9d85b358d7aba005e284122cbb925b2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 15:47:43 -0700 Subject: [PATCH 0942/1120] Update changelogs. --- CHANGES.md | 1 + plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 3 +++ 3 files changed, 7 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 87eacf12a5..0fbb14f7ff 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). * Support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793)) * Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)). +* New line endings mode `GIT_ATTRIBUTES_FAST_ALLSAME`. ([#1838](https://github.com/diffplug/spotless/pull/1838)) ### Fixed * Fix support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) * Fix configuration cache issue around `external process started '/usr/bin/git --version'`. ([#1806](https://github.com/diffplug/spotless/issues/1806)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7a92efc514..536747a4ff 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -13,6 +13,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Fixed support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) ### Changes * Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808)) +* **POSSIBLY BREAKING** the default line endings are now `GIT_ATTRIBUTES_FAST_ALLSAME` instead of `GIT_ATTRIBUTES`. ([#1838](https://github.com/diffplug/spotless/pull/1838)) + * If all the files within a format have the same line endings, then there is no change in behavior. + * Fixes large performance regression. ([#1527](https://github.com/diffplug/spotless/issues/1527)) ## [6.21.0] - 2023-08-29 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1338d42ddb..a6c98e2c96 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -28,6 +28,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801)) * Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808)) +* **POSSIBLY BREAKING** the default line endings are now `GIT_ATTRIBUTES_FAST_ALLSAME` instead of `GIT_ATTRIBUTES`. ([#1838](https://github.com/diffplug/spotless/pull/1838)) + * If all the files within a format have the same line endings, then there is no change in behavior. + * Fixes large performance regression. ([#1527](https://github.com/diffplug/spotless/issues/1527)) ## [2.39.0] - 2023-08-29 ### Added From 1a1fbfef95ff001ad0d4b5d8cbf8a46bc76c8896 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 28 Sep 2023 16:23:55 -0700 Subject: [PATCH 0943/1120] Remove unused field. --- lib/src/main/java/com/diffplug/spotless/LineEnding.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/LineEnding.java b/lib/src/main/java/com/diffplug/spotless/LineEnding.java index 708699904c..74d9c80618 100644 --- a/lib/src/main/java/com/diffplug/spotless/LineEnding.java +++ b/lib/src/main/java/com/diffplug/spotless/LineEnding.java @@ -19,11 +19,8 @@ import java.io.Serializable; import java.lang.reflect.Method; import java.util.Objects; -import java.util.function.BiFunction; import java.util.function.Supplier; -import javax.annotation.Nullable; - /** * Represents the line endings which should be written by the tool. */ @@ -76,8 +73,6 @@ public Policy createPolicy(File projectDir, Supplier> toFormat) { } } - private static volatile @Nullable BiFunction>, Policy> gitAttributesPolicyCreator; - // @formatter:off /** Should use {@link #createPolicy(File, Supplier)} instead, but this will work iff its a path-independent LineEnding policy. */ public Policy createPolicy() { @@ -85,7 +80,7 @@ public Policy createPolicy() { case PLATFORM_NATIVE: return _platformNativePolicy; case WINDOWS: return WINDOWS_POLICY; case UNIX: return UNIX_POLICY; - case MAC_CLASSIC: return MAC_CLASSIC_POLICY; + case MAC_CLASSIC: return MAC_CLASSIC_POLICY; default: throw new UnsupportedOperationException(this + " is a path-specific line ending."); } } @@ -129,7 +124,7 @@ public String str() { case PLATFORM_NATIVE: return _platformNative; case WINDOWS: return "\r\n"; case UNIX: return "\n"; - case MAC_CLASSIC: return "\r"; + case MAC_CLASSIC: return "\r"; default: throw new UnsupportedOperationException(this + " is a path-specific line ending."); } } From 79c7966760f55848fa41106d5d84e7d424214f8d Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 28 Sep 2023 23:43:11 +0000 Subject: [PATCH 0944/1120] Published lib/2.42.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 0fbb14f7ff..dd89d2c5bd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.42.0] - 2023-09-28 ### Added * Support for biome. The Rome project [was renamed to Biome](https://biomejs.dev/blog/annoucing-biome/). The configuration is still the same, but you should switch to the new `biome` tag / function and adjust From 5a02315dfefe37f8ece378a97bd3bf7f560c582b Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 28 Sep 2023 23:47:42 +0000 Subject: [PATCH 0945/1120] Published gradle/6.22.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 56 ++++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 536747a4ff..74f889fc04 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.22.0] - 2023-09-28 ### Added * Added support for `google-java-format`'s `skip-javadoc-formatting` option ([#1793](https://github.com/diffplug/spotless/pull/1793)) * Add support for `flexmark` in gradle. Previously only Maven was supported. ([#1801](https://github.com/diffplug/spotless/pull/1801)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index d4537d4b11..16285f88ad 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.21.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.22.0-blue.svg)](CHANGES.md) [![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -144,7 +144,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer. ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -301,8 +301,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -352,8 +352,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -427,7 +427,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -459,7 +459,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -491,7 +491,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -527,7 +527,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ### buf -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) **WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem. @@ -559,7 +559,7 @@ buf { ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -580,7 +580,7 @@ spotless { ## Flexmark -`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) [homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). @@ -599,7 +599,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -624,7 +624,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -664,7 +664,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -758,7 +758,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -823,7 +823,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -943,7 +943,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -975,7 +975,7 @@ spotless { ## Gherkin -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.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.22.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 { @@ -1362,7 +1362,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1442,9 +1442,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1477,11 +1477,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.21.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 9997e70cbde1ee1b09e97ad91928496d7eb5ac3f Mon Sep 17 00:00:00 2001 From: runner Date: Thu, 28 Sep 2023 23:52:57 +0000 Subject: [PATCH 0946/1120] Published maven/2.40.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a6c98e2c96..1825628c73 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.40.0] - 2023-09-28 ### Added * Add `-DspotlessIdeHook` that provides the ability to apply Spotless exclusively to a specified file. It accepts the absolute path of the file. ([#1782](https://github.com/diffplug/spotless/pull/1782)) * BETA, subject to change until we have proven compatibility with some IDE plugins. diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 919a05dfbb..3294575e20 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.39.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.39.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.40.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.40.0/index.html) - *.md + .gitattributes .gitignore From 0ab9e62f5dbf90edb46ae534e60ba85aceaae913 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 8 Nov 2023 00:17:55 +0800 Subject: [PATCH 0974/1120] Manually declaring junit-platform-launcher for testCommon Follow up e52c46fdaf9c91b9c44350b8d9d6d7bd18e71fe4. --- lib/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/build.gradle b/lib/build.gradle index 0288277c78..a3424a7ee9 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -69,6 +69,7 @@ dependencies { testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ" testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" + testCommonRuntimeOnly "org.junit.platform:junit-platform-launcher" // GLUE CODE (alphabetic order please) // cleanthat From 9f79a329fd9d667887ab55024cdcf675e957e498 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 8 Nov 2023 10:34:18 +0800 Subject: [PATCH 0975/1120] Capitalized Gradle names in docs --- CHANGES.md | 18 +++++++++--------- ISSUE_TEMPLATE.md | 2 +- README.md | 6 +++--- _ext/eclipse-wtp/CHANGES.md | 2 +- gradle/java-publish.gradle | 2 +- .../com/diffplug/spotless/FormatterStep.java | 2 +- .../npm/PrettierMissingParserException.java | 2 +- plugin-gradle/CHANGES.md | 12 ++++++------ .../gradle/spotless/FormatExtension.java | 2 +- .../gradle/spotless/SpotlessCheck.java | 4 ++-- .../spotless/SpotlessPluginRedirect.java | 2 +- .../spotless/SpotlessPluginRedirectTest.java | 2 +- plugin-maven/CHANGES.md | 2 +- .../diffplug/spotless/maven/MavenRunner.java | 2 +- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 93e693ebf5..d8d6a2a168 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -579,9 +579,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changed * **BREAKING** `FileSignature` can no longer sign folders, only files. Signatures are now based only on filename (not path), size, and a content hash. It throws an error if a signature is attempted on a folder or on multiple files with different paths but the same filename - it never breaks silently. This change does not break any of Spotless' internal logic, so it is unlikely to affect any of Spotless' consumers either. ([#571](https://github.com/diffplug/spotless/pull/571)) * This change allows the maven plugin to cache classloaders across subprojects when loading config resources from the classpath (fixes [#559](https://github.com/diffplug/spotless/issues/559)). - * This change also allows the gradle plugin to work with the remote buildcache (fixes [#280](https://github.com/diffplug/spotless/issues/280)). + * This change also allows the Gradle plugin to work with the remote buildcache (fixes [#280](https://github.com/diffplug/spotless/issues/280)). * **BREAKING** `FormatterFunc` no longer `extends ThrowingEx.Function` and `BiFunction`. In a major win for Java's idea of ["target typing"](https://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-final.html), this required no changes anywhere in the codebase except deleting the `extends` part of `FormatterFunc` ([#638](https://github.com/diffplug/spotless/issues/638)). -* **BREAKING** Heavy refactor of the `LicenseHeaderStep` public API. Doesn't change internal behavior, but makes implementation of the gradle and maven plugins much easier. ([#628](https://github.com/diffplug/spotless/pull/628)) +* **BREAKING** Heavy refactor of the `LicenseHeaderStep` public API. Doesn't change internal behavior, but makes implementation of the Gradle and maven plugins much easier. ([#628](https://github.com/diffplug/spotless/pull/628)) * **BREAKING** Removed all deprecated methods and classes from `lib` and `lib-extra`. * [#629](https://github.com/diffplug/spotless/pull/629) removes the code which wasn't being used in plugin-gradle or plugin-maven. * [#630](https://github.com/diffplug/spotless/pull/630) moves the code which was still being used in deprecated parts of plugin-gradle into `.deprecated` package in `plugin-gradle`, which allows us to break `lib` without a breaking change in `plugin-gradle`. @@ -614,7 +614,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `NodeJsGlobal.setSharedLibFolder` allows to set the location of nodejs shared libs. ([#586](https://github.com/diffplug/spotless/pull/586)) * `PaddedCell.isClean()` returns the instance of `PaddedCell.DirtyState` which represents clean. ([#590](https://github.com/diffplug/spotless/pull/590)) ### Fixed -* Previously, the nodejs-based steps would throw `UnsatisfiedLinkError` if they were ever used from more than one classloader. Now they can be used from any number of classloaders (important for gradle build daemon). ([#586](https://github.com/diffplug/spotless/pull/586)) +* Previously, the nodejs-based steps would throw `UnsatisfiedLinkError` if they were ever used from more than one classloader. Now they can be used from any number of classloaders (important for Gradle build daemon). ([#586](https://github.com/diffplug/spotless/pull/586)) ## [1.31.0] - 2020-05-21 ### Added @@ -636,8 +636,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changed * Updated a bunch of dependencies, most notably: ([#564](https://github.com/diffplug/spotless/pull/564)) * jgit `5.5.0.201909110433-r` -> `5.7.0.202003110725-r` - * gradle `6.2.2` -> `6.3` - * spotbugs gradle plugin `2.0.0` -> `4.0.8` + * Gradle `6.2.2` -> `6.3` + * spotbugs Gradle plugin `2.0.0` -> `4.0.8` ## [1.28.1] - 2020-04-02 ### Fixed @@ -654,7 +654,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * We now use [javadoc.io](https://javadoc.io/) instead of github pages. ([#508](https://github.com/diffplug/spotless/pull/508)) * We no longer publish `-SNAPSHOT` for every build to `main`, since we have good [JitPack integration](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#gradle---any-commit-in-a-public-github-repo-this-one-or-any-fork). ([#508](https://github.com/diffplug/spotless/pull/508)) * Improved how we use Spotless on itself. ([#509](https://github.com/diffplug/spotless/pull/509)) -* Fix build warnings when building on Gradle 6+, bump build gradle to 6.2.2, and fix javadoc links. ([#536](https://github.com/diffplug/spotless/pull/536)) +* Fix build warnings when building on Gradle 6+, bump build Gradle to 6.2.2, and fix javadoc links. ([#536](https://github.com/diffplug/spotless/pull/536)) ## [1.27.0] - 2020-01-01 * Ignored `KtLintStepTest`, because [gradle/gradle#11752](https://github.com/gradle/gradle/issues/11752) is causing too many CI failures. ([#499](https://github.com/diffplug/spotless/pull/499)) @@ -694,7 +694,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - but incorrectly marked as good by "check" - this led to "check" says all good, but then "apply" still causes format (https://github.com/diffplug/spotless/issues/453) - combined with up-to-date checking, could lead to even more confusing results (https://github.com/diffplug/spotless/issues/338) - - only affects the gradle plugin, since that was the only plugin to use this feature + - only affects the Gradle plugin, since that was the only plugin to use this feature * Minor change to `TestProvisioner`, which should fix the cache-breaking issues, allowing us to speed-up the CI builds a bit. * Bumped `scalafmt` default version from `1.1.0` to `2.0.1`, since there are [bugs](https://github.com/diffplug/spotless/issues/454) in the old default ([#458](https://github.com/diffplug/spotless/pull/458)). @@ -711,7 +711,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [1.23.1] - 2019-06-17 * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) -* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) +* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because Gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) ## [1.23.0] - 2019-04-24 * Updated default ktlint from 0.21.0 to 0.32.0, and Maven coords to com.pinterest ([#394](https://github.com/diffplug/spotless/pull/394)) @@ -787,7 +787,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [1.12.0] - 2018-05-14 * Fixed a bug in `LicenseHeaderStep` which caused an exception with some malformed date-aware licenses. ([#222](https://github.com/diffplug/spotless/pull/222)) * Updated default ktlint from 0.14.0 to 0.21.0 -* Add ability to pass custom options to ktlint in gradle plugin. See plugin-gradle/README for details. +* Add ability to pass custom options to ktlint in Gradle plugin. See plugin-gradle/README for details. ## [1.11.0] - 2018-02-26 * Added default indentation of `4` to `IndentStep`. ([#209](https://github.com/diffplug/spotless/pull/209)) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 0ae5167a13..36cda06b7e 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,7 +1,7 @@ If you are submitting a **bug**, please include the following: - [ ] summary of problem -- [ ] gradle or maven version +- [ ] Gradle or maven version - [ ] spotless version - [ ] operating system and version - [ ] copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible diff --git a/README.md b/README.md index 80dcec21eb..2c45e9e444 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ Once someone has filled in one square of the formatter/build system matrix, it's - breaking spotless into libraries [#56](https://github.com/diffplug/spotless/issues/56) - lots of other things, but especially the diff support in `spotlessCheck` - constant improvements on a variety of topics with high-quality code reviews -- Thanks to [Daz DeBoer](https://github.com/bigdaz) for the reworking the guts of our gradle plugin to support [buildcache](https://github.com/diffplug/spotless/pull/576), [InputChanges](https://github.com/diffplug/spotless/pull/607), and [lazy configuration](https://github.com/diffplug/spotless/pull/617). +- Thanks to [Daz DeBoer](https://github.com/bigdaz) for the reworking the guts of our Gradle plugin to support [buildcache](https://github.com/diffplug/spotless/pull/576), [InputChanges](https://github.com/diffplug/spotless/pull/607), and [lazy configuration](https://github.com/diffplug/spotless/pull/617). - Thanks to [Richard Willis](https://github.com/badsyntax) for creating the [VS Code extension for Spotless Gradle](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle). - Thanks to [Ryan Gurney](https://github.com/ragurney) for creating the [IntelliJ plugin for Spotless Gradle](https://plugins.jetbrains.com/plugin/18321-spotless-gradle). - Thanks to [Markus Heberling](https://github.com/tisoft) for adding [generic native formatters](https://github.com/diffplug/spotless/pull/949), [jsr-223 formatters](https://github.com/diffplug/spotless/pull/945), and [maven pom sorting](https://github.com/diffplug/spotless/pull/946). @@ -195,7 +195,7 @@ Once someone has filled in one square of the formatter/build system matrix, it's - Thanks to [Baptiste Mesta](https://github.com/baptistemesta) for - porting the DBeaver formatter to Spotless, and thanks to [DBeaver](https://dbeaver.jkiss.org/) and [its authors](https://github.com/serge-rider/dbeaver/graphs/contributors) for their excellent SQL formatter. - making license headers date-aware [#179](https://github.com/diffplug/spotless/pull/179) -- Thanks to [vmdominguez](https://github.com/vmdominguez) and [Luis Fors](https://github.com/luis-fors-cb) for adding the ability to limit formatting to specific files in gradle ([#322](https://github.com/diffplug/spotless/pull/322)) and maven ([#392](https://github.com/diffplug/spotless/pull/392)), respectively. +- Thanks to [vmdominguez](https://github.com/vmdominguez) and [Luis Fors](https://github.com/luis-fors-cb) for adding the ability to limit formatting to specific files in Gradle ([#322](https://github.com/diffplug/spotless/pull/322)) and maven ([#392](https://github.com/diffplug/spotless/pull/392)), respectively. - Thanks to [bender316](https://github.com/bender316) for fixing classloading on Java 9 ([#426](https://github.com/diffplug/spotless/pull/426)). - Thanks to [Stefan Oehme](https://github.com/oehme) for tons of help on the internal mechanics of Gradle. - Thanks to [eyalkaspi](https://github.com/eyalkaspi) for adding configurable date ranges to the date-aware license headers. @@ -203,7 +203,7 @@ Once someone has filled in one square of the formatter/build system matrix, it's - Thanks to [Oliver Horn](https://github.com/ohorn) for adding AOSP support for Spotless' google-java-format integration. - Formatting by Eclipse - Special thanks to [Mateusz Matela](https://waynebeaton.wordpress.com/2015/03/15/great-fixes-for-mars-winners-part-i/) for huge improvements to the eclipse code formatter! -- Thanks to [Zac Sweers](https://github.com/ZacSweers) for fixing the highly requested ktlint 0.34+ support ([#469](https://github.com/diffplug/spotless/pull/469)), multiple build updates and fixing a gradle deprecation warning ([#434](https://github.com/diffplug/spotless/pull/434) and others). +- Thanks to [Zac Sweers](https://github.com/ZacSweers) for fixing the highly requested ktlint 0.34+ support ([#469](https://github.com/diffplug/spotless/pull/469)), multiple build updates and fixing a Gradle deprecation warning ([#434](https://github.com/diffplug/spotless/pull/434) and others). - Thanks to [Stephen Panaro](https://github.com/smpanaro) for adding support for ktlint FilenameRule ([#974](https://github.com/diffplug/spotless/pull/974)). - Thanks to [Nelson Osacky](https://github.com/runningcode) for android doc improvements, versions bump, and a build improvement. - Thanks to [Stanley Shyiko](https://github.com/shyiko) for his help integrating [ktlint](https://github.com/shyiko/ktlint). diff --git a/_ext/eclipse-wtp/CHANGES.md b/_ext/eclipse-wtp/CHANGES.md index 0001618b1f..d57618ad8c 100644 --- a/_ext/eclipse-wtp/CHANGES.md +++ b/_ext/eclipse-wtp/CHANGES.md @@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed -* Fix typo in gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) +* Fix typo in Gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) ## [3.23.0] - 2021-09-22 ### Added diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 495694a5be..49075c5970 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -192,7 +192,7 @@ if (System.env['JITPACK'] == 'true' || version.endsWith('-SNAPSHOT')) { changelogTasks.named('changelogBump').configure { dependsOn ":${thisProj.path}:publishPluginMavenPublicationToSonatypeRepository" dependsOn ":closeAndReleaseSonatypeStagingRepository" - // if we have a gradle plugin, we need to push it up to the plugin portal too + // if we have a Gradle plugin, we need to push it up to the plugin portal too if (thisProj.tasks.names.contains('publishPlugins')) { dependsOn thisProj.tasks.named('publishPlugins') } diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java index 5f6ec168d4..ce24921509 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterStep.java @@ -86,7 +86,7 @@ public default FormatterStep filterByFile(SerializableFileFilter filter) { * Implements a FormatterStep in a strict way which guarantees correct and lazy implementation * of up-to-date checks. This maximizes performance for cases where the FormatterStep is not * actually needed (e.g. don't load eclipse setting file unless this step is actually running) - * while also ensuring that gradle can detect changes in a step's settings to determine that + * while also ensuring that Gradle can detect changes in a step's settings to determine that * it needs to rerun a format. */ abstract class Strict extends LazyForwardingEquality implements FormatterStep { diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java index 6956545135..4debfd5720 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java @@ -95,7 +95,7 @@ private static String recommendPlugin(File file) { + String.format("", pluginName) + "\n\n" + "For instructions on how to include plugins for prettier in spotless see our documentation:\n" - + "- for gradle \n" + + "- for Gradle \n" + "- for maven "; } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ec26cf5c63..ac3e4f1c38 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -161,7 +161,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `KtLint` does not maintain a stable API - before this PR, we supported every breaking change in the API since 2019. * From now on, we will support no more than 2 breaking changes at a time. * `npm`-based formatters `ESLint`, `prettier` and `tsfmt` delay their `npm install` call until the formatters are first - used. For gradle this effectively moves the `npm install` call out of the configuration phase and as such enables + used. For Gradle this effectively moves the `npm install` call out of the configuration phase and as such enables better integration with `gradle-node-plugin`. ([#1522](https://github.com/diffplug/spotless/pull/1522)) * Bump default `ktlint` version to latest `0.48.1` -> `0.48.2` ([#1529](https://github.com/diffplug/spotless/pull/1529)) * Bump default `scalafmt` version to latest `3.6.1` -> `3.7.1` ([#1529](https://github.com/diffplug/spotless/pull/1529)) @@ -371,7 +371,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [6.0.4] - 2021-12-07 ### Fixed -* Fix gradle composite builds ([#860](https://github.com/diffplug/spotless/issues/860)). +* Fix Gradle composite builds ([#860](https://github.com/diffplug/spotless/issues/860)). ## [6.0.3] - 2021-12-06 ### Fixed @@ -687,7 +687,7 @@ println "isEager $isEager" * LineEndings.GIT_ATTRIBUTES is now a bit more efficient, and paves the way for remote build cache support in Gradle. ([#621](https://github.com/diffplug/spotless/pull/621)) * `ratchetFrom` now ratchets from the merge base of `HEAD` and the specified branch. This fixes the surprising behavior when a remote branch advanced ([#631](https://github.com/diffplug/spotless/pull/631) fixes [#627](https://github.com/diffplug/spotless/issues/627)). ### Deprecated -* The default targets for `C/C++`, `freshmark`, `sql`, and `typescript` now generate a warning, asking the user to specify a target manually. There is no well-established convention for these languages in the gradle ecosystem, and the performance of the default target is far worse than a user-provided one. If you dislike this change, please complain in [#634](https://github.com/diffplug/spotless/pull/634). +* The default targets for `C/C++`, `freshmark`, `sql`, and `typescript` now generate a warning, asking the user to specify a target manually. There is no well-established convention for these languages in the Gradle ecosystem, and the performance of the default target is far worse than a user-provided one. If you dislike this change, please complain in [#634](https://github.com/diffplug/spotless/pull/634). * `customLazy` and `customLazyGroovy` now generate a warning, asking the user to migrate to `custom`. There is no longer a performance advantage to `customLazy` in the new modern plugin. See [#635](https://github.com/diffplug/spotless/pull/635/files) for example migrations. * inside the `cpp { }` block, the `eclipse` step now generates a warning, asking you to switch to `eclipseCdt`. It is the same underlying step, but the new name clears up any confusion with the more common Java `eclipse`. [#636](https://github.com/diffplug/spotless/pull/635/files) @@ -765,7 +765,7 @@ spotless { **TLDR: This version improves performance and adds support for the local Gradle Build Cache. You will not need to make any changes in your buildscript.** It is a breaking change only for a few users who have built *other* plugins on top of this one. ### Added -* Support for the gradle build cache. ([#576](https://github.com/diffplug/spotless/pull/576)) +* Support for the Gradle build cache. ([#576](https://github.com/diffplug/spotless/pull/576)) * The local cache will work great, but the remote cache will always miss until [#566](https://github.com/diffplug/spotless/issues/566) is resolved. ### Removed * **BREAKING** it used to be possible for any project to format files in any other project. For example, `:a` could format files in `:b`. It is now only possible to format files within the project directory. It is okay (but not advised) to format files in subprojects, since they are within the project directory. @@ -773,7 +773,7 @@ spotless { * Previously, the `check` and `apply` tasks were just marker tasks, and they called `setCheck` and `setApply` on the "worker" task. Now `check` and `apply` are real tasks in their own right, so the marker-task kludge is no longer necessary. ### Changed * (Power users only) **BREAKING** `SpotlessTask FormatExtension::createIndependentTask` has been removed, and replaced with `SpotlessApply::createIndependentApplyTask`. ([#576](https://github.com/diffplug/spotless/pull/576)) -* Improve suggested gradle invocation for running `spotlessApply`. ([#578](https://github.com/diffplug/spotless/pull/578)) +* Improve suggested Gradle invocation for running `spotlessApply`. ([#578](https://github.com/diffplug/spotless/pull/578)) ## [3.30.0] - 2020-05-11 ### Added @@ -868,7 +868,7 @@ spotless { ## [3.23.1] - 2019-06-17 * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) -* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) +* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because Gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) ## [3.23.0] - 2019-04-24 * Updated default ktlint from 0.21.0 to 0.32.0, and Maven coords to com.pinterest ([#394](https://github.com/diffplug/spotless/pull/394)) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 30fded9d5f..ff0d71b15a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -395,7 +395,7 @@ public void clearSteps() { * * Spotless tracks what files have changed from run to run, so that it can run * faster by only checking files which have changed, or whose formatting steps - * have changed. If you use the {@code custom} methods, then gradle can never + * have changed. If you use the {@code custom} methods, then Gradle can never * mark your files as {@code up-to-date}, because it can't know if perhaps the * behavior of your custom function has changed. * diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java index d0e27d60bf..98b88315ad 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java @@ -86,8 +86,8 @@ public void visitFile(FileVisitDetails fileVisitDetails) { // in its output directory which ought to have been removed. As // best I can tell, this is a filesytem race which is very hard // to trigger. GitRatchetGradleTest can *sometimes* reproduce it - // but it's very erratic, and that test writes both to gradle cache - // and git cache very quickly. Either of gradle or jgit might be + // but it's very erratic, and that test writes both to Gradle cache + // and git cache very quickly. Either of Gradle or jgit might be // caching something wrong because of the fast repeated writes. if (!Arrays.equals(userFile, formatted)) { // If the on-disk content is equal to the formatted content, diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java index 975ec5576e..bca8ea7c70 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPluginRedirect.java @@ -73,7 +73,7 @@ public void apply(Project project) { "If you like the idea behind 'ratchetFrom', you should checkout spotless-changelog", "https://github.com/diffplug/spotless-changelog"); if (gradleIsTooOld(project)) { - errorMsg = errorMsg.replace("To migrate:\n", "To migrate:\n- Upgrade gradle to " + SpotlessPlugin.VER_GRADLE_min + " or newer (you're on " + project.getGradle().getGradleVersion() + ")\n"); + errorMsg = errorMsg.replace("To migrate:\n", "To migrate:\n- Upgrade Gradle to " + SpotlessPlugin.VER_GRADLE_min + " or newer (you're on " + project.getGradle().getGradleVersion() + ")\n"); } throw new GradleException(errorMsg); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java index acb57f3763..e8616043d1 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java @@ -54,7 +54,7 @@ void redirectPluginOldGradle() throws IOException { " > We have moved from 'com.diffplug.gradle.spotless'", " to 'com.diffplug.spotless'", " To migrate:", - " - Upgrade gradle to 6.1.1 or newer (you're on 5.0)", + " - Upgrade Gradle to 6.1.1 or newer (you're on 5.0)", " - Test your build with: id 'com.diffplug.gradle.spotless' version '4.5.1'")); } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e941297aa3..ec10d96592 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -696,7 +696,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [1.23.1] - 2019-06-17 * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) -* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) +* Update jgit from `4.9.0.201710071750-r` to `5.3.2.201906051522-r` because Gradle project is sometimes broken by `apache httpcomponents` in transitive dependency. ([#407](https://github.com/diffplug/spotless/pull/407)) ## [1.23.0] - 2019-04-24 * Updated default ktlint from 0.21.0 to 0.32.0, and Maven coords to com.pinterest ([#394](https://github.com/diffplug/spotless/pull/394)) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java index d878b18c5f..3f4c163443 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java @@ -29,7 +29,7 @@ /** * Harness for running a maven build, same idea as the - * GradleRunner from the gradle testkit. + * GradleRunner from the Gradle testkit. */ public class MavenRunner { public static MavenRunner create() { From 5cc0c55f37cdbce9d4c7e2f887b6f986ee6ee409 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 8 Nov 2023 10:38:01 +0800 Subject: [PATCH 0976/1120] Capitalized Maven names in docs --- CHANGES.md | 18 +++++++++--------- CONTRIBUTING.md | 2 +- ISSUE_TEMPLATE.md | 2 +- README.md | 4 ++-- .../npm/PrettierMissingParserException.java | 2 +- plugin-gradle/CHANGES.md | 8 ++++---- plugin-gradle/README.md | 4 ++-- .../gradle/spotless/SpotlessCheck.java | 2 +- .../spotless/SpotlessPluginRedirectTest.java | 2 +- plugin-maven/CHANGES.md | 12 ++++++------ plugin-maven/README.md | 4 ++-- .../diffplug/spotless/maven/MavenRunner.java | 4 ++-- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d8d6a2a168..c1a11e3a0a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,7 +21,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( The configuration is still the same, but you should switch to the new `biome` tag / function and adjust the version accordingly. ([#1804](https://github.com/diffplug/spotless/issues/1804)). * Support for `google-java-format`'s `skip-javadoc-formatting` option. ([#1793](https://github.com/diffplug/spotless/pull/1793)) -* Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)). +* Support configuration of mirrors for P2 repositories in Maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)). * New line endings mode `GIT_ATTRIBUTES_FAST_ALLSAME`. ([#1838](https://github.com/diffplug/spotless/pull/1838)) ### Fixed * Fix support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802)) @@ -135,7 +135,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.33.0] - 2023-01-26 ### Added -* `ProcessRunner` has added some convenience methods so it can be used for maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) +* `ProcessRunner` has added some convenience methods so it can be used for Maven testing. ([#1496](https://github.com/diffplug/spotless/pull/1496)) * `ProcessRunner` allows to limit captured output to a certain number of bytes. ([#1511](https://github.com/diffplug/spotless/pull/1511)) * `ProcessRunner` is now capable of handling long-running tasks where waiting for exit is delegated to the caller. ([#1511](https://github.com/diffplug/spotless/pull/1511)) * Allow to specify node executable for node-based formatters using `nodeExecutable` parameter ([#1500](https://github.com/diffplug/spotless/pull/1500)) @@ -208,7 +208,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.29.0] - 2022-08-23 ### Added -* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) +* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the Maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) * Converted `scalafmt` integration to use a compile-only source set (fixes [#524](https://github.com/diffplug/spotless/issues/524)) ### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) @@ -433,7 +433,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changed * Update ktfmt from 0.21 to 0.24 ### Fixed -* The `` field in the maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) +* The `` field in the Maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) * Node is re-installed if some other build step removed it ([#863](https://github.com/diffplug/spotless/issues/863)) ## [2.13.4] - 2021-04-21 @@ -507,7 +507,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.8.0] - 2020-10-05 ### Added -* Exposed new methods in `GitRatchet` to support faster ratcheting in the maven plugin ([#706](https://github.com/diffplug/spotless/pull/706)). +* Exposed new methods in `GitRatchet` to support faster ratcheting in the Maven plugin ([#706](https://github.com/diffplug/spotless/pull/706)). ## [2.7.0] - 2020-09-21 ### Added @@ -578,10 +578,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `FormatterFunc.NeedsFile` for implementing file-based formatters more cleanly than we have so far ([#637](https://github.com/diffplug/spotless/issues/637)). ### Changed * **BREAKING** `FileSignature` can no longer sign folders, only files. Signatures are now based only on filename (not path), size, and a content hash. It throws an error if a signature is attempted on a folder or on multiple files with different paths but the same filename - it never breaks silently. This change does not break any of Spotless' internal logic, so it is unlikely to affect any of Spotless' consumers either. ([#571](https://github.com/diffplug/spotless/pull/571)) - * This change allows the maven plugin to cache classloaders across subprojects when loading config resources from the classpath (fixes [#559](https://github.com/diffplug/spotless/issues/559)). + * This change allows the Maven plugin to cache classloaders across subprojects when loading config resources from the classpath (fixes [#559](https://github.com/diffplug/spotless/issues/559)). * This change also allows the Gradle plugin to work with the remote buildcache (fixes [#280](https://github.com/diffplug/spotless/issues/280)). * **BREAKING** `FormatterFunc` no longer `extends ThrowingEx.Function` and `BiFunction`. In a major win for Java's idea of ["target typing"](https://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-final.html), this required no changes anywhere in the codebase except deleting the `extends` part of `FormatterFunc` ([#638](https://github.com/diffplug/spotless/issues/638)). -* **BREAKING** Heavy refactor of the `LicenseHeaderStep` public API. Doesn't change internal behavior, but makes implementation of the Gradle and maven plugins much easier. ([#628](https://github.com/diffplug/spotless/pull/628)) +* **BREAKING** Heavy refactor of the `LicenseHeaderStep` public API. Doesn't change internal behavior, but makes implementation of the Gradle and Maven plugins much easier. ([#628](https://github.com/diffplug/spotless/pull/628)) * **BREAKING** Removed all deprecated methods and classes from `lib` and `lib-extra`. * [#629](https://github.com/diffplug/spotless/pull/629) removes the code which wasn't being used in plugin-gradle or plugin-maven. * [#630](https://github.com/diffplug/spotless/pull/630) moves the code which was still being used in deprecated parts of plugin-gradle into `.deprecated` package in `plugin-gradle`, which allows us to break `lib` without a breaking change in `plugin-gradle`. @@ -659,7 +659,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [1.27.0] - 2020-01-01 * Ignored `KtLintStepTest`, because [gradle/gradle#11752](https://github.com/gradle/gradle/issues/11752) is causing too many CI failures. ([#499](https://github.com/diffplug/spotless/pull/499)) * Also fixed a minor problem in TestProvisioner. -* If you set the environment variable `SPOTLESS_EXCLUDE_MAVEN=true` then the maven plugin will be excluded from the build. ([#502](https://github.com/diffplug/spotless/pull/502)) +* If you set the environment variable `SPOTLESS_EXCLUDE_MAVEN=true` then the Maven plugin will be excluded from the build. ([#502](https://github.com/diffplug/spotless/pull/502)) * We have set this in JitPack, as a workaround for [jitpack/jitpack.io#4112](https://github.com/jitpack/jitpack.io/issues/4112) * Deprecated `SpotlessCache.clear()` in favor of the new `SpotlessCache.clearOnce(Object key)`. ([#501](https://github.com/diffplug/spotless/issues/#501)) @@ -707,7 +707,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Updated default eclipse-jdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * Updated default eclipse-cdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * **KNOWN BUG - accidentally published CDT 9.7 rather than 9.8 - fixed in 1.26.0** -* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) +* Added new Maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) ## [1.23.1] - 2019-06-17 * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 852a694470..287d835bca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,7 +27,7 @@ Spotless also provides `PaddedCell`, which makes it easy to diagnose and correct ## Project layout -For the folders below in monospace text, they are published on maven central at the coordinate `com.diffplug.spotless:spotless-${FOLDER_NAME}`. The other folders are dev infrastructure. +For the folders below in monospace text, they are published on MavenCentral at the coordinate `com.diffplug.spotless:spotless-${FOLDER_NAME}`. The other folders are dev infrastructure. | Folder | Description | | ------ | ----------- | diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 36cda06b7e..76d0ce19ab 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,7 +1,7 @@ If you are submitting a **bug**, please include the following: - [ ] summary of problem -- [ ] Gradle or maven version +- [ ] Gradle or Maven version - [ ] spotless version - [ ] operating system and version - [ ] copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible diff --git a/README.md b/README.md index 2c45e9e444..d31fd15b8c 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ Once someone has filled in one square of the formatter/build system matrix, it's ## Acknowledgements -- Thanks to [Konstantin Lutovich](https://github.com/lutovich) for [implementing and maintaining the maven plugin](https://github.com/diffplug/spotless/pull/188), as well as fixing [remote-build cache support for Gradle](https://github.com/diffplug/spotless/pull/571). +- Thanks to [Konstantin Lutovich](https://github.com/lutovich) for [implementing and maintaining the Maven plugin](https://github.com/diffplug/spotless/pull/188), as well as fixing [remote-build cache support for Gradle](https://github.com/diffplug/spotless/pull/571). - Thanks to [Frank Vennemeyer](https://github.com/fvgh) for [Groovy support via greclipse](https://github.com/diffplug/spotless/issues/13), [C++ support via CDT](https://github.com/diffplug/spotless/issues/232), [XML support via WTP](https://github.com/diffplug/spotless/pull/241) and a huge body of work with other eclipse-based formatters. - Thanks to [Jonathan Bluett-Duncan](https://github.com/jbduncan) for - implementing up-to-date checking [#31](https://github.com/diffplug/spotless/issues/31) @@ -195,7 +195,7 @@ Once someone has filled in one square of the formatter/build system matrix, it's - Thanks to [Baptiste Mesta](https://github.com/baptistemesta) for - porting the DBeaver formatter to Spotless, and thanks to [DBeaver](https://dbeaver.jkiss.org/) and [its authors](https://github.com/serge-rider/dbeaver/graphs/contributors) for their excellent SQL formatter. - making license headers date-aware [#179](https://github.com/diffplug/spotless/pull/179) -- Thanks to [vmdominguez](https://github.com/vmdominguez) and [Luis Fors](https://github.com/luis-fors-cb) for adding the ability to limit formatting to specific files in Gradle ([#322](https://github.com/diffplug/spotless/pull/322)) and maven ([#392](https://github.com/diffplug/spotless/pull/392)), respectively. +- Thanks to [vmdominguez](https://github.com/vmdominguez) and [Luis Fors](https://github.com/luis-fors-cb) for adding the ability to limit formatting to specific files in Gradle ([#322](https://github.com/diffplug/spotless/pull/322)) and Maven ([#392](https://github.com/diffplug/spotless/pull/392)), respectively. - Thanks to [bender316](https://github.com/bender316) for fixing classloading on Java 9 ([#426](https://github.com/diffplug/spotless/pull/426)). - Thanks to [Stefan Oehme](https://github.com/oehme) for tons of help on the internal mechanics of Gradle. - Thanks to [eyalkaspi](https://github.com/eyalkaspi) for adding configurable date ranges to the date-aware license headers. diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java index 4debfd5720..cc04c7b182 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierMissingParserException.java @@ -96,7 +96,7 @@ private static String recommendPlugin(File file) { + "\n\n" + "For instructions on how to include plugins for prettier in spotless see our documentation:\n" + "- for Gradle \n" - + "- for maven "; + + "- for Maven "; } private static String guessPlugin(File file) { diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index ac3e4f1c38..e2379a8b5c 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -211,7 +211,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [6.10.0] - 2022-08-23 ### Added -* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) +* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the Maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) ### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) * Bump default `scalafmt` to latest `3.0.8` -> `3.5.9` (removed support for pre-`3.0.0`) ([#1283](https://github.com/diffplug/spotless/pull/1283)) @@ -496,7 +496,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changed * Update ktfmt from 0.21 to 0.24 ### Fixed -* The `` field in the maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) +* The `` field in the Maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) * Node is re-installed if some other build step removed it ([#863](https://github.com/diffplug/spotless/issues/863)) ## [5.12.4] - 2021-04-21 @@ -864,7 +864,7 @@ spotless { * Updated default eclipse-jdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * Updated default eclipse-cdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * **KNOWN BUG - accidentally published CDT 9.7 rather than 9.8 - fixed in 3.26.0** -* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) +* Added new Maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) ## [3.23.1] - 2019-06-17 * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) @@ -1028,7 +1028,7 @@ spotless { ## [3.0.0] - 2017-01-09 * BREAKING CHANGE: `customReplace` and `customReplaceRegex` renamed to just `replace` and `replaceRegex`. -* BREAKING CHANGE: Plugin portal ID is still `com.diffplug.gradle.spotless`, but maven coordinate has changed to `com.diffplug.spotless:spotless-plugin-gradle`. +* BREAKING CHANGE: Plugin portal ID is still `com.diffplug.gradle.spotless`, but Maven coordinate has changed to `com.diffplug.spotless:spotless-plugin-gradle`. * HUGE SPEEDUP: Now supports incremental build / up-to-date-checking. + If you are using `custom` or `customLazy`, you might want to take a look at [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/3.27.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-). * BREAKING CHANGE: `freshmark` no longer includes all project properties by default. All properties must now be added manually: diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 16285f88ad..4a879fe49a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -5,7 +5,7 @@ output = [ link(shield('Gradle plugin', 'plugins.gradle.org', 'com.diffplug.spotless', 'blue'), 'https://plugins.gradle.org/plugin/com.diffplug.spotless'), link(shield('Changelog', 'changelog', '{{versionLast}}', 'blue'), 'CHANGES.md'), - link(shield('Maven central', 'mavencentral', 'here', 'blue'), 'https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22'), + link(shield('MavenCentral', 'mavencentral', 'here', 'blue'), 'https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22'), link(shield('Javadoc', 'javadoc', 'here', 'blue'), 'https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/{{versionLast}}/index.html'), '', link(shield('VS Code plugin', 'IDE', 'VS Code', 'blueviolet'), 'https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle'), @@ -15,7 +15,7 @@ output = [ --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) [![Changelog](https://img.shields.io/badge/changelog-6.22.0-blue.svg)](CHANGES.md) -[![Maven central](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) +[![MavenCentral](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) [![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java index 98b88315ad..95f051371b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessCheck.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 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. diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java index e8616043d1..a427d6f2ec 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/SpotlessPluginRedirectTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 DiffPlug + * Copyright 2020-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ec10d96592..10ebfc57c1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -142,7 +142,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * Respect `sourceDirectory` and `testSourceDirectory` POM configurations for Java formatters ([#1553](https://github.com/diffplug/spotless/pull/1553)) * **POTENTIALLY BREAKING** `sortByKeys` for JSON formatting now takes into account objects inside arrays ([#1546](https://github.com/diffplug/spotless/pull/1546)) -* Any commit of the Spotless maven plugin now available via JitPack ([#1547](https://github.com/diffplug/spotless/pull/1547)) +* Any commit of the Spotless Maven plugin now available via JitPack ([#1547](https://github.com/diffplug/spotless/pull/1547)) ## [2.31.0] - 2023-01-26 ### Added @@ -228,7 +228,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.25.0] - 2022-08-23 ### Added -* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) +* `scalafmt` integration now has a configuration option `majorScalaVersion` that allows you to configure the Scala version that gets resolved from the Maven artifact ([#1283](https://github.com/diffplug/spotless/pull/1283)) ### Changes * Add the `ktlint` rule in error messages when `ktlint` fails to apply a fix ([#1279](https://github.com/diffplug/spotless/pull/1279)) * Bump default `scalafmt` to latest `3.0.8` -> `3.5.9` (removed support for pre-`3.0.0`) ([#1283](https://github.com/diffplug/spotless/pull/1283)) @@ -462,7 +462,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changed * Update ktfmt from 0.21 to 0.24 ### Fixed -* The `` field in the maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) +* The `` field in the Maven POM is now set correctly ([#798](https://github.com/diffplug/spotless/issues/798)) ## [2.10.3] - 2021-04-21 ### Fixed @@ -596,7 +596,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `prettier` will now autodetect the parser (and formatter) to use based on the filename, unless you override this using `config` or `configFile` with the option `parser` or `filepath` ([#620](https://github.com/diffplug/spotless/pull/620)). * Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ### Removed -* **BREAKING** the default includes for `` and `` were removed, and will now generate an error if an `` is not specified. There is no well-established convention for these languages in the maven ecosystem, and the performance of the default includes is far worse than a user-provided one. If you dislike this change, please complain in [#634](https://github.com/diffplug/spotless/pull/634), it would not be a breaking change to bring the defaults back. +* **BREAKING** the default includes for `` and `` were removed, and will now generate an error if an `` is not specified. There is no well-established convention for these languages in the Maven ecosystem, and the performance of the default includes is far worse than a user-provided one. If you dislike this change, please complain in [#634](https://github.com/diffplug/spotless/pull/634), it would not be a breaking change to bring the defaults back. * **BREAKING** inside the `` block, `` has been renamed to `` to avoid any confusion with the java `` ([#636](https://github.com/diffplug/spotless/pull/636)). * **BREAKING** the long-deprecated `` and `` formats have been removed, in favor of the long-available [``](https://github.com/diffplug/spotless/tree/main/plugin-maven#eclipse-wtp) step which is available in every generic format ([#630](https://github.com/diffplug/spotless/pull/630)). * This probably doesn't affect you, but if it does, you just need to change `...` into `XML...` @@ -644,7 +644,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Enable IntelliJ-compatible token `$today.year` for specifying the year in license header files. ([#542](https://github.com/diffplug/spotless/pull/542)) ### Fixed -* Fix scala and kotlin maven config documentation. +* Fix scala and kotlin Maven config documentation. * Eclipse-WTP formatter (web tools platform, not java) could encounter errors in parallel multiproject builds [#492](https://github.com/diffplug/spotless/issues/492). Fixed for Eclipse-WTP formatter Eclipse version 4.13.0 (default version). ## [1.27.0] - 2020-01-01 @@ -692,7 +692,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Updated default eclipse-jdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * Updated default eclipse-cdt from 4.11.0 to 4.12.0 ([#423](https://github.com/diffplug/spotless/pull/423)). * **KNOWN BUG - accidentally published CDT 9.7 rather than 9.8 fixed in 1.26.0** -* Added new maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) +* Added new Maven coordinates for scalafmt 2.0.0+, maintains backwards compatability ([#415](https://github.com/diffplug/spotless/issues/415)) ## [1.23.1] - 2019-06-17 * Fixes incorrect M2 cache directory path handling of Eclipse based formatters ([#401](https://github.com/diffplug/spotless/issues/401)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 3294575e20..651eaa6720 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -2,12 +2,12 @@ -[![Maven central](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) +[![MavenCentral](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) [![Changelog](https://img.shields.io/badge/changelog-2.40.0-blue.svg)](CHANGES.md) [![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.40.0/index.html) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java index 3f4c163443..c8d845f8a2 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java @@ -28,7 +28,7 @@ import com.diffplug.spotless.ProcessRunner; /** - * Harness for running a maven build, same idea as the + * Harness for running a Maven build, same idea as the * GradleRunner from the Gradle testkit. */ public class MavenRunner { @@ -67,7 +67,7 @@ public MavenRunner withRemoteDebug(int port) { private ProcessRunner.Result run() throws IOException, InterruptedException { Objects.requireNonNull(projectDir, "Need to call withProjectDir() first"); Objects.requireNonNull(args, "Need to call withArguments() first"); - // run maven with the given args in the given directory + // run Maven with the given args in the given directory String argsString = "-e " + String.join(" ", Arrays.asList(args)); return runner.shellWinUnix(projectDir, environment, "mvnw " + argsString, "./mvnw " + argsString); } From 2ff556b74e485dec0115bf1db35cde99e78e025a Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 19 Nov 2023 01:46:50 +0800 Subject: [PATCH 0977/1120] Check if EditorConfig file exist for Ktlint in KotlinGradleExtension Follow up 959fd854c36080caa13123de2089ebcb7396adb4. --- plugin-gradle/CHANGES.md | 1 + .../diffplug/gradle/spotless/KotlinGradleExtension.java | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e2379a8b5c..9d833b0076 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Fix Eclipse JDT on some settings files. ([#1864](https://github.com/diffplug/spotless/pull/1864) fixes [#1638](https://github.com/diffplug/spotless/issues/1638)) +* Check if EditorConfig file exist for Ktlint in KotlinGradleExtension. ([#1889](https://github.com/diffplug/spotless/pull/1889) ### Changes * Bump default `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855)) ### Fixed diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index b3351194ba..751b649491 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -74,11 +74,14 @@ public class KotlinFormatExtension { } public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException { - if (editorConfigPath == null) { this.editorConfigPath = null; } else { - this.editorConfigPath = FileSignature.signAsList(getProject().file(editorConfigPath)); + File editorConfigFile = getProject().file(editorConfigPath); + if (!editorConfigFile.exists()) { + throw new IllegalArgumentException("EditorConfig file does not exist: " + editorConfigFile); + } + this.editorConfigPath = FileSignature.signAsList(editorConfigFile); } replaceStep(createStep()); return this; From 459708539308161e9f9f91de99a453053535dfb1 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 19 Nov 2023 01:55:53 +0800 Subject: [PATCH 0978/1120] Reuse configs for KotlinExtension and KotlinGradleExtension --- .../diffplug/spotless/kotlin/DiktatStep.java | 4 - .../diffplug/spotless/kotlin/KtLintStep.java | 17 -- .../gradle/spotless/BaseKotlinExtension.java | 209 ++++++++++++++++++ .../gradle/spotless/KotlinExtension.java | 183 +-------------- .../spotless/KotlinGradleExtension.java | 189 +--------------- 5 files changed, 217 insertions(+), 385 deletions(-) create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index fefda39784..a2650e31fc 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -53,10 +53,6 @@ public static FormatterStep create(String versionDiktat, Provisioner provisioner return create(versionDiktat, provisioner, false, config); } - public static FormatterStep createForScript(String versionDiktat, Provisioner provisioner, @Nullable FileSignature config) { - return create(versionDiktat, provisioner, true, config); - } - public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) { if (BadSemver.version(versionDiktat) < BadSemver.version(MIN_SUPPORTED_VERSION)) { throw new IllegalStateException("Minimum required Diktat version is " + MIN_SUPPORTED_VERSION + ", you tried " + versionDiktat + " which is too old"); diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 4aca4da02e..13fba97c57 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -54,23 +54,6 @@ public static FormatterStep create(String version, Provisioner provisioner, return create(version, provisioner, false, null, userData, editorConfigOverride); } - public static FormatterStep createForScript(String version, Provisioner provisioner) { - return create(version, provisioner, true, null, Collections.emptyMap(), Collections.emptyMap()); - } - - public static FormatterStep createForScript(String version, - Provisioner provisioner, - @Nullable FileSignature editorConfigPath, - Map userData, - Map editorConfigOverride) { - return create(version, - provisioner, - true, - editorConfigPath, - userData, - editorConfigOverride); - } - public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java new file mode 100644 index 0000000000..5ced54a94e --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -0,0 +1,209 @@ +/* + * 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.gradle.spotless; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; +import java.util.function.Consumer; + +import javax.annotation.Nullable; + +import com.diffplug.common.collect.ImmutableSortedMap; +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.kotlin.DiktatStep; +import com.diffplug.spotless.kotlin.KtLintStep; +import com.diffplug.spotless.kotlin.KtfmtStep; + +public abstract class BaseKotlinExtension extends FormatExtension { + public BaseKotlinExtension(SpotlessExtension spotless) { + super(spotless); + } + + public DiktatConfig diktat() { + return diktat(DiktatStep.defaultVersionDiktat()); + } + + /** Adds the specified version of diktat. */ + public DiktatConfig diktat(String version) { + return new DiktatConfig(version); + } + + public KtlintConfig ktlint() throws IOException { + return ktlint(KtLintStep.defaultVersion()); + } + + /** Adds the specified version of ktlint. */ + public KtlintConfig ktlint(String version) throws IOException { + return new KtlintConfig(version, Collections.emptyMap(), Collections.emptyMap()); + } + + /** Uses the ktfmt jar to format source code. */ + public KtfmtConfig ktfmt() { + return ktfmt(KtfmtStep.defaultVersion()); + } + + /** + * Uses the given version of ktfmt and applies the dropbox style + * option to format source code. + */ + public KtfmtConfig ktfmt(String version) { + return new KtfmtConfig(version); + } + + protected abstract boolean isScript(); + + public class DiktatConfig { + + private final String version; + private FileSignature config; + + DiktatConfig(String version) { + Objects.requireNonNull(version, "version"); + this.version = version; + addStep(createStep()); + } + + public DiktatConfig configFile(Object file) throws IOException { + // Specify the path to the configuration file + if (file == null) { + this.config = null; + } else { + this.config = FileSignature.signAsList(getProject().file(file)); + } + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return DiktatStep.create(version, provisioner(), isScript(), config); + } + } + + public class KtfmtConfig { + final String version; + KtfmtStep.Style style; + KtfmtStep.KtfmtFormattingOptions options; + + private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); + + KtfmtConfig(String version) { + Objects.requireNonNull(version); + this.version = Objects.requireNonNull(version); + addStep(createStep()); + } + + private ConfigurableStyle style(KtfmtStep.Style style) { + this.style = style; + replaceStep(createStep()); + return configurableStyle; + } + + public ConfigurableStyle dropboxStyle() { + return style(KtfmtStep.Style.DROPBOX); + } + + public ConfigurableStyle googleStyle() { + return style(KtfmtStep.Style.GOOGLE); + } + + public ConfigurableStyle kotlinlangStyle() { + return style(KtfmtStep.Style.KOTLINLANG); + } + + public void configure(Consumer optionsConfiguration) { + this.configurableStyle.configure(optionsConfiguration); + } + + private FormatterStep createStep() { + return KtfmtStep.create(version, provisioner(), style, options); + } + + public class ConfigurableStyle { + + public void configure(Consumer optionsConfiguration) { + KtfmtStep.KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtStep.KtfmtFormattingOptions(); + optionsConfiguration.accept(ktfmtFormattingOptions); + options = ktfmtFormattingOptions; + replaceStep(createStep()); + } + } + } + + public class KtlintConfig { + + private final String version; + @Nullable + private FileSignature editorConfigPath; + private Map userData; + private Map editorConfigOverride; + + KtlintConfig(String version, Map config, + Map editorConfigOverride) throws IOException { + Objects.requireNonNull(version); + File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); + FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; + this.version = version; + this.editorConfigPath = editorConfigPath; + this.userData = config; + this.editorConfigOverride = editorConfigOverride; + addStep(createStep()); + } + + public KtlintConfig setEditorConfigPath(Object editorConfigPath) throws IOException { + if (editorConfigPath == null) { + this.editorConfigPath = null; + } else { + File editorConfigFile = getProject().file(editorConfigPath); + if (!editorConfigFile.exists()) { + throw new IllegalArgumentException("EditorConfig file does not exist: " + editorConfigFile); + } + this.editorConfigPath = FileSignature.signAsList(editorConfigFile); + } + replaceStep(createStep()); + return this; + } + + public KtlintConfig userData(Map userData) { + // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized + // representation. + this.userData = ImmutableSortedMap.copyOf(userData); + replaceStep(createStep()); + return this; + } + + public KtlintConfig editorConfigOverride(Map editorConfigOverride) { + // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized + // representation. + this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return KtLintStep.create( + version, + provisioner(), + isScript(), + editorConfigPath, + userData, + editorConfigOverride); + } + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index 27d93717f4..21ccb8dd0f 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -17,28 +17,11 @@ import static com.diffplug.spotless.kotlin.KotlinConstants.LICENSE_HEADER_DELIMITER; -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Objects; -import java.util.function.Consumer; - -import javax.annotation.Nullable; import javax.inject.Inject; import org.gradle.api.tasks.SourceSet; -import com.diffplug.common.collect.ImmutableSortedMap; -import com.diffplug.spotless.FileSignature; -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.kotlin.DiktatStep; -import com.diffplug.spotless.kotlin.KtLintStep; -import com.diffplug.spotless.kotlin.KtfmtStep; -import com.diffplug.spotless.kotlin.KtfmtStep.KtfmtFormattingOptions; -import com.diffplug.spotless.kotlin.KtfmtStep.Style; - -public class KotlinExtension extends FormatExtension implements HasBuiltinDelimiterForLicense, JvmLang { +public class KotlinExtension extends BaseKotlinExtension implements HasBuiltinDelimiterForLicense, JvmLang { static final String NAME = "kotlin"; @Inject @@ -56,167 +39,9 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { return licenseHeaderFile(licenseHeaderFile, LICENSE_HEADER_DELIMITER); } - /** Adds the specified version of ktlint. */ - public KotlinFormatExtension ktlint(String version) throws IOException { - Objects.requireNonNull(version); - File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); - FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; - return new KotlinFormatExtension(version, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); - } - - public KotlinFormatExtension ktlint() throws IOException { - return ktlint(KtLintStep.defaultVersion()); - } - - public class KotlinFormatExtension { - - private final String version; - @Nullable - private FileSignature editorConfigPath; - private Map userData; - private Map editorConfigOverride; - - KotlinFormatExtension(String version, @Nullable FileSignature editorConfigPath, Map config, - Map editorConfigOverride) { - this.version = version; - this.editorConfigPath = editorConfigPath; - this.userData = config; - this.editorConfigOverride = editorConfigOverride; - addStep(createStep()); - } - - public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException { - if (editorConfigPath == null) { - this.editorConfigPath = null; - } else { - File editorConfigFile = getProject().file(editorConfigPath); - if (!editorConfigFile.exists()) { - throw new IllegalArgumentException("EditorConfig file does not exist: " + editorConfigFile); - } - this.editorConfigPath = FileSignature.signAsList(editorConfigFile); - } - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension userData(Map userData) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.userData = ImmutableSortedMap.copyOf(userData); - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension editorConfigOverride(Map editorConfigOverride) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return KtLintStep.create(version, provisioner(), false, editorConfigPath, userData, editorConfigOverride); - } - } - - /** Uses the ktfmt jar to format source code. */ - public KtfmtConfig ktfmt() { - return ktfmt(KtfmtStep.defaultVersion()); - } - - /** - * Uses the given version of ktfmt and applies the dropbox style - * option to format source code. - */ - public KtfmtConfig ktfmt(String version) { - Objects.requireNonNull(version); - return new KtfmtConfig(version); - } - - public class KtfmtConfig { - final String version; - Style style; - KtfmtFormattingOptions options; - - private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); - - KtfmtConfig(String version) { - this.version = Objects.requireNonNull(version); - addStep(createStep()); - } - - private ConfigurableStyle style(Style style) { - this.style = style; - replaceStep(createStep()); - return configurableStyle; - } - - public ConfigurableStyle dropboxStyle() { - return style(Style.DROPBOX); - } - - public ConfigurableStyle googleStyle() { - return style(Style.GOOGLE); - } - - public ConfigurableStyle kotlinlangStyle() { - return style(Style.KOTLINLANG); - } - - public void configure(Consumer optionsConfiguration) { - this.configurableStyle.configure(optionsConfiguration); - } - - private FormatterStep createStep() { - return KtfmtStep.create(version, provisioner(), style, options); - } - - public class ConfigurableStyle { - - public void configure(Consumer optionsConfiguration) { - KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtFormattingOptions(); - optionsConfiguration.accept(ktfmtFormattingOptions); - options = ktfmtFormattingOptions; - replaceStep(createStep()); - } - } - } - - /** Adds the specified version of diktat. */ - public DiktatFormatExtension diktat(String version) { - Objects.requireNonNull(version); - return new DiktatFormatExtension(version); - } - - public DiktatFormatExtension diktat() { - return diktat(DiktatStep.defaultVersionDiktat()); - } - - public class DiktatFormatExtension { - - private final String version; - private FileSignature config; - - DiktatFormatExtension(String version) { - this.version = version; - addStep(createStep()); - } - - public DiktatFormatExtension configFile(Object file) throws IOException { - // Specify the path to the configuration file - if (file == null) { - this.config = null; - } else { - this.config = FileSignature.signAsList(getProject().file(file)); - } - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return DiktatStep.create(version, provisioner(), config); - } + @Override + protected boolean isScript() { + return false; } /** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */ diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index 751b649491..5cf2847d62 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -15,26 +15,9 @@ */ package com.diffplug.gradle.spotless; -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Objects; -import java.util.function.Consumer; - -import javax.annotation.Nullable; import javax.inject.Inject; -import com.diffplug.common.collect.ImmutableSortedMap; -import com.diffplug.spotless.FileSignature; -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.kotlin.DiktatStep; -import com.diffplug.spotless.kotlin.KtLintStep; -import com.diffplug.spotless.kotlin.KtfmtStep; -import com.diffplug.spotless.kotlin.KtfmtStep.KtfmtFormattingOptions; -import com.diffplug.spotless.kotlin.KtfmtStep.Style; - -public class KotlinGradleExtension extends FormatExtension { +public class KotlinGradleExtension extends BaseKotlinExtension { private static final String GRADLE_KOTLIN_DSL_FILE_EXTENSION = "*.gradle.kts"; static final String NAME = "kotlinGradle"; @@ -44,173 +27,9 @@ public KotlinGradleExtension(SpotlessExtension spotless) { super(spotless); } - /** Adds the specified version of ktlint. */ - public KotlinFormatExtension ktlint(String version) throws IOException { - Objects.requireNonNull(version, "version"); - File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); - FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; - return new KotlinFormatExtension(version, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); - } - - public KotlinFormatExtension ktlint() throws IOException { - return ktlint(KtLintStep.defaultVersion()); - } - - public class KotlinFormatExtension { - - private final String version; - @Nullable - private FileSignature editorConfigPath; - private Map userData; - private Map editorConfigOverride; - - KotlinFormatExtension(String version, FileSignature editorConfigPath, Map config, - Map editorConfigOverride) { - this.version = version; - this.editorConfigPath = editorConfigPath; - this.userData = config; - this.editorConfigOverride = editorConfigOverride; - addStep(createStep()); - } - - public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException { - if (editorConfigPath == null) { - this.editorConfigPath = null; - } else { - File editorConfigFile = getProject().file(editorConfigPath); - if (!editorConfigFile.exists()) { - throw new IllegalArgumentException("EditorConfig file does not exist: " + editorConfigFile); - } - this.editorConfigPath = FileSignature.signAsList(editorConfigFile); - } - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension userData(Map userData) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.userData = ImmutableSortedMap.copyOf(userData); - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension editorConfigOverride(Map editorConfigOverride) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return KtLintStep.createForScript( - version, - provisioner(), - editorConfigPath, - userData, - editorConfigOverride); - } - } - - /** Uses the ktfmt jar to format source code. */ - public KtfmtConfig ktfmt() { - return ktfmt(KtfmtStep.defaultVersion()); - } - - /** - * Uses the given version of ktfmt to format source - * code. - */ - public KtfmtConfig ktfmt(String version) { - Objects.requireNonNull(version); - return new KtfmtConfig(version); - } - - public class KtfmtConfig { - final String version; - Style style; - KtfmtFormattingOptions options; - - private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); - - KtfmtConfig(String version) { - this.version = Objects.requireNonNull(version); - this.style = Style.DEFAULT; - addStep(createStep()); - } - - private ConfigurableStyle style(Style style) { - this.style = style; - replaceStep(createStep()); - return configurableStyle; - } - - public ConfigurableStyle dropboxStyle() { - return style(Style.DROPBOX); - } - - public ConfigurableStyle googleStyle() { - return style(Style.GOOGLE); - } - - public ConfigurableStyle kotlinlangStyle() { - return style(Style.KOTLINLANG); - } - - public void configure(Consumer optionsConfiguration) { - this.configurableStyle.configure(optionsConfiguration); - } - - private FormatterStep createStep() { - return KtfmtStep.create(version, provisioner(), style, options); - } - - public class ConfigurableStyle { - - public void configure(Consumer optionsConfiguration) { - KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtFormattingOptions(); - optionsConfiguration.accept(ktfmtFormattingOptions); - options = ktfmtFormattingOptions; - replaceStep(createStep()); - } - } - } - - /** Adds the specified version of diktat. */ - public DiktatFormatExtension diktat(String version) { - Objects.requireNonNull(version, "version"); - return new DiktatFormatExtension(version); - } - - public DiktatFormatExtension diktat() { - return diktat(DiktatStep.defaultVersionDiktat()); - } - - public class DiktatFormatExtension { - - private final String version; - private FileSignature config; - - DiktatFormatExtension(String version) { - this.version = version; - addStep(createStep()); - } - - public DiktatFormatExtension configFile(Object file) throws IOException { - // Specify the path to the configuration file - if (file == null) { - this.config = null; - } else { - this.config = FileSignature.signAsList(getProject().file(file)); - } - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return DiktatStep.createForScript(version, provisioner(), config); - } + @Override + protected boolean isScript() { + return true; } @Override From a392c72e4383952faa564b892e38357666986cf9 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 19 Nov 2023 18:22:11 +0800 Subject: [PATCH 0979/1120] Clean up BaseKotlinExtension --- .../gradle/spotless/BaseKotlinExtension.java | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java index 5ced54a94e..69de375800 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -31,8 +31,8 @@ import com.diffplug.spotless.kotlin.KtLintStep; import com.diffplug.spotless.kotlin.KtfmtStep; -public abstract class BaseKotlinExtension extends FormatExtension { - public BaseKotlinExtension(SpotlessExtension spotless) { +abstract class BaseKotlinExtension extends FormatExtension { + protected BaseKotlinExtension(SpotlessExtension spotless) { super(spotless); } @@ -70,11 +70,10 @@ public KtfmtConfig ktfmt(String version) { protected abstract boolean isScript(); public class DiktatConfig { - private final String version; private FileSignature config; - DiktatConfig(String version) { + private DiktatConfig(String version) { Objects.requireNonNull(version, "version"); this.version = version; addStep(createStep()); @@ -97,24 +96,17 @@ private FormatterStep createStep() { } public class KtfmtConfig { - final String version; - KtfmtStep.Style style; - KtfmtStep.KtfmtFormattingOptions options; - + private final String version; private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); + private KtfmtStep.Style style; + private KtfmtStep.KtfmtFormattingOptions options; - KtfmtConfig(String version) { + private KtfmtConfig(String version) { Objects.requireNonNull(version); this.version = Objects.requireNonNull(version); addStep(createStep()); } - private ConfigurableStyle style(KtfmtStep.Style style) { - this.style = style; - replaceStep(createStep()); - return configurableStyle; - } - public ConfigurableStyle dropboxStyle() { return style(KtfmtStep.Style.DROPBOX); } @@ -131,13 +123,18 @@ public void configure(Consumer optionsConfigur this.configurableStyle.configure(optionsConfiguration); } + private ConfigurableStyle style(KtfmtStep.Style style) { + this.style = style; + replaceStep(createStep()); + return configurableStyle; + } + private FormatterStep createStep() { return KtfmtStep.create(version, provisioner(), style, options); } public class ConfigurableStyle { - - public void configure(Consumer optionsConfiguration) { + private void configure(Consumer optionsConfiguration) { KtfmtStep.KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtStep.KtfmtFormattingOptions(); optionsConfiguration.accept(ktfmtFormattingOptions); options = ktfmtFormattingOptions; @@ -147,26 +144,26 @@ public void configure(Consumer optionsConfigur } public class KtlintConfig { - private final String version; - @Nullable private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KtlintConfig(String version, Map config, + private KtlintConfig( + String version, + Map userData, Map editorConfigOverride) throws IOException { Objects.requireNonNull(version); File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; this.version = version; this.editorConfigPath = editorConfigPath; - this.userData = config; + this.userData = userData; this.editorConfigOverride = editorConfigOverride; addStep(createStep()); } - public KtlintConfig setEditorConfigPath(Object editorConfigPath) throws IOException { + public KtlintConfig setEditorConfigPath(@Nullable Object editorConfigPath) throws IOException { if (editorConfigPath == null) { this.editorConfigPath = null; } else { From 7cb08d1a4c6e5e44a8279c7abe5149d8782f6794 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 19 Nov 2023 18:37:58 +0800 Subject: [PATCH 0980/1120] Remove unused userData param in Ktlint format step We don't need this param anymore. --- .../compat/KtLintCompat0Dot48Dot0Adapter.java | 9 ++++++--- .../compat/KtLintCompat0Dot49Dot0Adapter.java | 9 ++++++--- .../compat/KtLintCompat0Dot50Dot0Adapter.java | 9 ++++++--- .../compat/KtLintCompat1Dot0Dot0Adapter.java | 9 ++++++--- .../glue/ktlint/compat/KtLintCompatAdapter.java | 6 +++++- .../glue/ktlint/KtlintFormatterFunc.java | 6 ++---- .../com/diffplug/spotless/kotlin/KtLintStep.java | 16 ++++++---------- .../KtLintCompat0Dot48Dot0AdapterTest.java | 8 ++------ .../KtLintCompat0Dot49Dot0AdapterTest.java | 8 ++------ .../KtLintCompat0Dot50Dot0AdapterTest.java | 8 ++------ .../compat/KtLintCompat1Dot0Dot0AdapterTest.java | 8 ++------ plugin-gradle/README.md | 3 +-- .../gradle/spotless/BaseKotlinExtension.java | 14 +------------- .../diffplug/spotless/maven/kotlin/Ktlint.java | 3 +-- 14 files changed, 48 insertions(+), 68 deletions(-) diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 418720aa59..b409552031 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -73,9 +73,12 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format( + String text, + Path path, + boolean isScript, + Path editorConfigPath, + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV2.class, RuleSetProviderV2.class.getClassLoader()) diff --git a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java index ad228c131d..b524ca0e91 100644 --- a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java @@ -119,9 +119,12 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format( + String text, + Path path, + boolean isScript, + Path editorConfigPath, + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) diff --git a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java index f7c61439de..b78a539b76 100644 --- a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java @@ -82,9 +82,12 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format( + String text, + Path path, + boolean isScript, + Path editorConfigPath, + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index 119cb86373..c38203b900 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -82,9 +82,12 @@ public Unit invoke(LintError lint, Boolean corrected) { } @Override - public String format(final String text, Path path, final boolean isScript, - Path editorConfigPath, final Map userData, - final Map editorConfigOverrideMap) { + public String format( + String text, + Path path, + boolean isScript, + Path editorConfigPath, + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 5e5e5fb445..5cbbac843c 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -20,6 +20,10 @@ public interface KtLintCompatAdapter { - String format(String text, Path path, boolean isScript, Path editorConfigPath, Map userData, + String format( + String text, + Path path, + boolean isScript, + Path editorConfigPath, Map editorConfigOverrideMap); } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 7ae0222566..870d3d4139 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -25,13 +25,12 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { - private final Map userData; private final boolean isScript; private final KtLintCompatAdapter adapter; private final FileSignature editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath, Map userData, + public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath, Map editorConfigOverrideMap) { String[] versions = version.split("\\."); int majorVersion = Integer.parseInt(versions[0]); @@ -58,7 +57,6 @@ public KtlintFormatterFunc(String version, boolean isScript, FileSignature edito } this.editorConfigPath = editorConfigPath; this.editorConfigOverrideMap = editorConfigOverrideMap; - this.userData = userData; this.isScript = isScript; } @@ -69,6 +67,6 @@ public String applyWithFile(String unix, File file) { if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } - return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, userData, editorConfigOverrideMap); + return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 13fba97c57..7c6801a2b6 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -46,24 +46,23 @@ public static FormatterStep create(Provisioner provisioner) { } public static FormatterStep create(String version, Provisioner provisioner) { - return create(version, provisioner, Collections.emptyMap(), Collections.emptyMap()); + return create(version, provisioner, Collections.emptyMap()); } public static FormatterStep create(String version, Provisioner provisioner, - Map userData, Map editorConfigOverride) { - return create(version, provisioner, false, null, userData, editorConfigOverride); + Map editorConfigOverride) { + return create(version, provisioner, false, null, editorConfigOverride); } public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, @Nullable FileSignature editorConfig, - Map userData, Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, isScript, editorConfig, userData, editorConfigOverride), + () -> new State(version, provisioner, isScript, editorConfig, editorConfigOverride), State::createFormat); } @@ -78,7 +77,6 @@ static final class State implements Serializable { private final boolean isScript; /** The jar that contains the formatter. */ final JarState jarState; - private final TreeMap userData; private final TreeMap editorConfigOverride; private final String version; @Nullable @@ -88,10 +86,8 @@ static final class State implements Serializable { Provisioner provisioner, boolean isScript, @Nullable FileSignature editorConfigPath, - Map userData, Map editorConfigOverride) throws IOException { this.version = version; - this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); this.jarState = JarState.from((version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version, provisioner); @@ -103,8 +99,8 @@ FormatterFunc createFormat() throws Exception { final ClassLoader classLoader = jarState.getClassLoader(); Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); Constructor constructor = formatterFunc.getConstructor( - String.class, boolean.class, FileSignature.class, Map.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, userData, editorConfigOverride); + String.class, boolean.class, FileSignature.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, editorConfigOverride); } } } diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index 7fc9d1d9a4..4ad5bf46cc 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -36,11 +36,9 @@ public void testDefaults(@TempDir Path path) throws IOException { String text = loadAndWriteText(path, "empty_class_body.kt"); final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @@ -50,15 +48,13 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { String text = loadAndWriteText(path, "fails_no_semicolons.kt"); final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); // ktlint_filename is an invalid rule in ktlint 0.48.0 editorConfigOverrideMap.put("ktlint_filename", "disabled"); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java index a0db6ecddc..50897d875f 100644 --- a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java @@ -36,11 +36,9 @@ public void testDefaults(@TempDir Path path) throws IOException { String text = loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -50,13 +48,11 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java index f5b76ccae0..a44ee93386 100644 --- a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java @@ -36,11 +36,9 @@ public void testDefaults(@TempDir Path path) throws IOException { String text = loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -50,13 +48,11 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java index 1f8e6023b4..a62ab22610 100644 --- a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -36,11 +36,9 @@ public void testDefaults(@TempDir Path path) throws IOException { String text = loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -50,13 +48,11 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); - Map userData = new HashMap<>(); - Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 64c8845d25..3341bb29ef 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -399,9 +399,8 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```kotlin spotless { kotlin { - // version, userData and editorConfigOverride are all optional + // version, editorConfigPath and editorConfigOverride are all optional ktlint("1.0.0") - .userData(mapOf("android" to "true")) .setEditorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement .editorConfigOverride( mapOf( diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java index 69de375800..e446ce67c4 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -51,7 +51,7 @@ public KtlintConfig ktlint() throws IOException { /** Adds the specified version of ktlint. */ public KtlintConfig ktlint(String version) throws IOException { - return new KtlintConfig(version, Collections.emptyMap(), Collections.emptyMap()); + return new KtlintConfig(version, Collections.emptyMap()); } /** Uses the ktfmt jar to format source code. */ @@ -146,19 +146,16 @@ private void configure(Consumer optionsConfigu public class KtlintConfig { private final String version; private FileSignature editorConfigPath; - private Map userData; private Map editorConfigOverride; private KtlintConfig( String version, - Map userData, Map editorConfigOverride) throws IOException { Objects.requireNonNull(version); File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; this.version = version; this.editorConfigPath = editorConfigPath; - this.userData = userData; this.editorConfigOverride = editorConfigOverride; addStep(createStep()); } @@ -177,14 +174,6 @@ public KtlintConfig setEditorConfigPath(@Nullable Object editorConfigPath) throw return this; } - public KtlintConfig userData(Map userData) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.userData = ImmutableSortedMap.copyOf(userData); - replaceStep(createStep()); - return this; - } - public KtlintConfig editorConfigOverride(Map editorConfigOverride) { // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized // representation. @@ -199,7 +188,6 @@ private FormatterStep createStep() { provisioner(), isScript(), editorConfigPath, - userData, editorConfigOverride); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index fd59d8ba9d..1fc0e75ad3 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.maven.kotlin; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -48,6 +47,6 @@ public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { editorConfigOverride = new HashMap<>(); } - return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, configPath, Collections.emptyMap(), editorConfigOverride); + return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, configPath, editorConfigOverride); } } From cb6a7888c3ff7a4f88192530f7f11c885e432338 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 20 Nov 2023 01:42:46 +0800 Subject: [PATCH 0981/1120] Reuse configs for GroovyExtension and GroovyGradleExtension --- .../gradle/spotless/BaseGroovyExtension.java | 75 +++++++++++++++++++ .../gradle/spotless/GroovyExtension.java | 56 +------------- .../spotless/GroovyGradleExtension.java | 26 +------ 3 files changed, 79 insertions(+), 78 deletions(-) create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java new file mode 100644 index 0000000000..6aa28d1853 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java @@ -0,0 +1,75 @@ +/* + * 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.gradle.spotless; + +import static com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull; + +import java.util.Map; +import java.util.Objects; + +import org.gradle.api.Project; + +import com.diffplug.spotless.extra.EquoBasedStepBuilder; +import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; +import com.diffplug.spotless.java.ImportOrderStep; + +abstract class BaseGroovyExtension extends FormatExtension { + protected BaseGroovyExtension(SpotlessExtension spotless) { + super(spotless); + } + + public void importOrder(String... importOrder) { + addStep(ImportOrderStep.forGroovy().createFrom(importOrder)); + } + + public void importOrderFile(Object importOrderFile) { + Objects.requireNonNull(importOrderFile); + addStep(ImportOrderStep.forGroovy().createFrom(getProject().file(importOrderFile))); + } + + public GrEclipseConfig greclipse() { + return greclipse(GrEclipseFormatterStep.defaultVersion()); + } + + public GrEclipseConfig greclipse(String version) { + return new GrEclipseConfig(version, this); + } + + public static class GrEclipseConfig { + private final EquoBasedStepBuilder builder; + private final FormatExtension extension; + + private GrEclipseConfig(String version, FormatExtension extension) { + this.extension = extension; + builder = GrEclipseFormatterStep.createBuilder(extension.provisioner()); + builder.setVersion(version); + extension.addStep(builder.build()); + } + + public void configFile(Object... configFiles) { + requireElementsNonNull(configFiles); + Project project = extension.getProject(); + builder.setPreferences(project.files(configFiles).getFiles()); + extension.replaceStep(builder.build()); + } + + public GrEclipseConfig withP2Mirrors(Map mirrors) { + builder.setP2Mirrors(mirrors); + extension.replaceStep(builder.build()); + return this; + } + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java index a7f3d98ce4..676bed0aea 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java @@ -15,27 +15,19 @@ */ package com.diffplug.gradle.spotless; -import static com.diffplug.gradle.spotless.PluginGradlePreconditions.requireElementsNonNull; - -import java.util.Map; -import java.util.Objects; - import javax.inject.Inject; import org.gradle.api.GradleException; -import org.gradle.api.Project; import org.gradle.api.internal.plugins.DslObject; import org.gradle.api.plugins.GroovyBasePlugin; import org.gradle.api.tasks.GroovySourceDirectorySet; import org.gradle.api.tasks.GroovySourceSet; import org.gradle.util.GradleVersion; -import com.diffplug.spotless.extra.EquoBasedStepBuilder; -import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; import com.diffplug.spotless.generic.LicenseHeaderStep; -import com.diffplug.spotless.java.ImportOrderStep; -public class GroovyExtension extends FormatExtension implements HasBuiltinDelimiterForLicense, JvmLang { +public class GroovyExtension extends BaseGroovyExtension implements HasBuiltinDelimiterForLicense, JvmLang { + private boolean excludeJava = false; static final String NAME = "groovy"; @Inject @@ -43,8 +35,6 @@ public GroovyExtension(SpotlessExtension spotless) { super(spotless); } - boolean excludeJava = false; - /** Excludes .java files, to focus on only .groovy files. */ public void excludeJava() { excludeJava(true); @@ -65,48 +55,6 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { return licenseHeaderFile(licenseHeaderFile, JavaExtension.LICENSE_HEADER_DELIMITER); } - public void importOrder(String... importOrder) { - addStep(ImportOrderStep.forGroovy().createFrom(importOrder)); - } - - public void importOrderFile(Object importOrderFile) { - Objects.requireNonNull(importOrderFile); - addStep(ImportOrderStep.forGroovy().createFrom(getProject().file(importOrderFile))); - } - - public GrEclipseConfig greclipse() { - return greclipse(GrEclipseFormatterStep.defaultVersion()); - } - - public GrEclipseConfig greclipse(String version) { - return new GrEclipseConfig(version, this); - } - - public static class GrEclipseConfig { - private final EquoBasedStepBuilder builder; - private final FormatExtension extension; - - GrEclipseConfig(String version, FormatExtension extension) { - this.extension = extension; - builder = GrEclipseFormatterStep.createBuilder(extension.provisioner()); - builder.setVersion(version); - extension.addStep(builder.build()); - } - - public void configFile(Object... configFiles) { - requireElementsNonNull(configFiles); - Project project = extension.getProject(); - builder.setPreferences(project.files(configFiles).getFiles()); - extension.replaceStep(builder.build()); - } - - public GrEclipseConfig withP2Mirrors(Map mirrors) { - builder.setP2Mirrors(mirrors); - extension.replaceStep(builder.build()); - return this; - } - } - /** If the user hasn't specified the files yet, we'll assume he/she means all of the groovy files. */ @Override protected void setupTask(SpotlessTask task) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java index 30cb75a2a3..120f99f27a 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -15,14 +15,9 @@ */ package com.diffplug.gradle.spotless; -import java.util.Objects; - import javax.inject.Inject; -import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; -import com.diffplug.spotless.java.ImportOrderStep; - -public class GroovyGradleExtension extends FormatExtension { +public class GroovyGradleExtension extends BaseGroovyExtension { private static final String GRADLE_FILE_EXTENSION = "*.gradle"; static final String NAME = "groovyGradle"; @@ -31,23 +26,6 @@ public GroovyGradleExtension(SpotlessExtension spotless) { super(spotless); } - public void importOrder(String... importOrder) { - addStep(ImportOrderStep.forGroovy().createFrom(importOrder)); - } - - public void importOrderFile(Object importOrderFile) { - Objects.requireNonNull(importOrderFile); - addStep(ImportOrderStep.forGroovy().createFrom(getProject().file(importOrderFile))); - } - - public GroovyExtension.GrEclipseConfig greclipse() { - return new GroovyExtension.GrEclipseConfig(GrEclipseFormatterStep.defaultVersion(), this); - } - - public GroovyExtension.GrEclipseConfig greclipse(String version) { - return new GroovyExtension.GrEclipseConfig(version, this); - } - @Override protected void setupTask(SpotlessTask task) { if (target == null) { From 705e72a7d66efc083e3a87997413f43b2682b756 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 21 Nov 2023 10:41:11 +0800 Subject: [PATCH 0982/1120] Support custom rule sets for Ktlint --- CHANGES.md | 2 ++ .../diffplug/spotless/kotlin/KtLintStep.java | 19 ++++++++++----- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 7 +++++- .../gradle/spotless/BaseKotlinExtension.java | 18 +++++++++++--- .../gradle/spotless/KotlinExtensionTest.java | 24 +++++++++++++++++++ plugin-maven/CHANGES.md | 1 + plugin-maven/README.md | 3 +++ .../spotless/maven/kotlin/Ktlint.java | 9 ++++++- .../spotless/maven/kotlin/KtlintTest.java | 18 ++++++++++++++ .../resources/kotlin/ktlint/listScreen.dirty | 6 +++++ 11 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 testlib/src/main/resources/kotlin/ktlint/listScreen.dirty diff --git a/CHANGES.md b/CHANGES.md index c1a11e3a0a..404363e199 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896) ### Fixed * Fix Eclipse JDT on some settings files. ([#1864](https://github.com/diffplug/spotless/pull/1864) fixes [#1638](https://github.com/diffplug/spotless/issues/1638)) ### Changes diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 7c6801a2b6..e131b2b46f 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -19,8 +19,11 @@ import java.io.Serializable; import java.lang.reflect.Constructor; import java.util.Collections; +import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.TreeMap; import javax.annotation.Nullable; @@ -51,18 +54,19 @@ public static FormatterStep create(String version, Provisioner provisioner) { public static FormatterStep create(String version, Provisioner provisioner, Map editorConfigOverride) { - return create(version, provisioner, false, null, editorConfigOverride); + return create(version, provisioner, false, null, editorConfigOverride, Collections.emptyList()); } public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, @Nullable FileSignature editorConfig, - Map editorConfigOverride) { + Map editorConfigOverride, + List customRuleSets) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, isScript, editorConfig, editorConfigOverride), + () -> new State(version, provisioner, isScript, editorConfig, editorConfigOverride, customRuleSets), State::createFormat); } @@ -86,11 +90,14 @@ static final class State implements Serializable { Provisioner provisioner, boolean isScript, @Nullable FileSignature editorConfigPath, - Map editorConfigOverride) throws IOException { + Map editorConfigOverride, + List customRuleSets) throws IOException { this.version = version; this.editorConfigOverride = new TreeMap<>(editorConfigOverride); - this.jarState = JarState.from((version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version, - provisioner); + String ktlintCoordinate = (version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version; + Set mavenCoordinates = new HashSet<>(customRuleSets); + mavenCoordinates.add(ktlintCoordinate); + this.jarState = JarState.from(mavenCoordinates, provisioner); this.editorConfigPath = editorConfigPath; this.isScript = isScript; } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 9d833b0076..04d3e9bb38 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896) ### Fixed * Fix Eclipse JDT on some settings files. ([#1864](https://github.com/diffplug/spotless/pull/1864) fixes [#1638](https://github.com/diffplug/spotless/issues/1638)) * Check if EditorConfig file exist for Ktlint in KotlinGradleExtension. ([#1889](https://github.com/diffplug/spotless/pull/1889) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 3341bb29ef..6232f9c0e1 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -399,7 +399,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```kotlin spotless { kotlin { - // version, editorConfigPath and editorConfigOverride are all optional + // version, editorConfigPath, editorConfigOverride and customRuleSets are all optional ktlint("1.0.0") .setEditorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement .editorConfigOverride( @@ -407,6 +407,11 @@ spotless { "indent_size" to 2, ) ) + .customRuleSets( + listOf( + "io.nlopez.compose.rules:ktlint:0.3.3" + ) + ) } } ``` diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java index e446ce67c4..0d89e224f6 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -18,12 +18,14 @@ import java.io.File; import java.io.IOException; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Consumer; import javax.annotation.Nullable; +import com.diffplug.common.collect.ImmutableList; import com.diffplug.common.collect.ImmutableSortedMap; import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterStep; @@ -51,7 +53,7 @@ public KtlintConfig ktlint() throws IOException { /** Adds the specified version of ktlint. */ public KtlintConfig ktlint(String version) throws IOException { - return new KtlintConfig(version, Collections.emptyMap()); + return new KtlintConfig(version, Collections.emptyMap(), Collections.emptyList()); } /** Uses the ktfmt jar to format source code. */ @@ -147,16 +149,19 @@ public class KtlintConfig { private final String version; private FileSignature editorConfigPath; private Map editorConfigOverride; + private List customRuleSets; private KtlintConfig( String version, - Map editorConfigOverride) throws IOException { + Map editorConfigOverride, + List customRuleSets) throws IOException { Objects.requireNonNull(version); File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; this.version = version; this.editorConfigPath = editorConfigPath; this.editorConfigOverride = editorConfigOverride; + this.customRuleSets = customRuleSets; addStep(createStep()); } @@ -182,13 +187,20 @@ public KtlintConfig editorConfigOverride(Map editorConfigOverrid return this; } + public KtlintConfig customRuleSets(List customRuleSets) { + this.customRuleSets = ImmutableList.copyOf(customRuleSets); + replaceStep(createStep()); + return this; + } + private FormatterStep createStep() { return KtLintStep.create( version, provisioner(), isScript(), editorConfigPath, - editorConfigOverride); + editorConfigOverride, + customRuleSets); } } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 7ce1819d60..dd0f2f5e21 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -141,6 +141,30 @@ void testSetEditorConfigCanOverrideEditorConfigFile() throws IOException { checkKtlintOfficialStyle(); } + @Test + void withCustomRuleSetApply() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'com.diffplug.spotless'", + "}", + "repositories { mavenCentral() }", + "spotless {", + " kotlin {", + " ktlint(\"1.0.1\")", + " .customRuleSets([", + " \"io.nlopez.compose.rules:ktlint:0.3.3\"", + " ])", + " .editorConfigOverride([", + " ktlint_function_naming_ignore_when_annotated_with: \"Composable\",", + " ])", + " }", + "}"); + setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/listScreen.dirty"); + String buildOutput = gradleRunner().withArguments("spotlessCheck").buildAndFail().getOutput(); + assertThat(buildOutput).contains("Composable functions that return Unit should start with an uppercase letter."); + } + @Test void testWithHeader() throws IOException { setFile("build.gradle").toLines( diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 10ebfc57c1..5122402019 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * CompileSourceRoots and TestCompileSourceRoots are now respected as default includes. These properties are commonly set when adding extra source directories. ([#1846](https://github.com/diffplug/spotless/issues/1846)) +* Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896) ### Fixed * Fix crash when build dir is a softlink to another directory. ([#1859](https://github.com/diffplug/spotless/pull/1859)) * Fix Eclipse JDT on some settings files. ([#1864](https://github.com/diffplug/spotless/pull/1864) fixes [#1638](https://github.com/diffplug/spotless/issues/1638)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 7944b5a450..f7849fbdfc 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -416,6 +416,9 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. true true + + io.nlopez.compose.rules:ktlint:0.3.3 + ``` diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 1fc0e75ad3..5c939687b8 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -15,7 +15,9 @@ */ package com.diffplug.spotless.maven.kotlin; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.maven.plugins.annotations.Parameter; @@ -35,6 +37,8 @@ public class Ktlint implements FormatterStepFactory { private String editorConfigPath; @Parameter private Map editorConfigOverride; + @Parameter + private List customRuleSets; @Override public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { @@ -46,7 +50,10 @@ public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { if (editorConfigOverride == null) { editorConfigOverride = new HashMap<>(); } + if (customRuleSets == null) { + customRuleSets = Collections.emptyList(); + } - return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, configPath, editorConfigOverride); + return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, configPath, editorConfigOverride, customRuleSets); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index 2916e118a5..fe5b0e1b57 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -15,8 +15,11 @@ */ package com.diffplug.spotless.maven.kotlin; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.Test; +import com.diffplug.spotless.ProcessRunner; import com.diffplug.spotless.maven.MavenIntegrationHarness; class KtlintTest extends MavenIntegrationHarness { @@ -63,6 +66,21 @@ void testSetEditorConfigCanOverrideEditorConfigFile() throws Exception { checkKtlintOfficialStyle(); } + @Test + void testWithCustomRuleSetApply() throws Exception { + writePomWithKotlinSteps("\n" + + " \n" + + " io.nlopez.compose.rules:ktlint:0.3.3\n" + + " \n" + + " \n" + + " Composable\n" + + " \n" + + ""); + setFile("src/main/kotlin/Main.kt").toResource("kotlin/ktlint/listScreen.dirty"); + ProcessRunner.Result result = mavenRunner().withArguments("spotless:check").runHasError(); + assertTrue(result.toString().contains("Composable functions that return Unit should start with an uppercase letter.")); + } + private void checkKtlintOfficialStyle() throws Exception { String path = "src/main/kotlin/Main.kt"; setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); diff --git a/testlib/src/main/resources/kotlin/ktlint/listScreen.dirty b/testlib/src/main/resources/kotlin/ktlint/listScreen.dirty new file mode 100644 index 0000000000..14c06d6d43 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktlint/listScreen.dirty @@ -0,0 +1,6 @@ +import androidx.compose.runtime.Composable + +@Composable +fun listScreen() { + val list: List = mutableListOf() +} From 8bbed1f6f2289bbc79645257851f619e0706ab84 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 21 Nov 2023 11:49:22 +0800 Subject: [PATCH 0983/1120] Remove unused isScript param in Ktlint format step --- .../compat/KtLintCompat0Dot48Dot0Adapter.java | 1 - .../compat/KtLintCompat0Dot49Dot0Adapter.java | 1 - .../compat/KtLintCompat0Dot50Dot0Adapter.java | 1 - .../compat/KtLintCompat1Dot0Dot0Adapter.java | 1 - .../ktlint/compat/KtLintCompatAdapter.java | 1 - .../glue/ktlint/KtlintFormatterFunc.java | 6 ++---- .../diffplug/spotless/kotlin/KtLintStep.java | 19 ++++--------------- .../KtLintCompat0Dot48Dot0AdapterTest.java | 4 ++-- .../KtLintCompat0Dot49Dot0AdapterTest.java | 4 ++-- .../KtLintCompat0Dot50Dot0AdapterTest.java | 4 ++-- .../KtLintCompat1Dot0Dot0AdapterTest.java | 4 ++-- .../gradle/spotless/BaseKotlinExtension.java | 1 - .../spotless/maven/kotlin/Ktlint.java | 2 +- 13 files changed, 15 insertions(+), 34 deletions(-) diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index b409552031..d7e997abaf 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -76,7 +76,6 @@ public Unit invoke(LintError lint, Boolean corrected) { public String format( String text, Path path, - boolean isScript, Path editorConfigPath, Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java index b524ca0e91..ea8698cfe8 100644 --- a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java @@ -122,7 +122,6 @@ public Unit invoke(LintError lint, Boolean corrected) { public String format( String text, Path path, - boolean isScript, Path editorConfigPath, Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java index b78a539b76..c792e2bb62 100644 --- a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java @@ -85,7 +85,6 @@ public Unit invoke(LintError lint, Boolean corrected) { public String format( String text, Path path, - boolean isScript, Path editorConfigPath, Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index c38203b900..ac90893157 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -85,7 +85,6 @@ public Unit invoke(LintError lint, Boolean corrected) { public String format( String text, Path path, - boolean isScript, Path editorConfigPath, Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 5cbbac843c..e508633b95 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -23,7 +23,6 @@ public interface KtLintCompatAdapter { String format( String text, Path path, - boolean isScript, Path editorConfigPath, Map editorConfigOverrideMap); } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 870d3d4139..ec5fbcb67b 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -25,12 +25,11 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { - private final boolean isScript; private final KtLintCompatAdapter adapter; private final FileSignature editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath, + public KtlintFormatterFunc(String version, FileSignature editorConfigPath, Map editorConfigOverrideMap) { String[] versions = version.split("\\."); int majorVersion = Integer.parseInt(versions[0]); @@ -57,7 +56,6 @@ public KtlintFormatterFunc(String version, boolean isScript, FileSignature edito } this.editorConfigPath = editorConfigPath; this.editorConfigOverrideMap = editorConfigOverrideMap; - this.isScript = isScript; } @Override @@ -67,6 +65,6 @@ public String applyWithFile(String unix, File file) { if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } - return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, editorConfigOverrideMap); + return adapter.format(unix, file.toPath(), absoluteEditorConfigPath, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 7c6801a2b6..856b39cc4a 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -46,23 +46,17 @@ public static FormatterStep create(Provisioner provisioner) { } public static FormatterStep create(String version, Provisioner provisioner) { - return create(version, provisioner, Collections.emptyMap()); - } - - public static FormatterStep create(String version, Provisioner provisioner, - Map editorConfigOverride) { - return create(version, provisioner, false, null, editorConfigOverride); + return create(version, provisioner, null, Collections.emptyMap()); } public static FormatterStep create(String version, Provisioner provisioner, - boolean isScript, @Nullable FileSignature editorConfig, Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, isScript, editorConfig, editorConfigOverride), + () -> new State(version, provisioner, editorConfig, editorConfigOverride), State::createFormat); } @@ -72,9 +66,6 @@ public static String defaultVersion() { static final class State implements Serializable { private static final long serialVersionUID = 1L; - - /** Are the files being linted Kotlin script files. */ - private final boolean isScript; /** The jar that contains the formatter. */ final JarState jarState; private final TreeMap editorConfigOverride; @@ -84,7 +75,6 @@ static final class State implements Serializable { State(String version, Provisioner provisioner, - boolean isScript, @Nullable FileSignature editorConfigPath, Map editorConfigOverride) throws IOException { this.version = version; @@ -92,15 +82,14 @@ static final class State implements Serializable { this.jarState = JarState.from((version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version, provisioner); this.editorConfigPath = editorConfigPath; - this.isScript = isScript; } FormatterFunc createFormat() throws Exception { final ClassLoader classLoader = jarState.getClassLoader(); Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); Constructor constructor = formatterFunc.getConstructor( - String.class, boolean.class, FileSignature.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, editorConfigOverride); + String.class, FileSignature.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(version, editorConfigPath, editorConfigOverride); } } } diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index 4ad5bf46cc..bab3764147 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @@ -54,7 +54,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { // ktlint_filename is an invalid rule in ktlint 0.48.0 editorConfigOverrideMap.put("ktlint_filename", "disabled"); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java index 50897d875f..5804c0b2d7 100644 --- a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -52,7 +52,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java index a44ee93386..1a1f595991 100644 --- a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -52,7 +52,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java index a62ab22610..1d36082815 100644 --- a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -52,7 +52,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java index e446ce67c4..ac6a03c2b8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -186,7 +186,6 @@ private FormatterStep createStep() { return KtLintStep.create( version, provisioner(), - isScript(), editorConfigPath, editorConfigOverride); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 1fc0e75ad3..fa033dd2e7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -47,6 +47,6 @@ public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { editorConfigOverride = new HashMap<>(); } - return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, configPath, editorConfigOverride); + return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), configPath, editorConfigOverride); } } From 0bd1d066a2ae865a64d5d08adc6fe03443383498 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 21 Nov 2023 12:25:22 +0800 Subject: [PATCH 0984/1120] Remove unused text param in KtLintCompatAdapter --- .../glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java | 1 - .../glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java | 1 - .../glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java | 1 - .../glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java | 1 - .../spotless/glue/ktlint/compat/KtLintCompatAdapter.java | 1 - .../spotless/glue/ktlint/KtlintFormatterFunc.java | 3 +-- .../ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java | 8 ++++---- .../ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java | 8 ++++---- .../ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java | 8 ++++---- .../ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java | 8 ++++---- 10 files changed, 17 insertions(+), 23 deletions(-) diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index d7e997abaf..32ef497de8 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -74,7 +74,6 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( - String text, Path path, Path editorConfigPath, Map editorConfigOverrideMap) { diff --git a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java index ea8698cfe8..1ad52da661 100644 --- a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java @@ -120,7 +120,6 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( - String text, Path path, Path editorConfigPath, Map editorConfigOverrideMap) { diff --git a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java index c792e2bb62..2c7fff3f2e 100644 --- a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java @@ -83,7 +83,6 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( - String text, Path path, Path editorConfigPath, Map editorConfigOverrideMap) { diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index ac90893157..e65d0503ba 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -83,7 +83,6 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( - String text, Path path, Path editorConfigPath, Map editorConfigOverrideMap) { diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index e508633b95..1bfa0da6da 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -21,7 +21,6 @@ public interface KtLintCompatAdapter { String format( - String text, Path path, Path editorConfigPath, Map editorConfigOverrideMap); diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index ec5fbcb67b..8b2331f3b9 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -60,11 +60,10 @@ public KtlintFormatterFunc(String version, FileSignature editorConfigPath, @Override public String applyWithFile(String unix, File file) { - Path absoluteEditorConfigPath = null; if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } - return adapter.format(unix, file.toPath(), absoluteEditorConfigPath, editorConfigOverrideMap); + return adapter.format(file.toPath(), absoluteEditorConfigPath, editorConfigOverrideMap); } } diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index bab3764147..17fe40fb9c 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -33,19 +33,19 @@ public class KtLintCompat0Dot48Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - String text = loadAndWriteText(path, "empty_class_body.kt"); + loadAndWriteText(path, "empty_class_body.kt"); final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - String text = loadAndWriteText(path, "fails_no_semicolons.kt"); + loadAndWriteText(path, "fails_no_semicolons.kt"); final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); Map editorConfigOverrideMap = new HashMap<>(); @@ -54,7 +54,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { // ktlint_filename is an invalid rule in ktlint 0.48.0 editorConfigOverrideMap.put("ktlint_filename", "disabled"); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java index 5804c0b2d7..b34a83ebc3 100644 --- a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java @@ -33,26 +33,26 @@ public class KtLintCompat0Dot49Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); - String text = loadAndWriteText(path, "EmptyClassBody.kt"); + loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); - String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java index 1a1f595991..0bb501a06e 100644 --- a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java @@ -33,26 +33,26 @@ public class KtLintCompat0Dot50Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); - String text = loadAndWriteText(path, "EmptyClassBody.kt"); + loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); - String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java index 1d36082815..0f5f9cf16c 100644 --- a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -33,26 +33,26 @@ public class KtLintCompat1Dot0Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); - String text = loadAndWriteText(path, "EmptyClassBody.kt"); + loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); - String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } From 84693002052c91bceaea4c84a3444106f3f5dedf Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 21 Nov 2023 13:07:27 +0800 Subject: [PATCH 0985/1120] Refine styles --- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 10 +++++++--- .../java/com/diffplug/spotless/kotlin/KtLintStep.java | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 8b2331f3b9..b81e107609 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -24,12 +24,13 @@ import com.diffplug.spotless.glue.ktlint.compat.*; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { - private final KtLintCompatAdapter adapter; private final FileSignature editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, FileSignature editorConfigPath, + public KtlintFormatterFunc( + String version, + FileSignature editorConfigPath, Map editorConfigOverrideMap) { String[] versions = version.split("\\."); int majorVersion = Integer.parseInt(versions[0]); @@ -64,6 +65,9 @@ public String applyWithFile(String unix, File file) { if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } - return adapter.format(file.toPath(), absoluteEditorConfigPath, editorConfigOverrideMap); + return adapter.format( + file.toPath(), + absoluteEditorConfigPath, + editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 856b39cc4a..9564dd7d50 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -37,9 +37,9 @@ public class KtLintStep { private KtLintStep() {} private static final String DEFAULT_VERSION = "1.0.1"; - static final String NAME = "ktlint"; - static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; - static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; + private static final String NAME = "ktlint"; + private static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; + private static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); @@ -67,7 +67,7 @@ public static String defaultVersion() { static final class State implements Serializable { private static final long serialVersionUID = 1L; /** The jar that contains the formatter. */ - final JarState jarState; + private final JarState jarState; private final TreeMap editorConfigOverride; private final String version; @Nullable From a83c2a994b3813b60c165df56654d9e17b8a90e4 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Tue, 21 Nov 2023 14:17:34 +0600 Subject: [PATCH 0986/1120] Add missing bracket in plugin-gradle/CHANGES.md --- plugin-gradle/CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 9d833b0076..c35e7879b1 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Fix Eclipse JDT on some settings files. ([#1864](https://github.com/diffplug/spotless/pull/1864) fixes [#1638](https://github.com/diffplug/spotless/issues/1638)) -* Check if EditorConfig file exist for Ktlint in KotlinGradleExtension. ([#1889](https://github.com/diffplug/spotless/pull/1889) +* Check if EditorConfig file exist for Ktlint in KotlinGradleExtension. ([#1889](https://github.com/diffplug/spotless/pull/1889)) ### Changes * Bump default `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855)) ### Fixed From 6d4a67906d9c5e48aa5c0b745ce81ba30df8ca9c Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 22 Nov 2023 04:48:41 +0800 Subject: [PATCH 0987/1120] Cleanups --- .../java/com/diffplug/spotless/kotlin/KtLintStep.java | 9 ++------- .../java/com/diffplug/spotless/maven/kotlin/Ktlint.java | 9 ++++++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 8fa679e7aa..55b4ca4520 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -49,12 +49,7 @@ public static FormatterStep create(Provisioner provisioner) { } public static FormatterStep create(String version, Provisioner provisioner) { - return create(version, provisioner, Collections.emptyMap()); - } - - public static FormatterStep create(String version, Provisioner provisioner, - Map editorConfigOverride) { - return create(version, provisioner, null, editorConfigOverride, Collections.emptyList()); + return create(version, provisioner, null, Collections.emptyMap(), Collections.emptyList()); } public static FormatterStep create(String version, @@ -73,7 +68,7 @@ public static String defaultVersion() { return DEFAULT_VERSION; } - static final class State implements Serializable { + private static final class State implements Serializable { private static final long serialVersionUID = 1L; /** The jar that contains the formatter. */ private final JarState jarState; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 7fe492ca6e..2459a52828 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -30,7 +30,6 @@ import com.diffplug.spotless.maven.FormatterStepFactory; public class Ktlint implements FormatterStepFactory { - @Parameter private String version; @Parameter @@ -53,7 +52,11 @@ public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { if (customRuleSets == null) { customRuleSets = Collections.emptyList(); } - - return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), configPath, editorConfigOverride, customRuleSets); + return KtLintStep.create( + ktlintVersion, + stepConfig.getProvisioner(), + configPath, + editorConfigOverride, + customRuleSets); } } From 81c3511f3590b789516d41d630643e38ef051fef Mon Sep 17 00:00:00 2001 From: Jose Luis Badano Date: Mon, 6 Nov 2023 00:25:47 -0300 Subject: [PATCH 0988/1120] Add a step to remove semicolons in Groovy files Co-authored-by: Goooler --- CHANGES.md | 1 + .../spotless/groovy/RemoveSemicolonsStep.java | 76 +++++++++++++++++++ plugin-gradle/CHANGES.md | 1 + plugin-gradle/README.md | 2 + .../gradle/spotless/BaseGroovyExtension.java | 5 ++ .../gradle/spotless/GroovyExtensionTest.java | 21 +++++ plugin-maven/CHANGES.md | 1 + plugin-maven/README.md | 2 + .../spotless/maven/groovy/Groovy.java | 4 + .../maven/groovy/RemoveSemicolons.java | 29 +++++++ .../maven/groovy/RemoveSemicolonsTest.java | 52 +++++++++++++ .../GroovyCodeWithSemicolons.test | 10 +++ .../GroovyCodeWithSemicolonsFormatted.test | 10 +++ 13 files changed, 214 insertions(+) create mode 100644 lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/RemoveSemicolons.java create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java create mode 100644 testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolons.test create mode 100644 testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test diff --git a/CHANGES.md b/CHANGES.md index 404363e199..7d7c3dc355 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Fix Eclipse JDT on some settings files. ([#1864](https://github.com/diffplug/spotless/pull/1864) fixes [#1638](https://github.com/diffplug/spotless/issues/1638)) ### Changes * Bump default `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855)) +* Add a Step to remove semicolons from Groovy files. ([#1881](https://github.com/diffplug/spotless/pull/1881)) ## [2.42.0] - 2023-09-28 ### Added diff --git a/lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java b/lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java new file mode 100644 index 0000000000..e24feb5cd3 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/groovy/RemoveSemicolonsStep.java @@ -0,0 +1,76 @@ +/* + * 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.groovy; + +import java.io.BufferedReader; +import java.io.Serializable; +import java.io.StringReader; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; + +/** + * Removes all semicolons from the end of lines. + * + * @author Jose Luis Badano + */ +public final class RemoveSemicolonsStep { + private static final String NAME = "Remove unnecessary semicolons"; + + private RemoveSemicolonsStep() { + // do not instantiate + } + + public static FormatterStep create() { + return FormatterStep.createLazy(NAME, + State::new, + RemoveSemicolonsStep.State::toFormatter); + } + + private static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + FormatterFunc toFormatter() { + return raw -> { + try (BufferedReader reader = new BufferedReader(new StringReader(raw))) { + StringBuilder result = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + result.append(removeSemicolon(line)); + result.append(System.lineSeparator()); + } + return result.toString(); + } + }; + } + + /** + * Removes the last semicolon in a line if it exists. + * + * @param line the line to remove the semicolon from + * @return the line without the last semicolon + */ + private String removeSemicolon(String line) { + // find last semicolon in a string a remove it + int lastSemicolon = line.lastIndexOf(";"); + if (lastSemicolon != -1 && lastSemicolon == line.length() - 1) { + return line.substring(0, lastSemicolon); + } else { + return line; + } + } + } +} diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 32bf1bd7c0..03ddf370f4 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Check if EditorConfig file exist for Ktlint in KotlinGradleExtension. ([#1889](https://github.com/diffplug/spotless/pull/1889)) ### Changes * Bump default `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855)) +* Add a Step to remove semicolons from Groovy files. ([#1881](https://github.com/diffplug/spotless/pull/1881)) ### Fixed * Fix `GoogleJavaFormatConfig.reorderImports` not working. ([#1872](https://github.com/diffplug/spotless/issues/1872)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 6232f9c0e1..6b707a1eaa 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -320,6 +320,8 @@ spotless { // optional: instead of specifying import groups directly you can specify a config file // export config file: https://github.com/diffplug/spotless/blob/main/ECLIPSE_SCREENSHOTS.md#creating-spotlessimportorder importOrderFile('eclipse-import-order.txt') // import order file as exported from eclipse + // removes semicolons at the end of lines + removeSemicolons() excludeJava() // excludes all Java sources within the Groovy source dirs from formatting // the Groovy Eclipse formatter extends the Java Eclipse formatter, diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java index 6aa28d1853..657ef06a66 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseGroovyExtension.java @@ -24,6 +24,7 @@ import com.diffplug.spotless.extra.EquoBasedStepBuilder; import com.diffplug.spotless.extra.groovy.GrEclipseFormatterStep; +import com.diffplug.spotless.groovy.RemoveSemicolonsStep; import com.diffplug.spotless.java.ImportOrderStep; abstract class BaseGroovyExtension extends FormatExtension { @@ -40,6 +41,10 @@ public void importOrderFile(Object importOrderFile) { addStep(ImportOrderStep.forGroovy().createFrom(getProject().file(importOrderFile))); } + public void removeSemicolons() { + addStep(RemoveSemicolonsStep.create()); + } + public GrEclipseConfig greclipse() { return greclipse(GrEclipseFormatterStep.defaultVersion()); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java index c38df40d54..7f87d8793c 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyExtensionTest.java @@ -88,6 +88,27 @@ void excludeJavaWithCustomTarget() throws IOException { assertThat(error).hasMessageContaining("'excludeJava' is not supported"); } + @Test + void removeSemicolons() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "apply plugin: 'groovy'", + "", + "spotless {", + " groovy {", + " removeSemicolons()", + " }", + "}"); + + String withSemicolons = getTestResource("groovy/removeSemicolons/GroovyCodeWithSemicolons.test"); + String withoutSemicolons = getTestResource("groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test"); + setFile("src/main/groovy/test.groovy").toContent(withSemicolons); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/groovy/test.groovy").hasContent(withoutSemicolons); + } + @Test void groovyPluginMissingCheck() throws IOException { setFile("build.gradle").toLines( diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 5122402019..78fb6f84ca 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Fix Eclipse JDT on some settings files. ([#1864](https://github.com/diffplug/spotless/pull/1864) fixes [#1638](https://github.com/diffplug/spotless/issues/1638)) ### Changes * Bump default `ktlint` version to latest `1.0.0` -> `1.0.1`. ([#1855](https://github.com/diffplug/spotless/pull/1855)) +* Add a Step to remove semicolons from Groovy files. ([#1881](https://github.com/diffplug/spotless/pull/1881)) ## [2.40.0] - 2023-09-28 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index f7849fbdfc..5eb523eca2 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -336,6 +336,8 @@ These mechanisms already exist for the Gradle plugin. java|javax,org,com,com.diffplug,,\#com.diffplug,\# + + diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java index 35b91f3677..db4b35dfd6 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/Groovy.java @@ -52,4 +52,8 @@ public void addGreclipse(GrEclipse greclipse) { public void addImportOrder(ImportOrder importOrder) { addStepFactory(importOrder); } + + public void addRemoveSemicolons(RemoveSemicolons removeSemicolons) { + addStepFactory(removeSemicolons); + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/RemoveSemicolons.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/RemoveSemicolons.java new file mode 100644 index 0000000000..a96a078692 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/groovy/RemoveSemicolons.java @@ -0,0 +1,29 @@ +/* + * 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. + * 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.groovy; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.groovy.RemoveSemicolonsStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +public class RemoveSemicolons implements FormatterStepFactory { + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig config) { + return RemoveSemicolonsStep.create(); + } +} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java new file mode 100644 index 0000000000..fc78c87a27 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/groovy/RemoveSemicolonsTest.java @@ -0,0 +1,52 @@ +/* + * 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.groovy; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +class RemoveSemicolonsTest extends MavenIntegrationHarness { + + @Test + void testRemoveSemicolonsString() throws Exception { + writePomWithGroovySteps(""); + runTest("Hello World;", "Hello World"); + } + + @Test + void testNotRemoveSemicolonsString() throws Exception { + writePomWithGroovySteps(""); + runTest("Hello;World", "Hello;World"); + } + + @Test + void testRemoveSemicolons() throws Exception { + writePomWithGroovySteps(""); + + String path = "src/main/groovy/test.groovy"; + setFile(path).toResource("groovy/removeSemicolons/GroovyCodeWithSemicolons.test"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).sameAsResource("groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test"); + } + + private void runTest(String sourceContent, String targetContent) throws Exception { + String path = "src/main/groovy/test.groovy"; + setFile(path).toContent(sourceContent); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile(path).hasContent(targetContent); + } +} diff --git a/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolons.test b/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolons.test new file mode 100644 index 0000000000..b66af4e820 --- /dev/null +++ b/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolons.test @@ -0,0 +1,10 @@ +import mylib.Unused; +import mylib.UsedB; +import mylib.UsedA; + +public class SomeClass { +System.out.println("hello"); +UsedB.someMethod(); +UsedA.someMethod(); +} +} \ No newline at end of file diff --git a/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test b/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test new file mode 100644 index 0000000000..434addfa68 --- /dev/null +++ b/testlib/src/main/resources/groovy/removeSemicolons/GroovyCodeWithSemicolonsFormatted.test @@ -0,0 +1,10 @@ +import mylib.Unused +import mylib.UsedB +import mylib.UsedA + +public class SomeClass { +System.out.println("hello") +UsedB.someMethod() +UsedA.someMethod() +} +} \ No newline at end of file From ad2f3ca8d2adceb1cc10cee131f9bd65ae9b2ac4 Mon Sep 17 00:00:00 2001 From: Goooler Date: Wed, 22 Nov 2023 11:00:23 +0800 Subject: [PATCH 0989/1120] Reorder section about Groovy integration --- plugin-gradle/README.md | 9 ++++++--- plugin-maven/README.md | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 6b707a1eaa..4f6b74bdb7 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -322,13 +322,16 @@ spotless { importOrderFile('eclipse-import-order.txt') // import order file as exported from eclipse // removes semicolons at the end of lines removeSemicolons() - - excludeJava() // excludes all Java sources within the Groovy source dirs from formatting // the Groovy Eclipse formatter extends the Java Eclipse formatter, // so it formats Java files by default (unless `excludeJava` is used). greclipse() // has its own section below + + licenseHeader('/* (C) $YEAR */') // or licenseHeaderFile - licenseHeader '/* (C) $YEAR */' // or licenseHeaderFile + //---- Below is for `groovy` only ---- + + // excludes all Java sources within the Groovy source dirs from formatting + excludeJava() } groovyGradle { target '*.gradle' // default target of groovyGradle diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 5eb523eca2..857597beb2 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -331,16 +331,16 @@ These mechanisms already exist for the Gradle plugin. src/test/groovy/**/*.groovy - + java|javax,org,com,com.diffplug,,\#com.diffplug,\# - - - + + + /* (C)$YEAR */ From 1f78412810a2f325993b05ae026ce558683dc717 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 26 Nov 2023 13:11:57 +0800 Subject: [PATCH 0990/1120] Bump SpotBugs plugin to 5.2.3 https://github.com/spotbugs/spotbugs-gradle-plugin/releases/tag/5.2.3 https://github.com/spotbugs/spotbugs-gradle-plugin?tab=readme-ov-file#refer-the-version-in-the-build-script --- gradle.properties | 1 - gradle/java-setup.gradle | 9 +-------- settings.gradle | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/gradle.properties b/gradle.properties index c65ea39f94..b60fa2f805 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,6 @@ artifactIdGradle=spotless-plugin-gradle # Build requirements VER_JAVA=11 -VER_SPOTBUGS=4.7.3 VER_JSR_305=3.0.2 # Dependencies provided by Spotless plugin diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 5a1e23ef0a..91f2f13e8c 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -14,7 +14,6 @@ tasks.withType(JavaCompile).configureEach { ////////////// apply plugin: 'com.github.spotbugs' spotbugs { - toolVersion = VER_SPOTBUGS ignoreFailures = false // bug free or it doesn't ship! reportLevel = 'medium' // low|medium|high (low = sensitive to even minor mistakes) omitVisitors = [ @@ -30,16 +29,10 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach { reports { html.enabled = true } - notCompatibleWithConfigurationCache("https://github.com/spotbugs/spotbugs-gradle-plugin/issues/670") } -tasks.named('spotbugsMain') { - reports { - html.enabled = true - } -} dependencies { compileOnly 'net.jcip:jcip-annotations:1.0' - compileOnly "com.github.spotbugs:spotbugs-annotations:${VER_SPOTBUGS}" + compileOnly "com.github.spotbugs:spotbugs-annotations:${spotbugs.toolVersion.get()}" compileOnly "com.google.code.findbugs:jsr305:${VER_JSR_305}" } diff --git a/settings.gradle b/settings.gradle index e7b9649cf3..e7e5a6d4ea 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ plugins { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.2.1' apply false + id 'com.github.spotbugs' version '5.2.3' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md id 'com.diffplug.spotless-changelog' version '3.0.2' apply false // https://github.com/diffplug/goomph/blob/main/CHANGES.md From dd344320b5183a20d175d79f3766bde735c8d784 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 26 Nov 2023 15:28:57 +0800 Subject: [PATCH 0991/1120] Omit ConstructorThrow visitor https://spotbugs.readthedocs.io/en/latest/detectors.html#constructorthrow --- gradle/java-setup.gradle | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index 91f2f13e8c..b152097653 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -17,7 +17,11 @@ spotbugs { ignoreFailures = false // bug free or it doesn't ship! reportLevel = 'medium' // low|medium|high (low = sensitive to even minor mistakes) omitVisitors = [ - 'FindReturnRef'] // https://spotbugs.readthedocs.io/en/latest/detectors.html#findreturnref + // https://spotbugs.readthedocs.io/en/latest/detectors.html#constructorthrow + 'ConstructorThrow', + // https://spotbugs.readthedocs.io/en/latest/detectors.html#findreturnref + 'FindReturnRef', + ] } tasks.named('spotbugsTest') { enabled = false From 997ae051d3b4e3386ccf3d1b8e0229cc6756422e Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 26 Nov 2023 15:37:53 +0800 Subject: [PATCH 0992/1120] Sign task is now CC compatible --- gradle/java-publish.gradle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gradle/java-publish.gradle b/gradle/java-publish.gradle index 49075c5970..d6f0afa5a0 100644 --- a/gradle/java-publish.gradle +++ b/gradle/java-publish.gradle @@ -199,10 +199,6 @@ if (System.env['JITPACK'] == 'true' || version.endsWith('-SNAPSHOT')) { } } -tasks.withType(Sign).configureEach { - notCompatibleWithConfigurationCache("https://github.com/gradle/gradle/issues/13470") -} - tasks.withType(AbstractArchiveTask).configureEach { preserveFileTimestamps = false reproducibleFileOrder = true From 1031d15db96d159e42614532883d5f1319ffc206 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 26 Nov 2023 15:55:00 +0800 Subject: [PATCH 0993/1120] Defer Jar task configuration --- lib-extra/build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index 07135ff726..e6524f76bf 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -56,16 +56,16 @@ for (needsP2 in NEEDS_P2_DEPS) { add("${needsP2}CompileOnly", "dev.equo.ide:solstice:${VER_SOLSTICE}") } } -jar { + +def jar = tasks.named('jar', Jar) { for (needsP2 in NEEDS_P2_DEPS) { - from sourceSets.getByName(needsP2).output.classesDirs + from sourceSets.named(needsP2).map { it.output.classesDirs } } } + tasks.withType(Test).configureEach { dependsOn jar - doFirst { - classpath += jar.outputs.files - } + classpath += jar.get().outputs.files } apply plugin: 'dev.equo.p2deps' From 53fe1e0bb2c063e6f9bbbea80bab52306975a1db Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 26 Nov 2023 13:11:57 +0800 Subject: [PATCH 0994/1120] Polish KotlinGradleExtensionTest --- .../gradle/spotless/KotlinExtensionTest.java | 2 +- .../spotless/KotlinGradleExtensionTest.java | 61 ++++++------------- 2 files changed, 19 insertions(+), 44 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index dd0f2f5e21..6973eb020c 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -30,7 +30,7 @@ class KotlinExtensionTest extends GradleIntegrationHarness { void integrationDiktat() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.4.30'", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 7dade5f2ff..f2b8590083 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -15,34 +15,19 @@ */ package com.diffplug.gradle.spotless; -import static org.assertj.core.api.Assertions.assertThat; - import java.io.IOException; -import org.gradle.testkit.runner.BuildResult; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -class KotlinGradleExtensionTest extends GradleIntegrationHarness { - @Test - void integration_default_diktat() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.4.30'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " diktat()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/diktat/basic.dirty"); - BuildResult result = gradleRunner().withArguments("spotlessApply").buildAndFail(); - assertThat(result.getOutput()).contains("[AVOID_NESTED_FUNCTIONS] try to avoid using nested functions"); - } +/** + * We test KotlinGradleExtension only behaviors here. + */ +class KotlinGradleExtensionTest extends KotlinExtensionTest { - @Test - void withExperimentalEditorConfigOverride() throws IOException { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testTarget(boolean useDefaultTarget) throws IOException { setFile("build.gradle").toLines( "plugins {", " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", @@ -51,6 +36,7 @@ void withExperimentalEditorConfigOverride() throws IOException { "repositories { mavenCentral() }", "spotless {", " kotlinGradle {", + " " + (useDefaultTarget ? "" : "target \"*.kts\""), " ktlint().editorConfigOverride([", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", @@ -59,25 +45,14 @@ void withExperimentalEditorConfigOverride() throws IOException { " }", "}"); setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + setFile("configuration.kts").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); - } - - @Test - void integration_ktfmt_with_dropbox_style() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktfmt().dropboxStyle()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktfmt/dropboxstyle.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktfmt/dropboxstyle.clean"); + if (useDefaultTarget) { + assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + assertFile("configuration.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + } else { + assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + assertFile("configuration.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + } } } From 4775485957c5cafcf5c6c65dab4f3203c5471b06 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 26 Nov 2023 17:17:21 +0800 Subject: [PATCH 0995/1120] Polish GroovyGradleExtensionTest --- .../spotless/GroovyGradleExtensionTest.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyGradleExtensionTest.java index 7f4d593a9c..e94d269644 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GroovyGradleExtensionTest.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. @@ -17,24 +17,20 @@ import java.io.IOException; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import com.diffplug.common.base.StringPrinter; -class GroovyGradleExtensionTest extends GradleIntegrationHarness { +/** + * We test GroovyGradleExtension only behaviors here. + */ +class GroovyGradleExtensionTest extends GroovyExtensionTest { private static final String HEADER = "//My tests header"; - @Test - void defaultTarget() throws IOException { - testTarget(true); - } - - @Test - void customTarget() throws IOException { - testTarget(false); - } - - private void testTarget(boolean useDefaultTarget) throws IOException { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testTarget(boolean useDefaultTarget) throws IOException { String target = useDefaultTarget ? "" : "target 'other.gradle'"; String buildContent = StringPrinter.buildStringFromLines( "plugins {", From f183b61485616b8c2eb2c5946e03759d5ecc5228 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 26 Nov 2023 18:18:43 +0800 Subject: [PATCH 0996/1120] Bump Kotlin to 1.6.21 in integration tests We can't use the latest version, due to the Gradle matrix limit in tests. --- .../gradle/spotless/KotlinExtensionTest.java | 18 +++++++++--------- .../spotless/KotlinGradleExtensionTest.java | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 6973eb020c..bd1175b992 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -30,7 +30,7 @@ class KotlinExtensionTest extends GradleIntegrationHarness { void integrationDiktat() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -48,7 +48,7 @@ void integrationDiktat() throws IOException { void integrationKtfmt_dropboxStyle_0_19() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -66,7 +66,7 @@ void integrationKtfmt_dropboxStyle_0_19() throws IOException { void withExperimentalEditorConfigOverride() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -90,7 +90,7 @@ void testWithInvalidEditorConfigFile() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -110,7 +110,7 @@ void testReadCodeStyleFromEditorConfigFile() throws IOException { setFile(".editorconfig").toResource("kotlin/ktlint/ktlint_official/.editorconfig"); setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -127,7 +127,7 @@ void testSetEditorConfigCanOverrideEditorConfigFile() throws IOException { setFile(".editorconfig").toResource("kotlin/ktlint/intellij_idea/.editorconfig"); setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -145,7 +145,7 @@ void testSetEditorConfigCanOverrideEditorConfigFile() throws IOException { void withCustomRuleSetApply() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -169,7 +169,7 @@ void withCustomRuleSetApply() throws IOException { void testWithHeader() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", @@ -188,7 +188,7 @@ void testWithHeader() throws IOException { void testWithCustomMaxWidthDefaultStyleKtfmt() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index f2b8590083..c607c36912 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -30,7 +30,7 @@ class KotlinGradleExtensionTest extends KotlinExtensionTest { void testTarget(boolean useDefaultTarget) throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", + " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", From 23972d3fa9c9950bc34eb653f0e598cc968b2620 Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 27 Nov 2023 05:38:38 +0000 Subject: [PATCH 0997/1120] Published lib/2.43.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7d7c3dc355..f2bc6974c6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.43.0] - 2023-11-27 ### Added * Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896) ### Fixed From 43b5276771e09f4e800c97ffe8a3dce27ad1776a Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 27 Nov 2023 05:40:51 +0000 Subject: [PATCH 0998/1120] Published gradle/6.23.0 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 56 ++++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 03ddf370f4..b602c5af2d 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.23.0] - 2023-11-27 ### Added * Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896) ### Fixed diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 4f6b74bdb7..1fdea63c8c 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.22.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.23.0-blue.svg)](CHANGES.md) [![MavenCentral](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -144,7 +144,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer. ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -301,8 +301,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -357,8 +357,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -436,7 +436,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -468,7 +468,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -500,7 +500,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -536,7 +536,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ### buf -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) **WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem. @@ -568,7 +568,7 @@ buf { ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -589,7 +589,7 @@ spotless { ## Flexmark -`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) [homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). @@ -608,7 +608,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -633,7 +633,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -673,7 +673,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -767,7 +767,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -832,7 +832,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -952,7 +952,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -984,7 +984,7 @@ spotless { ## Gherkin -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.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.23.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 { @@ -1371,7 +1371,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1451,9 +1451,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1486,11 +1486,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.22.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 6b8568ff45cd8107f806b393afeb8b1c0719d8c6 Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 27 Nov 2023 05:42:21 +0000 Subject: [PATCH 0999/1120] Published maven/2.41.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 78fb6f84ca..576f8f68bd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.41.0] - 2023-11-27 ### Added * CompileSourceRoots and TestCompileSourceRoots are now respected as default includes. These properties are commonly set when adding extra source directories. ([#1846](https://github.com/diffplug/spotless/issues/1846)) * Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 857597beb2..3709a65cdf 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![MavenCentral](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.40.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.40.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.41.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.41.0/index.html) [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.23.0-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.23.1-blue.svg)](CHANGES.md) [![MavenCentral](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -144,7 +144,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer. ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -301,8 +301,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -357,8 +357,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -436,7 +436,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -468,7 +468,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -500,7 +500,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -536,7 +536,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ### buf -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) **WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem. @@ -568,7 +568,7 @@ buf { ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -589,7 +589,7 @@ spotless { ## Flexmark -`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) [homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). @@ -608,7 +608,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -633,7 +633,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -673,7 +673,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -767,7 +767,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -832,7 +832,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -952,7 +952,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -984,7 +984,7 @@ spotless { ## Gherkin -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.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.23.1/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 { @@ -1371,7 +1371,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1451,9 +1451,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1486,11 +1486,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 5ecf292924f349a0dabcc4eeba6f7ffaeb5bc433 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 29 Nov 2023 15:44:12 -0800 Subject: [PATCH 1007/1120] Prepare to publish 6.23.2. --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index f1dce305b9..14e39cbae5 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Fix a stuck mavencentral sync from `6.23.1`. ## [6.23.1] - 2023-11-29 ### Fixed From afe162e6784e879b1998dedabfbefbc12cd46579 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:26:48 +0000 Subject: [PATCH 1008/1120] Update dependency org.mockito:mockito-core to v5.8.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index b60fa2f805..c824d18ffd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -31,4 +31,4 @@ VER_DURIAN=1.2.0 VER_JGIT=6.7.0.202309050840-r VER_JUNIT=5.10.0 VER_ASSERTJ=3.24.2 -VER_MOCKITO=5.6.0 +VER_MOCKITO=5.8.0 From 28e948ebe6875d1a645bd9323bc8f0658c03eeac Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 1 Dec 2023 18:43:40 +0800 Subject: [PATCH 1009/1120] Update Gradle plugin version refs to 6.23.2 --- plugin-gradle/CHANGES.md | 4 ++- plugin-gradle/README.md | 56 ++++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 14e39cbae5..7d2691306a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,8 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.23.2] - 2023-12-01 ### Fixed -* Fix a stuck mavencentral sync from `6.23.1`. +* Fix a stuck MavenCentral sync from `6.23.1`. ## [6.23.1] - 2023-11-29 ### Fixed diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index f54e5a12d4..be694f910a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.23.1-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.23.2-blue.svg)](CHANGES.md) [![MavenCentral](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -144,7 +144,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer. ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -301,8 +301,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -357,8 +357,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -436,7 +436,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -468,7 +468,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -500,7 +500,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -536,7 +536,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ### buf -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) **WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem. @@ -568,7 +568,7 @@ buf { ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -589,7 +589,7 @@ spotless { ## Flexmark -`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) [homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). @@ -608,7 +608,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -633,7 +633,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -673,7 +673,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -767,7 +767,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -832,7 +832,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -952,7 +952,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -984,7 +984,7 @@ spotless { ## Gherkin -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/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.23.2/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 { @@ -1371,7 +1371,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1451,9 +1451,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1486,11 +1486,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.1/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From de20ea93bc3cc0c923a39af8068c9873709b1d30 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sat, 30 Sep 2023 02:43:12 +0800 Subject: [PATCH 1010/1120] Use palantir-java-format 2.38.0 on Java 21 Co-authored-by: Goooler --- CHANGES.md | 2 ++ .../java/com/diffplug/spotless/java/PalantirJavaFormatStep.java | 2 +- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d5443669a0..f49010b0c8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Use palantir-java-format 2.38.0 on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ## [2.43.0] - 2023-11-27 ### Added diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java index f769ad09ec..2c3b84c40d 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java @@ -30,7 +30,7 @@ private PalantirJavaFormatStep() {} private static final String DEFAULT_STYLE = "PALANTIR"; private static final String NAME = "palantir-java-format"; private static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.1.0").add(11, "2.28.0"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.1.0").add(11, "2.28.0").add(21, "2.38.0"); /** Creates a step which formats everything - code, import order, and unused imports. */ public static FormatterStep create(Provisioner provisioner) { diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7d2691306a..74dad45058 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Changes +* Use palantir-java-format 2.38.0 on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ## [6.23.2] - 2023-12-01 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6313c8c8b5..9192df0540 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Use palantir-java-format 2.38.0 on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ## [2.41.0] - 2023-11-27 ### Added From 3908da9c05ff28a46be9df81f33b247085224c67 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 2 Dec 2023 12:13:49 +0800 Subject: [PATCH 1011/1120] Update PR 1892 link ref --- plugin-gradle/CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7d2691306a..c02b710050 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -24,7 +24,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Add a Step to remove semicolons from Groovy files. ([#1881](https://github.com/diffplug/spotless/pull/1881)) * **POSSIBLY BREAKING** `userData` method has been removed from Ktlint step in ([#1891](https://github.com/diffplug/spotless/pull/1891)), you may use `editorConfigOverride` instead. * **POSSIBLY BREAKING** Reuse configs for `KotlinExtension` and `KotlinGradleExtension` in ([#1890](https://github.com/diffplug/spotless/pull/1890)), this may break your integrations in Gradle Kotlin DSL, wait for Spotless 6.23.1 to fix this. -* **POSSIBLY BREAKING** Reuse configs for `GroovyExtension` and `GroovyGradleExtension` in ([#1890](https://github.com/diffplug/spotless/pull/1890)), this may break your integrations in Gradle Kotlin DSL, wait for Spotless 6.23.1 to fix this. +* **POSSIBLY BREAKING** Reuse configs for `GroovyExtension` and `GroovyGradleExtension` in ([#1892](https://github.com/diffplug/spotless/pull/1892)), this may break your integrations in Gradle Kotlin DSL, wait for Spotless 6.23.1 to fix this. ## [6.22.0] - 2023-09-28 ### Added From 5f840aa14418718e2d08c9f48af6a748bced7050 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 2 Dec 2023 12:03:44 +0800 Subject: [PATCH 1012/1120] Make KtfmtConfig.ConfigurableStyle#configure public --- plugin-gradle/CHANGES.md | 2 ++ .../gradle/spotless/BaseKotlinExtension.java | 2 +- .../gradle/spotless/KotlinExtensionTest.java | 17 +++++++++++------ .../kotlin/ktfmt/basic-dropbox-style.clean | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 testlib/src/main/resources/kotlin/ktfmt/basic-dropbox-style.clean diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 7d2691306a..bb0d8f3a03 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Make `KtfmtConfig.ConfigurableStyle#configure` public. ([#1926](https://github.com/diffplug/spotless/pull/1926)) ## [6.23.2] - 2023-12-01 ### Fixed diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java index c622c27d0a..4be814a470 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -136,7 +136,7 @@ private FormatterStep createStep() { } public class ConfigurableStyle { - private void configure(Consumer optionsConfiguration) { + public void configure(Consumer optionsConfiguration) { KtfmtStep.KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtStep.KtfmtFormattingOptions(); optionsConfiguration.accept(ktfmtFormattingOptions); options = ktfmtFormattingOptions; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index d8d5b63e01..1e96d34574 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -45,21 +45,26 @@ void integrationDiktat() throws IOException { } @Test - void integrationKtfmt_dropboxStyle_0_19() throws IOException { - setFile("build.gradle").toLines( + void integrationKtfmtDropboxStyleWithPublicApi() throws IOException { + setFile("build.gradle.kts").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.6.21'", - " id 'com.diffplug.spotless'", + " id(\"org.jetbrains.kotlin.jvm\") version \"1.6.21\"", + " id(\"com.diffplug.spotless\")", "}", "repositories { mavenCentral() }", "spotless {", " kotlin {", - " ktfmt('0.19').dropboxStyle()", + " ktfmt().dropboxStyle().configure {", + " it.setMaxWidth(4)", + " it.setBlockIndent(4)", + " it.setContinuationIndent(4)", + " it.setRemoveUnusedImport(false)", + " }", " }", "}"); setFile("src/main/kotlin/basic.kt").toResource("kotlin/ktfmt/basic.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean"); + assertFile("src/main/kotlin/basic.kt").sameAsResource("kotlin/ktfmt/basic-dropbox-style.clean"); } @Test diff --git a/testlib/src/main/resources/kotlin/ktfmt/basic-dropbox-style.clean b/testlib/src/main/resources/kotlin/ktfmt/basic-dropbox-style.clean new file mode 100644 index 0000000000..428b6d69fb --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktfmt/basic-dropbox-style.clean @@ -0,0 +1,14 @@ +import a.* +import a.b +import a.b.c.* +import kotlinx.android.synthetic.main.layout_name.* + +fun main() { + fun name() { + a() + return b + } + println( + ";") + println() +} From 21c9090d178e41f428235c2acfc81b79e32ab6b6 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 2 Dec 2023 23:28:17 +0800 Subject: [PATCH 1013/1120] Bump default ktfmt version to latest 0.46 https://github.com/facebook/ktfmt/releases/tag/v0.46 --- CHANGES.md | 2 ++ lib/build.gradle | 2 +- lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java | 2 +- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d5443669a0..7f90146d86 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Bump default `ktfmt` version to latest `0.44` -> `0.46`. ([#1927](https://github.com/diffplug/spotless/pull/1927)) ## [2.43.0] - 2023-11-27 ### Added diff --git a/lib/build.gradle b/lib/build.gradle index a3424a7ee9..d2b6a0a19b 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -92,7 +92,7 @@ dependencies { jacksonCompileOnly "com.fasterxml.jackson.core:jackson-databind:$VER_JACKSON" jacksonCompileOnly "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$VER_JACKSON" // ktfmt - ktfmtCompileOnly "com.facebook:ktfmt:0.44" + ktfmtCompileOnly "com.facebook:ktfmt:0.46" ktfmtCompileOnly("com.google.googlejavaformat:google-java-format") { version { strictly '1.7' // for JDK 8 compatibility diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java index 098f68d5bd..cf9a2dd231 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -39,7 +39,7 @@ public class KtfmtStep { // prevent direct instantiation private KtfmtStep() {} - private static final String DEFAULT_VERSION = "0.44"; + private static final String DEFAULT_VERSION = "0.46"; static final String NAME = "ktfmt"; static final String PACKAGE = "com.facebook"; static final String MAVEN_COORDINATE = PACKAGE + ":ktfmt:"; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index bb0d8f3a03..298161476e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Make `KtfmtConfig.ConfigurableStyle#configure` public. ([#1926](https://github.com/diffplug/spotless/pull/1926)) +### Changes +* Bump default `ktfmt` version to latest `0.44` -> `0.46`. ([#1927](https://github.com/diffplug/spotless/pull/1927)) ## [6.23.2] - 2023-12-01 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6313c8c8b5..69be17b2dc 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Changes +* Bump default `ktfmt` version to latest `0.44` -> `0.46`. ([#1927](https://github.com/diffplug/spotless/pull/1927)) ## [2.41.0] - 2023-11-27 ### Added From 00596df153e16d12df2ad8da5403485eba55fe52 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 2 Dec 2023 23:54:09 +0800 Subject: [PATCH 1014/1120] Gradle 8.5 https://docs.gradle.org/8.5/release-notes.html --- gradle/wrapper/gradle-wrapper.jar | Bin 63721 -> 43462 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- .../spotless/GradleIntegrationHarness.java | 7 ++++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f93135c49b765f8051ef9d0a6055ff8e46073d8..d64cd4917707c1f8861d8cb53dd15194d4248596 100644 GIT binary patch literal 43462 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 literal 63721 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鯊%1Et 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⁢ zv5o9#E7!G0XmdzfsS{efPNi`1b44~SZ4Z8fuX!I}#8g+(wxzQwUT#Xb2(tbY1+EUhGKoT@KEU9Ktl>_0 z%bjDJg;#*gtJZv!-Zs`?^}v5eKmnbjqlvnSzE@_SP|LG_PJ6CYU+6zY6>92%E+ z=j@TZf-iW4(%U{lnYxQA;7Q!b;^brF8n0D>)`q5>|WDDXLrqYU_tKN2>=#@~OE7grMnNh?UOz-O~6 z6%rHy{#h9K0AT+lDC7q4{hw^|q6*Ry;;L%Q@)Ga}$60_q%D)rv(CtS$CQbpq9|y1e zRSrN4;$Jyl{m5bZw`$8TGvb}(LpY{-cQ)fcyJv7l3S52TLXVDsphtv&aPuDk1OzCA z4A^QtC(!11`IsNx_HnSy?>EKpHJWT^wmS~hc^p^zIIh@9f6U@I2 zC=Mve{j2^)mS#U$e{@Q?SO6%LDsXz@SY+=cK_QMmXBIU)j!$ajc-zLx3V60EXJ!qC zi<%2x8Q24YN+&8U@CIlN zrZkcT9yh%LrlGS9`G)KdP(@9Eo-AQz@8GEFWcb7U=a0H^ZVbLmz{+&M7W(nXJ4sN8 zJLR7eeK(K8`2-}j(T7JsO`L!+CvbueT%izanm-^A1Dn{`1Nw`9P?cq;7no+XfC`K(GO9?O^5zNIt4M+M8LM0=7Gz8UA@Z0N+lg+cX)NfazRu z5D)~HA^(u%w^cz+@2@_#S|u>GpB+j4KzQ^&Wcl9f z&hG#bCA(Yk0D&t&aJE^xME^&E-&xGHhXn%}psEIj641H+Nl-}boj;)Zt*t(4wZ5DN z@GXF$bL=&pBq-#vkTkh>7hl%K5|3 z{`Vn9b$iR-SoGENp}bn4;fR3>9sA%X2@1L3aE9yTra;Wb#_`xWwLSLdfu+PAu+o3| zGVnpzPr=ch{uuoHjtw7+_!L_2;knQ!DuDl0R`|%jr+}jFzXtrHIKc323?JO{l&;VF z*L1+}JU7%QJOg|5|Tc|D8fN zJORAg=_vsy{ak|o);@)Yh8Lkcg@$FG3k@ep36BRa^>~UmnRPziS>Z=`Jb2x*Q#`%A zU*i3&Vg?TluO@X0O;r2Jl6LKLUOVhSqg1*qOt^|8*c7 zo(298@+r$k_wQNGHv{|$tW(T8L+4_`FQ{kEW5Jgg{yf7ey4ss_(SNKfz(N9lx&a;< je(UuV8hP?p&}TPdm1I$XmG#(RzlD&B2izSj9sl%y5~4qc diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3fa8f862f7..1af9e0930b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java index ade5cf3d1d..9e1856b6b0 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java @@ -54,9 +54,14 @@ public enum GradleVersionSupport { GradleVersionSupport(String version) { String minVersionForRunningJRE; switch (Jvm.version()) { + case 22: + // TODO: https://docs.gradle.org/current/userguide/compatibility.html case 21: + minVersionForRunningJRE = "8.5"; + break; case 20: - // TODO: https://docs.gradle.org/current/userguide/compatibility.html + minVersionForRunningJRE = "8.3"; + break; case 19: minVersionForRunningJRE = "7.6"; break; From 1ba268b7755bc22f3ab40bc7308b33b6b4c1680f Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 2 Dec 2023 23:55:30 +0800 Subject: [PATCH 1015/1120] Add Java 21 to CI matrix --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e436abd95..d11b0b1166 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,8 @@ jobs: fail-fast: false matrix: kind: [maven, gradle] - jre: [11, 17] + # Test on the latest Java version once Gradle & Maven support it. + jre: [11, 17, 21] os: [ubuntu-latest] include: # test windows at the diagonals of the above matrix From 7b6cefdadeb1856ef5172d3e6785ec8d2b6fd838 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 3 Dec 2023 00:57:32 +0800 Subject: [PATCH 1016/1120] Bump default googleJavaFormat version to latest 1.18.1 https://github.com/google/google-java-format/releases --- CHANGES.md | 1 + lib/build.gradle | 2 +- .../java/com/diffplug/spotless/java/GoogleJavaFormatStep.java | 2 +- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f49010b0c8..c1e3d9d101 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] ### Changes * Use palantir-java-format 2.38.0 on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ## [2.43.0] - 2023-11-27 ### Added diff --git a/lib/build.gradle b/lib/build.gradle index a3424a7ee9..50d6c983f6 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -84,7 +84,7 @@ dependencies { gherkinCompileOnly 'io.cucumber:gherkin-utils:8.0.2' gherkinCompileOnly 'org.slf4j:slf4j-api:2.0.0' // googleJavaFormat - googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.17.0' + googleJavaFormatCompileOnly 'com.google.googlejavaformat:google-java-format:1.18.1' // gson gsonCompileOnly 'com.google.code.gson:gson:2.10.1' // jackson diff --git a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java index e5d990d807..0911c1d48d 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java @@ -83,7 +83,7 @@ public static FormatterStep create(String groupArtifact, String version, String .addMin(11, "1.8") // we only support google-java-format >= 1.8 due to api changes .addMin(16, "1.10.0") // java 16 requires at least 1.10.0 due to jdk api changes in JavaTokenizer .addMin(21, "1.17.0") // java 21 requires at least 1.17.0 due to https://github.com/google/google-java-format/issues/898 - .add(11, "1.17.0"); // default version + .add(11, "1.18.1"); // default version public static String defaultGroupArtifact() { return MAVEN_COORDINATE; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 74dad45058..6e0e64195e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes * Use palantir-java-format 2.38.0 on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ## [6.23.2] - 2023-12-01 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 9192df0540..713769f76c 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes * Use palantir-java-format 2.38.0 on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ## [2.41.0] - 2023-11-27 ### Added From 682dcd6d4840002adb834b2db67038869efe5d57 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 3 Dec 2023 01:50:45 +0800 Subject: [PATCH 1017/1120] Declare TARGET_JVM_ENVIRONMENT_ATTRIBUTE attr for resolving Guava --- .../java/com/diffplug/gradle/spotless/GradleProvisioner.java | 4 ++++ .../src/main/java/com/diffplug/spotless/TestProvisioner.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index 288cc10c72..9003445ddd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -26,6 +26,7 @@ import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.dsl.DependencyHandler; +import org.gradle.api.attributes.Attribute; import org.gradle.api.attributes.Bundling; import org.gradle.api.attributes.Category; import org.gradle.api.initialization.dsl.ScriptHandler; @@ -124,6 +125,9 @@ private static Provisioner forConfigurationContainer(Project project, Configurat config.attributes(attr -> { attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY)); attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); + // TODO: This is a copy-paste from org.gradle.api.attributes.java.TargetJvmEnvironment which is added in Gradle 7.0, remove this once we drop support for Gradle 6.x. + // Add this attribute for resolving Guava dependency, see https://github.com/google/guava/issues/6801. + attr.attribute(Attribute.of("org.gradle.jvm.environment", String.class), "standard-jvm"); }); return config.resolve(); } catch (Exception e) { diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java index 7c7b7b67f7..04c4476804 100644 --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java @@ -31,6 +31,7 @@ import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.ResolveException; import org.gradle.api.artifacts.dsl.RepositoryHandler; +import org.gradle.api.attributes.Attribute; import org.gradle.api.attributes.Bundling; import org.gradle.api.attributes.Category; import org.gradle.testfixtures.ProjectBuilder; @@ -73,6 +74,9 @@ private static Provisioner createWithRepositories(Consumer re config.attributes(attr -> { attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY)); attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); + // TODO: This is a copy-paste from org.gradle.api.attributes.java.TargetJvmEnvironment which is added in Gradle 7.0, remove this once we drop support for Gradle 6.x. + // Add this attribute for resolving Guava dependency, see https://github.com/google/guava/issues/6801. + attr.attribute(Attribute.of("org.gradle.jvm.environment", String.class), "standard-jvm"); }); try { return config.resolve(); From a6495edd25ce9ca41f118576f2f28196fe211467 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 3 Dec 2023 02:58:59 +0800 Subject: [PATCH 1018/1120] Use Guava 32.1.3 --- .../spotless/java/GoogleJavaFormatStep.java | 2 +- .../spotless/java/PalantirJavaFormatStep.java | 2 +- .../diffplug/gradle/spotless/GradleProvisioner.java | 13 ++++++++++++- .../java/com/diffplug/spotless/TestProvisioner.java | 13 ++++++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java index 0911c1d48d..6a48924170 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java @@ -35,7 +35,7 @@ private GoogleJavaFormatStep() {} private static final boolean DEFAULT_REORDER_IMPORTS = false; private static final boolean DEFAULT_FORMAT_JAVADOC = true; static final String NAME = "google-java-format"; - static final String MAVEN_COORDINATE = "com.google.googlejavaformat:google-java-format"; + public static final String MAVEN_COORDINATE = "com.google.googlejavaformat:google-java-format"; /** Creates a step which formats everything - code, import order, and unused imports. */ public static FormatterStep create(Provisioner provisioner) { diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java index 2c3b84c40d..8cb828c624 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java @@ -29,7 +29,7 @@ private PalantirJavaFormatStep() {} private static final String DEFAULT_STYLE = "PALANTIR"; private static final String NAME = "palantir-java-format"; - private static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:"; + public static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:"; private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(8, "1.1.0").add(11, "2.28.0").add(21, "2.38.0"); /** Creates a step which formats everything - code, import order, and unused imports. */ diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index 9003445ddd..6bb8c1b50e 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -36,6 +36,8 @@ import com.diffplug.common.base.Unhandled; import com.diffplug.common.collect.ImmutableList; import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.java.GoogleJavaFormatStep; +import com.diffplug.spotless.java.PalantirJavaFormatStep; /** Should be package-private. */ class GradleProvisioner { @@ -117,7 +119,16 @@ private static Provisioner forConfigurationContainer(Project project, Configurat + new Request(withTransitives, mavenCoords).hashCode()); mavenCoords.stream() .map(dependencies::create) - .forEach(config.getDependencies()::add); + .forEach(dependency -> { + config.getDependencies().add(dependency); + String coordinate = dependency.getGroup() + ":" + dependency.getName(); + if (coordinate.startsWith(GoogleJavaFormatStep.MAVEN_COORDINATE) || + coordinate.startsWith(PalantirJavaFormatStep.MAVEN_COORDINATE)) { + // Use Guava 32.1.3, see https://github.com/google/guava/issues/6657. + // TODO: May remove this after https://github.com/google/google-java-format/pull/996 and https://github.com/palantir/palantir-java-format/issues/957 are released. + config.getDependencies().add(dependencies.create("com.google.guava:guava:32.1.3-jre")); + } + }); config.setDescription(mavenCoords.toString()); config.setTransitive(withTransitives); config.setCanBeConsumed(false); diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java index 04c4476804..53a5cfed30 100644 --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; +import java.util.stream.Stream; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; @@ -41,6 +42,8 @@ import com.diffplug.common.base.Suppliers; import com.diffplug.common.collect.ImmutableSet; import com.diffplug.common.io.Files; +import com.diffplug.spotless.java.GoogleJavaFormatStep; +import com.diffplug.spotless.java.PalantirJavaFormatStep; public class TestProvisioner { public static Project gradleProject(File dir) { @@ -65,7 +68,15 @@ private static Provisioner createWithRepositories(Consumer re Project project = TestProvisioner.gradleProject(tempDir); repoConfig.accept(project.getRepositories()); return (withTransitives, mavenCoords) -> { - Dependency[] deps = mavenCoords.stream() + boolean forceGuava = mavenCoords.stream().anyMatch(coordinate -> coordinate.startsWith(GoogleJavaFormatStep.MAVEN_COORDINATE) || + coordinate.startsWith(PalantirJavaFormatStep.MAVEN_COORDINATE)); + Stream coordinateStream = mavenCoords.stream(); + if (forceGuava) { + // Use Guava 32.1.3, see https://github.com/google/guava/issues/6657. + // TODO: May remove this after https://github.com/google/google-java-format/pull/996 and https://github.com/palantir/palantir-java-format/issues/957 are released. + coordinateStream = Stream.concat(coordinateStream, Stream.of("com.google.guava:guava:32.1.3-jre")); + } + Dependency[] deps = coordinateStream .map(project.getDependencies()::create) .toArray(Dependency[]::new); Configuration config = project.getConfigurations().detachedConfiguration(deps); From b5341815b942ae5882333cacec23b6a3f0aeff02 Mon Sep 17 00:00:00 2001 From: Kostiantyn Liutovych Date: Sat, 2 Dec 2023 22:28:58 +0100 Subject: [PATCH 1019/1120] Revert "feat: Maven plugin uses CompileSourceRoots" This reverts commit 101c4c9e99eef71597f61b421693de42f9bf77a9. --- .../java/com/diffplug/spotless/maven/java/Java.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java index e0ff14b51e..b0692446b7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Java.java @@ -20,9 +20,8 @@ import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; import java.util.Set; +import java.util.stream.Stream; import org.apache.maven.model.Build; import org.apache.maven.project.MavenProject; @@ -45,15 +44,7 @@ public class Java extends FormatterFactory { public Set defaultIncludes(MavenProject project) { Path projectDir = project.getBasedir().toPath(); Build build = project.getBuild(); - - List includes = new ArrayList<>(); - includes.add(build.getSourceDirectory()); - includes.add(build.getTestSourceDirectory()); - includes.addAll(project.getCompileSourceRoots()); - includes.addAll(project.getTestCompileSourceRoots()); - - return includes.stream() - .distinct() + return Stream.of(build.getSourceDirectory(), build.getTestSourceDirectory()) .map(Paths::get) .map(projectDir::relativize) .map(Java::fileMask) From 0990a866f524441a75929763c4398d52660c3df0 Mon Sep 17 00:00:00 2001 From: Kostiantyn Liutovych Date: Sat, 2 Dec 2023 22:36:49 +0100 Subject: [PATCH 1020/1120] Update changelog --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 6313c8c8b5..590e57a196 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Revert [#1846](https://github.com/diffplug/spotless/issues/1846) from 2.41.0 which causes the plugin to format generated sources in the `target` directory. ([#1928](https://github.com/diffplug/spotless/pull/1928)) ## [2.41.0] - 2023-11-27 ### Added From ce7563c70fe6fbb0a5b5ecbda71d9f715ebc7d33 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 3 Dec 2023 13:27:19 +0800 Subject: [PATCH 1021/1120] Fix tests related to Java 21 * Fix CombinedJavaFormatStepTest * Fix GoogleJavaFormatStepTest * Fix PalantirJavaFormatStepTest * Fix GoogleJavaFormatIntegrationTest * Fix MultiProjectTest * Fix MavenProvisionerTest * Fix PalantirJavaFormatTest * Fix SpecificFilesTest * Fix GoogleJavaFormatTest --- .../spotless/GoogleJavaFormatIntegrationTest.java | 12 ++++++------ .../diffplug/gradle/spotless/MultiProjectTest.java | 14 +++++++------- .../spotless/maven/MavenProvisionerTest.java | 1 - .../diffplug/spotless/maven/SpecificFilesTest.java | 1 - .../spotless/maven/java/GoogleJavaFormatTest.java | 10 +++++----- .../maven/java/PalantirJavaFormatTest.java | 2 +- .../combined/CombinedJavaFormatStepTest.java | 2 +- .../spotless/java/GoogleJavaFormatStepTest.java | 9 ++++++--- .../spotless/java/PalantirJavaFormatStepTest.java | 2 +- 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java index b2ee012091..e7fc9d4b74 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoogleJavaFormatIntegrationTest.java @@ -31,7 +31,7 @@ void integration() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.10.0')", + " googleJavaFormat('1.17.0')", " }", "}"); @@ -41,7 +41,7 @@ void integration() throws IOException { checkRunsThenUpToDate(); replace("build.gradle", - "googleJavaFormat('1.10.0')", + "googleJavaFormat('1.17.0')", "googleJavaFormat()"); checkRunsThenUpToDate(); } @@ -57,7 +57,7 @@ void integrationWithReorderImports() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.12.0').aosp().reorderImports(true)", + " googleJavaFormat('1.17.0').aosp().reorderImports(true)", " }", "}"); @@ -67,7 +67,7 @@ void integrationWithReorderImports() throws IOException { checkRunsThenUpToDate(); replace("build.gradle", - "googleJavaFormat('1.12.0')", + "googleJavaFormat('1.17.0')", "googleJavaFormat()"); checkRunsThenUpToDate(); } @@ -83,7 +83,7 @@ void integrationWithSkipJavadocFormatting() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.12.0').skipJavadocFormatting()", + " googleJavaFormat('1.17.0').skipJavadocFormatting()", " }", "}"); @@ -93,7 +93,7 @@ void integrationWithSkipJavadocFormatting() throws IOException { checkRunsThenUpToDate(); replace("build.gradle", - "googleJavaFormat('1.12.0')", + "googleJavaFormat('1.17.0')", "googleJavaFormat()"); checkRunsThenUpToDate(); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java index 98761b472a..5d184e15e5 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/MultiProjectTest.java @@ -47,7 +47,7 @@ void createSubproject(String name) throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.16.0')", + " googleJavaFormat('1.17.0')", " }", "}"); setFile(name + "/test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); @@ -71,7 +71,7 @@ public void hasRootSpotless() throws IOException { "spotless {", " java {", " target file('test.java')", - " googleJavaFormat('1.16.0')", + " googleJavaFormat('1.17.0')", " }", "}"); setFile("test.java").toResource("java/googlejavaformat/JavaCodeUnformatted.test"); @@ -88,7 +88,7 @@ public void predeclaredFails() throws IOException { "spotless { predeclareDeps() }"); createNSubprojects(); Assertions.assertThat(gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput()) - .contains("Add a step with [com.google.googlejavaformat:google-java-format:1.16.0] into the `spotlessPredeclare` block in the root project."); + .contains("Add a step with [com.google.googlejavaformat:google-java-format:1.17.0] into the `spotlessPredeclare` block in the root project."); } @Test @@ -100,7 +100,7 @@ public void predeclaredSucceeds() throws IOException { "repositories { mavenCentral() }", "spotless { predeclareDeps() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.16.0') }", + " java { googleJavaFormat('1.17.0') }", "}"); createNSubprojects(); gradleRunner().withArguments("spotlessApply").build(); @@ -115,7 +115,7 @@ public void predeclaredFromBuildscriptSucceeds() throws IOException { "repositories { mavenCentral() }", "spotless { predeclareDepsFromBuildscript() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.16.0') }", + " java { googleJavaFormat('1.17.0') }", "}"); createNSubprojects(); gradleRunner().withArguments("spotlessApply").build(); @@ -129,7 +129,7 @@ public void predeclaredOrdering() throws IOException { "}", "repositories { mavenCentral() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.16.0') }", + " java { googleJavaFormat('1.17.0') }", "}", "spotless { predeclareDepsFromBuildscript() }"); createNSubprojects(); @@ -145,7 +145,7 @@ public void predeclaredUndeclared() throws IOException { "}", "repositories { mavenCentral() }", "spotlessPredeclare {", - " java { googleJavaFormat('1.16.0') }", + " java { googleJavaFormat('1.17.0') }", "}"); createNSubprojects(); Assertions.assertThat(gradleRunner().withArguments("spotlessApply").buildAndFail().getOutput()) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java index 5af146c736..e1214a0d59 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenProvisionerTest.java @@ -33,7 +33,6 @@ void testMultipleDependenciesExcludingTransitives() throws Exception { void testSingleDependencyIncludingTransitives() throws Exception { writePomWithJavaSteps( "", - " 1.10.0", ""); assertResolveDependenciesWorks(); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java index 11cca5994a..6ce11d179f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/SpecificFilesTest.java @@ -58,7 +58,6 @@ private void integration(String patterns, boolean firstFormatted, boolean second " src/**/java/**/*.java", "", "", - " 1.10.0", ""); setFile(testFile(1)).toResource(fixture(false)); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java index 40d8edfed2..52e89e58db 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/GoogleJavaFormatTest.java @@ -24,7 +24,7 @@ class GoogleJavaFormatTest extends MavenIntegrationHarness { void specificVersionDefaultStyle() throws Exception { writePomWithJavaSteps( "", - " 1.10.0", + " 1.17.0", ""); runTest("java/googlejavaformat/JavaCodeFormatted.test"); @@ -34,7 +34,7 @@ void specificVersionDefaultStyle() throws Exception { void specificVersionSpecificStyle() throws Exception { writePomWithJavaSteps( "", - " 1.10.0", + " 1.17.0", " ", ""); @@ -45,7 +45,7 @@ void specificVersionSpecificStyle() throws Exception { void specificVersionReflowLongStrings() throws Exception { writePomWithJavaSteps( "", - " 1.10.0", + " 1.17.0", " true", ""); @@ -56,7 +56,7 @@ void specificVersionReflowLongStrings() throws Exception { void specificVersionReorderImports() throws Exception { writePomWithJavaSteps( "", - " 1.12.0", + " 1.17.0", " ", " true", ""); @@ -68,7 +68,7 @@ void specificVersionReorderImports() throws Exception { void specificVersionSkipJavadocFormatting() throws Exception { writePomWithJavaSteps( "", - " 1.12.0", + " 1.17.0", " false", ""); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java index d8d66fa46d..6a3fd8b08b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java @@ -34,7 +34,7 @@ void specificVersionDefaultStyle() throws Exception { void specificJava11Version2() throws Exception { writePomWithJavaSteps( "", - " 2.10.0", + " 2.38.0", ""); runTest("java/palantirjavaformat/JavaCodeFormatted.test"); diff --git a/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java index cc32281771..d1eb023400 100644 --- a/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/combined/CombinedJavaFormatStepTest.java @@ -34,7 +34,7 @@ public class CombinedJavaFormatStepTest extends ResourceHarness { @Test void checkIssue1679() { - FormatterStep gjf = GoogleJavaFormatStep.create("1.15.0", "AOSP", mavenCentral()); + FormatterStep gjf = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultVersion(), "AOSP", mavenCentral()); FormatterStep indentWithSpaces = IndentStep.Type.SPACE.create(); FormatterStep importOrder = ImportOrderStep.forJava().createFrom(); FormatterStep removeUnused = RemoveUnusedImportsStep.create(mavenCentral()); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java index f8766d7c6f..c2ec5b5d7f 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/GoogleJavaFormatStepTest.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.condition.JRE.JAVA_13; import static org.junit.jupiter.api.condition.JRE.JAVA_15; import static org.junit.jupiter.api.condition.JRE.JAVA_16; +import static org.junit.jupiter.api.condition.JRE.JAVA_20; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledForJreRange; @@ -52,7 +53,7 @@ void behavior18() throws Exception { @Test void behavior() throws Exception { - FormatterStep step = GoogleJavaFormatStep.create("1.10.0", TestProvisioner.mavenCentral()); + FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultVersion(), TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormatted.test") .testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormatted.test") @@ -79,7 +80,7 @@ void versionBelowOneDotTenIsNotAllowed() throws Exception { @Test void behaviorWithAospStyle() throws Exception { - FormatterStep step = GoogleJavaFormatStep.create("1.10.0", "AOSP", TestProvisioner.mavenCentral()); + FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultVersion(), "AOSP", TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormattedAOSP.test") .testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormattedAOSP.test") @@ -111,7 +112,7 @@ void behaviorWithSkipFormatJavadoc() throws Exception { @Test void behaviorWithCustomGroupArtifact() throws Exception { - FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), "1.10.0", GoogleJavaFormatStep.defaultStyle(), TestProvisioner.mavenCentral(), false); + FormatterStep step = GoogleJavaFormatStep.create(GoogleJavaFormatStep.defaultGroupArtifact(), GoogleJavaFormatStep.defaultVersion(), GoogleJavaFormatStep.defaultStyle(), TestProvisioner.mavenCentral(), false); StepHarness.forStep(step) .testResource("java/googlejavaformat/JavaCodeUnformatted.test", "java/googlejavaformat/JavaCodeFormatted.test") .testResource("java/googlejavaformat/JavaCodeWithLicenseUnformatted.test", "java/googlejavaformat/JavaCodeWithLicenseFormatted.test") @@ -133,6 +134,7 @@ void behaviorWithReorderImports() throws Exception { } @Test + @EnabledForJreRange(max = JAVA_20) void equality() throws Exception { new SerializableEqualityTester() { String version = "1.10.0"; @@ -163,6 +165,7 @@ protected FormatterStep create() { } @Test + @EnabledForJreRange(max = JAVA_20) void equalityGroupArtifact() throws Exception { new SerializableEqualityTester() { String groupArtifact = GoogleJavaFormatStep.defaultGroupArtifact(); diff --git a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java index 81d03b6c32..7cd1aad438 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java @@ -38,7 +38,7 @@ void jvm13Features() throws Exception { @Test void behavior2() throws Exception { - FormatterStep step = PalantirJavaFormatStep.create("2.28.0", TestProvisioner.mavenCentral()); + FormatterStep step = PalantirJavaFormatStep.create(TestProvisioner.mavenCentral()); StepHarness.forStep(step) .testResource("java/palantirjavaformat/JavaCodeUnformatted.test", "java/palantirjavaformat/JavaCodeFormatted.test") .testResource("java/palantirjavaformat/JavaCodeWithLicenseUnformatted.test", "java/palantirjavaformat/JavaCodeWithLicenseFormatted.test") From 7901c6422c9d92d522eacf6951c7bb024ec502f0 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 3 Dec 2023 14:37:38 +0800 Subject: [PATCH 1022/1120] SpotBugs Gradle plugin v6 https://github.com/spotbugs/spotbugs-gradle-plugin/releases/tag/6.0.0 https://github.com/spotbugs/spotbugs-gradle-plugin/blob/53f780917d10293098a766f0b568a4fcf0c4cc03/src/main/kotlin/com/github/spotbugs/snom/Confidence.kt#L45-L64 --- gradle/java-setup.gradle | 3 ++- lib-extra/build.gradle | 5 ++++- lib/build.gradle | 5 ++++- settings.gradle | 2 +- testlib/build.gradle | 5 ++++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/gradle/java-setup.gradle b/gradle/java-setup.gradle index b152097653..6663447ba4 100644 --- a/gradle/java-setup.gradle +++ b/gradle/java-setup.gradle @@ -15,7 +15,8 @@ tasks.withType(JavaCompile).configureEach { apply plugin: 'com.github.spotbugs' spotbugs { ignoreFailures = false // bug free or it doesn't ship! - reportLevel = 'medium' // low|medium|high (low = sensitive to even minor mistakes) + // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). + reportLevel = com.github.spotbugs.snom.Confidence.valueOf('MEDIUM') omitVisitors = [ // https://spotbugs.readthedocs.io/en/latest/detectors.html#constructorthrow 'ConstructorThrow', diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index e6524f76bf..a7a8a0d39f 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -91,5 +91,8 @@ p2deps { } // we'll hold the core lib to a high standard -spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) +spotbugs { + // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). + reportLevel = com.github.spotbugs.snom.Confidence.valueOf('LOW') +} diff --git a/lib/build.gradle b/lib/build.gradle index a3424a7ee9..6dcb888e73 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -126,7 +126,10 @@ dependencies { } // we'll hold the core lib to a high standard -spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) +spotbugs { + // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). + reportLevel = com.github.spotbugs.snom.Confidence.valueOf('LOW') +} apply from: rootProject.file('gradle/special-tests.gradle') tasks.withType(Test).configureEach { diff --git a/settings.gradle b/settings.gradle index e7e5a6d4ea..ff03ca6ca3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,7 +12,7 @@ plugins { // https://github.com/gradle-nexus/publish-plugin/releases id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases - id 'com.github.spotbugs' version '5.2.3' apply false + id 'com.github.spotbugs' version '6.0.1' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md id 'com.diffplug.spotless-changelog' version '3.0.2' apply false // https://github.com/diffplug/goomph/blob/main/CHANGES.md diff --git a/testlib/build.gradle b/testlib/build.gradle index a4c83cfdf4..ce36b83adb 100644 --- a/testlib/build.gradle +++ b/testlib/build.gradle @@ -21,7 +21,10 @@ dependencies { } // we'll hold the testlib to a low standard (prize brevity) -spotbugs { reportLevel = 'high' } // low|medium|high (low = sensitive to even minor mistakes) +spotbugs { + // LOW|MEDIUM|DEFAULT|HIGH (low = sensitive to even minor mistakes). + reportLevel = com.github.spotbugs.snom.Confidence.valueOf('HIGH') +} apply from: rootProject.file('gradle/special-tests.gradle') tasks.withType(Test).configureEach { From 950cbc72c48cb77752c166e08c1206cfdf826bde Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 08:32:21 -0800 Subject: [PATCH 1023/1120] Bump the nexus publishing plugin, hopefully we can have fewer publishing snafus now... --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index ff03ca6ca3..4e81688d29 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,7 +10,7 @@ plugins { // https://plugins.gradle.org/plugin/com.gradle.plugin-publish id 'com.gradle.plugin-publish' version '1.2.1' apply false // https://github.com/gradle-nexus/publish-plugin/releases - id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' apply false + id 'io.github.gradle-nexus.publish-plugin' version '2.0.0-rc-1' apply false // https://github.com/spotbugs/spotbugs-gradle-plugin/releases id 'com.github.spotbugs' version '6.0.1' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md From 770a495462923308c43578211ed20acb14a7ea08 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 08:53:05 -0800 Subject: [PATCH 1024/1120] Bump the gradle plugin major version to reflect the breaking change. --- plugin-gradle/CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b125024b79..d00ba16d37 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Make `KtfmtConfig.ConfigurableStyle#configure` public. ([#1926](https://github.com/diffplug/spotless/pull/1926)) +* **BREAKING CHANGE** `6.23.0` made breaking changes to the ABI of the `KotlinExtension` and `GroovyExtension`. Those are reflected retroactively now. + - Previously, we had done semver on the Gradle plugin based only on buildscript compatibility. + - From now on, we will consider ABI for the benefit of convention-based plugins. ## [6.23.2] - 2023-12-01 ### Fixed From 2a989c596d20319a7f0572c8f8ab5ffa6eb4a975 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 3 Dec 2023 17:11:21 +0000 Subject: [PATCH 1025/1120] Update dependency org.junit.jupiter:junit-jupiter to v5.10.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index c824d18ffd..222012d500 100644 --- a/gradle.properties +++ b/gradle.properties @@ -29,6 +29,6 @@ VER_SLF4J=[1.6,2.0[ # Used in multiple places VER_DURIAN=1.2.0 VER_JGIT=6.7.0.202309050840-r -VER_JUNIT=5.10.0 +VER_JUNIT=5.10.1 VER_ASSERTJ=3.24.2 VER_MOCKITO=5.8.0 From f2cc906e22570898e3d2ff2c745eb4d4d13d6b45 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 14:56:39 -0800 Subject: [PATCH 1026/1120] Add info about the maven reversion to changelog. --- plugin-maven/CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 034f89c319..2880df029b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -11,7 +11,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [2.41.0] - 2023-11-27 ### Added -* CompileSourceRoots and TestCompileSourceRoots are now respected as default includes. These properties are commonly set when adding extra source directories. ([#1846](https://github.com/diffplug/spotless/issues/1846)) +* ~~CompileSourceRoots and TestCompileSourceRoots are now respected as default includes. These properties are commonly set when adding extra source directories.~~ ([#1846](https://github.com/diffplug/spotless/issues/1846)) + * Reverted in the next release (`2.41.1`) due to backward compatibility problems, see [#1914](https://github.com/diffplug/spotless/issues/1914). * Support custom rule sets for Ktlint. ([#1896](https://github.com/diffplug/spotless/pull/1896)) ### Fixed * Fix crash when build dir is a softlink to another directory. ([#1859](https://github.com/diffplug/spotless/pull/1859)) From c95574f246a8ad5ee93bf0cbce316c838d9d58ea Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 15:33:11 -0800 Subject: [PATCH 1027/1120] `jvmLocalCache` was failing on Java 21 because the trick we used to test JvmLocalCache doesn't work with Gradle 8.5. --- .../diffplug/gradle/spotless/ConfigurationCacheTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java index 396a884cc5..70be5adb82 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ConfigurationCacheTest.java @@ -20,6 +20,8 @@ import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; public class ConfigurationCacheTest extends GradleIntegrationHarness { @Override @@ -63,6 +65,7 @@ public void helpConfiguresIfTasksAreCreated() throws IOException { } @Test + @EnabledForJreRange(max = JRE.JAVA_20) public void jvmLocalCache() throws IOException { setFile("build.gradle").toLines( "plugins {", @@ -91,6 +94,10 @@ public void jvmLocalCache() throws IOException { gradleRunner().withArguments("spotlessApply").build(); assertFile("test.java").sameAsResource("java/googlejavaformat/JavaCodeFormatted.test"); + // the withDebug forces it to start a new deamon, but only in Gradle 8.3 and older + // starting with Gradle 8.5 this doesn't work anymore + // and we need Gradle 8.5 for Java 21 + // so we can't test this on Java 21 for now BuildResult failure = gradleRunner().withDebug(true).withArguments("spotlessApply", "--stacktrace").buildAndFail(); failure.getOutput().contains("Spotless daemon-local cache is stale. Regenerate the cache with\n" + " rm -rf .gradle/configuration-cache\n" + From 00a31e366c842b9b1e476b3911f60e1311eb2a36 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 15:57:50 -0800 Subject: [PATCH 1028/1120] Remove the dev flow for Eclipse WTP from the project. --- _ext/eclipse-base/CHANGES.md | 53 -- _ext/eclipse-base/LICENSE.txt | 70 --- _ext/eclipse-base/README.md | 62 -- _ext/eclipse-base/build.gradle | 32 -- _ext/eclipse-base/gradle.properties | 8 - .../eclipse/base/SpotlessEclipseConfig.java | 43 -- .../base/SpotlessEclipseCoreConfig.java | 57 -- .../base/SpotlessEclipseFramework.java | 306 ---------- .../base/SpotlessEclipsePluginConfig.java | 90 --- .../base/SpotlessEclipseServiceConfig.java | 154 ----- .../extra/eclipse/base/osgi/BundleConfig.java | 98 ---- .../eclipse/base/osgi/BundleController.java | 256 --------- .../extra/eclipse/base/osgi/BundleSet.java | 71 --- .../base/osgi/EclipseBundleLookup.java | 182 ------ .../base/osgi/FrameworkBundleRegistry.java | 53 -- .../eclipse/base/osgi/ResourceAccessor.java | 150 ----- .../eclipse/base/osgi/ServiceCollection.java | 229 -------- .../extra/eclipse/base/osgi/SimpleBundle.java | 147 ----- .../base/osgi/SimpleBundleCapability.java | 114 ---- .../extra/eclipse/base/osgi/StaticBundle.java | 79 --- .../base/osgi/StaticBundleContext.java | 166 ------ .../eclipse/base/osgi/TemporaryBundle.java | 107 ---- .../extra/eclipse/base/osgi/package-info.java | 17 - .../extra/eclipse/base/package-info.java | 24 - .../eclipse/base/runtime/PluginRegistrar.java | 103 ---- .../eclipse/base/runtime/package-info.java | 19 - .../base/service/HiddenEnvironment.java | 81 --- .../NoContentTypeSpecificHandling.java | 95 ---- .../eclipse/base/service/NoDebugging.java | 87 --- .../base/service/NoEclipsePreferences.java | 129 ----- .../base/service/SingleSlf4JService.java | 533 ------------------ .../base/service/TemporaryLocation.java | 144 ----- .../eclipse/base/service/package-info.java | 17 - .../src/main/resources/META-INF/MANIFEST.MF | 3 - ...osgi.framework.connect.FrameworkUtilHelper | 1 - .../base/SpotlessEclipseFrameworkTest.java | 330 ----------- .../eclipse/base/osgi/BundleSetTest.java | 78 --- .../base/osgi/ServiceCollectionTest.java | 115 ---- .../extra/eclipse/base/osgi/TestBundle.java | 140 ----- _ext/eclipse-wtp/CHANGES.md | 76 --- _ext/eclipse-wtp/LICENSE.txt | 70 --- _ext/eclipse-wtp/README.md | 10 - _ext/eclipse-wtp/build.gradle | 126 ----- _ext/eclipse-wtp/gradle.properties | 16 - _ext/eclipse-wtp/spotless.xmlformat.prefs | 4 - .../wtp/EclipseCssFormatterStepImpl.java | 80 --- .../wtp/EclipseHtmlFormatterStepImpl.java | 159 ------ .../wtp/EclipseJsFormatterStepImpl.java | 187 ------ .../wtp/EclipseJsonFormatterStepImpl.java | 113 ---- .../wtp/EclipseXmlFormatterStepImpl.java | 140 ----- .../eclipse/wtp/html/JsRegionProcessor.java | 86 --- .../wtp/html/StructuredDocumentProcessor.java | 205 ------- .../extra/eclipse/wtp/html/package-info.java | 20 - .../extra/eclipse/wtp/package-info.java | 20 - .../extra/eclipse/wtp/sse/CleanupStep.java | 128 ----- .../eclipse/wtp/sse/ContentTypeManager.java | 235 -------- .../eclipse/wtp/sse/PluginPreferences.java | 130 ----- .../PreventExternalURIResolverExtension.java | 68 --- .../extra/eclipse/wtp/sse/package-info.java | 20 - .../src/main/resources/META-INF/MANIFEST.MF | 3 - .../eclipse-wtp/src/main/resources/plugin.xml | 13 - .../wtp/EclipseCssFormatterStepImplTest.java | 83 --- .../wtp/EclipseHtmlFormatterStepImplTest.java | 114 ---- .../wtp/EclipseJsFormatterStepImplTest.java | 88 --- .../wtp/EclipseJsonFormatterStepImplTest.java | 83 --- ...ormatterStepImplAllowExternalURIsTest.java | 66 --- ...XmlFormatterStepImplCatalogLookupTest.java | 58 -- .../wtp/EclipseXmlFormatterStepImplTest.java | 122 ---- .../spotless/extra/eclipse/wtp/TestData.java | 77 --- .../src/test/resources/html/expected/css.html | 39 -- .../test/resources/html/expected/html4.html | 10 - .../test/resources/html/expected/html5.html | 11 - .../html/expected/invalid_syntax.html | 7 - .../resources/html/expected/javascript.html | 41 -- .../test/resources/html/expected/utf-8.html | 7 - .../src/test/resources/html/input/bom.html | 2 - .../src/test/resources/html/input/css.html | 23 - .../src/test/resources/html/input/html4.html | 10 - .../src/test/resources/html/input/html5.html | 10 - .../resources/html/input/invalid_syntax.html | 4 - .../test/resources/html/input/javascript.html | 34 -- .../src/test/resources/html/input/utf-8.html | 2 - .../resources/html/restrictions/ReadMe.txt | 9 - .../resources/xml/expected/dtd_external.test | 8 - .../resources/xml/expected/dtd_relative.test | 8 - .../resources/xml/expected/xml_space.test | 4 - .../resources/xml/expected/xsd_external.test | 7 - .../resources/xml/expected/xsd_not_found.test | 7 - .../resources/xml/expected/xsd_relative.test | 7 - .../resources/xml/input/dtd_external.test | 8 - .../resources/xml/input/dtd_relative.test | 8 - .../test/resources/xml/input/xml_space.test | 1 - .../resources/xml/input/xsd_external.test | 4 - .../resources/xml/input/xsd_not_found.test | 4 - .../resources/xml/input/xsd_relative.test | 4 - .../resources/xml/restrictions/catalog.xml | 5 - .../test/resources/xml/restrictions/test.dtd | 4 - .../test/resources/xml/restrictions/test.xsd | 23 - _ext/gradle/java-setup.gradle | 28 - _ext/gradle/p2-fat-jar-setup.gradle | 169 ------ _ext/gradle/update-lockfile.gradle | 6 - settings.gradle | 31 - 102 files changed, 7588 deletions(-) delete mode 100644 _ext/eclipse-base/CHANGES.md delete mode 100644 _ext/eclipse-base/LICENSE.txt delete mode 100644 _ext/eclipse-base/README.md delete mode 100644 _ext/eclipse-base/build.gradle delete mode 100644 _ext/eclipse-base/gradle.properties delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseConfig.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseCoreConfig.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFramework.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipsePluginConfig.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseServiceConfig.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleConfig.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleController.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleSet.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/EclipseBundleLookup.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/FrameworkBundleRegistry.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/ResourceAccessor.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/ServiceCollection.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/SimpleBundle.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/SimpleBundleCapability.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/StaticBundle.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/StaticBundleContext.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/TemporaryBundle.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/package-info.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/package-info.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/runtime/PluginRegistrar.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/runtime/package-info.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/HiddenEnvironment.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoContentTypeSpecificHandling.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoDebugging.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoEclipsePreferences.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/SingleSlf4JService.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/TemporaryLocation.java delete mode 100644 _ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/package-info.java delete mode 100644 _ext/eclipse-base/src/main/resources/META-INF/MANIFEST.MF delete mode 100644 _ext/eclipse-base/src/main/resources/META-INF/services/org.osgi.framework.connect.FrameworkUtilHelper delete mode 100644 _ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFrameworkTest.java delete mode 100644 _ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleSetTest.java delete mode 100644 _ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/ServiceCollectionTest.java delete mode 100644 _ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/TestBundle.java delete mode 100644 _ext/eclipse-wtp/CHANGES.md delete mode 100644 _ext/eclipse-wtp/LICENSE.txt delete mode 100644 _ext/eclipse-wtp/README.md delete mode 100644 _ext/eclipse-wtp/build.gradle delete mode 100644 _ext/eclipse-wtp/gradle.properties delete mode 100644 _ext/eclipse-wtp/spotless.xmlformat.prefs delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/package-info.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/ContentTypeManager.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java delete mode 100644 _ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/package-info.java delete mode 100644 _ext/eclipse-wtp/src/main/resources/META-INF/MANIFEST.MF delete mode 100644 _ext/eclipse-wtp/src/main/resources/plugin.xml delete mode 100644 _ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImplTest.java delete mode 100644 _ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImplTest.java delete mode 100644 _ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImplTest.java delete mode 100644 _ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImplTest.java delete mode 100644 _ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplAllowExternalURIsTest.java delete mode 100644 _ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplCatalogLookupTest.java delete mode 100644 _ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplTest.java delete mode 100644 _ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/TestData.java delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/expected/css.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/expected/html4.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/expected/html5.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/expected/invalid_syntax.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/expected/javascript.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/expected/utf-8.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/input/bom.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/input/css.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/input/html4.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/input/html5.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/input/invalid_syntax.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/input/javascript.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/input/utf-8.html delete mode 100644 _ext/eclipse-wtp/src/test/resources/html/restrictions/ReadMe.txt delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/expected/dtd_external.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/expected/dtd_relative.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/expected/xml_space.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/expected/xsd_external.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/expected/xsd_not_found.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/expected/xsd_relative.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/input/dtd_external.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/input/dtd_relative.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/input/xml_space.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/input/xsd_external.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/input/xsd_not_found.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/input/xsd_relative.test delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/restrictions/catalog.xml delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/restrictions/test.dtd delete mode 100644 _ext/eclipse-wtp/src/test/resources/xml/restrictions/test.xsd delete mode 100644 _ext/gradle/java-setup.gradle delete mode 100644 _ext/gradle/p2-fat-jar-setup.gradle delete mode 100644 _ext/gradle/update-lockfile.gradle diff --git a/_ext/eclipse-base/CHANGES.md b/_ext/eclipse-base/CHANGES.md deleted file mode 100644 index 796ed584fd..0000000000 --- a/_ext/eclipse-base/CHANGES.md +++ /dev/null @@ -1,53 +0,0 @@ -# spotless-eclipse-base - -We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.2.1`). - -## [Unreleased] - -## [3.5.2] - 2021-10-23 -### Fixed -* Racing condition when cleaning up temporary workspace on JVM runtime shutdown (see [#967](https://github.com/diffplug/spotless/issues/967)). Can lead to error logs and remaining files in workspace. - -## [3.5.1] - 2021-10-16 -### Fixed -* ~~Racing condition when cleaning up temporary workspace on JVM runtime shutdown (see [#967](https://github.com/diffplug/spotless/issues/967)). Can lead to error logs and remaining files in workspace.~~ - -## [3.5.0] - 2021-06-20 -### Added -* Support of `org.eclipse.core.resources` version `3.15.0` required by Eclipse `4.20`. -* Minimum required Java version changed from 8 to 11. - -## [3.4.2] - 2020-12-26 -### Fixed -* `org.eclipse.osgi` version `3.16.100` does not allow `null` as Debug service for `CloseableBundleFile`. - -## [3.4.1] - 2020-09-24 -### Fixed -* Restored scope of transitive dependencies to 'compile'. - -## [3.4.0] - 2020-09-23 -### Added -* Upgraded to `org.eclipse.osgi` version `3.16`. - -## [3.3.0] - 2020-03-04 -### Added -* Added support of plugin extensions without activator ([#533](https://github.com/diffplug/spotless/issues/533)). Required since `org.eclipse.core.filesystem` version `1.7.600` (see -[Bug 550548](https://bugs.eclipse.org/bugs/show_bug.cgi?id=550548)) -* Updated configuration via single interface implementation. Functional based configuration still supported. - -## [3.2.1] - 2019-09-03 -* Fixed deletion of temporary workspace. ([#447](https://github.com/diffplug/spotless/issues/447)) - -## [3.2.0] - 2019-06-30 -* Added support of Eclipse 4.12 framework wiring. ([#413](https://github.com/diffplug/spotless/issues/413)) - -## [3.1.1] - 2019-06-04 -* Fixed problem handling URL escaped characters in JAR file location. ([#401](https://github.com/diffplug/spotless/issues/401)) - -## [3.1.0] - 2019-02-10 -* Added logging service based on SLF4J. ([#236](https://github.com/diffplug/spotless/issues/236)) -* Updated internal interfaces to support `org.eclipse.osgi` version 3.13. -* Corrected documentation of version number usage in `gradle.properties`. - -## [3.0.0] - 2018-06-18 -* Initial release! diff --git a/_ext/eclipse-base/LICENSE.txt b/_ext/eclipse-base/LICENSE.txt deleted file mode 100644 index 3d967aee74..0000000000 --- a/_ext/eclipse-base/LICENSE.txt +++ /dev/null @@ -1,70 +0,0 @@ -Eclipse Public License - v 1.0 - -THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. - -1. DEFINITIONS - -"Contribution" means: - -a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and -b) in the case of each subsequent Contributor: -i) changes to the Program, and -ii) additions to the Program; -where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. -"Contributor" means any person or entity that distributes the Program. - -"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. - -"Program" means the Contributions distributed in accordance with this Agreement. - -"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. - -2. GRANT OF RIGHTS - -a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. -b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. -c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. -d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. -3. REQUIREMENTS - -A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: - -a) it complies with the terms and conditions of this Agreement; and -b) its license agreement: -i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; -ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; -iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and -iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. -When the Program is made available in source code form: - -a) it must be made available under this Agreement; and -b) a copy of this Agreement must be included with each copy of the Program. -Contributors may not remove or alter any copyright notices contained within the Program. - -Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. - -4. COMMERCIAL DISTRIBUTION - -Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. - -For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. - -5. NO WARRANTY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. - -6. DISCLAIMER OF LIABILITY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -7. GENERAL - -If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. - -If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. - -All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. - -Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. - -This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. \ No newline at end of file diff --git a/_ext/eclipse-base/README.md b/_ext/eclipse-base/README.md deleted file mode 100644 index 39a03591ab..0000000000 --- a/_ext/eclipse-base/README.md +++ /dev/null @@ -1,62 +0,0 @@ -# spotless-eclipse-base - -Eclipse formatters are embedded in plugins serving multiple purposes and not necessarily supporting headless builds. Hence the plugin interfaces are depending on various Eclipse plugins and services not required for the formatting purpose. - -Spotless provides its own plugin framework with `com.diffplug.spotless.JarState`. This allows Spotless to use different Eclipse versions in parallel. - - -The `com.diffplug.gradle.spotless:spotless-eclipse-base` artifact mocks the redundant Eclipse OSGI/plugin framework for Spotless. Furthermore it provides Eclipse services adapted for Spotless's own use, which avoids for example the creation of a permanent Eclipse workspace and reduces dependencies on Eclipse modules unused by the Eclipse code formatters. - -## Usage - -Include the artifact in your Spotless Eclipse formatter project, where the major version must match the Eclipse core version your formatter supports. The exact default version should be selected by the **lib-extra**. -Minor versions indicate a change in the minimum Eclipse (core/resource) dependencies. -Patch versions are always backward compatible. - - -```Gradle -dependencies { - compile "com.diffplug.spotless:spotless-eclipse-base:3.+" -} -``` - -In the constructor of your formatter, the Spotless Eclipse Framework can be configured depending on your formatter's requirements. For example the JDT formatter can be configured like: - -```Java -public EclipseFormatterStepImpl(Properties settings) throws Exception { - SpotlessEclipseFramework.setup(plugins -> { - plugins.applyDefault(); - plugins.add(new org.eclipse.jdt.core.JavaCore()); - }); - ... -``` - -The framework also supports fat JARs, providing multiple plugins. -In this cases the resources required by plugins, especially the `META-INF` and plugin information, must be located in locations unique to the plugin. -For this purpose the framework expects that these resources are stored in a sub-directory -which has the name of the package containing the plugin. For example in case the JDT plugin -is included in your formatter fat JAR, the directory structure should be: - -``` -+ resources -| -+--+ org.eclipse.jdt.core -| | -| +--+ META-INF -| | | -| | +-- MANIFEST.MF -| | -| +--- plugin.properties -| | -| +--- plugin.xml - -``` - -## Build - -To publish a new version, update the `_ext/eclipse-base/gradle.properties` appropriately and see [CONTRIBUTING.md](../../CONTRIBUTING.md) how to enable -`_ext` projects. - -## License - -Spotless at large is under the Apache 2.0 license, but this jar is under the EPL v1. diff --git a/_ext/eclipse-base/build.gradle b/_ext/eclipse-base/build.gradle deleted file mode 100644 index 88255b57b3..0000000000 --- a/_ext/eclipse-base/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -apply from: rootProject.file('_ext/gradle/java-setup.gradle') -apply from: rootProject.file('gradle/java-publish.gradle') - -ext { - developers = [ - fvgh: [ name: 'Frank Vennemeyer', email: 'frankgh@zoho.com' ] - ] -} - -dependencies { - api("org.eclipse.platform:org.eclipse.core.resources:${VER_ECLIPSE_CORE_RESOURCES}") { - exclude group: 'org.eclipse.platform', module: 'org.eclipse.ant.core' - exclude group: 'org.eclipse.platform', module: 'org.eclipse.core.expressions' - } - api("org.slf4j:slf4j-api:${VER_SLF4J}") - - testImplementation("org.slf4j:slf4j-simple:${VER_SLF4J}") -} - -jar { - manifest { - from 'src/main/resources/META-INF/MANIFEST.MF' - } -} - -////////// -// Test // -////////// -sourceSets { - // Use JAR file with all resources for Eclipse-Base integration-tests - test.runtimeClasspath = jar.outputs.files + sourceSets.test.output + sourceSets.test.compileClasspath -} diff --git a/_ext/eclipse-base/gradle.properties b/_ext/eclipse-base/gradle.properties deleted file mode 100644 index 9f8774a417..0000000000 --- a/_ext/eclipse-base/gradle.properties +++ /dev/null @@ -1,8 +0,0 @@ -artifactId=spotless-eclipse-base -description=Eclipse bundle controller and services for Spotless - -# Build requirements -VER_JAVA=11 - -# Compile dependencies -VER_ECLIPSE_CORE_RESOURCES=[3.15.0,4.0.0[ diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseConfig.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseConfig.java deleted file mode 100644 index c8d1fb4db3..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseConfig.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base; - -/** - * Obtain configuration for Eclipse framework setup - *

      - * The setup consitst of 4 phases: - *

        - *
      1. Registration of framework bundles
      2. - *
      3. Registration of servicves
      4. - *
      5. Resitration of extension points, activation of bundles/plugins
      6. - *
      7. Customize bundle/plugin configuration
      8. - *
      - */ -public interface SpotlessEclipseConfig { - default public void registerBundles(SpotlessEclipseCoreConfig config) { - config.applyDefault(); - } - - default public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - } - - default public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - } - - default public void customize() {} -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseCoreConfig.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseCoreConfig.java deleted file mode 100644 index 4f3aa9c2a2..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseCoreConfig.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base; - -import org.osgi.framework.BundleActivator; - -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.DefaultBundles; -import com.diffplug.spotless.extra.eclipse.base.osgi.BundleConfig; - -/** - * Configuration of core bundles which shall be provided by the - * {@link SpotlessEclipseFramework}. - *

      - * Core bundles are not accessed via the plugin registry, but by static methods. - * Hence they do not require a registration, which allows a lightweight - * setup. - *

      - * See {@code org.eclipse.core.internal.runtime.PlatformActivator} implementation for details. - */ -public class SpotlessEclipseCoreConfig extends BundleConfig { - - /** - * Don't instantiate and call {@link SpotlessEclipseConfig} directly. - * Registered bundles should only be instantiated once, since - * older bundles still abusing singletons for access. - */ - SpotlessEclipseCoreConfig() {} - - @Override - public void applyDefault() { - add(SpotlessEclipseFramework.DefaultBundles.createAll()); - } - - @Override - protected BundleActivator create(DefaultBundles bundle) { - return bundle.create(); - } - - @Override - protected int getDefaultState(DefaultBundles bundle) { - return bundle.getDesiredState(); - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFramework.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFramework.java deleted file mode 100644 index 2eaf9e568e..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFramework.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * 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.spotless.extra.eclipse.base; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.List; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.stream.Collectors; - -import javax.xml.parsers.SAXParserFactory; - -import org.eclipse.core.internal.runtime.InternalPlatform; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; - -import com.diffplug.spotless.extra.eclipse.base.osgi.BundleConfig; -import com.diffplug.spotless.extra.eclipse.base.osgi.BundleController; -import com.diffplug.spotless.extra.eclipse.base.runtime.PluginRegistrar; - -/** Setup a framework for Spotless Eclipse based formatters */ -public final class SpotlessEclipseFramework { - /** Spotless demands for internal formatter chains Unix (LF) line endings. */ - public static final String LINE_DELIMITER = "\n"; - - /** - * Default core bundles required by most plugins. - */ - public enum DefaultBundles { - /** - * Plugins ask the platform whether core runtime bundle is in debug mode. - *

      - * Note that the bundle requires the - * {@link org.eclipse.osgi.service.environment.EnvironmentInfo} - * service. - *

      - *

      - * Per default, the platform is not activated. Some plugins use this information - * to determine whether they are running in a headless modes (without IDE). - *

      - */ - PLATFORM(org.eclipse.core.internal.runtime.PlatformActivator.class, Bundle.RESOLVED), - /** The Spotless {@link BundleController} wraps the OSGi layer. But the plugin/extension look-up still uses the Eclipse OSGi registry.*/ - REGISTRY(org.eclipse.core.internal.registry.osgi.Activator.class), - /** Eclipse preferences always check whether this bundle has been activated before preference are set.*/ - PREFERENCES(org.eclipse.core.internal.preferences.Activator.class), - /** The common runtime provides common services, like log and service adapters registry. */ - COMMON(org.eclipse.core.internal.runtime.Activator.class); - - private final Class activatorClass; - private final int state; - - private DefaultBundles(Class clazz) { - this(clazz, Bundle.ACTIVE); - } - - private DefaultBundles(Class clazz, int state) { - activatorClass = clazz; - this.state = state; - } - - /** Create new bundle activator instance. */ - public BundleActivator create() { - return createInstance(activatorClass); - } - - public int getDesiredState() { - return state; - } - - /** Create bundle activator instances for all enumerated values. */ - public static List createAll() { - return Arrays.stream(values()) - .map(value -> new BundleConfig.Entry(value.create(), value.getDesiredState())).collect(Collectors.toList()); - } - } - - /** - * Default plugins required by most Spotless formatters. - *

      - * Eclipse plugins are OSGI bundles themselves and do not necessarily derive from the Eclipse Plugin class. - * {@link BundleActivator} implementation may as well serve as plugins. - * All plugins must provide a MANIFEST.MF, plugin.properties and plugin.xml description file, - * required for the plugin registration. - *

      - */ - public enum DefaultPlugins { - /** - * The resources plugin initialized the Eclipse workspace and allows URL look-up. - * Most formatters using the workspace to resolve URLs or create - * file interfaces. - * See {@code org.eclipse.core.resources.IFile} implementation for details. - */ - RESOURCES(org.eclipse.core.resources.ResourcesPlugin.class); - - private final Class pluginClass; - - DefaultPlugins(Class clazz) { - pluginClass = clazz; - } - - /** Create new plugin instance. */ - public BundleActivator create() { - return createInstance(pluginClass); - } - - /** Create plugin instances for all enumerated values. */ - public static List createAll() { - return Arrays.stream(values()).map(value -> value.create()).collect(Collectors.toList()); - } - } - - private static T createInstance(Class clazz) { - try { - Constructor ctor = clazz.getConstructor(); - return ctor.newInstance(new Object[]{}); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { - throw new RuntimeException("Failed to create instance for: " + clazz.getCanonicalName(), e); - } - } - - private static SpotlessEclipseFramework INSTANCE = null; - - /** - * Creates and configures a new {@link SpotlessEclipseFramework} using - * {@link DefaultBundles}, {@link DefaultPlugins} and default {@link SpotlessEclipseServiceConfig}. - * If there is already a an instance, the call is ignored. - * @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise. - * @throws BundleException Throws exception in case the setup failed. - * @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead. - */ - @Deprecated - public synchronized static boolean setup() throws BundleException { - return setup(plugins -> plugins.applyDefault()); - } - - /** - * Creates and configures a new {@link SpotlessEclipseFramework} using - * {@link DefaultBundles} and {@link DefaultPlugins}. - * If there is already a an instance, the call is ignored. - * @param plugins Eclipse plugins (which are also OSGi bundles) to start - * @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise. - * @throws BundleException Throws exception in case the setup failed. - * @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead. - */ - @Deprecated - public synchronized static boolean setup(Consumer plugins) throws BundleException { - return setup(config -> config.applyDefault(), plugins); - } - - /** - * Creates and configures a new {@link SpotlessEclipseFramework} using {@link DefaultBundles}. - * If there is already a an instance, the call is ignored. - * @param config Framework service configuration - * @param plugins Eclipse plugins (which are also OSGi bundles) to start - * @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise. - * @throws BundleException Throws exception in case the setup failed. - * @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead. - */ - @Deprecated - public synchronized static boolean setup(Consumer config, Consumer plugins) throws BundleException { - return setup(core -> core.applyDefault(), config, plugins); - } - - /** - * Creates and configures a new {@link SpotlessEclipseFramework} if there is none. - * If there is already a an instance, the call is ignored. - * @param core Activators of core bundles - * @param services Framework service configuration - * @param plugins Eclipse plugins to start - * @return False if the {@link SpotlessEclipseFramework} instance already exists, true otherwise. - * @throws BundleException Throws exception in case the setup failed. - * @deprecated Use {@link #setup(SpotlessEclipseConfig)} instead. - */ - @Deprecated - public synchronized static boolean setup(Consumer core, Consumer services, Consumer plugins) throws BundleException { - if (null != INSTANCE) { - return false; - } - setup(new SpotlessEclipseConfig() { - @Override - public void registerBundles(SpotlessEclipseCoreConfig config) { - core.accept(config); - } - - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - services.accept(config); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - plugins.accept(config); - } - }); - return true; - } - - /** - * Creates and configures a new {@link SpotlessEclipseFramework} if there is none. - * If there is already a an instance, the call is ignored. - * @param config Configuration - * @throws BundleException Throws exception in case the setup failed. - */ - public synchronized static void setup(SpotlessEclipseConfig config) throws BundleException { - if (null == INSTANCE) { - INSTANCE = new SpotlessEclipseFramework(); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - try { - INSTANCE.shutdown(); - } catch (Exception e) { - //At shutdown everything is just done on best-efforts basis - } - })); - - config.registerServices(INSTANCE.getServiceConfig()); - - SpotlessEclipseCoreConfig coreConfig = new SpotlessEclipseCoreConfig(); - config.registerBundles(coreConfig); - INSTANCE.startCoreBundles(coreConfig); - - SpotlessEclipsePluginConfig pluginConfig = new SpotlessEclipsePluginConfig(); - config.activatePlugins(pluginConfig); - for (Class extension : pluginConfig.getExtensions()) { - INSTANCE.addExtension(extension); - } - for (BundleConfig.Entry plugin : pluginConfig.get()) { - INSTANCE.addPlugin(plugin.state, plugin.activator); - } - - config.customize(); - } - } - - private final Function registry; - private final BundleController controller; - - private SpotlessEclipseFramework() throws BundleException { - - controller = new BundleController(); - registry = (pluginBundle) -> { - return PluginRegistrar.register(pluginBundle); - }; - } - - void shutdown() { - controller.shutdown(); - } - - private SpotlessEclipseServiceConfig getServiceConfig() { - return controller.getServices(); - } - - private void addExtension(Class clazzInBundleJar) throws BundleException { - controller.addBundle(clazzInBundleJar, registry); - } - - private void addPlugin(int state, BundleActivator plugin) throws BundleException { - controller.addBundle(state, plugin, registry); - } - - private void startCoreBundles(SpotlessEclipseCoreConfig coreConfig) throws BundleException { - //The SAXParserFactory.class is required for parsing the plugin XML files - addMandatoryServiceIfMissing(SAXParserFactory.class, SAXParserFactory.newInstance()); - - /* - * Since org.eclipse.core.runtime version 3.15.300, the Eclipse bundle look-up is accomplished - * via the wiring framework, which requires starting the InternalPlatform. - * The internal platform initialization is customized by the services - * registered to the controller. - */ - InternalPlatform.getDefault().start(controller); - - for (BundleConfig.Entry coreBundle : coreConfig.get()) { - try { - BundleContext context = controller.createContext(coreBundle.state); - coreBundle.activator.start(context); - } catch (Exception e) { - throw new BundleException(String.format("Failed to start %s", coreBundle.activator.getClass().getName()), BundleException.ACTIVATOR_ERROR, e); - } - } - } - - private void addMandatoryServiceIfMissing(Class interfaceClass, S service) { - if (null == controller.getServiceReference(interfaceClass)) { - controller.getServices().add(interfaceClass, service); - } - } -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipsePluginConfig.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipsePluginConfig.java deleted file mode 100644 index 2569c12cd9..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipsePluginConfig.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleActivator; - -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.DefaultPlugins; -import com.diffplug.spotless.extra.eclipse.base.osgi.BundleConfig; - -/** - * Configuration of plugins which shall be provided by the - * {@link SpotlessEclipseFramework}. - *

      - * Plugins are registered via the Eclipse registry. Therefore they - * required a {@code plugin.xml} configuration description. - * Note that a plugin does not necessarily derive from the - * Eclipse {@link org.eclipse.core.runtime.Plugin} class. - *

      - *

      - * Some plugins are pure extensions without any activator. - * For resource and plugin information lookup, a class can be - * specified which is in the JAR containing the resources and - * plugin information. This lookup procedure also supports - * fat JAR lookups as described in the ReadMe.md. - *

      - * @see org.eclipse.core.runtime.RegistryFactory - */ -public class SpotlessEclipsePluginConfig extends BundleConfig { - private final List> extensions; - - /** - * Don't instantiate and call {@link SpotlessEclipseConfig} directly. - * Registered plugins and extensions should only be instantiated once, since - * some still abusing singletons for access. - */ - SpotlessEclipsePluginConfig() { - extensions = new ArrayList<>(); - } - - /** Add an extension plugin, identified by a class of the plugin. */ - public void add(Class extensionClass) { - Objects.requireNonNull(extensionClass, "Plugin extension class must nor be null"); - extensions.add(extensionClass); - } - - /** Add a set of default bundles with their default states */ - public void add(Class... extensionClasses) { - Arrays.asList(extensionClasses).forEach(extensionClass -> add(extensionClass)); - } - - /** Returns the current configuration */ - public List> getExtensions() { - return extensions; - } - - @Override - public void applyDefault() { - add(SpotlessEclipseFramework.DefaultPlugins.createAll()); - } - - @Override - protected BundleActivator create(DefaultPlugins bundle) { - return bundle.create(); - } - - @Override - protected int getDefaultState(DefaultPlugins bundle) { - return Bundle.ACTIVE; - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseServiceConfig.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseServiceConfig.java deleted file mode 100644 index f0b9a97cc4..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseServiceConfig.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - -import java.util.Map; -import java.util.function.BiFunction; - -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.core.runtime.preferences.IPreferencesService; -import org.eclipse.equinox.log.ExtendedLogReaderService; -import org.eclipse.equinox.log.ExtendedLogService; -import org.eclipse.osgi.service.datalocation.Location; -import org.eclipse.osgi.service.debug.DebugOptions; -import org.eclipse.osgi.service.environment.EnvironmentInfo; -import org.osgi.framework.ServiceException; -import org.osgi.service.log.LogLevel; - -import com.diffplug.spotless.extra.eclipse.base.service.*; - -/** - * Configuration/Provision of services which shall be provided by the {@link SpotlessEclipseFramework}. - *

      - * The services provide basic functions/configuration to the {@link SpotlessEclipseFramework} bundles use the services. - * Hence the services can be used to customize the behavior of core bundles and plugins configured - * in the {@link SpotlessEclipseCoreConfig} and {@link SpotlessEclipsePluginConfig}. - *

      - */ -public interface SpotlessEclipseServiceConfig { - - /** Sets property/preference value available to all bundles, plugins and services. */ - void set(String key, String value); - - /** Sets property/preference values available to all bundles, plugins and services. */ - default void set(Map properties) { - properties.forEach((k, v) -> this.set(k, v)); - } - - /** - * Add custom service to collection. - *

      - * Only one service per interface is allowed. - * A service instance implementing multiple interfaces, can be added for each interface. - *

      - * Please refer to the default method implementation for examples. - * - * @param interfaceClass Service interface - * @param service Service instance - * @throws ServiceException in case service has already been configured - */ - public void add(Class interfaceClass, S service) throws ServiceException; - - /** - * Spotless formatters should not be configured by environment variables, and - * they shall be OS independent. - * @throws ServiceException in case service has already been configured - */ - default public void hideEnvironment() throws ServiceException { - add(EnvironmentInfo.class, new HiddenEnvironment()); - } - - /** - * Eclipse provides means to lookup the file content type, e.g. by file name extensions. - * This possibility is not required by most Spotless formatters. - * @throws ServiceException in case service has already been configured - */ - default public void ignoreContentType() throws ServiceException { - add(IContentTypeManager.class, new NoContentTypeSpecificHandling()); - } - - /** - * Disable Eclipse internal debugging. - * @throws ServiceException in case service has already been configured - */ - default public void disableDebugging() throws ServiceException { - add(DebugOptions.class, new NoDebugging()); - } - - /** - * Ignore accesses of unsupported preference. - * @throws ServiceException in case service has already been configured - */ - default public void ignoreUnsupportedPreferences() throws ServiceException { - add(IPreferencesService.class, new NoEclipsePreferences()); - } - - /** - * Use temporary locations in case plugins require to store file. - * These files (for example workspace preferences) will be deleted - * as soon as the application terminates. - * @throws ServiceException in case service has already been configured - */ - default public void useTemporaryLocations() throws ServiceException { - add(Location.class, new TemporaryLocation()); - } - - /** - * In case the string which will be formatted does not contain any - * line delimiter (single line), Eclipse falls back to use the - * system property. - * Change the system default to the UNIX line separator as required - * by Spotless. - * @throws ServiceException in case service has already been configured - */ - default public void changeSystemLineSeparator() throws ServiceException { - System.setProperty("line.separator", LINE_DELIMITER); - } - - /** - * Adds Eclipse logging service Slf4J binding. - * @throws ServiceException in case service has already been configured - */ - default public void useSlf4J(String loggerName) { - useSlf4J(loggerName, (s, l) -> s); - } - - /** - * Adds Eclipse logging service Slf4J binding with a message customizer function. - * @throws ServiceException in case service has already been configured - */ - default public void useSlf4J(String loggerName, BiFunction messageCustomizer) throws ServiceException { - SingleSlf4JService slf4jServce = new SingleSlf4JService(loggerName, messageCustomizer); - add(ExtendedLogService.class, slf4jServce); - add(ExtendedLogReaderService.class, slf4jServce); - slf4jServce.debug("Initialized Eclipse logging service."); - } - - /** - * Applies the default configurations. - * @throws ServiceException in case a service has already been configured - */ - default public void applyDefault() throws ServiceException { - hideEnvironment(); - ignoreContentType(); - disableDebugging(); - ignoreUnsupportedPreferences(); - useTemporaryLocations(); - changeSystemLineSeparator(); - } -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleConfig.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleConfig.java deleted file mode 100644 index 8e4b12c8d0..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleConfig.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.osgi; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Objects; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleActivator; - -/** A bundle configuration is given by its activator and the desired state */ -public abstract class BundleConfig> { - public static class Entry { - public final BundleActivator activator; - public final int state; - - public Entry(BundleActivator activator, int state) { - Objects.requireNonNull(activator, "activator"); - this.activator = activator; - this.state = state; - } - } - - private final List config; - - protected BundleConfig() { - config = new ArrayList(); - } - - /** - * Activate a bundle with a certain state. A non-active state is used by - * some bundles to allow a slim instantiation (for example in a headless - * Eclipse). - */ - public void add(BundleActivator activator, int state) { - config.add(new Entry(activator, state)); - } - - /** Returns the current configuration */ - public List get() { - return config; - } - - /** Activate a set of bundles with certain states */ - public void add(List config) { - this.config.addAll(config); - } - - /** Activate a bundle in active state, which is the nominal choice */ - public void add(BundleActivator activator) { - add(activator, Bundle.ACTIVE); - } - - /** Activate a set of bundles with in active state */ - public void add(Collection config) { - config.stream().forEach(entry -> add(entry)); - } - - /** Activate a default bundle with its default state */ - public void add(T bundle) { - add(create(bundle), getDefaultState(bundle)); - } - - /** Activate a set of default bundles with their default states */ - @SuppressWarnings("unchecked") - public void add(T... bundles) { - Arrays.asList(bundles).forEach(bundle -> add(bundle)); - } - - /** Activate a default bundle with a custom state */ - public void add(T bundle, int state) { - add(create(bundle), state); - } - - /** Applies the default configurations. */ - public abstract void applyDefault(); - - protected abstract BundleActivator create(T bundle); - - protected abstract int getDefaultState(T bundle); - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleController.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleController.java deleted file mode 100644 index 3589bd7082..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleController.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * 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.spotless.extra.eclipse.base.osgi; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -import org.eclipse.core.internal.jobs.JobManager; -import org.eclipse.osgi.internal.location.LocationHelper; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.Constants; -import org.osgi.framework.Filter; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.wiring.FrameworkWiring; - -/** - * OSGi bundle controller allowing a minimal Eclipse platform setup - * by bypassing the Eclipse internal platform. - * - * Bundles are loaded by the same class loader, sharing the same context. - * Services do not provide individual properties, but making use of the framework properties. - * All bundles have a persistent state. The OSGi life-cycle is not supported. - */ -public final class BundleController implements StaticBundleContext { - private static final String ECLIPSE_LAUNCHER_SYMBOLIC_NAME = "org.eclipse.osgi"; - - private final SimpleBundle systemBundle; - private final Map properties; - private final ServiceCollection services; - private final BundleSet bundles; - - @SuppressWarnings("deprecation") - public BundleController() throws BundleException { - //OSGI locks are not required, since this framework does not allow changes after initialization. - System.setProperty(LocationHelper.PROP_OSGI_LOCKING, LocationHelper.LOCKING_NONE); - - this.properties = new HashMap(); - //Don't activate all plugin bundles. Activation is triggered by this controller where needed. - properties.put(org.eclipse.core.internal.runtime.InternalPlatform.PROP_ACTIVATE_PLUGINS, Boolean.toString(false)); - - /* - * Used to set-up an internal member of the Eclipse runtime FindSupport, - * which is used during resources look-up from different version of bundles. - * Since the concept of the Spotless Eclipse framework does not allow multiple versions - * for a bundle, this property is never used. - */ - properties.put(org.eclipse.core.internal.runtime.FindSupport.PROP_NL, ""); - - bundles = new BundleSet(); - systemBundle = new SimpleBundle(this, Bundle.ACTIVE); - bundles.add(systemBundle); - - services = new ServiceCollection(systemBundle, properties); - - //Eclipse core (InternalPlatform) still uses PackageAdmin for looking up bundles - EclipseBundleLookup bundleLookup = new EclipseBundleLookup(systemBundle, bundles); - services.add(org.osgi.service.packageadmin.PackageAdmin.class, bundleLookup); - services.add(FrameworkWiring.class, bundleLookup); - - //Redirect framework activator requests to the org.eclipse.osgi bundle to this instance. - bundles.add(new SimpleBundle(systemBundle, ECLIPSE_LAUNCHER_SYMBOLIC_NAME, Bundle.ACTIVE)); - FrameworkBundleRegistry.initialize(this); - } - - /** - * Stop {@link org.eclipse.core.internal.jobs.JobManager} worker pool - * and clean up resources of Spotless bundles and services. - * - * @implNote The {@link org.osgi.framework.BundleActivator}s - * are not stopped, since they are not completely started. - * For example services are suppressed by {@link StaticBundleContext}. - */ - public void shutdown() { - JobManager.shutdown(); - bundles.getAll().forEach(b -> { - try { - b.stop(); - } catch (IllegalStateException | BundleException e) { - //Stop on best effort basis - } - }); - services.stop(); - } - - public ServiceCollection getServices() { - return services; - } - - /** Adds and starts a new bundle. */ - public void addBundle(int bundleState, BundleActivator activator, Function register) throws BundleException { - BundleContext contextFacade = new BundleControllerContextFacade(this, bundleState, activator); - bundles.add(contextFacade.getBundle()); - BundleException exception = register.apply(contextFacade.getBundle()); - if (null != exception) - throw exception; - try { - activator.start(contextFacade); - } catch (Exception e) { - throw new BundleException(String.format("Failed do start %s.", activator.getClass().getName()), BundleException.ACTIVATOR_ERROR, e); - } - } - - /** Adds new bundel whithout activator (e.g. used for only for extensions) */ - public void addBundle(Class clazzInBundleJar, Function register) throws BundleException { - BundleContext contextFacade = new BundleControllerContextFacade(this, clazzInBundleJar); - bundles.add(contextFacade.getBundle()); - BundleException exception = register.apply(contextFacade.getBundle()); - if (null != exception) - throw exception; - } - - /** Creates a context with an individual state if required. */ - public BundleContext createContext(int state) { - if (state == systemBundle.getState()) { - return this; - } - return new BundleControllerContextFacade(systemBundle, state); - } - - @Override - public String getProperty(String key) { - return properties.get(key); - } - - @Override - public Bundle getBundle() { - return systemBundle; - } - - @Override - public Bundle[] getBundles() { - Collection shallowCopy = bundles.getAll(); - return shallowCopy.toArray(new Bundle[shallowCopy.size()]); - } - - @Override - public Bundle getBundle(long id) { - return bundles.get(id); - } - - @Override - public Bundle getBundle(String location) { - if (Constants.SYSTEM_BUNDLE_LOCATION.equals(location)) { - return systemBundle; - } - return null; - } - - @Override - public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException { - //Filters are based on class names - String interfaceClassName = (null == clazz) ? filter : clazz; - return services.getReferences(interfaceClassName); - } - - @Override - public S getService(ServiceReference reference) { - return services.getService(reference); - } - - @Override - public Filter createFilter(String filter) throws InvalidSyntaxException { - return services.createFilter(filter); - } - - /** - * Facade providing access to an existing controller for a bundle - *

      - * All bundles have unrestricted access to the framework services and properties. - * However, each bundle and its context needs to maintain its individual - * symbolic name for look-up. - *

      - */ - private static class BundleControllerContextFacade implements StaticBundleContext { - - private final BundleContext context; - private final Bundle bundle; - - private BundleControllerContextFacade(BundleContext context, int bundleState, BundleActivator activator) throws BundleException { - this.context = context; - bundle = new SimpleBundle(this, bundleState, activator); - } - - private BundleControllerContextFacade(BundleContext context, Class clazzInBundleJar) throws BundleException { - this.context = context; - bundle = new SimpleBundle(this, clazzInBundleJar); - } - - /** Fakes an individual bundle state */ - private BundleControllerContextFacade(SimpleBundle bundle, int bundleState) { - this.context = bundle.getBundleContext(); - this.bundle = new SimpleBundle(bundle, bundleState); - } - - @Override - public String getProperty(String key) { - return context.getProperty(key); - } - - @Override - public Bundle getBundle() { - return bundle; - } - - @Override - public Bundle[] getBundles() { - return context.getBundles(); - } - - @Override - public Bundle getBundle(long id) { - return context.getBundle(id); - } - - @Override - public Bundle getBundle(String location) { - return context.getBundle(location); - } - - @Override - public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException { - return context.getAllServiceReferences(clazz, filter); - } - - @Override - public S getService(ServiceReference reference) { - return context.getService(reference); - } - - @Override - public Filter createFilter(String filter) throws InvalidSyntaxException { - return context.createFilter(filter); - } - - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleSet.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleSet.java deleted file mode 100644 index 59e15929fd..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleSet.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.osgi; - -import java.util.Collection; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; - -/** Thread save set of bundles, whereas each bundle has a unique symbolic name and a unique ID. */ -class BundleSet { - private final Map symbolicName2bundle; - private final Map id2bundle; - - BundleSet() { - symbolicName2bundle = new ConcurrentHashMap(); - id2bundle = new ConcurrentHashMap(); - } - - /** Get all bundles in collection */ - Collection getAll() { - return symbolicName2bundle.values(); - } - - /** Get bundle by symbolic name or null if collection does not contain the corresponding bundle. */ - Bundle get(String symbolicName) { - return symbolicName2bundle.get(symbolicName); - } - - /** Get bundle by its ID or null if collection does not contain the corresponding bundle. */ - Bundle get(long id) { - return id2bundle.get(id); - } - - /** Add bundle to collection. - * @throws BundleException */ - void add(Bundle bundle) throws BundleException { - Bundle existingBundle = symbolicName2bundle.put(bundle.getSymbolicName(), bundle); - if (null != existingBundle) { - throw new BundleException( - String.format("Bundle '%s' (ID: %d) is already part of collection with ID %d.", - bundle.getSymbolicName(), bundle.getBundleId(), existingBundle.getBundleId()), - BundleException.DUPLICATE_BUNDLE_ERROR); - } - Bundle bundleWithSameID = id2bundle.put(bundle.getBundleId(), bundle); - if (null != bundleWithSameID) { - throw new BundleException( - String.format("Bundle ID '%d' for '%s' is already used by '%s'.", - bundle.getBundleId(), - bundle.getSymbolicName(), - bundleWithSameID.getSymbolicName()), - BundleException.DUPLICATE_BUNDLE_ERROR); - } - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/EclipseBundleLookup.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/EclipseBundleLookup.java deleted file mode 100644 index 0ec091a58b..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/EclipseBundleLookup.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.osgi; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.eclipse.osgi.internal.framework.FilterImpl; -import org.osgi.framework.Bundle; -import org.osgi.framework.FrameworkListener; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.namespace.IdentityNamespace; -import org.osgi.framework.wiring.BundleCapability; -import org.osgi.framework.wiring.FrameworkWiring; -import org.osgi.resource.Namespace; -import org.osgi.resource.Requirement; -import org.osgi.service.packageadmin.ExportedPackage; -import org.osgi.service.packageadmin.PackageAdmin; -import org.osgi.service.packageadmin.RequiredBundle; - -/** - * - * {@link PackageAdmin} and {@link FrameworkWiring} service for bundle look-up. - *

      - * The wiring information will always claim that all required bundles are present, since - * Spotlss does on purpose not provide all dependencies requested by plugins, since - * only small parts of the plugins are used. - * Removal and addition requests for bundles will always claim that there is nothing to do. - *

      - * PackageAdmin interface is deprecated, but might still be used by bundles. - * It is kept for backward compatibility until removed from Eclipse. - */ -@SuppressWarnings("deprecation") -class EclipseBundleLookup implements FrameworkWiring, PackageAdmin { - - private static final Set OSGI_KEYS_FOR_SYMBOLIC_NAMES = Collections.unmodifiableSet(Stream.of(IdentityNamespace.IDENTITY_NAMESPACE, IdentityNamespace.TYPE_BUNDLE).collect(Collectors.toSet())); - private final Bundle systemBundle; - private final BundleSet bundles; - - EclipseBundleLookup(final Bundle systemBundle, final BundleSet bundles) { - this.systemBundle = systemBundle; - this.bundles = bundles; - } - - @Override - @Deprecated - public ExportedPackage[] getExportedPackages(Bundle bundle) { - return null; - } - - @Override - @Deprecated - public ExportedPackage[] getExportedPackages(String name) { - return null; - } - - @Override - @Deprecated - public ExportedPackage getExportedPackage(String name) { - return null; - } - - @Override - @Deprecated - public void refreshPackages(Bundle[] bundles) {} - - @Override - public boolean resolveBundles(Bundle[] bundles) { - return true; //All required bundles can be considered available (to be confirmed by UT) - } - - @Override - public RequiredBundle[] getRequiredBundles(String symbolicName) { - return null; // No unresolved required bundles exist - } - - @Override - public Bundle[] getBundles(String symbolicName, String versionRange) { - //Bundles with different versions cannot be supported due to the usage of same class-loader - Bundle bundle = bundles.get(symbolicName); - return (null == bundle) ? null : new Bundle[]{bundle}; - } - - @Override - public Bundle[] getFragments(Bundle bundle) { - return null; //No fragments - } - - @Override - public Bundle[] getHosts(Bundle bundle) { - return null; //No fragments - } - - @Override - public Bundle getBundle(@SuppressWarnings("rawtypes") Class clazz) { - return bundles.get(clazz.getName()); - } - - @Override - public int getBundleType(Bundle bundle) { - return 0; //No fragments - } - - @Override - public Bundle getBundle() { - return systemBundle; - } - - @Override - public void refreshBundles(Collection bundles, FrameworkListener... listeners) { - //Spotless bundles cannot be loaded dynamically - } - - @Override - public boolean resolveBundles(Collection bundles) { - return true; - } - - @Override - public Collection getRemovalPendingBundles() { - return Collections.emptyList(); //Nothing to remove - } - - @Override - public Collection getDependencyClosure(Collection bundles) { - return Collections.emptyList(); //No dependencies - } - - @Override - public Collection findProviders(Requirement requirement) { - // requirement must not be null (according to interface description)! - String filterSpec = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE); - if (null == filterSpec) { - throw new IllegalArgumentException("Requirement filter diretive '" + Namespace.REQUIREMENT_FILTER_DIRECTIVE + "' not found."); - } - try { - FilterImpl requirementFilter = FilterImpl.newInstance(filterSpec); - Collection requiredSymbolicNames = getRequestedSymbolicNames(requirementFilter); - Collection capabilities = new ArrayList(requiredSymbolicNames.size()); - requiredSymbolicNames.forEach(symbolicName -> { - Bundle bundle = bundles.get(symbolicName); - if (bundle != null) { - capabilities.add(new SimpleBundleCapability(bundle)); - } - }); - return capabilities; - } catch (InvalidSyntaxException e) { - throw new IllegalArgumentException("Filter specifiation invalid:\n" + filterSpec, e); - } - } - - /** - * Simplified parser irgnoreing the version. - * Parser is incomplete since it ignores the filter operation. - * It basicall implements the bespoke way Eclipse maps its old style bundle handling to OSGI. - */ - private static Collection getRequestedSymbolicNames(FilterImpl filter) { - List symbolicNames = filter.getStandardOSGiAttributes().entrySet().stream().filter(entry -> OSGI_KEYS_FOR_SYMBOLIC_NAMES.contains(entry.getKey())).map(entry -> entry.getValue()).collect(Collectors.toList()); - filter.getChildren().forEach(childFilter -> { - symbolicNames.addAll(getRequestedSymbolicNames(childFilter)); - }); - return symbolicNames; - } -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/FrameworkBundleRegistry.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/FrameworkBundleRegistry.java deleted file mode 100644 index 18d5c4bed4..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/FrameworkBundleRegistry.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2016-2020 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.extra.eclipse.base.osgi; - -import java.util.Optional; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; -import org.osgi.framework.connect.FrameworkUtilHelper; - -/** - * Framework bundle registry service for bundles which do not come with an activator. - * - * Instead of returning the system bundle, a new bundle is created - * to provide an individual resource accessor, so that - * the correct JAR is searched for relative resource paths. - * Note that this can also be used to override - * original resources by providing a resource in the - * corresponding fat JAR location. - */ -public class FrameworkBundleRegistry implements FrameworkUtilHelper { - static BundleController INSTANCE = null; - - static void initialize(BundleController bundleController) { - if (INSTANCE != null) { - throw new RuntimeException(FrameworkBundleRegistry.class.getName() + " already initialized."); - } - INSTANCE = bundleController; - } - - @Override - public Optional getBundle(Class classFromBundle) { - try { - return Optional.of(new SimpleBundle(INSTANCE, classFromBundle)); - } catch (BundleException e) { - //If the class cannot be associated to a JAR or fat JAR resource location, just retun null - } - return Optional.empty(); - } -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/ResourceAccessor.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/ResourceAccessor.java deleted file mode 100644 index b75a2835ac..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/ResourceAccessor.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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.spotless.extra.eclipse.base.osgi; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Enumeration; -import java.util.jar.JarFile; -import java.util.jar.Manifest; - -import org.eclipse.osgi.internal.debug.Debug; -import org.eclipse.osgi.storage.bundlefile.BundleEntry; -import org.eclipse.osgi.storage.bundlefile.BundleFile; -import org.eclipse.osgi.storage.bundlefile.DirBundleFile; -import org.eclipse.osgi.storage.bundlefile.ZipBundleFile; -import org.eclipse.osgi.util.ManifestElement; -import org.osgi.framework.BundleException; -import org.osgi.framework.Constants; - -import com.diffplug.spotless.extra.eclipse.base.service.NoDebugging; - -/** - * Helper to access resources. - *

      - * Spotless Eclipse formatters using in many cases fat JARs, compressing multiple - * bundles within one JAR. Their resources can get overridden in a fat JAR. - * Hence they provided under the bundle activators path name. - *

      - *

      - * The resource overriding prevention is required in case the Spotless - * Eclipse formatters integrate third party JARs, not available via M2. - * Additionally it can be used in case existing third party Eclipse plugins - * are mocked by Spotless, requiring the provision of multiple customized - * plugin information (META-INF, plugin.xml) within one JAR. - *

      - */ -class ResourceAccessor { - private static final Debug NO_DEBUGGING = new Debug(new NoDebugging()); - private final String fatJarResourcePath; - private final BundleFile bundleFile; - - /** Resources are located in the SpotlessFramework JAR */ - ResourceAccessor() throws BundleException { - this(ResourceAccessor.class); - } - - /** Resources are located in the JAR of the given class - * @throws BundleException */ - ResourceAccessor(Class clazz) throws BundleException { - String bundleObjPath = clazz.getName(); - fatJarResourcePath = bundleObjPath.substring(0, bundleObjPath.lastIndexOf('.')); - try { - bundleFile = getBundlFile(clazz); - } catch (BundleException e) { - throw new BundleException(String.format("Failed to locate resources for bundle '%s'.", clazz.getName()), e); - } - } - - private static BundleFile getBundlFile(Class clazz) throws BundleException { - URI objUri = getBundleUri(clazz); - File jarOrDirectory = new File(objUri.getPath()); - if (!(jarOrDirectory.exists() && jarOrDirectory.canRead())) { - throw new BundleException(String.format("Path '%s' for '%s' is not accessible exist on local file system.", objUri, clazz.getName()), BundleException.READ_ERROR); - } - try { - return jarOrDirectory.isDirectory() ? new DirBundleFile(jarOrDirectory, false) : new ZipBundleFile(jarOrDirectory, null, null, NO_DEBUGGING, false); - } catch (IOException e) { - throw new BundleException(String.format("Cannot access bundle at '%s'.", jarOrDirectory), BundleException.READ_ERROR, e); - } - } - - private static URI getBundleUri(Class clazz) throws BundleException { - try { - URL objUrl = clazz.getProtectionDomain().getCodeSource().getLocation(); - return objUrl.toURI(); - } catch (NullPointerException e) { - //No bunlde should be used for RT classes lookup. See also org.eclipse.core.runtime.PerformanceStats. - throw new BundleException(String.format("No code source can be located for class '%s'. Class is probably not within a bundle, but part of the RT.", clazz.getName()), BundleException.READ_ERROR, e); - } catch (SecurityException e) { - throw new BundleException(String.format("Access to class '%s' is denied.", clazz.getName()), BundleException.READ_ERROR, e); - } catch (URISyntaxException e) { - throw new BundleException(String.format("Path for '%s' is invalid.", clazz.getName()), BundleException.READ_ERROR, e); - } - } - - /** Get the manifest name from the resources. */ - String getManifestName() throws BundleException { - URL manifestUrl = getEntry(JarFile.MANIFEST_NAME); - if (null != manifestUrl) { - try { - Manifest manifest = new Manifest(manifestUrl.openStream()); - String headerValue = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); - if (null == headerValue) { - throw new BundleException(String.format("Symbolic values not found in '%s'.", manifestUrl), BundleException.MANIFEST_ERROR); - } - ManifestElement[] elements = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, headerValue); - if (null == elements) { - throw new BundleException(String.format("Symbolic name not found '%s'. Value is '%s'.", manifestUrl, headerValue), BundleException.MANIFEST_ERROR); - } - //The parser already checked that at least one value exists - return elements[0].getValueComponents()[0]; - - } catch (IOException e) { - throw new BundleException(String.format("Failed to parse Manifest '%s' in '%s'.", manifestUrl, bundleFile.toString()), BundleException.MANIFEST_ERROR, e); - } - } - throw new BundleException(String.format("'%s' in '%s' not found. Tried also fat JAR location '%s'.", JarFile.MANIFEST_NAME, bundleFile.toString(), fatJarResourcePath), BundleException.MANIFEST_ERROR); - } - - /** Get resource URL for relative path, or null if the path is not present */ - URL getEntry(String path) { - BundleEntry entry = bundleFile.getEntry(getFatJarPath(path)); - if (null == entry) { - entry = bundleFile.getEntry(path); - } - return null == entry ? null : entry.getLocalURL(); - } - - /** - * Enumeration of Strings that indicate the paths found or null if the path does not exist. - */ - Enumeration getEntries(String path) { - Enumeration entries = bundleFile.getEntryPaths(getFatJarPath(path)); - if (null == entries) { - entries = bundleFile.getEntryPaths(path); - } - return entries; - } - - private String getFatJarPath(String path) { - return fatJarResourcePath + "/" + path; - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/ServiceCollection.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/ServiceCollection.java deleted file mode 100644 index 2ea67f712f..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/ServiceCollection.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * 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.spotless.extra.eclipse.base.osgi; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Dictionary; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import org.eclipse.osgi.internal.framework.DTOBuilder; -import org.osgi.framework.Bundle; -import org.osgi.framework.Filter; -import org.osgi.framework.ServiceException; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.dto.ServiceReferenceDTO; - -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; - -/** - * Collection of services. - * Eclipse service are not expected to hold any resources. Spotless services - * can implement AutoCloseable in case a resource release is required on shutdown. - * - * Note that the collection access is not thread save, since it is expected - * that the collection is completed before starting any bundles. - */ -public class ServiceCollection implements SpotlessEclipseServiceConfig { - private final Map> className2Service; - private final List servicesWithResources; - private final Bundle systemBundle; - private final Map properties; - - /** - * Collection of services - * @param systemBundle All services will belong to the system bundles - * @param All services share the same properties - */ - ServiceCollection(Bundle systemBundle, Map properties) { - className2Service = new HashMap>(); - servicesWithResources = new ArrayList<>(); - this.systemBundle = systemBundle; - this.properties = properties; - } - - void stop() { - servicesWithResources.stream().forEach(s -> { - try { - s.close(); - } catch (Exception e) { - //Stop on best effort basis - } - }); - } - - @Override - public void set(String key, String value) { - properties.put(key, value); - } - - @Override - public void add(Class interfaceClass, S service) throws ServiceException { - String className = interfaceClass.getName(); - if (null != className2Service.put(interfaceClass.getName(), new FrameworkServiceReference(className, service))) { - throw new ServiceException( - String.format("Service '%s' is already registered.", interfaceClass.getName()), ServiceException.FACTORY_ERROR); - } - if (service instanceof AutoCloseable) { - servicesWithResources.add((AutoCloseable) service); - } - } - - /** Creates filter object suitable to lookup service by its interface name. */ - Filter createFilter(String filterDescr) { - Optional serviceClassName = className2Service.keySet().stream().filter(serviceClazzName -> filterDescr.contains(serviceClazzName)).findFirst(); - return new ClassNameBasedFilter(serviceClassName); - } - - /** - * Get reference matching interface class name or all references - * @param interfaceClassName Class name filter. All references are returned in case filter is null - * @return Matching or all interfaces. If no interface is matching the filter, null is returned. - */ - ServiceReference[] getReferences(String interfaceClassName) { - if (null == interfaceClassName) { - Collection> allServices = className2Service.values(); - return allServices.toArray(new ServiceReference[allServices.size()]); - } - ServiceReference singleService = className2Service.get(interfaceClassName); - return (null == singleService) ? null : new ServiceReference[]{singleService}; - } - - /** - * Return service for reference if it belongs to the system bundle. - * @param reference Service reference - * @return null, if service does not belong to the system bundle - */ - S getService(ServiceReference reference) { - if (systemBundle == reference.getBundle()) { - return ((FrameworkServiceReference) reference).getService(); - } - return null; - } - - /** References to static services (not modifiable at run-time */ - private class FrameworkServiceReference implements ServiceReference { - - private final String className; - private final S service; - - private FrameworkServiceReference(String className, S service) { - this.className = className; - this.service = service; - } - - private S getService() { - return service; - } - - @Override - public java.lang.Object getProperty(String key) { - return properties.get(key); - } - - @Override - public String[] getPropertyKeys() { - return properties.keySet().toArray(new String[properties.size()]); - } - - @Override - public Bundle getBundle() { - return systemBundle; - } - - @Override - public Bundle[] getUsingBundles() { - return new Bundle[]{systemBundle}; - } - - @Override - public boolean isAssignableTo(Bundle bundle, String className) { - // Since only one class loader is used, same class come from the same package - return this.className.equals(className); - } - - @Override - @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "EQ_COMPARETO_USE_OBJECT_EQUALS") - public int compareTo(Object reference) { - return (this == reference) ? 0 : 1; - } - - @Override - public Dictionary getProperties() { - return new Hashtable(properties); - } - - @SuppressWarnings("unchecked") - @Override - public A adapt(Class type) { - if (ServiceReferenceDTO.class.equals(type)) { - return (A) DTOBuilder.newServiceReferenceDTO(this); - } - return null; - } - - } - - /** - * Class name based service filter - *

      - * Dictionary and capability look-ups are not supported and marked as deprecated. - */ - private class ClassNameBasedFilter implements Filter { - - private final static String NO_MATCH_CLASS_NAME = ""; - - private final String className; - - private ClassNameBasedFilter(Optional className) { - this.className = className.orElse(NO_MATCH_CLASS_NAME); - } - - @Override - public boolean match(ServiceReference reference) { - return reference.isAssignableTo(systemBundle, className); - } - - @Override - @Deprecated - public boolean match(Dictionary dictionary) { - throw new UnsupportedOperationException("Dictionary based service look-up is not supported."); - } - - @Override - @Deprecated - public boolean matchCase(Dictionary dictionary) { - throw new UnsupportedOperationException("Dictionary based service look-up is not supported."); - } - - @Override - @Deprecated - public boolean matches(Map map) { - throw new UnsupportedOperationException("Capability based service look-up is not supported."); - } - - @Override - public String toString() { - return className; - } - - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/SimpleBundle.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/SimpleBundle.java deleted file mode 100644 index bdf8888b30..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/SimpleBundle.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.osgi; - -import java.net.URL; -import java.util.Enumeration; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; - -/** Fixed state simple bundle. */ -class SimpleBundle implements StaticBundle, TemporaryBundle { - private final String name; - private final int state; - private final BundleContext context; - private final int id; - private final ResourceAccessor resources; - - /** System bundle corresponding to the SpotlessFramework JARs manifest */ - SimpleBundle(BundleContext context, int state) throws BundleException { - this(context, state, new ResourceAccessor()); - } - - /** System bundle for a dedicated bundle activator */ - SimpleBundle(BundleContext context, int state, BundleActivator activator) throws BundleException { - this(context, state, new ResourceAccessor(activator.getClass())); - } - - /** System bundle providing only extensions and therefore does not require an activator */ - SimpleBundle(BundleContext context, Class clazzInBundleJar) throws BundleException { - //These bundles are always active (means that resources have been resolved) - this(context, Bundle.ACTIVE, new ResourceAccessor(clazzInBundleJar)); - } - - /** Internal constructor */ - private SimpleBundle(BundleContext context, int state, ResourceAccessor resources) throws BundleException { - this.state = state; - this.context = context; - this.resources = resources; - id = context.getBundles().length; - name = resources.getManifestName(); - } - - /** Additional bundle with a different symbolic name and state */ - SimpleBundle(SimpleBundle master, String name, int state) { - this.name = name; - this.state = state; - context = master.context; - resources = master.resources; - id = context.getBundles().length; - } - - /** Bundle clone with a different state */ - SimpleBundle(SimpleBundle master, int state) { - this.state = state; - context = master.context; - resources = master.resources; - id = master.id; - name = master.name; - } - - @Override - public A adapt(Class type) { - /* - * The adaptation is currently used by the InternalPlugin to get the framework wiring - * implementation from the system bundle. - * The original purpose to provide more specialized access to the Bundle object, - * seems not be used by Eclipse at all. - * Hence the call is mapped to old-style Eclipse services. - */ - try { - - ServiceReference[] references = context.getAllServiceReferences(type.getName(), ""); - if ((null != references) && (0 != references.length)) { - if (1 != references.length) { - throw new IllegalArgumentException("Multiple services found for " + type.getName()); //In Spotless services should always be unique - } - Object obj = context.getService(references[0]); - try { - return type.cast(obj); - } catch (ClassCastException e) { - throw new IllegalArgumentException("Received unexpected class for reference filter " + type.getName(), e); - } - } - return null; - } catch (InvalidSyntaxException e) { - throw new IllegalArgumentException("Unexpected syntax exception", e); //Should never be thrown by Spotless bundle controller - } - } - - @Override - public int getState() { - return state; - } - - @Override - public long getBundleId() { - return id; - } - - @Override - public ServiceReference[] getRegisteredServices() { - try { - return context.getAllServiceReferences(null, null); - } catch (InvalidSyntaxException e) { - throw new RuntimeException(e); //Filter 'null' is valid for 'select all'. - } - } - - @Override - public String getSymbolicName() { - return name; - } - - @Override - public BundleContext getBundleContext() { - return context; - } - - @Override - public Enumeration getEntryPaths(String path) { - return resources.getEntries(path); - } - - @Override - public URL getEntry(String path) { - return resources.getEntry(path); - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/SimpleBundleCapability.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/SimpleBundleCapability.java deleted file mode 100644 index 66f331807d..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/SimpleBundleCapability.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.osgi; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.osgi.framework.Bundle; -import org.osgi.framework.Version; -import org.osgi.framework.wiring.BundleCapability; -import org.osgi.framework.wiring.BundleRequirement; -import org.osgi.framework.wiring.BundleRevision; -import org.osgi.framework.wiring.BundleWiring; -import org.osgi.resource.Capability; -import org.osgi.resource.Requirement; - -/** - * Simplified bundle capability ignoring internal wiring and versions - *

      - * Since multiple versions/implementations of bundles for the same - * capability is not supported a split of bundle capability and revision is not required. - */ -class SimpleBundleCapability implements BundleCapability, BundleRevision { - private final Bundle bundle; - - SimpleBundleCapability(Bundle bundle) { - this.bundle = bundle; - } - - @Override - public BundleRevision getRevision() { - return this; - } - - @Override - public String getNamespace() { - return this.getClass().getName(); //All bundles live in th same namespace - } - - @Override - public Map getDirectives() { - return Collections.emptyMap(); - } - - @Override - public Map getAttributes() { - return Collections.emptyMap(); - } - - @Override - public BundleRevision getResource() { - return this; - } - - @Override - public Bundle getBundle() { - return bundle; - } - - @Override - public String getSymbolicName() { - return bundle.getSymbolicName(); - } - - @Override - public Version getVersion() { - return bundle.getVersion(); - } - - @Override - public List getDeclaredCapabilities(String namespace) { - return Collections.emptyList(); - } - - @Override - public List getDeclaredRequirements(String namespace) { - return Collections.emptyList(); - } - - @Override - public int getTypes() { - return 0; //It does not matter whether this bunddle is a fragment of not since all bundles are initially provided - } - - @Override - public BundleWiring getWiring() { - return null; //No wiring information - } - - @Override - public List getCapabilities(String namespace) { - return Collections.emptyList(); - } - - @Override - public List getRequirements(String namespace) { - return Collections.emptyList(); - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/StaticBundle.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/StaticBundle.java deleted file mode 100644 index 282804a332..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/StaticBundle.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.osgi; - -import java.io.InputStream; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; -import org.osgi.framework.ServiceReference; - -/** - * Unmodifiable bundle with a fixed life-cycle. - *

      - * All state related modifications are ignored. - * Installation related methods (update/uninstall) are unsupported. - * Unsupported methods are marked as deprecated and causing an exception. - */ -public interface StaticBundle extends Bundle { - - @Override - default public void start(int options) throws BundleException {} - - @Override - default public void start() throws BundleException {} - - @Override - default public void stop(int options) throws BundleException {} - - @Override - default public void stop() throws BundleException {} - - @Override - @Deprecated - default public void update(InputStream input) throws BundleException { - update(); - } - - @Override - @Deprecated - default public void update() throws BundleException { - throw new UnsupportedOperationException("Bundle modifications are not supported."); - } - - @Override - @Deprecated - default public void uninstall() throws BundleException { - throw new UnsupportedOperationException("Bundles cannot be uninstalled."); - } - - @Override - default public long getLastModified() { - return 0; - } - - @Override - @Deprecated - default public String getLocation() { - throw new UnsupportedOperationException("Bundle lookup by location only required for installation/update."); - } - - @Override - default public ServiceReference[] getServicesInUse() { - return getRegisteredServices(); //There is no distinction between available services and services in use. - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/StaticBundleContext.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/StaticBundleContext.java deleted file mode 100644 index 040ef98444..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/StaticBundleContext.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.osgi; - -import java.io.File; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Dictionary; -import java.util.Objects; -import java.util.stream.Collectors; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.BundleListener; -import org.osgi.framework.FrameworkListener; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceFactory; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceObjects; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; - -/** - * Restriction of the {@link BundleContext} interface rejecting run-time provision of bundles. - * Services provided at run-time are ignored. - *

      - * Multiple service instances per class are not supported, hence the services can be filtered by class name. - * Unsupported methods are marked as deprecated an causing an exception. - * Registration and removal of bundle/service listeners are ignored, since a run-time - * provision of bundles or services is not supported. - */ -interface StaticBundleContext extends BundleContext { - - @Override - @Deprecated - default public Bundle installBundle(String location, InputStream input) throws BundleException { - throw new UnsupportedOperationException("Run-time installation of bundles is not supported."); - } - - @Override - @Deprecated - default public Bundle installBundle(String location) throws BundleException { - throw new UnsupportedOperationException("Run-time installation of bundles is not supported."); - } - - @Override - default public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException {} - - @Override - default public void addServiceListener(ServiceListener listener) {} - - @Override - default public void removeServiceListener(ServiceListener listener) {} - - @Override - default public void addBundleListener(BundleListener listener) {} - - @Override - default public void removeBundleListener(BundleListener listener) {} - - @Override - default public void addFrameworkListener(FrameworkListener listener) {} - - @Override - default public void removeFrameworkListener(FrameworkListener listener) {} - - @Override - @Deprecated - default public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) { - throw new UnsupportedOperationException("Run-time provision of services is not supported."); - } - - @Override - @Deprecated - default public ServiceRegistration registerService(String clazz, Object service, Dictionary properties) { - return null; //Ignore additional services - } - - @Deprecated - @Override - default public ServiceRegistration registerService(Class clazz, S service, Dictionary properties) { - return null; //Ignore additional services - } - - @Override - @Deprecated - default public ServiceRegistration registerService(Class clazz, ServiceFactory factory, Dictionary properties) { - return null; //Ignore additional services - } - - @SuppressWarnings("unchecked") - @Override - default public ServiceReference getServiceReference(Class clazz) { - Objects.requireNonNull(clazz, "The class under whose name the service was registered must not be null."); - return (ServiceReference) getServiceReference(clazz.getName()); - } - - @Override - default public ServiceReference getServiceReference(String clazz) { - Objects.requireNonNull(clazz, "The class under whose name the service was registered must not be null."); - ServiceReference[] references; - try { - references = getServiceReferences(clazz, null); - } catch (InvalidSyntaxException e) { - throw new RuntimeException(e); //null is always valid - } - return (null == references) ? null : references[0]; - } - - @Override - default public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException { - return getAllServiceReferences(clazz, filter); //Services are always considered compatible - } - - @Override - default public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException { - //Filters are based on class names - ServiceReference reference = (null == clazz) ? getServiceReference(filter) : getServiceReference(clazz); - return (reference == null) ? null : new ServiceReference[]{reference}; - } - - @SuppressWarnings("unchecked") - @Override - default public Collection> getServiceReferences(Class clazz, String filter) throws InvalidSyntaxException { - ServiceReference[] references = getServiceReferences(clazz.getName(), filter); - Collection> result = new ArrayList>(0); - if (null != references) { - result = Arrays.stream(references).map(r -> (ServiceReference) r).collect(Collectors.toList()); - } - return result; - } - - @Override - default public boolean ungetService(ServiceReference reference) { - return true; //Services are persistent and never unregistered - } - - @Override - @Deprecated - default public ServiceObjects getServiceObjects(ServiceReference reference) { - throw new UnsupportedOperationException("Service specific objects are not supported."); - } - - @Override - @Deprecated - default public File getDataFile(String filename) { - throw new UnsupportedOperationException("Persistent data storage provision is handled by the Location service."); - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/TemporaryBundle.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/TemporaryBundle.java deleted file mode 100644 index 24cfadc8c2..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/TemporaryBundle.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.osgi; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.security.cert.X509Certificate; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.osgi.framework.Bundle; -import org.osgi.framework.Version; - -/** - * Temporary bundle loaded by common class loader and added temporarily. - * It shall not be recognized as a Eclipse plugin (providing plugin.xml) - * but as a mere OSGI bundle. - *

      - * META data look-ups are not supported (only required for Eclipse plugins). - * Entry look-up in the bundle space (findEntries) is not supported. - * Installation related methods (update/uninstall) are not supported. - * Unsupported methods are marked as deprecated and causing an exception. - */ -public interface TemporaryBundle extends Bundle { - - @Override - default public Version getVersion() { - return Version.emptyVersion; //Cannot support multiple version using single class loader. - } - - @Override - default public int compareTo(Bundle o) { - //Symbolic name is sufficient to distinguish bundles - return getSymbolicName().compareTo(o.getSymbolicName()); - } - - @Override - default public A adapt(Class type) { - return null; //Adaptation is not successful - } - - @Override - @Deprecated - default public Dictionary getHeaders() { - throw new UnsupportedOperationException("Bundle META information is not available."); - } - - @Override - @Deprecated - default public Dictionary getHeaders(String locale) { - return getHeaders(); - } - - @Override - default public URL getResource(String name) { - return getClass().getClassLoader().getResource(name); - } - - @Override - default public Enumeration getResources(String name) throws IOException { - return getClass().getClassLoader().getResources(name); - } - - @Override - @Deprecated - default public Enumeration findEntries(String path, String filePattern, boolean recurse) { - return null; //Local JAR look-up are not supported per default - } - - @Override - default public Class loadClass(String name) throws ClassNotFoundException { - return getClass().getClassLoader().loadClass(name); - } - - @Override - default public boolean hasPermission(Object permission) { - return true; //Dedicated permissions are not supported - } - - @Override - default public Map> getSignerCertificates(int signersType) { - return new HashMap>(0); //Bundle is not signed - } - - @Override - default public File getDataFile(String filename) { - return null; //No file system support for persistent files - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/package-info.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/package-info.java deleted file mode 100644 index da74c0471e..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/osgi/package-info.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2016 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. - */ -/** Simplified OSGIi implementation bypassing Equinox module layer. */ -package com.diffplug.spotless.extra.eclipse.base.osgi; diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/package-info.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/package-info.java deleted file mode 100644 index b82e4d40ca..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2016 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. - */ -/** - * Common Spotless Eclipse Equinox setup classes. - * Please refer to the {@code eclipse-base} {@code README.md} for - * usage instructions. - */ -@ParametersAreNonnullByDefault -package com.diffplug.spotless.extra.eclipse.base; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/runtime/PluginRegistrar.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/runtime/PluginRegistrar.java deleted file mode 100644 index cdee9893dc..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/runtime/PluginRegistrar.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.runtime; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.PropertyResourceBundle; -import java.util.ResourceBundle; - -import org.eclipse.core.internal.registry.ExtensionRegistry; -import org.eclipse.core.runtime.IContributor; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.RegistryFactory; -import org.eclipse.core.runtime.spi.RegistryContributor; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; - -/** Registers Eclipse plugins at runtime based on a loaded bundle. - *

      - * Note that the functionality provided by this class uses incubation features of the Eclipse core. - */ -public class PluginRegistrar { - private static final String PLUGIN_XML = "plugin.xml"; - private static final String PLUGIN_PROPERTIES = "plugin.properties"; - - public static BundleException register(Bundle bundle) { - PluginRegistrar registrar = new PluginRegistrar(bundle); - try { - registrar.register(); - } catch (BundleException e) { - return e; - } - return null; - } - - private final Bundle bundle; - - private PluginRegistrar(Bundle bundle) { - this.bundle = bundle; - } - - private void register() throws BundleException { - IExtensionRegistry reg = RegistryFactory.getRegistry(); - Object registryUser = ((ExtensionRegistry) reg).getTemporaryUserToken(); - if (!reg.addContribution(getStreamForEntry(PLUGIN_XML), createContributor(), false, null, getPluginProperties(), registryUser)) { - throw new BundleException("Could not add plugin: " + bundle.getSymbolicName(), BundleException.REJECTED_BY_HOOK); - } - } - - private IContributor createContributor() { - return new RegistryContributor( - Long.toString(bundle.getBundleId()), - bundle.getSymbolicName(), - // Local host - null, - null); - } - - private ResourceBundle getPluginProperties() throws BundleException { - //Some plugins, like the org.codehaus.groovy.eclipse.core, do not provide a property file. - InputStream is = entryExists(PLUGIN_PROPERTIES) ? getStreamForEntry(PLUGIN_PROPERTIES) : new ByteArrayInputStream(new byte[0]); - try { - return new PropertyResourceBundle(is); - } catch (IOException e) { - throw new BundleException(String.format("Bund resource '%s' is not encoded with ISO-8859-1.", PLUGIN_PROPERTIES), BundleException.MANIFEST_ERROR, e); - } - } - - private InputStream getStreamForEntry(String path) throws BundleException { - try { - return getEntry(path).openStream(); - } catch (IOException e) { - throw new BundleException(String.format("Cannot access mandatory resource '%s'.", path), BundleException.MANIFEST_ERROR, e); - } - } - - private URL getEntry(String path) throws BundleException { - URL url = bundle.getEntry(path); - if (null == url) { - throw new BundleException(String.format("Cannot find mandatory resource '%s'.", path), BundleException.MANIFEST_ERROR); - } - return url; - } - - private boolean entryExists(String path) { - return null != bundle.getEntry(path); - } -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/runtime/package-info.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/runtime/package-info.java deleted file mode 100644 index 5ed08616b9..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/runtime/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2016 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. - */ -/** - * Eclipse Core Runtime adapters allowing runtime modifications which normally requires an Eclipse restart. - */ -package com.diffplug.spotless.extra.eclipse.base.runtime; diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/HiddenEnvironment.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/HiddenEnvironment.java deleted file mode 100644 index 8c9c1a6c91..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/HiddenEnvironment.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.service; - -import java.util.Locale; - -import org.eclipse.osgi.service.environment.Constants; -import org.eclipse.osgi.service.environment.EnvironmentInfo; - -/** Empty default Eclipse environment. No system information is accessible. */ -public class HiddenEnvironment implements EnvironmentInfo { - - @Override - public String[] getCommandLineArgs() { - return new String[0]; - } - - @Override - public String[] getFrameworkArgs() { - return new String[0]; - } - - @Override - public String[] getNonFrameworkArgs() { - return new String[0]; - } - - @Override - public String getOSArch() { - return System.getProperty("os.arch"); - } - - @Override - public String getNL() { - return Locale.getDefault().getLanguage(); - } - - @Override - public String getOS() { - return Constants.OS_UNKNOWN; - } - - @Override - public String getWS() { - return null; //No window system - } - - @Override - public boolean inDebugMode() { - return false; - } - - @Override - public boolean inDevelopmentMode() { - return false; - } - - @Override - public String setProperty(String key, String value) { - return value; //Launcher information is not stored - } - - @Override - public String getProperty(String key) { - return null; //Launcher information/configuration is not required - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoContentTypeSpecificHandling.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoContentTypeSpecificHandling.java deleted file mode 100644 index 87e1f2f91b..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoContentTypeSpecificHandling.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.service; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.core.runtime.content.IContentTypeMatcher; -import org.eclipse.core.runtime.preferences.IScopeContext; - -/** No content type specific handling is supported. */ -public class NoContentTypeSpecificHandling implements IContentTypeManager { - - @Override - public IContentType findContentTypeFor(InputStream contents, String fileName) throws IOException { - return null; - } - - @Override - public IContentType findContentTypeFor(String fileName) { - return null; - } - - @Override - public IContentType[] findContentTypesFor(InputStream contents, String fileName) throws IOException { - return null; - } - - @Override - public IContentType[] findContentTypesFor(String fileName) { - return null; - } - - @Override - public IContentDescription getDescriptionFor(InputStream contents, String fileName, QualifiedName[] options) throws IOException { - return null; - } - - @Override - public IContentDescription getDescriptionFor(Reader contents, String fileName, QualifiedName[] options) throws IOException { - return null; - } - - @Override - public void addContentTypeChangeListener(IContentTypeChangeListener listener) {} - - @Override - public IContentType[] getAllContentTypes() { - return null; - } - - @Override - public IContentType getContentType(String contentTypeIdentifier) { - return null; - } - - @Override - public IContentTypeMatcher getMatcher(ISelectionPolicy customPolicy, IScopeContext context) { - return null; - } - - @Override - public void removeContentTypeChangeListener(IContentTypeChangeListener listener) { - - } - - @Override - public IContentType addContentType(String contentTypeIdentifier, String name, IContentType baseType) - throws CoreException { - return null; - } - - @Override - public void removeContentType(String contentTypeIdentifier) throws CoreException {} - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoDebugging.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoDebugging.java deleted file mode 100644 index 095be889e9..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoDebugging.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.service; - -import java.io.File; -import java.util.Map; - -import org.eclipse.osgi.service.debug.DebugOptions; -import org.eclipse.osgi.service.debug.DebugTrace; - -/** No debugging shall be performed */ -public class NoDebugging implements DebugOptions { - - @Override - public boolean getBooleanOption(String option, boolean defaultValue) { - return false; - } - - @Override - public String getOption(String option) { - return null; - } - - @Override - public String getOption(String option, String defaultValue) { - return null; - } - - @Override - public int getIntegerOption(String option, int defaultValue) { - return 0; - } - - @Override - public Map getOptions() { - return null; - } - - @Override - public void setOption(String option, String value) {} - - @Override - public void setOptions(Map options) {} - - @Override - public void removeOption(String option) {} - - @Override - public boolean isDebugEnabled() { - return false; - } - - @Override - public void setDebugEnabled(boolean value) {} - - @Override - public void setFile(File newFile) {} - - @Override - public File getFile() { - return null; - } - - @Override - public DebugTrace newDebugTrace(String bundleSymbolicName) { - return null; - } - - @Override - public DebugTrace newDebugTrace(String bundleSymbolicName, Class traceEntryClass) { - return null; - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoEclipsePreferences.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoEclipsePreferences.java deleted file mode 100644 index 7f6bed44ed..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/NoEclipsePreferences.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.service; - -import java.io.InputStream; -import java.io.OutputStream; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.preferences.DefaultScope; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.IExportedPreferences; -import org.eclipse.core.runtime.preferences.IPreferenceFilter; -import org.eclipse.core.runtime.preferences.IPreferencesService; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.osgi.service.prefs.Preferences; - -/** - * The formatters dependents on plugins which access Eclipse core functionality, - * configurable by preferences. This functionality is never used by the formatters itself. - * Hence modifications are ignored and default values are provided on request. - */ -public class NoEclipsePreferences implements IPreferencesService { - private static final String UNUSED = "unused"; - - @Override - public IEclipsePreferences getRootNode() { - //Return value is not effectively used. - return DefaultScope.INSTANCE.getNode(UNUSED); - } - - @Override - public String get(String key, String defaultValue, Preferences[] nodes) { - return null; - } - - @Override - public boolean getBoolean(String qualifier, String key, boolean defaultValue, IScopeContext[] contexts) { - return false; - } - - @Override - public byte[] getByteArray(String qualifier, String key, byte[] defaultValue, IScopeContext[] contexts) { - return null; - } - - @Override - public double getDouble(String qualifier, String key, double defaultValue, IScopeContext[] contexts) { - return 0; - } - - @Override - public float getFloat(String qualifier, String key, float defaultValue, IScopeContext[] contexts) { - return 0; - } - - @Override - public int getInt(String qualifier, String key, int defaultValue, IScopeContext[] contexts) { - return 0; - } - - @Override - public long getLong(String qualifier, String key, long defaultValue, IScopeContext[] contexts) { - return 0; - } - - @Override - public String getString(String qualifier, String key, String defaultValue, IScopeContext[] contexts) { - return null; - } - - @Override - public IStatus exportPreferences(IEclipsePreferences node, OutputStream output, String[] excludesList) throws CoreException { - return null; - } - - @Override - public IStatus importPreferences(InputStream input) throws CoreException { - return null; - } - - @Override - public IStatus applyPreferences(IExportedPreferences preferences) throws CoreException { - return null; - } - - @Override - public IExportedPreferences readPreferences(InputStream input) throws CoreException { - return null; - } - - @Override - public String[] getDefaultLookupOrder(String qualifier, String key) { - return null; - } - - @Override - public String[] getLookupOrder(String qualifier, String key) { - return null; - } - - @Override - public void setDefaultLookupOrder(String qualifier, String key, String[] order) {} - - @Override - public void exportPreferences(IEclipsePreferences node, IPreferenceFilter[] filters, OutputStream output) throws CoreException {} - - @Override - public IPreferenceFilter[] matches(IEclipsePreferences node, IPreferenceFilter[] filters) throws CoreException { - return null; - } - - @Override - public void applyPreferences(IEclipsePreferences node, IPreferenceFilter[] filters) throws CoreException {} - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/SingleSlf4JService.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/SingleSlf4JService.java deleted file mode 100644 index 6928621c83..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/SingleSlf4JService.java +++ /dev/null @@ -1,533 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.service; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Supplier; - -import javax.annotation.Nullable; - -import org.eclipse.core.internal.runtime.InternalPlatform; -import org.eclipse.equinox.log.ExtendedLogReaderService; -import org.eclipse.equinox.log.ExtendedLogService; -import org.eclipse.equinox.log.LogFilter; -import org.eclipse.equinox.log.Logger; -import org.osgi.framework.Bundle; -import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogEntry; -import org.osgi.service.log.LogLevel; -import org.osgi.service.log.LogListener; -import org.osgi.service.log.LoggerConsumer; - -/** - * Eclipse log service facade that delegates to a Slf4J logger. - * The service does not provide historical log entries (empty history reported). - * No factory service is provided for OSGI logger extensions (method are marked - * as deprecated and raise UnsupportedOperationException). - * All Eclipse logger are delegated to a single Slf4J logger instance. - * The log messages can be formatted by customizer. - */ -public class SingleSlf4JService implements ExtendedLogService, ExtendedLogReaderService { - - private final org.slf4j.Logger delegate; - private final Map logLevel2methods; - private final Set listener; - private final BiFunction messageCustomizer; - - /** Create facade for named logger with customized messages. */ - public SingleSlf4JService(String name, BiFunction messageCustomizer) { - delegate = org.slf4j.LoggerFactory.getLogger(name); - logLevel2methods = new HashMap(); - /* - * Audit message are treated as normal info-messages and might not get logged. - * Logging of Eclipse messages in Spotless formatter is meant for debugging purposes and - * detection of erroneous usage/override of internal Eclipse methods. - * Hence the concept of Audit is not required. - */ - logLevel2methods.put(LogLevel.AUDIT, - create(() -> true, m -> delegate.info(m), (m, e) -> delegate.info(m, e))); - logLevel2methods.put(LogLevel.DEBUG, - create(() -> delegate.isDebugEnabled(), m -> delegate.debug(m), (m, e) -> delegate.debug(m, e))); - logLevel2methods.put(LogLevel.ERROR, - create(() -> delegate.isErrorEnabled(), m -> delegate.error(m), (m, e) -> delegate.error(m, e))); - logLevel2methods.put(LogLevel.INFO, - create(() -> delegate.isInfoEnabled(), m -> delegate.info(m), (m, e) -> delegate.info(m, e))); - logLevel2methods.put(LogLevel.TRACE, - create(() -> delegate.isTraceEnabled(), m -> delegate.trace(m), (m, e) -> delegate.trace(m, e))); - logLevel2methods.put(LogLevel.WARN, - create(() -> delegate.isWarnEnabled(), m -> delegate.warn(m), (m, e) -> delegate.warn(m, e))); - listener = new HashSet(); - this.messageCustomizer = messageCustomizer; - } - - @Override - @Deprecated - //Backward compatibility with Eclipse OSGI 3.12 - public void log(int level, String message) { - log(this, level, message); - } - - @Override - @Deprecated - //Backward compatibility with Eclipse OSGI 3.12 - public void log(int level, String message, @Nullable Throwable exception) { - log(this, level, message, exception); - } - - @SuppressWarnings("rawtypes") - @Override - @Deprecated - //Backward compatibility with Eclipse OSGI 3.12 - public void log(ServiceReference sr, int level, String message) { - log(this, level, message); - } - - @SuppressWarnings("rawtypes") - @Override - @Deprecated - //Backward compatibility with Eclipse OSGI 3.12 - public void log(ServiceReference sr, int level, String message, Throwable exception) { - log(this, level, message, exception); - } - - @Override - public void log(Object context, int level, String message) { - log(context, level, message, null); - } - - @Override - public void log(Object context, int level, String message, @Nullable Throwable exception) { - LogLevel logLevel = convertDeprectatedOsgiLevel(level); - log(new SimpleLogEntry(logLevel, message, exception)); - } - - @Override - public boolean isLoggable(int level) { - LogLevel logLevel = convertDeprectatedOsgiLevel(level); - return logLevel2methods.get(logLevel).isEnabled(); - } - - @SuppressWarnings("deprecation") ////Backward compatibility with Eclipse OSGI 3.12 - private static LogLevel convertDeprectatedOsgiLevel(int level) { - switch (level) { - case SingleSlf4JService.LOG_DEBUG: - return LogLevel.DEBUG; - case SingleSlf4JService.LOG_INFO: - return LogLevel.INFO; - case SingleSlf4JService.LOG_ERROR: - return LogLevel.ERROR; - case SingleSlf4JService.LOG_WARNING: - return LogLevel.WARN; - default: - return LogLevel.AUDIT; - } - } - - @Override - public String getName() { - return delegate.getName(); - } - - @Override - public Logger getLogger(String loggerName) { - return this; - } - - @Override - public Logger getLogger(Bundle bundle, String loggerName) { - return this; - } - - @Override - public void addLogListener(LogListener listener) { - synchronized (this.listener) { - this.listener.add(listener); - } - } - - @Override - public void removeLogListener(LogListener listener) { - synchronized (this.listener) { - this.listener.remove(listener); - } - } - - private void log(LogEntry entry) { - synchronized (listener) { - listener.stream().forEach(l -> l.logged(entry)); - } - String customMessage = messageCustomizer.apply(entry.getMessage(), entry.getLogLevel()); - logLevel2methods.get(entry.getLogLevel()).log(customMessage, entry.getException()); - } - - @Override - @Deprecated - //Backward compatibility with Eclipse OSGI 3.12 - public Enumeration getLog() { - return Collections.emptyEnumeration(); //We do not provide historical information - } - - @Override - public void addLogListener(LogListener listener, LogFilter filter) { - addLogListener(listener); //Listener must filter if required - - } - - @Override - public org.osgi.service.log.Logger getLogger(Class clazz) { - return this; - } - - @Override - @Deprecated - public L getLogger(String name, Class loggerType) { - throw new UnsupportedOperationException("Logger factory for indifivaul types currently not supported."); - } - - @Override - @Deprecated - public L getLogger(Class clazz, Class loggerType) { - return getLogger(getName(), loggerType); - } - - @Override - @Deprecated - public L getLogger(Bundle bundle, String name, Class loggerType) { - return getLogger(getName(), loggerType); - } - - @Override - public boolean isTraceEnabled() { - return delegate.isTraceEnabled(); - } - - @Override - public void trace(String message) { - log(new SimpleLogEntry(LogLevel.TRACE, message)); - } - - @Override - public void trace(String format, Object arg) { - trace(String.format(format, arg)); - } - - @Override - public void trace(String format, Object arg1, Object arg2) { - trace(String.format(format, arg1, arg2)); - } - - @Override - public void trace(String format, Object... arguments) { - trace(String.format(format, arguments)); - } - - @Override - public void trace(LoggerConsumer consumer) throws E { - consumer.accept(this); - } - - @Override - public boolean isDebugEnabled() { - return delegate.isDebugEnabled(); - } - - @Override - public void debug(String message) { - log(new SimpleLogEntry(LogLevel.DEBUG, message)); - } - - @Override - public void debug(String format, Object arg) { - debug(String.format(format, arg)); - } - - @Override - public void debug(String format, Object arg1, Object arg2) { - debug(String.format(format, arg1, arg2)); - } - - @Override - public void debug(String format, Object... arguments) { - debug(String.format(format, arguments)); - } - - @Override - public void debug(LoggerConsumer consumer) throws E { - consumer.accept(this); - } - - @Override - public boolean isInfoEnabled() { - return delegate.isInfoEnabled(); - } - - @Override - public void info(String message) { - log(new SimpleLogEntry(LogLevel.INFO, message)); - } - - @Override - public void info(String format, Object arg) { - info(String.format(format, arg)); - } - - @Override - public void info(String format, Object arg1, Object arg2) { - info(String.format(format, arg1, arg2)); - } - - @Override - public void info(String format, Object... arguments) { - info(String.format(format, arguments)); - } - - @Override - public void info(LoggerConsumer consumer) throws E { - consumer.accept(this); - } - - @Override - public boolean isWarnEnabled() { - return delegate.isWarnEnabled(); - } - - @Override - public void warn(String message) { - log(new SimpleLogEntry(LogLevel.WARN, message)); - } - - @Override - public void warn(String format, Object arg) { - warn(String.format(format, arg)); - } - - @Override - public void warn(String format, Object arg1, Object arg2) { - warn(String.format(format, arg1, arg2)); - } - - @Override - public void warn(String format, Object... arguments) { - warn(String.format(format, arguments)); - } - - @Override - public void warn(LoggerConsumer consumer) throws E { - consumer.accept(this); - } - - @Override - public boolean isErrorEnabled() { - return delegate.isErrorEnabled(); - } - - @Override - public void error(String message) { - log(new SimpleLogEntry(LogLevel.ERROR, message)); - } - - @Override - public void error(String format, Object arg) { - error(String.format(format, arg)); - } - - @Override - public void error(String format, Object arg1, Object arg2) { - error(String.format(format, arg1, arg2)); - } - - @Override - public void error(String format, Object... arguments) { - error(String.format(format, arguments)); - } - - @Override - public void error(LoggerConsumer consumer) throws E { - consumer.accept(this); - } - - @Override - public void audit(String message) { - log(new SimpleLogEntry(LogLevel.AUDIT, message)); - } - - @Override - public void audit(String format, Object arg) { - audit(String.format(format, arg)); - } - - @Override - public void audit(String format, Object arg1, Object arg2) { - audit(String.format(format, arg1, arg2)); - } - - @Override - public void audit(String format, Object... arguments) { - audit(String.format(format, arguments)); - } - - /** Internal wrapper for Eclipse OSGI 3.12 based logs and new log services. */ - private static class SimpleLogEntry implements LogEntry { - - private final LogLevel level; - private final String message; - private final Optional execption; - - public SimpleLogEntry(LogLevel level, String message) { - this(level, message, Optional.empty()); - } - - public SimpleLogEntry(LogLevel level, String message, @Nullable Throwable execption) { - this(level, message, Optional.ofNullable(execption)); - } - - private SimpleLogEntry(LogLevel level, String message, Optional execption) { - this.level = level; - this.message = message; - this.execption = execption; - } - - @Override - public Bundle getBundle() { - //Return the spotless framework bundle - return InternalPlatform.getDefault().getBundleContext().getBundle(); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - @Override - public ServiceReference getServiceReference() { - return null; - } - - @Override - @Deprecated - //Backward compatibility with Eclipse OSGI 3.12 - public int getLevel() { - switch (level) { - case DEBUG: - case TRACE: - return SingleSlf4JService.LOG_DEBUG; - case AUDIT: - case INFO: - return SingleSlf4JService.LOG_INFO; - case ERROR: - return SingleSlf4JService.LOG_ERROR; - case WARN: - return SingleSlf4JService.LOG_WARNING; - } - return SingleSlf4JService.LOG_ERROR; //Don't fail here. Just log it as error. This is anyway just for debugging internal problems. - } - - @Override - public String getMessage() { - return message; - } - - @Override - public Throwable getException() { - return execption.orElse(null); - } - - @Override - public long getTime() { - return 0; - } - - @Override - public String toString() { - StringWriter result = new StringWriter(); - result.write(message); - if (execption.isPresent()) { - result.write('\n'); - result.write(execption.get().toString()); - result.write('\n'); - execption.get().printStackTrace(new PrintWriter(result)); - } - return result.toString(); - } - - @Override - public LogLevel getLogLevel() { - return level; - } - - @Override - public String getLoggerName() { - return this.getClass().getSimpleName(); - } - - @Override - public long getSequence() { - return 0; - } - - @Override - public String getThreadInfo() { - return null; - } - - @Override - public StackTraceElement getLocation() { - return null; // Not used by SingleSlf4JService - } - - } - - private static LogMethods create(Supplier enabled, Consumer log, BiConsumer logException) { - return new LogMethods(enabled, log, logException); - } - - private static class LogMethods { - private final Supplier enabled; - private final Consumer log; - private final BiConsumer logException; - - private LogMethods(Supplier enabled, Consumer log, BiConsumer logException) { - this.enabled = enabled; - this.log = log; - this.logException = logException; - } - - public boolean isEnabled() { - return enabled.get(); - } - - public void log(String message) { - log.accept(message); - } - - public void log(String message, @Nullable Throwable exception) { - if (null == exception) { - log(message); - } else { - logException.accept(message, exception); - } - } - - }; - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/TemporaryLocation.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/TemporaryLocation.java deleted file mode 100644 index 2999014d23..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/TemporaryLocation.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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.spotless.extra.eclipse.base.service; - -import java.io.File; -import java.io.IOError; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Comparator; - -import org.eclipse.osgi.service.datalocation.Location; - -/** All files generated at runtime are stored in a temporary location. */ -public class TemporaryLocation implements Location, AutoCloseable { - private static final String TEMP_PREFIX = "com_diffplug_spotless_extra_eclipse"; - private final URL location; - private Location parent; - - public TemporaryLocation() { - this(null, createTemporaryDirectory()); - } - - private TemporaryLocation(Location parent, URL defaultValue) { - this.location = defaultValue; - this.parent = parent; - } - - private static URL createTemporaryDirectory() { - try { - Path location = Files.createTempDirectory(TEMP_PREFIX); - return location.toUri().toURL(); - } catch (IOException e) { - throw new IOError(e); - } - } - - @Override - public boolean allowsDefault() { - return false; - } - - @Override - public URL getDefault() { - return null; - } - - @Override - public Location getParentLocation() { - return parent; - } - - @Override - public URL getURL() { - return location; - } - - @Override - public boolean isSet() { - return true; - } - - @Override - public boolean isReadOnly() { - return false; - } - - @Override - @Deprecated - public boolean setURL(URL value, boolean lock) throws IllegalStateException { - throw new IllegalStateException("URL not modifyable."); - } - - @Override - public boolean set(URL value, boolean lock) throws IllegalStateException, IOException { - throw new IllegalStateException("URL not modifyable."); - } - - @Override - public boolean set(URL value, boolean lock, String lockFilePath) throws IllegalStateException, IOException { - throw new IllegalStateException("URL not modifyable."); - } - - @Override - public boolean lock() throws IOException { - return false; //Lock not supported - } - - @Override - public void release() { - //Lock not supported - } - - @Override - public boolean isLocked() throws IOException { - return false; //Lock not supported - } - - @Override - public Location createLocation(Location parent, URL defaultValue, boolean readonly) { - return new TemporaryLocation(parent, defaultValue); - } - - @Override - public URL getDataArea(String path) throws IOException { - try { - Path locationPath = Paths.get(location.toURI()); - return locationPath.resolve(path).toUri().toURL(); - } catch (URISyntaxException e) { - throw new IOException("Location not correctly formatted.", e); - } - } - - @Override - public void close() throws Exception { - try { - Path path = Path.of(location.toURI()); - Files.walk(path) - .sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - path.toFile().delete(); - } catch (IOException e) { - //At shutdown everything is just done on best-efforts basis - } - } - -} diff --git a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/package-info.java b/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/package-info.java deleted file mode 100644 index b444c0c76a..0000000000 --- a/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/service/package-info.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2016 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. - */ -/** Mocking Eclipse Equinox OSGi services. */ -package com.diffplug.spotless.extra.eclipse.base.service; diff --git a/_ext/eclipse-base/src/main/resources/META-INF/MANIFEST.MF b/_ext/eclipse-base/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index 348dc4c453..0000000000 --- a/_ext/eclipse-base/src/main/resources/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-SymbolicName: com.diffplug.gradle.spotless.eclipse; singleton:=true diff --git a/_ext/eclipse-base/src/main/resources/META-INF/services/org.osgi.framework.connect.FrameworkUtilHelper b/_ext/eclipse-base/src/main/resources/META-INF/services/org.osgi.framework.connect.FrameworkUtilHelper deleted file mode 100644 index 0bd6c29641..0000000000 --- a/_ext/eclipse-base/src/main/resources/META-INF/services/org.osgi.framework.connect.FrameworkUtilHelper +++ /dev/null @@ -1 +0,0 @@ -com.diffplug.spotless.extra.eclipse.base.osgi.FrameworkBundleRegistry \ No newline at end of file diff --git a/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFrameworkTest.java b/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFrameworkTest.java deleted file mode 100644 index ca76c92ce1..0000000000 --- a/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseFrameworkTest.java +++ /dev/null @@ -1,330 +0,0 @@ -/* - * 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.spotless.extra.eclipse.base; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -import org.assertj.core.api.AbstractAssert; -import org.assertj.core.api.ObjectArrayAssert; -import org.assertj.core.api.StringAssert; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.ILog; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.equinox.log.ExtendedLogReaderService; -import org.eclipse.equinox.log.ExtendedLogService; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogEntry; -import org.osgi.service.log.LogLevel; -import org.osgi.service.log.LogListener; -import org.slf4j.simple.SimpleLogger; - -import com.diffplug.spotless.extra.eclipse.base.service.SingleSlf4JService; - -/** Integration tests */ -class SpotlessEclipseFrameworkTest { - - private final static String TEST_LOGGER_NAME = SpotlessEclipseFrameworkTest.class.getSimpleName(); - private final static String CUSTOM_PREFIX = "prefix\t"; - private final static String CUSTOM_POSTFIX = "\tpostfix"; - private final static String TEST_EXCEPTION_MESSAGE = "MY TEST-EXCEPTION"; - private static Slf4JMesssageListener SLF4J_RECEIVER = null; - - private static boolean TREAT_ERROR_AS_EXCEPTION = false; - - @BeforeAll - static void frameworkTestSetup() throws BundleException { - //Prepare interception of SLF4J messages to System.out - SLF4J_RECEIVER = new Slf4JMesssageListener(); - - //Configure SLF4J-Simple - System.setProperty(SimpleLogger.LOG_FILE_KEY, "System.out"); - System.setProperty(SimpleLogger.SHOW_SHORT_LOG_NAME_KEY, "true"); - System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "warn"); - - //Instantiate default framework + SLF4J logger - SpotlessEclipseFramework.setup(new SpotlessEclipseConfig() { - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - config.useSlf4J(TEST_LOGGER_NAME, (s, l) -> { - if (TREAT_ERROR_AS_EXCEPTION && (LogLevel.ERROR == l)) { - throw new IllegalArgumentException(TEST_EXCEPTION_MESSAGE); - } - return CUSTOM_PREFIX + s + CUSTOM_POSTFIX; - }); - } - }); - } - - @AfterAll - static void deregisterSlf4JReceiver() { - SLF4J_RECEIVER.deregister(); - } - - private EclipseMessageListener eclipseMessageListener; - - @BeforeEach - void eclipseReceiverSetup() { - ExtendedLogReaderService service = getService(ExtendedLogReaderService.class); - eclipseMessageListener = new EclipseMessageListener(); - service.addLogListener(eclipseMessageListener); - SLF4J_RECEIVER.clear(); - } - - @AfterEach - void logReceiverTearDown() { - ExtendedLogReaderService service = getService(ExtendedLogReaderService.class); - service.removeLogListener(eclipseMessageListener); - } - - @Test - void testCustomizedLogMessage() { - ResourcesPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, "Some plugin", "Hello World!")); - assertSlf4J() - .as("Error message logged.").received("Hello World!").contains(TEST_LOGGER_NAME) - .as("Customization method has been applied.").contains(CUSTOM_PREFIX, CUSTOM_POSTFIX) - .as("Status level has been converted to simple SLF4J level").contains("ERROR"); - assertEclipse() - .as("Warning message received.").received("Hello World!") - .as("Customization method is only for SLF4J").doesNotContain(CUSTOM_PREFIX); - } - - @Test - void testCustomizedLogException() { - assertThatExceptionOfType(IllegalArgumentException.class) - .isThrownBy(() -> { - try { - TREAT_ERROR_AS_EXCEPTION = true; - ResourcesPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, "Some plugin", "Hello World!")); - } finally { - TREAT_ERROR_AS_EXCEPTION = false; - } - }) - .withMessage(TEST_EXCEPTION_MESSAGE); - } - - @Test - void testPluginLog() { - List logLevels = Arrays.asList(IStatus.CANCEL, IStatus.ERROR, IStatus.INFO, IStatus.OK, IStatus.WARNING); - List enabledLogLevels = Arrays.asList(IStatus.ERROR, IStatus.WARNING); - List disabledLogLevels = logLevels.stream().filter(level -> !enabledLogLevels.contains(level)).collect(Collectors.toList()); - ILog logger = ResourcesPlugin.getPlugin().getLog(); - logLevels.forEach(logLevel -> logger.log(new Status(logLevel, "Some plugin", logLevel.toString()))); - assertSlf4J() - .as("Messages for all enabled levels are logged.").received( - enabledLogLevels.stream().map(i -> i.toString()).collect(Collectors.toList())); - assertSlf4J() - .as("Messages all disabled levels are not logged.").notReceived( - disabledLogLevels.stream().map(i -> i.toString()).collect(Collectors.toList())); - assertEclipse() - .as("All messages received.").received( - logLevels.stream().map(i -> i.toString()).collect(Collectors.toList())); - } - - @Test - void testLogServiceLevel() { - ExtendedLogService service = getService(ExtendedLogService.class); - assertThat(service.isErrorEnabled()).as("Error log level is enabled").isTrue(); - assertThat(service.isWarnEnabled()).as("Warning log level is enabled").isTrue(); - assertThat(service.isInfoEnabled()).as("Info log level is disabled").isFalse(); - assertThat(service.isDebugEnabled()).as("Debug log level is disabled").isFalse(); - assertThat(service.isTraceEnabled()).as("Trace log level is disabled").isFalse(); - } - - @Test - void testLogServiceLog() { - ExtendedLogService service = getService(ExtendedLogService.class); - service.info("Log Info"); - service.warn("Log Warn"); - assertSlf4J().received("Log Warn"); - assertSlf4J().notReceived("Log Info"); - assertEclipse().received(Arrays.asList("Log Warn", "Log Info")); - } - - @Test - @Deprecated - void testLogServiceLog_3_12() { - ExtendedLogService service = getService(ExtendedLogService.class); - service.log(SingleSlf4JService.LOG_INFO, "Log Info"); - try { - throw new IllegalArgumentException(TEST_EXCEPTION_MESSAGE); - } catch (Exception e) { - service.log(SingleSlf4JService.LOG_WARNING, "Log Warn", e); - } - assertSlf4J().received(Arrays.asList("Log Warn", TEST_EXCEPTION_MESSAGE)); - assertSlf4J().notReceived("Log Info"); - assertEclipse().received(Arrays.asList("Log Warn", TEST_EXCEPTION_MESSAGE, "Log Info")); - } - - private static T getService(Class serviceClass) { - ResourcesPlugin plugin = ResourcesPlugin.getPlugin(); - assertThat(plugin).as("ResourcesPlugin instantiated as part of framework defaults").isNotNull(); - Bundle bundle = plugin.getBundle(); - assertThat(bundle).as("ResourcesPlugin has been started.").isNotNull(); - BundleContext context = bundle.getBundleContext(); - assertThat(context).as("ResourcesPlugin has been started.").isNotNull(); - ServiceReference reference = context.getServiceReference(serviceClass); - assertThat(reference).as(serviceClass.getSimpleName() + " has been registered.").isNotNull(); - T service = context.getService(reference); - assertThat(service).as(serviceClass.getSimpleName() + " can be resolved.").isNotNull(); - return service; - } - - private static interface IMessageListener { - Collection getMessages(); - } - - private static class EclipseMessageListener implements LogListener, IMessageListener { - - private final List messages; - - public EclipseMessageListener() { - messages = new ArrayList(); - } - - @Override - public Collection getMessages() { - return Collections.unmodifiableList(messages); - } - - @Override - public void logged(LogEntry entry) { - messages.add(entry.getMessage()); - if (null != entry.getException()) { - messages.add(entry.getException().getMessage()); - } - } - } - - private final static class Slf4JMesssageListener extends PrintStream implements IMessageListener { - - private final List messages; - private final PrintStream originalStream; - - public Slf4JMesssageListener() { - super(System.out); - messages = new ArrayList(); - originalStream = System.out; - System.setOut(this); - } - - @Override - public void println(String x) { - if (x.contains(TEST_LOGGER_NAME)) { - messages.add(x); - } else { - super.println(x); - } - } - - @Override - public void println(Object x) { - if (x instanceof Exception) { - Exception e = (Exception) x; - if (TEST_EXCEPTION_MESSAGE == e.getMessage()) { - messages.add(TEST_EXCEPTION_MESSAGE); - } - } - super.println(x); - } - - public void deregister() { - System.setOut(originalStream); - } - - public void clear() { - messages.clear(); - } - - @Override - public Collection getMessages() { - return Collections.unmodifiableList(messages); - } - } - - private static class MessageListenerAssert extends AbstractAssert, T> { - - public MessageListenerAssert(T actual) { - super(actual, MessageListenerAssert.class); - } - - public ObjectArrayAssert received(Collection unformattedMessages) { - List formattedMessages = unformattedMessages.stream() - .map(unformattedMessage -> getReceivedMessage(unformattedMessage, false)) - .collect(Collectors.toList()); - return new ObjectArrayAssert(formattedMessages.toArray(new String[0])); - } - - public StringAssert received(String unformattedMessage) { - return new StringAssert(getReceivedMessage(unformattedMessage, false)); - } - - public MessageListenerAssert notReceived(String unformattedMessage) { - getReceivedMessage(unformattedMessage, true); - return this; - } - - public MessageListenerAssert notReceived(Collection unformattedMessages) { - unformattedMessages.forEach(unformattedMessage -> getReceivedMessage(unformattedMessage, true)); - return this; - } - - private String getReceivedMessage(String unformattedMessage, boolean negate) { - isNotNull(); - String receivedMessage = null; - for (String formattedMessage : actual.getMessages()) { - if (formattedMessage.contains(unformattedMessage)) { - receivedMessage = formattedMessage; - break; - } - } - if ((!negate) && (null == receivedMessage)) { - failWithMessage("Message <%s> not received.", unformattedMessage); - } - if (negate && (null != receivedMessage)) { - failWithMessage("Message <%s> has been received. Formatted message is: %s", unformattedMessage, receivedMessage); - } - return receivedMessage; - } - - } - - private static MessageListenerAssert assertSlf4J() { - return new MessageListenerAssert(SLF4J_RECEIVER).as("SLF4J"); - } - - private MessageListenerAssert assertEclipse() { - return new MessageListenerAssert(eclipseMessageListener).as("Eclipse"); - } -} diff --git a/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleSetTest.java b/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleSetTest.java deleted file mode 100644 index 9c5c97ddb8..0000000000 --- a/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/BundleSetTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.spotless.extra.eclipse.base.osgi; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Arrays; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; - -class BundleSetTest { - - BundleSet instance; - - @BeforeEach - void initialize() { - instance = new BundleSet(); - } - - @Test - void testAddGet() throws BundleException { - Bundle testBundle1 = new TestBundle(1, "a"); - Bundle testBundle2 = new TestBundle(2, "b"); - instance.add(testBundle1); - instance.add(testBundle2); - assertEquals(testBundle1, instance.get(1), "Get by ID 1"); - assertEquals(testBundle2, instance.get(2), "Get by ID 2"); - assertEquals(testBundle1, instance.get("a"), "Get by symbolic name 'a'"); - assertEquals(testBundle2, instance.get("b"), "Get by symbolic name 'b'"); - assertTrue(instance.getAll().containsAll(Arrays.asList(testBundle1, testBundle2)), "Contains all"); - } - - @Test - void testSameSymbolicName() throws BundleException { - final String symbolicName = "sym.a"; - final long id1 = 12345; - final long id2 = 23456; - Bundle testBundle1 = new TestBundle(id1, symbolicName); - Bundle testBundle2 = new TestBundle(id2, symbolicName); - instance.add(testBundle1); - BundleException e = assertThrows(BundleException.class, () -> instance.add(testBundle2)); - assertThat(e.getMessage()).as("BundleException does not contain symbolic name.").contains(symbolicName); - assertThat(e.getMessage()).as("BundleException does not contain ID of exisiting bundle.").contains(Long.toString(id1)); - assertThat(e.getMessage()).as("BundleException does not contain ID of new bundle.").contains(Long.toString(id2)); - } - - @Test - void testSameID() throws BundleException { - final String symbolicName1 = "sym.a"; - final String symbolicName2 = "sym.b"; - final long id = 12345; - Bundle testBundle1 = new TestBundle(id, symbolicName1); - Bundle testBundle2 = new TestBundle(id, symbolicName2); - instance.add(testBundle1); - BundleException e = assertThrows(BundleException.class, () -> instance.add(testBundle2)); - assertThat(e.getMessage()).as("BundleException does not contain ID.").contains(Long.toString(id)); - assertThat(e.getMessage()).as("BundleException does not contain symbolic name of exisiting bundle.").contains(symbolicName1); - assertThat(e.getMessage()).as("BundleException does not contain symbolic name of new bundle.").contains(symbolicName2); - } - -} diff --git a/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/ServiceCollectionTest.java b/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/ServiceCollectionTest.java deleted file mode 100644 index 05f18c475c..0000000000 --- a/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/ServiceCollectionTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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.spotless.extra.eclipse.base.osgi; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.HashMap; - -import org.assertj.core.api.AbstractAssert; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.ServiceException; -import org.osgi.framework.ServiceReference; - -class ServiceCollectionTest { - - ServiceCollection instance; - - @BeforeEach - void initialize() { - Bundle systemBundle = new TestBundle(0, "test.system"); - instance = new ServiceCollection(systemBundle, new HashMap()); - } - - @Test - void testAddGet() { - Service1 service1 = new Service1(); - Service2 service2 = new Service2(); - instance.add(Interf1.class, service1); - instance.add(Interf2a.class, service2); - instance.add(Interf2b.class, service2); - assertFor(instance).getServiceForReferences(Interf1.class).matchesService(service1); - assertFor(instance).getServiceForReferences(Interf2a.class).matchesService(service2); - assertFor(instance).getServiceForReferences(Interf2b.class).matchesService(service2); - } - - @Test - void testMultipleServicesPerInterface() { - Service1 serviceX = new Service1(); - Service1 serviceY = new Service1(); - instance.add(Interf1.class, serviceX); - ServiceException e = assertThrows(ServiceException.class, () -> instance.add(Interf1.class, serviceY)); - assertThat(e.getMessage()).as("ServiceException does not contain interface class name.").contains(Interf1.class.getName()); - } - - private static class ServiceReferenceAssert extends AbstractAssert { - - private final ServiceCollection actual; - private final ServiceReference reference; - - public ServiceReferenceAssert(ServiceCollection actual) { - this(actual, null); - } - - public ServiceReferenceAssert(ServiceCollection actual, ServiceReference reference) { - super(actual, ServiceReferenceAssert.class); - this.reference = reference; - this.actual = actual; - - } - - ServiceReferenceAssert getServiceForReferences(Class interfaceClass) { - ServiceReference[] references = actual.getReferences(interfaceClass.getName()); - int numberOfFoundReferences = null == references ? 0 : references.length; - if (numberOfFoundReferences != 1) { - failWithMessage("Expected to find exactly 1 reference for <%s> , but found %d.", interfaceClass.getName(), numberOfFoundReferences); - } - return new ServiceReferenceAssert(actual, references[0]); - } - - ServiceReferenceAssert matchesService(Object expected) { - if (null == reference) { - failWithMessage("No reference requested."); - } - Object serviceForRef = actual.getService(reference); - if (null == serviceForRef) { - failWithMessage("No service provided for reference."); - } - if (!serviceForRef.equals(expected)) { - failWithMessage("Unexpected service found."); - } - - return this; - } - } - - private static ServiceReferenceAssert assertFor(ServiceCollection actual) { - return new ServiceReferenceAssert(actual); - } - - private static interface Interf1 {}; - - private static interface Interf2a {}; - - private static interface Interf2b {}; - - private static class Service1 implements Interf1 {}; - - private static class Service2 implements Interf2a, Interf2b {}; -} diff --git a/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/TestBundle.java b/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/TestBundle.java deleted file mode 100644 index 177442101d..0000000000 --- a/_ext/eclipse-base/src/test/java/com/diffplug/spotless/extra/eclipse/base/osgi/TestBundle.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.base.osgi; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.security.cert.X509Certificate; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.List; -import java.util.Map; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.Version; - -/** Helper for testing */ -public class TestBundle implements StaticBundle, TemporaryBundle { - private final String symbolicName; - private final long id; - - public TestBundle(long id, String symbolicName) { - this.id = id; - this.symbolicName = symbolicName; - } - - @Override - public int getState() { - return 0; - } - - @Override - @Deprecated - public Dictionary getHeaders() { - return null; - } - - @Override - public long getBundleId() { - return id; - } - - @Override - public ServiceReference[] getRegisteredServices() { - return null; - } - - @Override - public boolean hasPermission(Object permission) { - return false; - } - - @Override - public URL getResource(String name) { - return null; - } - - @Override - @Deprecated - public Dictionary getHeaders(String locale) { - return null; - } - - @Override - public String getSymbolicName() { - return symbolicName; - } - - @Override - public Class loadClass(String name) throws ClassNotFoundException { - return null; - } - - @Override - public Enumeration getResources(String name) throws IOException { - return null; - } - - @Override - public Enumeration getEntryPaths(String path) { - return null; - } - - @Override - public URL getEntry(String path) { - return null; - } - - @Override - @Deprecated - public Enumeration findEntries(String path, String filePattern, boolean recurse) { - return null; - } - - @Override - public BundleContext getBundleContext() { - return null; - } - - @Override - public Map> getSignerCertificates(int signersType) { - return null; - } - - @Override - public Version getVersion() { - return null; - } - - @Override - public A adapt(Class type) { - return null; - } - - @Override - public File getDataFile(String filename) { - return null; - } - - @Override - public int compareTo(Bundle o) { - return 0; - } - -} diff --git a/_ext/eclipse-wtp/CHANGES.md b/_ext/eclipse-wtp/CHANGES.md deleted file mode 100644 index d57618ad8c..0000000000 --- a/_ext/eclipse-wtp/CHANGES.md +++ /dev/null @@ -1,76 +0,0 @@ -# spotless-eclipse-wtp - -We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.15.1`). - -## [Unreleased] -### Fixed -* Fix typo in Gradle variable names ([#1425](https://github.com/diffplug/spotless/pull/1425)) - -## [3.23.0] - 2021-09-22 -### Added -* Switch to Web Tools Platform release 3.23.0 for Eclipse 4.21. - -## [3.22.0] - 2021-06-27 -### Added -* Switch to Web Tools Platform release 3.22.0 for Eclipse 4.20. - -## [3.21.0] - 2021-06-07 -### Added -* Switch to Web Tools Platform release 3.21.0 for Eclipse 4.19. Minimum required Java version changed from 8 to 11. - -## [3.20.0] - 2020-12-26 -### Added -* Switch to Web Tools Platform release 3.20.0 for Eclipse 4.18. - -## [3.19.0] - 2020-10-17 -### Added -* Fixed version number determined by change log. - -## [3.18.1] - 2020-10-17 -### Added -* Switch to Web Tools Platform release 3.19.0 for Eclipse 4.17. - -## [3.18.0] - 2020-10-03 -### Added -* Switch to Web Tools Platform release 3.18.0 for Eclipse 4.16. - -## [3.17.0] - 2020-10-03 -### Added -* Switch to Web Tools Platform release 3.17.0 for Eclipse 4.15. - -## [3.16.0] - 2020-09-26 -### Added -* Switch to Web Tools Platform release 3.16.0 for Eclipse 4.14. - -## [3.15.3] - 2020-03-26 -### Fixed -* Handling of character encodings on OS with non-unicode default file encoding format. CSS, HTML and JSON formatter steps encoded intermediately the input using the default file encoding, which was not lossless if the default file encoding did not support the full unicode character set. ([#545](https://github.com/diffplug/spotless/issues/545)). - -## [3.15.2] - 2020-03-04 -### Fixed -* Racing conditions in WTP formatter configurations. Multiple configurations within the same project are no longer supported. ([#492](https://github.com/diffplug/spotless/pull/492)). - -## [3.15.1] - 2019-11-27 -* Bugfix: Fix NPE in EclipseXmlFormatterStepImpl ([#490](https://github.com/diffplug/spotless/pull/490)). - -## [3.15.0] - 2019-11-06 -* Switch to Web Tools Platform release 3.15.0 for Eclipse 4.13 ([#480](https://github.com/diffplug/spotless/issues/480)). - -## [3.14.0] - 2019-06-24 -* Switch to Web Tools Platform release 3.14.0 for Eclipse 4.12 ([#423](https://github.com/diffplug/spotless/pull/423)). - -## [3.10.0] - 2019-03-17 -* Switch to Web Tools Platform release 3.10.0 for Eclipse 4.8 ([#378](https://github.com/diffplug/spotless/pull/378)). -* Include Eclipse logging allowing formatter warnings/errors to be logged via SLF4J ([#236](https://github.com/diffplug/spotless/issues/236)). - -## [3.9.8] - 2019-03-10 -* XML formatter ignores external URIs per default. ([#369](https://github.com/diffplug/spotless/issues/369)). Add `resolveExternalURI=true` property to switch to previous behavior. - -## [3.9.7] - 2019-02-25 -* Replaced `http` update-site with `https` ([#360](https://github.com/diffplug/spotless/issues/360)). - -## [3.9.6] - 2019-02-11 -* Fixed formatting of JSON arrays ([#344](https://github.com/diffplug/spotless/issues/344)). - -## [3.9.5] - 2018-08-08 -* Initial release! diff --git a/_ext/eclipse-wtp/LICENSE.txt b/_ext/eclipse-wtp/LICENSE.txt deleted file mode 100644 index 3d967aee74..0000000000 --- a/_ext/eclipse-wtp/LICENSE.txt +++ /dev/null @@ -1,70 +0,0 @@ -Eclipse Public License - v 1.0 - -THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. - -1. DEFINITIONS - -"Contribution" means: - -a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and -b) in the case of each subsequent Contributor: -i) changes to the Program, and -ii) additions to the Program; -where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. -"Contributor" means any person or entity that distributes the Program. - -"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. - -"Program" means the Contributions distributed in accordance with this Agreement. - -"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. - -2. GRANT OF RIGHTS - -a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. -b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. -c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. -d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. -3. REQUIREMENTS - -A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: - -a) it complies with the terms and conditions of this Agreement; and -b) its license agreement: -i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; -ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; -iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and -iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. -When the Program is made available in source code form: - -a) it must be made available under this Agreement; and -b) a copy of this Agreement must be included with each copy of the Program. -Contributors may not remove or alter any copyright notices contained within the Program. - -Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. - -4. COMMERCIAL DISTRIBUTION - -Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. - -For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. - -5. NO WARRANTY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. - -6. DISCLAIMER OF LIABILITY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -7. GENERAL - -If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. - -If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. - -All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. - -Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. - -This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. \ No newline at end of file diff --git a/_ext/eclipse-wtp/README.md b/_ext/eclipse-wtp/README.md deleted file mode 100644 index 41dd58ff9b..0000000000 --- a/_ext/eclipse-wtp/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# spotless-eclipse-wtp - -Eclipse WTP is not available in a form which can be easily consumed by maven or gradle. To fix this, we publish Eclipse's WTP formatters, along with a small amount of glue code, into the `com.diffplug.spotless.extra:spotless-eclipse-wtp` artifact. - -To publish a new version, update the `_ext/eclipse-wtp/gradle.properties` appropriately and see [CONTRIBUTING.md](../../CONTRIBUTING.md) how to enable -`_ext` projects. - -## License - -Spotless at large is under the Apache 2.0 license, but this jar is under the EPL v1. diff --git a/_ext/eclipse-wtp/build.gradle b/_ext/eclipse-wtp/build.gradle deleted file mode 100644 index feacfbf4c1..0000000000 --- a/_ext/eclipse-wtp/build.gradle +++ /dev/null @@ -1,126 +0,0 @@ -ext { - developers = [ - fvgh: [ name: 'Frank Vennemeyer', email: 'frankgh@zoho.com' ], - ] - - p2Repository = "https://download.eclipse.org/webtools/repository/${VER_ECLIPSE_WTP}" - - p2Dependencies = [ - // XML/HTML Formatter - Dependencies - 'org.eclipse.wst.xml.core':'+', // DefaultXMLPartitionFormatter and XMLAssociationProvider - 'org.eclipse.wst.sse.core':'+', // Structure models - 'org.eclipse.wst.common.uriresolver':'+', // URI resolver for model queries - 'org.eclipse.wst.dtd.core':'+', // Support DTD extensions - - // XML Formatter - Dependencies - 'org.eclipse.wst.xsd.core':'+', // Support XSD extensions - - // JS Formatter - Dependencies - 'org.eclipse.wst.jsdt.core':'+', // DefaultCodeFormatter and related - 'org.eclipse.wst.jsdt.ui':'+', // Functionality to format comments - - // JSON Formatter - Dependencies - 'org.eclipse.wst.json.core':'+', // FormatProcessorJSON and related - 'org.eclipse.json':'+', // Provides JSON node interfaces - - // CSS Formatter - Dependencies - 'org.eclipse.wst.css.core':'+', // FormatProcessorCSS and related - - // HTML Formatter - Dependencies - 'org.eclipse.wst.html.core':'+', // HTMLFormatProcessorImpl and related - ] - - jarInclude = [ - '**/*.class', - // Take all classes - '**/*.properties', - // Text resources (for messages, etc) - '**/*.rsc', - // JSDT requires gramar files - '**/*.xml', - // Plugin XML and other resources - '*.html', - // License information about the included JARs, - 'META-INF/**' // Plugin manifest and addtional information - ] - - fatJarResourcesMap = [ - 'org.eclipse.wst.common.uriresolver': 'org.eclipse.wst.common.uriresolver.internal.provisional', - 'org.eclipse.wst.css.core': 'org.eclipse.wst.css.core.internal', - 'org.eclipse.wst.dtd.core': 'org.eclipse.wst.dtd.core.internal', - 'org.eclipse.wst.html.core': 'org.eclipse.wst.html.core.internal', - 'org.eclipse.wst.sse.core': 'org.eclipse.wst.sse.core.internal.encoding.util', - 'org.eclipse.wst.xml.core': 'org.eclipse.wst.xml.core.internal', - 'org.eclipse.wst.xsd.core': 'org.eclipse.wst.xsd.core.internal' - ] -} - -apply from: rootProject.file('_ext/gradle/update-lockfile.gradle') -apply from: rootProject.file('_ext/gradle/p2-fat-jar-setup.gradle') -apply from: rootProject.file('gradle/java-publish.gradle') - -dependencies { - implementation "com.diffplug.spotless:spotless-eclipse-base:${VER_SPOTLESS_ECLIPSE_BASE}" - // Required by most WPT formatters - implementation "com.ibm.icu:icu4j:${VER_IBM_ICU}" - // The XSD/DTD and other models are defined with EMF. - implementation "org.eclipse.emf:org.eclipse.emf.common:${VER_ECLIPSE_EMF}" - implementation "org.eclipse.emf:org.eclipse.emf.ecore:${VER_ECLIPSE_EMF}" - // Some WPT plugins requires OSGI bundle interfaces (but not effectively used) - implementation "org.eclipse.platform:org.eclipse.osgi.services:${VER_ECLIPSE_OSGI_SERVICES}" - // Provides document data structure and file buffers for formatters - implementation "org.eclipse.platform:org.eclipse.core.filebuffers:${VER_ECLIPSE_FILE_BUFFERS}" - // Provides text partitioners for formatters - implementation ("org.eclipse.platform:org.eclipse.jface.text:${VER_ECLIPSE_JFACE}") { - exclude group: 'org.eclipse.platform', module: 'org.eclipse.swt' - } - // Some WPT plugins use the EFS for storing temporary worspace data - implementation "org.eclipse.platform:org.eclipse.core.filesystem:${VER_ECLIPSE_EFS}" - // Required by org.eclipse.wst.xsd.core - implementation "org.eclipse.emf:org.eclipse.xsd:${VER_ECLIPSE_XSD}" - - testImplementation("org.slf4j:slf4j-simple:${VER_SLF4J}") -} - -jar { - manifest { - from 'src/main/resources/META-INF/MANIFEST.MF' - } -} - -////////// -// Test // -////////// -sourceSets { - // Use JAR file with all resources for Eclipse-WTP integration-tests - test.runtimeClasspath = jar.outputs.files + sourceSets.test.output + sourceSets.test.compileClasspath -} - -/* - * All test classes need to run separately since they all instatiate different setups of the - * Eclipse framework. - */ -tasks.withType(Test).configureEach { - //Skip default tests, which would run every test case. - exclude '**' -} - -//Instead make a separate test task per case -def testLocation = 'src/test/java' -fileTree(dir: testLocation).include('**/*Test.java').each { file -> - def testFile = file.getName().replace(".java", "") - def filePath = file.getAbsolutePath().replace(".java", "**") //Don't ask me why the task is not happy when it gets no asterisk - filePath = filePath.substring(filePath.lastIndexOf(testLocation) + testLocation.length() + 1) - task "${testFile}"(type: Test) { - group = LifecycleBasePlugin.VERIFICATION_GROUP - description = "Runs ${testFile} integration test." - include "${filePath}" - reports { - html.destination = new File("$buildDir/reports/${testFile}") - junitXml.destination = new File("$buildDir/${testFile}") - } - //classpath = jar.outputs.files + sourceSets.test.output + sourceSets.test.compileClasspath - mustRunAfter tasks.jar - } - test.dependsOn "${testFile}" -} diff --git a/_ext/eclipse-wtp/gradle.properties b/_ext/eclipse-wtp/gradle.properties deleted file mode 100644 index a341c0fb49..0000000000 --- a/_ext/eclipse-wtp/gradle.properties +++ /dev/null @@ -1,16 +0,0 @@ -artifactId=spotless-eclipse-wtp -description=Eclipse's WTP formatters bundled for Spotless - -# Build requirements -VER_JAVA=11 - -# Compile -VER_ECLIPSE_WTP=2021-09 -VER_SPOTLESS_ECLIPSE_BASE=[3.5.0,4.0.0[ -VER_IBM_ICU=[67.1,68[ -VER_ECLIPSE_EMF=[2.22.0,3.0.0[ -VER_ECLIPSE_OSGI_SERVICES=[3.10.0,4.0.0[ -VER_ECLIPSE_FILE_BUFFERS=[3.7.0,4.0.0[ -VER_ECLIPSE_JFACE=[3.18.0,4.0.0[ -VER_ECLIPSE_EFS=[1.9.0,2.0.0[ -VER_ECLIPSE_XSD=[2.18.0,3.0.0[ diff --git a/_ext/eclipse-wtp/spotless.xmlformat.prefs b/_ext/eclipse-wtp/spotless.xmlformat.prefs deleted file mode 100644 index 3bbd7ecd72..0000000000 --- a/_ext/eclipse-wtp/spotless.xmlformat.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -indentationChar=space -indentationSize=2 -lineWidth=999 diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java deleted file mode 100644 index fb0e1ffeac..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp; - -import java.util.Properties; - -import org.eclipse.wst.css.core.internal.CSSCorePlugin; -import org.eclipse.wst.css.core.internal.cleanup.CleanupProcessorCSS; -import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceInitializer; -import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; - -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; - -/** Formatter step which calls out to the Eclipse CSS cleanup and formatter. */ -public class EclipseCssFormatterStepImpl extends CleanupStep { - - public EclipseCssFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor(), new FrameworkConfig(properties)); - PluginPreferences.assertNoChanges(CSSCorePlugin.getDefault(), properties); - } - - /** - * The FormatProcessorCSS does not allow a strict case formatting. - * Hence additionally the CleanupProcessorCSS is used. - */ - private static class CleanupProcessor extends CleanupProcessorCSS implements CleanupStep.ProcessorAccessor { - @Override - public String getTypeId() { - return getContentType(); - } - - @Override - public void refreshPreferences() { - refreshCleanupPreferences(); - } - - @Override - public AbstractStructuredCleanupProcessor get() { - return this; - } - } - - static class FrameworkConfig extends CleanupStep.FrameworkConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - this.properties = properties; - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - super.activatePlugins(config); - activateCssPlugins(config); - } - - static void activateCssPlugins(SpotlessEclipsePluginConfig config) { - config.add(new CSSCorePlugin()); - } - - @Override - public void customize() { - PluginPreferences.configure(CSSCorePlugin.getDefault(), new CSSCorePreferenceInitializer(), properties); - } - } -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java deleted file mode 100644 index 4b7f592c3c..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImpl.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - -import java.util.Arrays; -import java.util.List; -import java.util.Properties; - -import org.eclipse.wst.html.core.internal.HTMLCorePlugin; -import org.eclipse.wst.html.core.internal.cleanup.HTMLCleanupProcessorImpl; -import org.eclipse.wst.html.core.internal.encoding.HTMLDocumentLoader; -import org.eclipse.wst.html.core.internal.format.HTMLFormatProcessorImpl; -import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceInitializer; -import org.eclipse.wst.html.core.text.IHTMLPartitions; -import org.eclipse.wst.jsdt.core.JavaScriptCore; -import org.eclipse.wst.jsdt.core.ToolFactory; -import org.eclipse.wst.jsdt.core.formatter.CodeFormatter; -import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; -import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; - -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseCoreConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.wtp.html.JsRegionProcessor; -import com.diffplug.spotless.extra.eclipse.wtp.html.StructuredDocumentProcessor; -import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; - -/** Formatter step which calls out to the Eclipse HTML cleanup and formatter. */ -public class EclipseHtmlFormatterStepImpl extends CleanupStep { - - private final String htmlFormatterIndent; - private final CodeFormatter jsFormatter; - - public EclipseHtmlFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor(), new FrameworkConfig(properties)); - PluginPreferences.assertNoChanges(HTMLCorePlugin.getDefault(), properties); - htmlFormatterIndent = ((CleanupProcessor) processorAccessor).getIndent(); - jsFormatter = ToolFactory.createCodeFormatter(JavaScriptCore.getOptions(), ToolFactory.M_FORMAT_EXISTING); - } - - @Override - public String format(String raw) throws Exception { - raw = super.format(raw); - - // Not sure how Eclipse binds the JS formatter to HTML. The formatting is accomplished manually instead. - IStructuredDocument document = (IStructuredDocument) new HTMLDocumentLoader().createNewStructuredDocument(); - document.setPreferredLineDelimiter(LINE_DELIMITER); - document.set(raw); - StructuredDocumentProcessor jsProcessor = new StructuredDocumentProcessor( - document, IHTMLPartitions.SCRIPT, JsRegionProcessor.createFactory(htmlFormatterIndent)); - jsProcessor.apply(jsFormatter); - - return document.get(); - } - - /** - * * The WTP {@link HTMLFormatProcessorImpl} does not allow a strict case formatting. - * Hence additionally the {@link HTMLCleanupProcessorImpl} is used. - *

      - * Note that a preferences like {@code TAG_NAME_CASE} are not used by the - * formatter, though configurable in the formatters preference GUI. - * The user must instead configure for example {@code CLEANUP_TAG_NAME_CASE} - * in the cleanup GUI. - *

      - */ - private static class CleanupProcessor extends HTMLCleanupProcessorImpl implements CleanupStep.ProcessorAccessor { - private HTMLFormatProcessorImpl processor; - - CleanupProcessor() { - processor = new HTMLFormatProcessorImpl(); - } - - @Override - public String getTypeId() { - return getContentType(); - } - - @Override - public void refreshPreferences() { - refreshCleanupPreferences(); - processor = new HTMLFormatProcessorImpl(); //Constructor reads new preferences - processor.refreshFormatPreferences = false; //Don't refresh when cloning - } - - @Override - public AbstractStructuredCleanupProcessor get() { - return this; - } - - @Override - protected IStructuredFormatProcessor getFormatProcessor() { - return processor; - } - - String getIndent() { - return processor.getFormatPreferences().getIndent(); - } - - } - - private static class FrameworkConfig extends CleanupStep.FrameworkConfig { - private final List dependentConfigs; - private final Properties properties; - - public FrameworkConfig(Properties properties) { - dependentConfigs = Arrays.asList( - new EclipseCssFormatterStepImpl.FrameworkConfig(properties), - new EclipseJsFormatterStepImpl.FrameworkConfig(properties), - new EclipseXmlFormatterStepImpl.FrameworkConfig(properties)); - this.properties = properties; - } - - @Override - public void registerBundles(SpotlessEclipseCoreConfig config) { - EclipseJsFormatterStepImpl.FrameworkConfig.registerNonHeadlessBundles(config); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - super.activatePlugins(config); - EclipseCssFormatterStepImpl.FrameworkConfig.activateCssPlugins(config); - EclipseJsFormatterStepImpl.FrameworkConfig.activateJsPlugins(config); - /* - * The HTML formatter only uses the DOCTYPE/SCHEMA for content model selection. - * Hence no external URIs are required. - */ - boolean allowExternalURI = false; - EclipseXmlFormatterStepImpl.FrameworkConfig.activateXmlPlugins(config, allowExternalURI); - config.add(new HTMLCorePlugin()); - } - - @Override - public void customize() { - dependentConfigs.stream().forEach(c -> { - c.customize(); - }); - PluginPreferences.configure(HTMLCorePlugin.getDefault(), new HTMLCorePreferenceInitializer(), properties); - } - - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java deleted file mode 100644 index c101b1a27a..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImpl.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.DefaultBundles.*; -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - -import java.util.AbstractMap.SimpleEntry; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.TypedPosition; -import org.eclipse.jface.text.formatter.FormattingContextProperties; -import org.eclipse.jface.text.formatter.IFormattingContext; -import org.eclipse.jface.text.rules.FastPartitioner; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.TextEdit; -import org.eclipse.wst.jsdt.core.JavaScriptCore; -import org.eclipse.wst.jsdt.core.ToolFactory; -import org.eclipse.wst.jsdt.core.formatter.CodeFormatter; -import org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants; -import org.eclipse.wst.jsdt.internal.ui.text.FastJavaPartitionScanner; -import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingContext; -import org.eclipse.wst.jsdt.internal.ui.text.comment.CommentFormattingStrategy; -import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions; -import org.osgi.framework.Bundle; - -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseCoreConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; - -/** Formatter step which calls out to the Eclipse JS formatter. */ -public class EclipseJsFormatterStepImpl { - - private final static String[] COMMENT_TYPES = { - IJavaScriptPartitions.JAVA_DOC, - IJavaScriptPartitions.JAVA_MULTI_LINE_COMMENT, - IJavaScriptPartitions.JAVA_SINGLE_LINE_COMMENT, - IJavaScriptPartitions.JAVA_STRING, - IJavaScriptPartitions.JAVA_CHARACTER - }; - - private final static Map OPTION_2_COMMENT_TYPE = Collections.unmodifiableMap(Stream.of( - new SimpleEntry<>(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT, IJavaScriptPartitions.JAVA_SINGLE_LINE_COMMENT), - new SimpleEntry<>(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT, IJavaScriptPartitions.JAVA_MULTI_LINE_COMMENT), - new SimpleEntry<>(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT, IJavaScriptPartitions.JAVA_DOC)).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))); - - private final CodeFormatter formatter; - private final Hashtable options; - private final Set commentTypesToBeFormatted; - - public EclipseJsFormatterStepImpl(Properties properties) throws Exception { - SpotlessEclipseFramework.setup(new FrameworkConfig(properties)); - PluginPreferences.assertNoChanges(JavaScriptCore.getPlugin(), properties); - options = JavaScriptCore.getOptions(); - commentTypesToBeFormatted = OPTION_2_COMMENT_TYPE.entrySet().stream().filter(x -> DefaultCodeFormatterConstants.TRUE.equals(options.get(x.getKey()))).map(x -> x.getValue()).collect(Collectors.toSet()); - formatter = ToolFactory.createCodeFormatter(options, ToolFactory.M_FORMAT_EXISTING); - } - - /** Formatting JavaScript string */ - public String format(String raw) throws Exception { - raw = formatComments(raw); - // The comment formatter messed up the code a little bit (adding some line breaks). Now we format the code. - IDocument doc = new Document(raw); - TextEdit edit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, raw, 0, raw.length(), 0, LINE_DELIMITER); - if (edit == null) { - throw new IllegalArgumentException("Invalid JavaScript syntax for formatting."); - } else { - edit.apply(doc); - } - return doc.get(); - } - - /** - * Comment formats like it would be accomplished by the JDTS UI, without setting up the UI. - * @see org.eclipse.wst.jsdt.internal.ui.fix.CommentFormatFix - */ - private String formatComments(String raw) { - Document doc = new Document(raw); - IDocumentPartitioner commentPartitioner = new FastPartitioner(new FastJavaPartitionScanner(), COMMENT_TYPES); - doc.setDocumentPartitioner(IJavaScriptPartitions.JAVA_PARTITIONING, commentPartitioner); - commentPartitioner.connect(doc); - CommentFormattingStrategy commentFormatter = new CommentFormattingStrategy(); - IFormattingContext context = new CommentFormattingContext(); - context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES, options); - context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE); - context.setProperty(FormattingContextProperties.CONTEXT_MEDIUM, doc); - try { - ITypedRegion[] regions = TextUtilities.computePartitioning(doc, IJavaScriptPartitions.JAVA_PARTITIONING, 0, doc.getLength(), false); - MultiTextEdit resultEdit = new MultiTextEdit(); - Arrays.asList(regions).stream().filter(reg -> commentTypesToBeFormatted.contains(reg.getType())).forEach(region -> { - TypedPosition typedPosition = new TypedPosition(region.getOffset(), region.getLength(), region.getType()); - context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, typedPosition); - commentFormatter.formatterStarts(context); - TextEdit edit = commentFormatter.calculateTextEdit(); - commentFormatter.formatterStops(); - if (null != edit && edit.hasChildren()) { - resultEdit.addChild(edit); - } - }); - resultEdit.apply(doc); - return doc.get(); - } catch (BadLocationException e) { - //Silently ignore comment formatting exceptions and return the original string - return raw; - } - } - - static class FrameworkConfig implements SpotlessEclipseConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - this.properties = properties; - } - - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - config.useSlf4J(this.getClass().getPackage().getName()); - } - - @Override - public void registerBundles(SpotlessEclipseCoreConfig config) { - registerNonHeadlessBundles(config); - } - - static void registerNonHeadlessBundles(SpotlessEclipseCoreConfig config) { - //The JS model requires the JDT indexer, hence a headless Eclipse cannot be used. - config.add(PLATFORM, Bundle.ACTIVE); - config.add(REGISTRY, PREFERENCES, COMMON); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - activateJsPlugins(config); - } - - static void activateJsPlugins(SpotlessEclipsePluginConfig config) { - // The JS core uses EFS for determination of temporary storage location - config.add(org.eclipse.core.filesystem.EFS.class); - // The JS core provides the JSDT formatter - config.add(new org.eclipse.wst.jsdt.core.JavaScriptCore()); - } - - @Override - @SuppressWarnings("unchecked") - public void customize() { - PluginPreferences.store(JavaScriptCore.getPlugin(), properties); - Hashtable options = JavaScriptCore.getDefaultOptions(); - options.putAll(DefaultCodeFormatterConstants.getJSLintConventionsSettings()); - options.putAll(new HashMap(properties)); - JavaScriptCore.setOptions(options); - } - - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java deleted file mode 100644 index 91d8516b24..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImpl.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp; - -import java.io.IOException; -import java.util.Properties; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.wst.json.core.JSONCorePlugin; -import org.eclipse.wst.json.core.cleanup.CleanupProcessorJSON; -import org.eclipse.wst.json.core.format.FormatProcessorJSON; -import org.eclipse.wst.json.core.internal.preferences.JSONCorePreferenceInitializer; -import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; - -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.wtp.sse.CleanupStep; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; - -/** - * Formatter step which calls out to the Eclipse JSON cleanup processor and formatter. - * Note that the cleanup is escaped, since it has known bugs and is currently not used by Eclipse. - */ -public class EclipseJsonFormatterStepImpl extends CleanupStep { - - public EclipseJsonFormatterStepImpl(Properties properties) throws Exception { - super(new CleanupProcessor(), new FrameworkConfig(properties)); - PluginPreferences.assertNoChanges(JSONCorePlugin.getDefault(), properties); - } - - /** - * The JSON CleanUp is partly implemented. - *

      - * For example the abstract formatter supports the - * CASE_PROPERTY_NAME configuration item. - * However, this seems to be all dead code and there seems - * to be no way in the latest Eclipse GUI to configure - * or trigger the clean-up process. - *

      - *

      - * Here we just use the CleanupProcessorJSON to reuse the common - * interface to trigger the formatting. - *

      - * See {@code org.eclipse.wst.json.core.internal.format.AbstractJSONSourceFormatter} for details. - */ - private static class CleanupProcessor extends CleanupProcessorJSON implements CleanupStep.ProcessorAccessor { - private final FormatProcessorJSON formatter; - - CleanupProcessor() { - formatter = new FormatProcessorJSON(); - } - - @Override - public String getTypeId() { - return getContentType(); - } - - @Override - public AbstractStructuredCleanupProcessor get() { - return this; - } - - @Override - public void refreshPreferences() { - refreshCleanupPreferences(); - } - - @Override - public String cleanupContent(String input) throws IOException, CoreException { - /* - * The CleanupProcessorJSON.cleanupContent is erroneous and disabled in IDE. - * Hence the clean-up itself is replaced by a format processor. - * The SpotlessJsonCleanup still derives from the CleanupStep base class - * to use the common Spotless WTP configuration. - * - * See Spotless issue #344 for details. - */ - return formatter.formatContent(input); - } - } - - private static class FrameworkConfig extends CleanupStep.FrameworkConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - this.properties = properties; - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - super.activatePlugins(config); - config.add(new JSONCorePlugin()); - } - - @Override - public void customize() { - PluginPreferences.configure(JSONCorePlugin.getDefault(), new JSONCorePreferenceInitializer(), properties); - } - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java deleted file mode 100644 index 57fce0d503..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImpl.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; -import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.*; - -import java.util.Properties; - -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.text.edits.TextEdit; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.eclipse.wst.dtd.core.internal.DTDCorePlugin; -import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.Catalog; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager; -import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.xml.core.internal.document.DOMModelImpl; -import org.eclipse.wst.xml.core.internal.formatter.DefaultXMLPartitionFormatter; -import org.eclipse.wst.xml.core.internal.formatter.XMLFormattingPreferences; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryAdapterFactoryForXML; -import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceInitializer; -import org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML; -import org.eclipse.wst.xsd.core.internal.XSDCorePlugin; -import org.eclipse.xsd.util.XSDSchemaBuildingTools; - -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; -import com.diffplug.spotless.extra.eclipse.wtp.sse.PreventExternalURIResolverExtension; - -/** Formatter step which calls out to the Eclipse XML formatter. */ -public class EclipseXmlFormatterStepImpl { - private final DefaultXMLPartitionFormatter formatter; - private final XMLFormattingPreferences preferences; - private final INodeAdapterFactory xmlAdapterFactory; - - public EclipseXmlFormatterStepImpl(Properties properties) throws Exception { - SpotlessEclipseFramework.setup(new FrameworkConfig(properties)); - PluginPreferences.assertNoChanges(XMLCorePlugin.getDefault(), properties); - preferences = new XMLFormattingPreferences(); - formatter = new DefaultXMLPartitionFormatter(); - //The adapter factory maintains the common CMDocumentCache - xmlAdapterFactory = new ModelQueryAdapterFactoryForXML(); - } - - static class FrameworkConfig implements SpotlessEclipseConfig { - private final Properties properties; - - FrameworkConfig(Properties properties) { - /* - * The cache is only used for system catalogs, but not for user catalogs. - * It requires the SSECorePLugin, which has either a big performance overhead, - * or needs a dirty mocking (we don't really require its functions but it needs to be there). - * So we disable the cache for now. - * This might cause a performance drop in case for example XSDs are formatted. - * But these standard/system restriction files contain anyway no formatting rules. - * So in case of performance inconveniences, we could add a Spotless property to disable the - * XSD/DTD parsing entirely (for example by adding an own URI resolver). - */ - properties.setProperty(CMDOCUMENT_GLOBAL_CACHE_ENABLED, Boolean.toString(false)); - this.properties = properties; - } - - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.applyDefault(); - config.useSlf4J(EclipseXmlFormatterStepImpl.class.getPackage().getName()); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - activateXmlPlugins(config, PluginPreferences.isExternalUriAllowed(properties)); - } - - static void activateXmlPlugins(SpotlessEclipsePluginConfig config, boolean allowExternalURI) { - //The WST XML formatter - config.add(new XMLCorePlugin()); - //XSDs/DTDs must be resolved by URI - config.add(new URIResolverPlugin()); - //Support formatting based on DTD restrictions - config.add(new DTDCorePlugin()); - //Support formatting based on XSD restrictions - config.add(new XSDCorePlugin()); - if (!allowExternalURI) { - config.add(new PreventExternalURIResolverExtension()); - } - } - - @Override - public void customize() { - //Register required EMF factories - XSDSchemaBuildingTools.getXSDFactory(); - PluginPreferences.configure(XMLCorePlugin.getDefault(), new XMLCorePreferenceInitializer(), properties); - PluginPreferences.configureCatalog(properties, (Catalog) XMLCorePlugin.getDefault().getDefaultXMLCatalog()); - } - - }; - - /** Formatting XML string resolving URIs according its base location */ - public String format(String raw, String baseLocation) throws Exception { - IStructuredDocument document = new BasicStructuredDocument(new XMLSourceParser()); - document.setPreferredLineDelimiter(LINE_DELIMITER); - IDocumentPartitioner partitioner = new StructuredTextPartitionerForXML(); - document.setDocumentPartitioner(new StructuredTextPartitionerForXML()); - partitioner.connect(document); - document.set(raw); - DOMModelImpl xmlDOM = new DOMModelImpl(); - xmlDOM.setBaseLocation(baseLocation); - xmlDOM.getFactoryRegistry().addFactory(xmlAdapterFactory); - xmlDOM.setStructuredDocument(document); - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(xmlDOM); - modelQuery.getCMDocumentManager().setPropertyEnabled(CMDocumentManager.PROPERTY_USE_CACHED_RESOLVED_URI, true); - TextEdit formatterChanges = formatter.format(xmlDOM, 0, document.getLength(), preferences); - formatterChanges.apply(document); - return document.get(); - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java deleted file mode 100644 index d856335c1b..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/JsRegionProcessor.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp.html; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - -import java.util.function.BiFunction; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.TextEdit; -import org.eclipse.wst.jsdt.core.formatter.CodeFormatter; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; - -import com.diffplug.spotless.extra.eclipse.wtp.html.StructuredDocumentProcessor.RegionProcessor; - -/** - * Provides additional formating to the plain JS {@link CodeFormatter}: - *
        - *
      • Eclipse HTML places the embedded JS in separated lines by adding a line break after/before <script/> tag.
      • - *
      • Eclipse HTML treats the text before the closing </script> tag as part of the script region.
      • - *
      - *

      - * Note that the closing tag is indented by Eclipse using the embedded formatters indentation, - * whereas the opening tag indentation is configured by the HTML preferences. - * This is more a bug than a feature, but Spotless formatter output shall be identical - * to the one of Eclipse. - *

      - */ -public class JsRegionProcessor extends RegionProcessor { - public JsRegionProcessor(IStructuredDocument document, ITypedRegion scriptRegion, String htmlIndent) { - super(document, scriptRegion, htmlIndent); - } - - @Override - protected void applyFirst(CodeFormatter formatter) throws MalformedTreeException, BadLocationException { - MultiTextEdit modifications = new MultiTextEdit(); - String jsSource = document.get(region.getOffset(), region.getLength()); - TextEdit jsEdit = formatter.format(CodeFormatter.K_JAVASCRIPT_UNIT, jsSource, 0, jsSource.length(), indentationLevel + 1, LINE_DELIMITER); - if (null != jsEdit) { - jsEdit.moveTree(region.getOffset()); - modifications.addChild(jsEdit); - } - modifications.apply(document); - } - - @Override - protected void applySecond(CodeFormatter formatter) throws MalformedTreeException, BadLocationException { - MultiTextEdit modifications = new MultiTextEdit(); - int regionEnd = region.getOffset() + region.getLength(); - regionEnd += fixDelimiter(modifications, region.getOffset(), false); - regionEnd += fixDelimiter(modifications, region.getOffset() + region.getLength() - 1, true); - modifications.apply(document); - modifications.removeChildren(); - fixTagIndent(modifications, regionEnd, formatter.createIndentationString(indentationLevel)); - modifications.apply(document); - } - - /** Factory for {@link StructuredDocumentProcessor}*/ - public static BiFunction createFactory(String htmlIndent) { - return new BiFunction() { - - @Override - public JsRegionProcessor apply(IStructuredDocument document, ITypedRegion region) { - return new JsRegionProcessor(document, region, htmlIndent); - } - - }; - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java deleted file mode 100644 index 6adc258c78..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/StructuredDocumentProcessor.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp.html; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.function.BiFunction; -import java.util.stream.Collectors; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.text.edits.InsertEdit; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.text.edits.TextEdit; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; - -/** - * The HTML formatter uses for different regions of the structured document, - * other formatters, explicitly for CSS and JS. - * Adaptations of the current formatter modifications are tedious, - * since the adaptations e.g. overlap with the required additional modifications. - * Hence the modifications is split in steps, whereas the regions of the - * structured documents and their offsets are regenerate between the first - * ad second step. - */ -public class StructuredDocumentProcessor { - private final String type; - private final BiFunction> factory; - private final IStructuredDocument document; - private final int numberOfRegions; - - /** - * Constructs a document processor - * @param document Document to be processed - * @param type Document type ID recognized by {@code IContentTypeManager} service - * @param factory Factory for structured document processor - */ - public StructuredDocumentProcessor(IStructuredDocument document, String type, - BiFunction> factory) { - this.type = type; - this.factory = factory; - this.document = document; - numberOfRegions = getRegions().size(); - } - - /** Applies processor on document, using a given formatter */ - public void apply(T formatter) { - for (int currentRegionId = 0; currentRegionId < numberOfRegions; currentRegionId++) { - applyOnRegion(currentRegionId, formatter); - } - } - - private List getRegions() { - try { - return Arrays.asList(document.computePartitioning(0, document.getLength())).stream().filter(reg -> type == reg.getType()).collect(Collectors.toList()); - } catch (BadLocationException e) { - /* - * This prevents the processing in case the entire document - * cannot be processed (e.g. the document is incomplete). - */ - return new ArrayList(0); - } - } - - private void applyOnRegion(int number, T formatter) { - RegionProcessor adapter = getRegionProcessor(number); - try { - adapter.applyFirst(formatter); - adapter = getRegionProcessor(number); - adapter.applySecond(formatter); - } catch (MalformedTreeException | BadLocationException e) { - throw new IllegalArgumentException( - String.format("%s formatting failed between lines %d and %d. Most likely the syntax is not recognized.", - type, adapter.getFirstLine(), adapter.getLastLine()), - e); - } - } - - private RegionProcessor getRegionProcessor(int number) { - List regions = getRegions(); - if (numberOfRegions != regions.size()) { - //Don't catch this. This is a severe internal bug! - throw new IllegalArgumentException( - String.format( - "During first '%s' formatting step, the number of detected regions changed from '%d' to '%d'", - type, numberOfRegions, regions.size())); - } - ITypedRegion region = regions.get(number); - return factory.apply(document, region); - } - - /** Base class for region adaptations. */ - public static abstract class RegionProcessor { - protected final IStructuredDocument document; - protected final ITypedRegion region; - protected final int indentationLevel; - protected final int firstLine; - protected final int lastLine; - - protected RegionProcessor(IStructuredDocument document, ITypedRegion region, String htmlIndent) { - this.document = document; - this.region = region; - indentationLevel = computeIndent(document, region, htmlIndent); - firstLine = document.getLineOfOffset(region.getOffset()); - lastLine = document.getLineOfOffset(region.getOffset() + region.getLength()); - } - - public int getFirstLine() { - return firstLine; - } - - public int getLastLine() { - return lastLine; - } - - private static int computeIndent(IStructuredDocument document, ITypedRegion region, String htmlIndent) { - int indent = 0; - try { - int lineNumber = document.getLineOfOffset(region.getOffset()); - document.getNumberOfLines(); - int lineOffset = document.getLineOffset(lineNumber); - String lineStart = document.get(lineOffset, region.getOffset() - lineOffset); - while (lineStart.length() > htmlIndent.length()) { - if (lineStart.startsWith(htmlIndent)) { - indent++; - } else { - break; - } - lineStart = lineStart.substring(htmlIndent.length()); - } - } catch (BadLocationException e) { - /* - * Skip addition indentation. This normally indicates a malformed HTML - * outside of this region, which cannot be handled here. - */ - indent = 0; - } - return indent; - } - - /** Add delimiter at or after given offset, if there is none at the offset position. Returns the number of characters inserted. */ - protected int fixDelimiter(MultiTextEdit modifications, int offset, boolean addAfter) throws BadLocationException { - int delimiterLength = LINE_DELIMITER.length(); - String delimiter = document.get(offset, delimiterLength); - if (!LINE_DELIMITER.equals(delimiter)) { - if (addAfter) { - offset += 1; - } - modifications.addChild(new InsertEdit(offset, LINE_DELIMITER)); - return LINE_DELIMITER.length(); - } - return 0; - } - - /** Fix the tag indentation at a given position with a predefined indentation. */ - protected void fixTagIndent(MultiTextEdit modifications, int offset, String indentString) throws BadLocationException { - int lineNumber = document.getLineOfOffset(offset); - if (lineNumber >= document.getNumberOfLines()) { - //Nothing to change for last line. If syntax is correct, there is no indentation. If syntax is not correct, there is nothing to do. - return; - } - int lineStart = document.getLineOffset(lineNumber); - int lineEnd = document.getLineOffset(lineNumber + 1); - String lineContent = document.get(lineStart, lineEnd - lineStart); - StringBuilder currentIndent = new StringBuilder(); - lineContent.chars().filter(c -> { - if (c == ' ' || c == '\t') { - currentIndent.append(c); - return false; - } - return true; - }).findFirst(); - if (!indentString.equals(currentIndent.toString())) { - TextEdit replaceIndent = new ReplaceEdit(lineStart, currentIndent.length(), indentString); - replaceIndent.apply(document); - } - } - - /** First application of modifications */ - abstract protected void applyFirst(T formatter) throws MalformedTreeException, BadLocationException; - - /** Second application of modifications (based on new regions) */ - abstract protected void applySecond(T formatter) throws MalformedTreeException, BadLocationException; - - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/package-info.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/package-info.java deleted file mode 100644 index 770e126a1b..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/html/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2016 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. - */ -/** Eclipse WTP HTML formatter helper */ -@ParametersAreNonnullByDefault -package com.diffplug.spotless.extra.eclipse.wtp.html; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java deleted file mode 100644 index 6cf6f0bfff..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2016 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. - */ -/** Eclipse WTP based Spotless formatters */ -@ParametersAreNonnullByDefault -package com.diffplug.spotless.extra.eclipse.wtp; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java deleted file mode 100644 index 01be583bd8..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/CleanupStep.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp.sse; - -import org.eclipse.core.internal.preferences.PreferencesService; -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.core.runtime.preferences.IPreferencesService; -import org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor; - -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipsePluginConfig; -import com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseServiceConfig; - -/** - * Common base class for step implementations based on an SSE cleanup processor. - *

      - * Some WTP formatters do not apply all formatting within a formatter process, - * but provide a cleanup and a formatter process, whereas the cleanup process - * calls the formatter process. - *

      - *

      - * Not all cleanup processes provided by WTP are suitable for Spotless formatting. - * For example the XML cleanup processor focus on syntax and line delimiter - * corrections. The syntax correction is based on the corresponding XSD/DTD, - * but it must be assumed by the Spotless formatter that the provided files - * are valid. It cannot be the purpose of a formatter to correct syntax. - * A Java formatter should also not attempt to correct compilation errors. - * A line delimiter correction would furthermore violate the Spotless rule - * that the strings processed by a Spotless formatter chain must use - * UNIX style delimiters. - *

      - * @see org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor - */ -public class CleanupStep { - - /** Make some of the protected SEE AbstractStructuredCleanupProcessor methods public. */ - public interface ProcessorAccessor { - - /** Configure from Eclipse framework preferences */ - void refreshPreferences(); - - /** Get underlying processor */ - AbstractStructuredCleanupProcessor get(); - - /** Get processor content type */ - String getTypeId(); - } - - /** Framework configuration public to all formatters using the Cleanup step */ - public static abstract class FrameworkConfig implements SpotlessEclipseConfig { - - private String processorContentTypeID; - - protected FrameworkConfig() { - processorContentTypeID = "none"; - } - - void setProcessorTypeID(String contentTypeID) { - processorContentTypeID = contentTypeID; - } - - @Override - public void registerServices(SpotlessEclipseServiceConfig config) { - config.disableDebugging(); - config.hideEnvironment(); - config.useTemporaryLocations(); - config.changeSystemLineSeparator(); - config.useSlf4J(this.getClass().getPackage().getName() + "-" + processorContentTypeID); - - //Assure that all file content processed by this formatter step are associated to this cleanup-step - config.add(IContentTypeManager.class, new ContentTypeManager(processorContentTypeID)); - - //The preference lookup via the ContentTypeManager, requires a preference service - config.add(IPreferencesService.class, PreferencesService.getDefault()); - } - - @Override - public void activatePlugins(SpotlessEclipsePluginConfig config) { - config.applyDefault(); - /* - * The core preferences require do lookup the resources "config/override.properties" - * from the plugin ID. - * The values are never used, nor do we require the complete SSE core plugin to be started. - * Hence we just provide the internal plugin. - */ - config.add(new org.eclipse.wst.sse.core.internal.encoding.util.CodedResourcePlugin()); - } - } - - protected final ProcessorAccessor processorAccessor; - - protected CleanupStep(ProcessorAccessor processorAccessor, FrameworkConfig config) throws Exception { - config.setProcessorTypeID(processorAccessor.getTypeId()); - SpotlessEclipseFramework.setup(config); - this.processorAccessor = processorAccessor; - this.processorAccessor.refreshPreferences(); - /* - * Don't refresh the preferences every time a clone of the processor is created. - * All processors shall use the preferences of its parent. - */ - processorAccessor.get().refreshCleanupPreferences = false; - } - - /** - * Calls the cleanup and formatting task of the processor and returns the formatted string. - * @param raw Dirty string - * @return Formatted string - * @throws Exception All exceptions are considered fatal to the build process (Gradle, Maven, ...) and should not be caught. - */ - public String format(String raw) throws Exception { - return processorAccessor.get().cleanupContent(raw); - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/ContentTypeManager.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/ContentTypeManager.java deleted file mode 100644 index 499a147ae9..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/ContentTypeManager.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp.sse; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.content.IContentDescription; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeSettings; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS; -import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML; -import org.eclipse.wst.json.core.contenttype.ContentTypeIdForJSON; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; - -import com.diffplug.spotless.extra.eclipse.base.service.NoContentTypeSpecificHandling; - -/** - - * WTP ModelHandlerRegistry uses the content type mamanger clean-up formatters - * to provide association of content to content type related functionality. - *

      - * Preference lookup per content type is accomplished via the - * Eclipse PreferencesService, which must be provided in combination with - * this service. - *

      - * The input byte steam encoding detection is accomplished by the - * content type manager. Normally the encoding is bount do a document/file. - * Spotless applies the formatting on strings already decoded. - * The WTP AbstractStructuredCleanupProcessor provides for non-documents - * a clean-up function converting the decoded string into an UTF-8 encoded byte stream. - * WTP AbstractDocumentLoader uses content type mamanger to determine the encoding - * of the input stream. - * Only the steps are affected that are using the - * AbstractStructuredCleanupProcessor. All other steps creating an empty document - * (e.g. via WTP AbstractDocumentLoader) and setting the textual content of the new document. - * - * @see org.eclipse.core.internal.preferences.PreferencesService - * @see org.eclipse.wst.sse.core.internal.cleanup.AbstractStructuredCleanupProcessor - * @see org.eclipse.wst.sse.core.internal.document.AbstractDocumentLoader - * @see org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry - */ -class ContentTypeManager extends NoContentTypeSpecificHandling { - private final Map id2Object; - private final IContentType processorStepType; - private final IContentDescription processorStepDescription; - - /** - * Content type manager as required for cleanup steps. - * @param formatterContentTypeID The content type of the formatter step - */ - ContentTypeManager(String formatterContentTypeID) { - id2Object = new HashMap(); - Arrays.asList( - ContentTypeIdForCSS.ContentTypeID_CSS, - ContentTypeIdForXML.ContentTypeID_XML, - ContentTypeIdForHTML.ContentTypeID_HTML, - ContentTypeIdForJSON.ContentTypeID_JSON) - .stream().forEach(id -> id2Object.put(id, new ContentTypeId(id))); - processorStepType = id2Object.get(formatterContentTypeID); - if (null == processorStepType) { - throw new IllegalArgumentException("The manager does not support content type " + formatterContentTypeID); - } - processorStepDescription = new StringDescription(processorStepType); - } - - @Override - public IContentType getContentType(String contentTypeIdentifier) { - /* - * It is OK to return null here since the manager is only used as an additional - * helper to alter default behavior. - */ - return id2Object.get(contentTypeIdentifier); - } - - @Override - public IContentType findContentTypeFor(InputStream contents, String fileName) throws IOException { - //We only format things here with the given processor, so this answer is always correct. - return processorStepType; - } - - @Override - public IContentDescription getDescriptionFor(InputStream contents, String fileName, QualifiedName[] options) throws IOException { - return processorStepDescription; - } - - private static class StringDescription implements IContentDescription { - - private final IContentType type; - - public StringDescription(IContentType type) { - this.type = type; - } - - @Override - public boolean isRequested(QualifiedName key) { - return false; //Don't use set Property - } - - @Override - public String getCharset() { - //Called by AbstractDocumentLoader.readInputStream - return "UTF-8"; //UTF-8 encoded by AbstractStructuredCleanupProcessor.cleanupContent - } - - @Override - public IContentType getContentType() { - return type; - } - - @Override - public Object getProperty(QualifiedName key) { - return null; //Assume that the property map is empty - } - - @Override - public void setProperty(QualifiedName key, Object value) { - throw new IllegalArgumentException("Content description key cannot be set: " + key); - } - } - - /** - * The WTP uses the manager mainly for ID mapping, so most of the methods are not used. - * Actually it has a hand stitched way for transforming the content type ID - * {@code org.eclipse.wst...source} to the plugin ID {@code org.eclipse.wst...core}. - * @see org.eclipse.wst.sse.core.internal.encoding.ContentBasedPreferenceGateway - */ - private static class ContentTypeId implements IContentType { - - private final String id; - - ContentTypeId(String id) { - this.id = id; - } - - @Override - public void addFileSpec(String fileSpec, int type) throws CoreException {} - - @Override - public void removeFileSpec(String fileSpec, int type) throws CoreException {} - - @Override - public void setDefaultCharset(String userCharset) throws CoreException {} - - @Override - public boolean isUserDefined() { - return false; - } - - @Override - public IContentType getBaseType() { - return null; - } - - @Override - public IContentDescription getDefaultDescription() { - return null; - } - - @Override - public IContentDescription getDescriptionFor(InputStream contents, QualifiedName[] options) throws IOException { - return null; - } - - @Override - public IContentDescription getDescriptionFor(Reader contents, QualifiedName[] options) throws IOException { - return null; - } - - @Override - public String getDefaultCharset() { - return null; - } - - @Override - public String[] getFileSpecs(int type) { - return null; - } - - @Override - public String getId() { - return id; - } - - @Override - public String getName() { - return id; - } - - @Override - public boolean isAssociatedWith(String fileName) { - return false; - } - - @Override - public boolean isAssociatedWith(String fileName, IScopeContext context) { - return false; - } - - @Override - public boolean isKindOf(IContentType another) { - if (null == another) { - return false; - } - return this.id.equals(another.getId()); - } - - @Override - public IContentTypeSettings getSettings(IScopeContext context) throws CoreException { - return null; - } - - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java deleted file mode 100644 index 81aa772617..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PluginPreferences.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp.sse; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Properties; - -import org.eclipse.core.runtime.Plugin; -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.core.runtime.preferences.DefaultScope; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.wst.xml.core.internal.catalog.Catalog; -import org.eclipse.wst.xml.core.internal.catalog.CatalogReader; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; - -/** - * The plugin preference configuration of most WTP formatters is accomplished via the - * globabl Eclipse preference lookup. - * Spotless allows different formatter configurations per sub-projects. - * Fortunately most formatters only perform a lookup on instantiation and not afterwards. - * This is sometimes not true for all preferences of the formatter. - * - * - */ -public class PluginPreferences { - /** - * Optional XML catalog for XSD/DTD lookup. - * Catalog versions 1.0 and 1.1 are supported. - *

      - * Value is of type {@code Path}. - *

      - */ - public static final String USER_CATALOG = "userCatalog"; - - /** - * Indicates if external URIs (location hints) should be resolved - * and the referenced DTD/XSD shall be applied. Per default - * external URIs are ignored. - *

      - * Value is of type Boolean. - *

      - */ - public static final String RESOLVE_EXTERNAL_URI = "resolveExternalURI"; - - /** Storage of latest global configuration */ - private static final Map CONFIG = new HashMap<>(); - - /** \return True if user explicitly set the */ - public static boolean isExternalUriAllowed(Properties properties) { - return Boolean.parseBoolean(properties.getProperty(PluginPreferences.RESOLVE_EXTERNAL_URI, "false")); - } - - /** Configures persistent Eclipse properties */ - public static void configure(Plugin plugin, AbstractPreferenceInitializer defaultInitializer, Properties properties) { - defaultInitializer.initializeDefaultPreferences(); - IEclipsePreferences globalPreferences = DefaultScope.INSTANCE.getNode(getPluginId(plugin)); - properties.forEach((key, value) -> { - globalPreferences.put((String) key, (String) value); - }); - store(plugin, properties); - } - - /** Stores Eclipse properties for later comparison */ - public static void store(Plugin plugin, Properties properties) { - CONFIG.put(getPluginId(plugin), properties); - } - - /** Keep in mind that the ID is e.g. equal for all plugins. So assure that all user properties ge stored. */ - private static String getPluginId(Plugin plugin) { - return plugin.getBundle().getSymbolicName(); - } - - public static void configureCatalog(final Properties properties, final ICatalog defaultCatalogInterface) { - Objects.requireNonNull(properties, "Property values are missing."); - Objects.requireNonNull(defaultCatalogInterface, "Default catalog missing."); - if (!(defaultCatalogInterface instanceof Catalog)) { - throw new IllegalArgumentException("Internal error: Catalog implementation '" + defaultCatalogInterface.getClass().getCanonicalName() + "' unsupported."); - } - Catalog defaultCatalog = (Catalog) defaultCatalogInterface; - String catalogProperty = properties.getProperty(USER_CATALOG, ""); - if (!catalogProperty.isEmpty()) { - final File catalogFile = new File(catalogProperty); - try { - InputStream inputStream = new FileInputStream(catalogFile); - String orgBase = defaultCatalog.getBase(); - defaultCatalog.setBase(catalogFile.toURI().toString()); - CatalogReader.read((Catalog) defaultCatalog, inputStream); - defaultCatalog.setBase(orgBase); - } catch (IOException e) { - throw new IllegalArgumentException( - String.format("Value of '%s' refers to '%s', which cannot be read.", USER_CATALOG, catalogFile)); - } - } else { - defaultCatalog.clear(); - } - } - - /** Throws exception in case configuration has changed */ - public static void assertNoChanges(Plugin plugin, Properties properties) { - Objects.requireNonNull(properties, "Property values are missing."); - final String preferenceId = plugin.getBundle().getSymbolicName(); - Properties originalValues = CONFIG.get(preferenceId); - if (null == originalValues) { - throw new IllegalArgumentException("No configuration found for " + preferenceId); - } - if (!originalValues.equals(properties)) { - throw new IllegalArgumentException("The Eclipse formatter does not support multiple configurations."); - } - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java deleted file mode 100644 index d0b95e5632..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/PreventExternalURIResolverExtension.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp.sse; - -import org.eclipse.core.resources.IFile; -import org.eclipse.emf.common.util.URI; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverExtension; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -/** - * The URI resolver extension - */ -public class PreventExternalURIResolverExtension implements URIResolverExtension, BundleActivator { - - private static final String REFUSE_EXTERNAL_URI = "file://refused.external.uri"; - - /** - * @param file the in-workspace base resource, if one exists - * @param baseLocation - the location of the resource that contains the uri - * @param publicId - an optional public identifier (i.e. namespace name), or null if none - * @param systemId - an absolute or relative URI, or null if none - * - * @return an absolute URI or null if this extension can not resolve this reference - */ - @Override - public String resolve(IFile file, String baseLocation, String publicId, String systemId) { - if (null != systemId) { - try { - URI proposalByPreviousResolver = org.eclipse.emf.common.util.URI.createURI(systemId); - String host = proposalByPreviousResolver.host(); - /* - * The host is empty (not null) - */ - if (!(null == host || host.isEmpty())) { - return REFUSE_EXTERNAL_URI; - } - } catch (IllegalArgumentException ignore) { - //If it is no a valid URI, there is nothing to do here. - } - } - return null; //Don't alter the proposal of previous resolver extensions by proposing something else - } - - @Override - public void start(BundleContext context) throws Exception { - //Nothing to do. The bundle-activator interface only allows to load this extension as a stand-alone plugin. - } - - @Override - public void stop(BundleContext context) throws Exception { - //Nothing to do. The bundle-activator interface only allows to load this extension as a stand-alone plugin. - } - -} diff --git a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/package-info.java b/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/package-info.java deleted file mode 100644 index 931b7e085e..0000000000 --- a/_ext/eclipse-wtp/src/main/java/com/diffplug/spotless/extra/eclipse/wtp/sse/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2016 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. - */ -/** Eclipse WTP Structured Source Editing (SEE) formatter helper */ -@ParametersAreNonnullByDefault -package com.diffplug.spotless.extra.eclipse.wtp.sse; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/_ext/eclipse-wtp/src/main/resources/META-INF/MANIFEST.MF b/_ext/eclipse-wtp/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index 9f785fea6c..0000000000 --- a/_ext/eclipse-wtp/src/main/resources/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-SymbolicName: com.diffplug.gradle.spotless.eclipse.wtp; singleton:=true diff --git a/_ext/eclipse-wtp/src/main/resources/plugin.xml b/_ext/eclipse-wtp/src/main/resources/plugin.xml deleted file mode 100644 index 7ffd251c94..0000000000 --- a/_ext/eclipse-wtp/src/main/resources/plugin.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImplTest.java b/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImplTest.java deleted file mode 100644 index 8dda3149c0..0000000000 --- a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseCssFormatterStepImplTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.spotless.extra.eclipse.wtp; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceNames.*; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Properties; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -class EclipseCssFormatterStepImplTest { - - private final static String ILLEGAL_CHAR = Character.toString((char) 254); - private final static String UNFORMATTED = " body {a: v; b: v;}\n".replaceAll("\n", LINE_DELIMITER); - private final static String FORMATTED = "BODY {\n a: v;\n b: v;\n}".replaceAll("\n", LINE_DELIMITER); - private final static String PRE_CODE_UNFORMATTED = "/**
      \"Hello\"
      */\n".replaceAll("\n", LINE_DELIMITER); - - private EclipseCssFormatterStepImpl formatter; - - @BeforeEach - void initialize() throws Exception { - /* - * The instantiation can be repeated for each step, but only with the same configuration - * All formatter configuration is stored in - * org.eclipse.core.runtime/.settings/org.eclipse.wst.css.core.prefs. - */ - Properties properties = new Properties(); - properties.put(INDENTATION_SIZE, "3"); - properties.put(INDENTATION_CHAR, SPACE); //Default is TAB - properties.put(CLEANUP_CASE_SELECTOR, Integer.toString(UPPER)); //Done by cleanup - formatter = new EclipseCssFormatterStepImpl(properties); - } - - @Test - void format() throws Exception { - String output = formatter.format(UNFORMATTED); - assertEquals(FORMATTED, - output, "Unexpected formatting with default preferences."); - } - - @Test - void illegalCharacter() throws Exception { - String output = formatter.format(ILLEGAL_CHAR + UNFORMATTED); - assertThat(output).as("Illeagl characters are not handled on best effort basis.").contains("BODY {"); - } - - @Test - void illegalSyntax() throws Exception { - String output = formatter.format("{" + UNFORMATTED); - assertEquals("{" + LINE_DELIMITER + FORMATTED, - output, "Illeagl syntax is not handled on best effort basis."); - } - - @Test - void formatComment() throws Exception { - String output = formatter.format(PRE_CODE_UNFORMATTED + UNFORMATTED); - assertEquals(PRE_CODE_UNFORMATTED + FORMATTED, - output, "Unexpected formatting of cpomments."); - } - - @Test - void configurationChange() throws Exception { - assertThrows(IllegalArgumentException.class, () -> new EclipseCssFormatterStepImpl(new Properties())); - } - -} diff --git a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImplTest.java b/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImplTest.java deleted file mode 100644 index b75421692a..0000000000 --- a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseHtmlFormatterStepImplTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.spotless.extra.eclipse.wtp; - -import static org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames.*; -import static org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants.*; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Properties; - -import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames; -import org.eclipse.wst.jsdt.core.JavaScriptCore; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -class EclipseHtmlFormatterStepImplTest { - - private TestData testData = null; - private EclipseHtmlFormatterStepImpl formatter; - - @BeforeEach - void initialize() throws Exception { - testData = TestData.getTestDataOnFileSystem("html"); - /* - * The instantiation can be repeated for each step, but only with the same configuration - * All formatter configuration is stored in - * org.eclipse.core.runtime/.settings/org.eclipse.wst.xml.core.prefs. - * So a simple test of one configuration item change is considered sufficient. - */ - Properties properties = new Properties(); - properties.put(CLEANUP_TAG_NAME_CASE, Integer.toString(HTMLCorePreferenceNames.UPPER)); //HTML config - properties.put(FORMATTER_INSERT_SPACE_BEFORE_SEMICOLON, JavaScriptCore.INSERT); //JS config - properties.put(QUOTE_ATTR_VALUES, "TRUE"); //CSS config - formatter = new EclipseHtmlFormatterStepImpl(properties); - } - - @Test - void formatHtml4() throws Exception { - String[] input = testData.input("html4.html"); - String output = formatter.format(input[0]); - assertEquals(testData.expected("html4.html"), - output, "Unexpected HTML4 formatting."); - } - - @Test - void formatHtml5() throws Exception { - String[] input = testData.input("html5.html"); - String output = formatter.format(input[0]); - assertEquals(testData.expected("html5.html"), - output, "Unexpected HTML5 formatting."); - } - - @Test - void invalidSyntax() throws Exception { - String[] input = testData.input("invalid_syntax.html"); - String output = formatter.format(input[0]); - assertEquals(testData.expected("invalid_syntax.html"), - output, "Unexpected HTML formatting in case syntax is not valid."); - } - - @Test - void formatJavaScript() throws Exception { - String[] input = testData.input("javascript.html"); - String output = formatter.format(input[0]); - assertEquals(testData.expected("javascript.html"), - output, "Unexpected JS formatting."); - } - - @Test - void formatCSS() throws Exception { - String[] input = testData.input("css.html"); - String output = formatter.format(input[0]); - assertEquals(testData.expected("css.html"), - output, "Unexpected CSS formatting."); - } - - @Test - void checkCleanupForNonUtf8() throws Exception { - String osEncoding = System.getProperty("file.encoding"); - System.setProperty("file.encoding", "ISO-8859-1"); //Simulate a non UTF-8 OS - String[] input = testData.input("utf-8.html"); - String output = formatter.format(input[0]); - System.setProperty("file.encoding", osEncoding); - assertEquals(testData.expected("utf-8.html"), output, "Unexpected formatting of UTF-8"); - } - - @Test - void checkBOMisStripped() throws Exception { - String[] input = testData.input("bom.html"); - String[] inputWithoutBom = testData.input("utf-8.html"); - //The UTF-8 BOM is interpreted as on UTF-16 character. - assertEquals(input[0].length() - 1, inputWithoutBom[0].length(), "BOM input invalid"); - String output = formatter.format(input[0]); - assertEquals(testData.expected("utf-8.html"), output, "BOM is not stripped"); - } - - @Test - void configurationChange() throws Exception { - assertThrows(IllegalArgumentException.class, () -> new EclipseHtmlFormatterStepImpl(new Properties())); - } -} diff --git a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImplTest.java b/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImplTest.java deleted file mode 100644 index 0858c3a04d..0000000000 --- a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsFormatterStepImplTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.spotless.extra.eclipse.wtp; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Arrays; -import java.util.Properties; - -import org.eclipse.wst.jsdt.core.JavaScriptCore; -import org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -class EclipseJsFormatterStepImplTest { - private final static String ILLEGAL_CHAR = Character.toString((char) 254); - private final static String UNFORMATTED = "var TEST = TEST || {};\n" + - "TEST.say = function() {\n" + - " console.log(\"Hello world!\"); }\n".replaceAll("\n", LINE_DELIMITER); - private final static String FORMATTED = "var TEST = TEST || {};\n" + - "TEST.say = function () {\n" + - "\tconsole.log(\"Hello world!\");\n}\n".replaceAll("\n", LINE_DELIMITER); - // Single line comment remains untouched - private final static String SINGLE_LINE_COMMENT = "// One line \"hello world\"\n".replaceAll("\n", LINE_DELIMITER); - // JavaDoc comment get indentation. Within PPRE code, HTML entities are escaped. - private final static String PRE_CODE_UNFORMATTED = "/**
      \"Hello\"
      */\n".replaceAll("\n", LINE_DELIMITER); - private final static String PRE_CODE_FORMATTED = "/**\n *
      \n * "Hello"\n * 
      \n */\n".replaceAll("\n", LINE_DELIMITER); - - private EclipseJsFormatterStepImpl formatter; - - @BeforeEach - void initialize() throws Exception { - /* - * The instantiation can be repeated for each step, but only with the same configuration - * All formatter configuration is stored in - * org.eclipse.core.runtime/.settings/org.eclipse.jst.jsdt.core.prefs. - */ - Properties properties = new Properties(); - properties.setProperty(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaScriptCore.TAB); - formatter = new EclipseJsFormatterStepImpl(properties); - } - - @Test - void invalidSyntax() throws Exception { - IllegalArgumentException error = assertThrows(IllegalArgumentException.class, () -> formatter.format(UNFORMATTED.replace("()", ""))); - assertThat(error.getMessage()).as("Exception has no hint about invalid syntax.").contains(Arrays.asList("Invalid", "syntax")); - } - - @Test - void illegalCharacter() throws Exception { - String output = formatter.format(UNFORMATTED.replace("function", "function" + ILLEGAL_CHAR)); - assertThat(output).as("Illegal ASCII charactes are not treated on best effort basis.").contains("function" + ILLEGAL_CHAR); - } - - @Test - void nominal() throws Exception { - String output = formatter.format(UNFORMATTED); - assertEquals(FORMATTED, output, "User configuration ignored by formatter."); - } - - @Test - void formatComments() throws Exception { - String output = formatter.format(SINGLE_LINE_COMMENT + PRE_CODE_UNFORMATTED + UNFORMATTED); - assertEquals(SINGLE_LINE_COMMENT + PRE_CODE_FORMATTED + FORMATTED, - output, "Invalid user configuration not treated on best effort basis."); - } - - @Test - void configurationChange() throws Exception { - assertThrows(IllegalArgumentException.class, () -> new EclipseJsFormatterStepImpl(new Properties())); - } - -} diff --git a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImplTest.java b/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImplTest.java deleted file mode 100644 index 3bb3b7c988..0000000000 --- a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseJsonFormatterStepImplTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.spotless.extra.eclipse.wtp; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; -import static org.eclipse.wst.json.core.preferences.JSONCorePreferenceNames.*; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Properties; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -class EclipseJsonFormatterStepImplTest { - private final static String ILLEGAL_CHAR = Character.toString((char) 254); - private final static String UNFORMATTED_OBJECT = "{\n \"x\": { \"a\" : \"v\",\"properties\" : \"v\" }}".replaceAll("\n", LINE_DELIMITER); - private final static String FORMATTED_OBJECT = "{\n \"x\": {\n \"a\": \"v\",\n \"properties\": \"v\"\n }\n}".replaceAll("\n", LINE_DELIMITER); - private final static String UNFORMATTED_ARRAY = "[\n { \"a\" : \"v\",\"properties\" : \"v\" }]".replaceAll("\n", LINE_DELIMITER); - private final static String FORMATTED_ARRAY = "[\n {\n \"a\": \"v\",\n \"properties\": \"v\"\n }\n]".replaceAll("\n", LINE_DELIMITER); - - private EclipseJsonFormatterStepImpl formatter; - - @BeforeEach - void initialize() throws Exception { - /* - * The instantiation can be repeated for each step, but only with the same configuration - * All formatter configuration is stored in - * org.eclipse.core.runtime/.settings/org.eclipse.wst.json.core.prefs. - * So a simple test of one configuration item change is considered sufficient. - */ - Properties properties = new Properties(); - properties.put(INDENTATION_SIZE, "3"); //Default is 1 - properties.put(INDENTATION_CHAR, SPACE); //Default is TAB - properties.put(CASE_PROPERTY_NAME, Integer.toString(UPPER)); //Dead code, ignored - formatter = new EclipseJsonFormatterStepImpl(properties); - } - - @Test - void formatObject() throws Exception { - String output = formatter.format(UNFORMATTED_OBJECT); - assertEquals(FORMATTED_OBJECT, - output, "Unexpected formatting with default preferences."); - } - - @Test - void formatArray() throws Exception { - String output = formatter.format(UNFORMATTED_ARRAY); - assertEquals(FORMATTED_ARRAY, - output, "Unexpected formatting with default preferences."); - } - - @Test - void illegalCharacter() throws Exception { - String output = formatter.format(ILLEGAL_CHAR + UNFORMATTED_OBJECT); - assertEquals(ILLEGAL_CHAR + FORMATTED_OBJECT, - output, "Illeagl characteds are not ignored."); - } - - @Test - void illegalSyntax() throws Exception { - String output = formatter.format("{" + UNFORMATTED_OBJECT); - assertEquals(FORMATTED_OBJECT, - output, "Illeagl syntax is not handled on best effort basis."); - } - - @Test - void configurationChange() throws Exception { - assertThrows(IllegalArgumentException.class, () -> new EclipseJsonFormatterStepImpl(new Properties())); - } -} diff --git a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplAllowExternalURIsTest.java b/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplAllowExternalURIsTest.java deleted file mode 100644 index ac3b2c45f6..0000000000 --- a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplAllowExternalURIsTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.spotless.extra.eclipse.wtp; - -import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.INDENTATION_CHAR; -import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.INDENTATION_SIZE; -import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.SPACE; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Properties; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; - -/** Test configuration allowExternalURI=false */ -class EclipseXmlFormatterStepImplAllowExternalURIsTest { - private TestData testData = null; - private EclipseXmlFormatterStepImpl formatter; - - @BeforeEach - void initializeStatic() throws Exception { - testData = TestData.getTestDataOnFileSystem("xml"); - /* - * The instantiation can be repeated for each step, but only with the same configuration - * All formatter configuration is stored in - * org.eclipse.core.runtime/.settings/org.eclipse.wst.xml.core.prefs. - * So a simple test of one configuration item change is considered sufficient. - */ - Properties properties = new Properties(); - properties.put(PluginPreferences.RESOLVE_EXTERNAL_URI, "TRUE"); - properties.put(INDENTATION_SIZE, "2"); - properties.put(INDENTATION_CHAR, SPACE); //Default is TAB - formatter = new EclipseXmlFormatterStepImpl(properties); - } - - @Test - void dtdExternalPath() throws Throwable { - String[] input = testData.input("dtd_external.test"); - String output = formatter.format(input[0], input[1]); - assertEquals(testData.expected("dtd_external.test"), - output, "External DTD not resolved. Restrictions are not applied by formatter."); - } - - @Test - void xsdExternalPath() throws Throwable { - String[] input = testData.input("xsd_external.test"); - String output = formatter.format(input[0], input[1]); - assertEquals(testData.expected("xsd_external.test"), - output, "External XSD not resolved. Restrictions are not applied by formatter."); - } -} diff --git a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplCatalogLookupTest.java b/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplCatalogLookupTest.java deleted file mode 100644 index a9ccd85720..0000000000 --- a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplCatalogLookupTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.spotless.extra.eclipse.wtp; - -import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.INDENTATION_CHAR; -import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.INDENTATION_SIZE; -import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.SPACE; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Properties; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import com.diffplug.spotless.extra.eclipse.wtp.sse.PluginPreferences; - -/** Test configuration allowExternalURI=false */ -class EclipseXmlFormatterStepImplCatalogLookupTest { - private TestData testData = null; - private EclipseXmlFormatterStepImpl formatter; - - @BeforeEach - void initializeStatic() throws Exception { - testData = TestData.getTestDataOnFileSystem("xml"); - /* - * The instantiation can be repeated for each step, but only with the same configuration - * All formatter configuration is stored in - * org.eclipse.core.runtime/.settings/org.eclipse.wst.xml.core.prefs. - * So a simple test of one configuration item change is considered sufficient. - */ - Properties properties = new Properties(); - properties.put(INDENTATION_SIZE, "2"); - properties.put(INDENTATION_CHAR, SPACE); //Default is TAB - properties.put(PluginPreferences.USER_CATALOG, testData.getRestrictionsPath("catalog.xml").toString()); - formatter = new EclipseXmlFormatterStepImpl(properties); - } - - @Test - void catalogLookup() throws Throwable { - String[] input = testData.input("xsd_not_found.test"); - String output = formatter.format(input[0], input[1]); - assertEquals(testData.expected("xsd_not_found.test").replace(" remove spaces ", "remove spaces"), - output, "XSD not resolved by catalog. Restrictions are not applied by formatter."); - } -} diff --git a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplTest.java b/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplTest.java deleted file mode 100644 index 88b15c42e2..0000000000 --- a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/EclipseXmlFormatterStepImplTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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.spotless.extra.eclipse.wtp; - -import static com.diffplug.spotless.extra.eclipse.base.SpotlessEclipseFramework.LINE_DELIMITER; -import static org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames.*; -import static org.junit.jupiter.api.Assertions.*; - -import java.util.Properties; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -/** Eclipse WST wrapper integration tests */ -class EclipseXmlFormatterStepImplTest { - - private final static String INCOMPLETE = ""; - private final static String ILLEGAL_CHAR = "\0"; - - private TestData testData = null; - private EclipseXmlFormatterStepImpl formatter; - - @BeforeEach - void initialize() throws Exception { - testData = TestData.getTestDataOnFileSystem("xml"); - /* - * The instantiation can be repeated for each step, but only with the same configuration - * All formatter configuration is stored in - * org.eclipse.core.runtime/.settings/org.eclipse.wst.xml.core.prefs. - * So a simple test of one configuration item change is considered sufficient. - */ - Properties properties = new Properties(); - properties.put(INDENTATION_SIZE, "2"); - properties.put(INDENTATION_CHAR, SPACE); //Default is TAB - formatter = new EclipseXmlFormatterStepImpl(properties); - } - - @Test - void simpleDefaultFormat() throws Throwable { - String[] input = testData.input("xml_space.test"); - String output = formatter.format(input[0], input[1]); - assertEquals(testData.expected("xml_space.test"), - output, "Unexpected formatting with default preferences."); - } - - @Test - void invalidXmlFormat() throws Throwable { - String[] input = testData.input("xml_space.test"); - input[0] += INCOMPLETE; - String output = formatter.format(input[0], input[1]); - String expected = testData.expected("xml_space.test") + LINE_DELIMITER + INCOMPLETE; - assertEquals(expected, - output, "Incomplete XML not formatted on best effort basis."); - } - - @Test - void illegalXmlCharater() throws Throwable { - String[] input = testData.input("xml_space.test"); - input[0] = ILLEGAL_CHAR + input[0]; - String output = formatter.format(input[0], input[1]); - String expected = LINE_DELIMITER + LINE_DELIMITER + testData.expected("xml_space.test"); - assertEquals(expected, output, "Illegal character not replaced by line delimiter."); - } - - @Test - void dtdRelativePath() throws Throwable { - String[] input = testData.input("dtd_relative.test"); - String output = formatter.format(input[0], input[1]); - assertEquals(testData.expected("dtd_relative.test"), - output, "Relative DTD not resolved. Restrictions are not applied by formatter."); - } - - @Test - void dtdExternalPath() throws Throwable { - String[] input = testData.input("dtd_external.test"); - String output = formatter.format(input[0], input[1]); - assertNotEquals(testData.expected("dtd_external.test"), - output, "External DTD resolved by default. Restrictions are applied by formatter."); - } - - @Test - void xsdRelativePath() throws Throwable { - String[] input = testData.input("xsd_relative.test"); - String output = formatter.format(input[0], input[1]); - assertEquals(testData.expected("xsd_relative.test"), - output, "Relative XSD not resolved. Restrictions are not applied by formatter."); - } - - @Test - void xsdExternalPath() throws Throwable { - String[] input = testData.input("xsd_external.test"); - String output = formatter.format(input[0], input[1]); - assertNotEquals(testData.expected("xsd_external.test"), - output, "External XSD resolved per default. Restrictions are applied by formatter."); - } - - @Test - void xsdNotFound() throws Throwable { - String[] input = testData.input("xsd_not_found.test"); - String output = formatter.format(input[0], input[1]); - assertEquals(testData.expected("xsd_not_found.test"), - output, "Unresolved XSD/DTD not silently ignored."); - } - - @Test - void configurationChange() throws Exception { - assertThrows(IllegalArgumentException.class, () -> new EclipseXmlFormatterStepImpl(new Properties())); - } -} diff --git a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/TestData.java b/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/TestData.java deleted file mode 100644 index d767337970..0000000000 --- a/_ext/eclipse-wtp/src/test/java/com/diffplug/spotless/extra/eclipse/wtp/TestData.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2016 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.extra.eclipse.wtp; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class TestData { - public static TestData getTestDataOnFileSystem(String kind) { - final String userDir = System.getProperty("user.dir", "."); - Path dataPath = Paths.get(userDir, "src", "test", "resources", kind); - if (Files.isDirectory(dataPath)) { - return new TestData(dataPath); - } - return null; - } - - private final Path inputPath; - private final Path expectedPath; - private final Path restrictionsPath; - - private TestData(Path dataPath) { - inputPath = dataPath.resolve("input").toAbsolutePath(); - expectedPath = dataPath.resolve("expected").toAbsolutePath(); - restrictionsPath = dataPath.resolve("restrictions").toAbsolutePath(); - for (Path testDataDir : new Path[]{inputPath, expectedPath, restrictionsPath}) { - if (!Files.isDirectory(testDataDir)) { - throw new IllegalArgumentException(String.format("'%1$s' is not a directory.", testDataDir)); - } - } - } - - public String[] input(final String fileName) throws Exception { - Path xmlPath = inputPath.resolve(fileName); - return new String[]{read(xmlPath), xmlPath.toString()}; - } - - public String expected(final String fileName) { - Path xmlPath = expectedPath.resolve(fileName); - return read(xmlPath); - } - - private String read(final Path xmlPath) { - if (!Files.isRegularFile(xmlPath)) { - throw new IllegalArgumentException(String.format("'%1$s' is not a regular file.", xmlPath)); - } - try { - String checkedOutFileContent = new String(java.nio.file.Files.readAllBytes(xmlPath), "UTF8"); - return checkedOutFileContent.replace("\r", ""); //Align GIT end-of-line normalization - } catch (IOException e) { - throw new IllegalArgumentException(String.format("Failed to read '%1$s'.", xmlPath), e); - } - } - - public Path getRestrictionsPath(String fileName) { - Path filePath = restrictionsPath.resolve(fileName); - if (!Files.exists(filePath)) { - throw new IllegalArgumentException(String.format("'%1$s' is not a restrictions file.", fileName)); - } - return filePath; - } -} diff --git a/_ext/eclipse-wtp/src/test/resources/html/expected/css.html b/_ext/eclipse-wtp/src/test/resources/html/expected/css.html deleted file mode 100644 index cfaea67cd0..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/expected/css.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/expected/html4.html b/_ext/eclipse-wtp/src/test/resources/html/expected/html4.html deleted file mode 100644 index a344ed08a0..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/expected/html4.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - Before -
      After - -
      - - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/expected/html5.html b/_ext/eclipse-wtp/src/test/resources/html/expected/html5.html deleted file mode 100644 index c79dfdce62..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/expected/html5.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - Before -
      After - - - - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/expected/invalid_syntax.html b/_ext/eclipse-wtp/src/test/resources/html/expected/invalid_syntax.html deleted file mode 100644 index 9c05557bb7..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/expected/invalid_syntax.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - -T<WHATSOEVER></WHATSOEVER> - - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/expected/javascript.html b/_ext/eclipse-wtp/src/test/resources/html/expected/javascript.html deleted file mode 100644 index a33ea60503..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/expected/javascript.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/expected/utf-8.html b/_ext/eclipse-wtp/src/test/resources/html/expected/utf-8.html deleted file mode 100644 index 4bcd6a03c1..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/expected/utf-8.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - -ÄÜ€ - - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/input/bom.html b/_ext/eclipse-wtp/src/test/resources/html/input/bom.html deleted file mode 100644 index 3fe6abe797..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/input/bom.html +++ /dev/null @@ -1,2 +0,0 @@ - -ÄÜ€ \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/input/css.html b/_ext/eclipse-wtp/src/test/resources/html/input/css.html deleted file mode 100644 index 8ccbc4dcc8..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/input/css.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/input/html4.html b/_ext/eclipse-wtp/src/test/resources/html/input/html4.html deleted file mode 100644 index 45aa7b56f7..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/input/html4.html +++ /dev/null @@ -1,10 +0,0 @@ - - - -Before -
      -After - - - - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/input/html5.html b/_ext/eclipse-wtp/src/test/resources/html/input/html5.html deleted file mode 100644 index 216c53e8e3..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/input/html5.html +++ /dev/null @@ -1,10 +0,0 @@ - - - -Before -
      -After - - - - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/input/invalid_syntax.html b/_ext/eclipse-wtp/src/test/resources/html/input/invalid_syntax.html deleted file mode 100644 index 04c6cf7f2a..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/input/invalid_syntax.html +++ /dev/null @@ -1,4 +0,0 @@ - - - -T</whatsoever> \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/input/javascript.html b/_ext/eclipse-wtp/src/test/resources/html/input/javascript.html deleted file mode 100644 index dccde2c2dd..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/input/javascript.html +++ /dev/null @@ -1,34 +0,0 @@ -<!DOCTYPE html> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<script type="text/javascript">console.log("One line")</script> -<script type="text/javascript"> -console.log("Line break, no indent"); -</script> -<script type="text/javascript"> - console.log("Line break, wrong indent") -</script> -</head> -<body> -<nav> -<script type="text/javascript">console.log("One line, nested")</script> -<script type="text/javascript"> -console.log("Line break, no indent, nested") -</script> -<script type="text/javascript"> - console.log("Line break, wrong indent, nested"); -</script> - <script type="text/javascript"> -console.log("Wrong tag indents") - </script> -<script type="text/javascript"> -console.log("Empty lines when closing."); - - </script> -<script>console.log("Script without type")</script> -<script type="text/javascript"></script> -<script type="text/javascript"> if (condition) { console.log("Missing end of JS block")</script> -</nav> -</body> -</html> \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/input/utf-8.html b/_ext/eclipse-wtp/src/test/resources/html/input/utf-8.html deleted file mode 100644 index abf1a7d9a7..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/input/utf-8.html +++ /dev/null @@ -1,2 +0,0 @@ -<!DOCTYPE html> -<html><head><meta charset="UTF-8"><title>ÄÜ€ \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/html/restrictions/ReadMe.txt b/_ext/eclipse-wtp/src/test/resources/html/restrictions/ReadMe.txt deleted file mode 100644 index 37c58641d8..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/html/restrictions/ReadMe.txt +++ /dev/null @@ -1,9 +0,0 @@ -Various manual tests have been performed with external and internal DTDs. -They seem not to be used by the HTML formatter. Instead they are a -helper to parse the DOCTYPE and select the right content model. -The DTDParser.parse throws a SAXParseException when parsing the -HTML DTDs provided with the WST JARs (accessed by the System catalog). -This nominal and expected exception is eaten (DTDParser.currentDTD not set). - -Since currently there seems to be no use case for DTD/XSD/catalog, -we omit it for Spotless integration. \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/expected/dtd_external.test b/_ext/eclipse-wtp/src/test/resources/xml/expected/dtd_external.test deleted file mode 100644 index 6f383afaa7..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/expected/dtd_external.test +++ /dev/null @@ -1,8 +0,0 @@ - - - - indent - this text - preserve - spaces - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/expected/dtd_relative.test b/_ext/eclipse-wtp/src/test/resources/xml/expected/dtd_relative.test deleted file mode 100644 index 37c565592b..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/expected/dtd_relative.test +++ /dev/null @@ -1,8 +0,0 @@ - - - - indent - this text - preserve - spaces - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/expected/xml_space.test b/_ext/eclipse-wtp/src/test/resources/xml/expected/xml_space.test deleted file mode 100644 index 8bc506f692..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/expected/xml_space.test +++ /dev/null @@ -1,4 +0,0 @@ - - foo bar - preserve space - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_external.test b/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_external.test deleted file mode 100644 index 0456632618..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_external.test +++ /dev/null @@ -1,7 +0,0 @@ - - - remove spaces - preserve spaces - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_not_found.test b/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_not_found.test deleted file mode 100644 index 78a27d902c..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_not_found.test +++ /dev/null @@ -1,7 +0,0 @@ - - - remove spaces - preserve spaces - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_relative.test b/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_relative.test deleted file mode 100644 index 93e86ab38e..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/expected/xsd_relative.test +++ /dev/null @@ -1,7 +0,0 @@ - - - remove spaces - preserve spaces - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/input/dtd_external.test b/_ext/eclipse-wtp/src/test/resources/xml/input/dtd_external.test deleted file mode 100644 index 1293b55e18..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/input/dtd_external.test +++ /dev/null @@ -1,8 +0,0 @@ - - - - indent - this text - preserve - spaces - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/input/dtd_relative.test b/_ext/eclipse-wtp/src/test/resources/xml/input/dtd_relative.test deleted file mode 100644 index 431354868c..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/input/dtd_relative.test +++ /dev/null @@ -1,8 +0,0 @@ - - - - indent - this text - preserve - spaces - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/input/xml_space.test b/_ext/eclipse-wtp/src/test/resources/xml/input/xml_space.test deleted file mode 100644 index 2ddd865f1c..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/input/xml_space.test +++ /dev/null @@ -1 +0,0 @@ - foo bar preserve space \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_external.test b/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_external.test deleted file mode 100644 index e75b7ca06f..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_external.test +++ /dev/null @@ -1,4 +0,0 @@ - - - remove spaces preserve spaces - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_not_found.test b/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_not_found.test deleted file mode 100644 index 483be84785..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_not_found.test +++ /dev/null @@ -1,4 +0,0 @@ - - - remove spaces preserve spaces - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_relative.test b/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_relative.test deleted file mode 100644 index ce8392adf8..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/input/xsd_relative.test +++ /dev/null @@ -1,4 +0,0 @@ - - - remove spaces preserve spaces - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/restrictions/catalog.xml b/_ext/eclipse-wtp/src/test/resources/xml/restrictions/catalog.xml deleted file mode 100644 index 2fba8dc2b9..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/restrictions/catalog.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.dtd b/_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.dtd deleted file mode 100644 index 5076fd91e0..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.dtd +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.xsd b/_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.xsd deleted file mode 100644 index 6b0e3b5e00..0000000000 --- a/_ext/eclipse-wtp/src/test/resources/xml/restrictions/test.xsd +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/_ext/gradle/java-setup.gradle b/_ext/gradle/java-setup.gradle deleted file mode 100644 index 0007407250..0000000000 --- a/_ext/gradle/java-setup.gradle +++ /dev/null @@ -1,28 +0,0 @@ -////////// -// JAVA // -////////// -apply from: rootProject.file('gradle/changelog.gradle') -version = spotlessChangelog.versionNext -apply from: rootProject.file('gradle/java-setup.gradle') - -// Allow declaration of api/compile dependencies -apply plugin: 'java-library' - -// Show warning locations, fail on warnings -tasks.withType(JavaCompile).configureEach { - options.compilerArgs << "-Xlint:unchecked" - options.compilerArgs << "-Xlint:deprecation" - options.compilerArgs << "-Werror" -} - -//Currently testlib is not used by _ext. Hence the external dependencies are added here. -dependencies { - testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}" - testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}" - testImplementation projects.testlib - testRuntimeOnly "org.junit.platform:junit-platform-launcher" -} - -tasks.withType(Test).configureEach { - useJUnitPlatform() -} diff --git a/_ext/gradle/p2-fat-jar-setup.gradle b/_ext/gradle/p2-fat-jar-setup.gradle deleted file mode 100644 index 0bba3c43c2..0000000000 --- a/_ext/gradle/p2-fat-jar-setup.gradle +++ /dev/null @@ -1,169 +0,0 @@ -apply from: rootProject.file('_ext/gradle/java-setup.gradle') - -apply plugin: 'com.diffplug.p2.asmaven' - -ext { - // P2 Repository URL - if (!project.hasProperty('p2Repository')) { - p2Repository = "p2Repository not defined in project" - } - // P2 dependencies - if (!project.hasProperty('p2Dependencies')) { - p2Dependencies = "p2Dependencies not defined in project" - } - - // Some JARs may include JARs themselfs, which shall be unpacked and added to the embedded class folder. - if (!project.hasProperty('internalJars')) { - internalJars = [] - } - - // Include form the JARs, which goes into a fat-jar with the spottless formatter interface. - if (!project.hasProperty('jarInclude')) { - jarInclude = [ - '**/*.class', // Take all classes - '**/*.properties', // Text resources (for messages, etc) - '**/*.xml', // Plugin XML and other resources - '*.html', // License information about the included JARs, - 'META-INF/**' // Plugin manifest and addtional information - ] - } - - // Exclude form the JARs, which goes into a fat-jar with the spottless formatter interface. - if (!project.hasProperty('jarExclude')) { - jarExclude = [ - 'META-INF/*.RSA', // The eclipse jars are signed, and our fat-jar breaks the signatures - 'META-INF/*.SF', // ... so all signatures are filtered - ] - } - - // Map fat-JAR resources path if JAR file name does not correspond to plugin package name (e.g. required for internal plugins) - if (!project.hasProperty('fatJarResourcesMap')) { - fatJarResourcesMap = [:] - } - - - // The directory contains all external classes for the fat-jar - embeddedClassesDirName = 'build/embeddedClasses' - embeddedClassesDir = project.file(embeddedClassesDirName) -} - -if (gradle.startParameter.projectProperties.get('com.diffplug.spotless.include.ext.nop2') != 'true') { - // build a maven repo in our build folder containing these artifacts - p2AsMaven { - group 'p2', { - repo project.p2Repository - p2Dependencies.keySet.each { p2.addIU(it) } - p2ant { - /* - Define p2ant proxy settings as a closure. Refer to the API documents for instructions: - https://diffplug.github.io/goomph/javadoc/3.17.4/com/diffplug/gradle/p2/AsMavenPlugin.html - */ - if (project.hasProperty('setP2AntProxy')) { - setP2AntProxy(it) - } - } - } - } -} - -configurations { - embeddedJars // P2 JARs the fat-JAR is based uppon -} - -dependencies { - p2Dependencies.each { groupArtifact, version -> - embeddedJars "p2:${groupArtifact}:${version}" - } - // Includes the classes from P2 JARs during compilation - implementation files(embeddedClassesDir) -} - -jar { - // Add P2 clases to fat-JAR - from embeddedClassesDir -} - -////////////////////////// -// Unpack External Deps // -////////////////////////// -import java.io.File - -task unjarEmbeddedClasses { - description = "Copies filtered set of embedded classes from the Eclise/GrEclipse dependencies to '${project.relativePath(embeddedClassesDir)}'." - inputs.files(configurations.embeddedJars) - inputs.property('internalJars', internalJars) - inputs.property('jarInclude', jarInclude) - inputs.property('jarExclude', jarExclude) - inputs.property('fatJarResourcesMap', fatJarResourcesMap) - outputs.dir(embeddedClassesDir) - - doLast { - embeddedClassesDir.deleteDir() - embeddedClassesDir.mkdirs() - configurations.embeddedJars.each { - unjar(it, embeddedClassesDir) - } - // Unpack internal JARs. Maintain the order defined in internalJars - internalJars.each { - fileTree(embeddedClassesDir).include("${it}.jar").each { - unjar(it, embeddedClassesDir) - delete(it) - } - } - } -} - -def unjar(File jarFile, File destDir) { - ant.unjar(src: jarFile, dest: destDir) { - patternset { - jarInclude.each { - include(name: "${it}") - } - internalJars.each { - include(name: "**/${it}.jar") - } - jarExclude.each { - exclude(name: "${it}") - } - } - } - // Provide Fat JAR resources (following naming convention of spotless-eclipse-base) - def fat_jar_resource_dir = jarFile.getName().split('-')[0] - fat_jar_resource_dir = fatJarResourcesMap.getOrDefault(fat_jar_resource_dir, fat_jar_resource_dir) - ant.move(todir: "${destDir}/${fat_jar_resource_dir}/META-INF", quiet: 'true', failonerror: 'false') { - fileset(dir: "${destDir}/META-INF") - } - //Keep licenses and other human readable information for transparency - ant.move(todir: "${destDir}/${fat_jar_resource_dir}", quiet: 'true') { - fileset(dir: destDir) { - include(name: '*') - type(type: 'file') - exclude(name: '*jar-*') - exclude(name: '*.jar') - } - } - -} - -tasks.compileJava.dependsOn(unjarEmbeddedClasses) - -///////// -// IDE // -///////// - -apply plugin: 'eclipse' - -// always create fresh projects -tasks.eclipse.dependsOn(cleanEclipse) -// Encure that the dependent classes are preovided for compilation if project is build via Eclipse instead of command line -tasks.eclipseClasspath.dependsOn(unjarEmbeddedClasses) - -apply plugin: 'idea' - -// Encure that the dependent classes are preovided for compilation if project is build via Eclipse instead of command line -tasks.idea.dependsOn(unjarEmbeddedClasses) - -tasks.named('ideaModule') { - notCompatibleWithConfigurationCache("https://github.com/gradle/gradle/issues/13480") -} - diff --git a/_ext/gradle/update-lockfile.gradle b/_ext/gradle/update-lockfile.gradle deleted file mode 100644 index 3c23bb860b..0000000000 --- a/_ext/gradle/update-lockfile.gradle +++ /dev/null @@ -1,6 +0,0 @@ -// Use file locking -configurations.configureEach { - resolutionStrategy { - activateDependencyLocking() - } -} diff --git a/settings.gradle b/settings.gradle index 4e81688d29..d01f901ee6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,9 +15,6 @@ plugins { id 'com.github.spotbugs' version '6.0.1' apply false // https://github.com/diffplug/spotless-changelog/blob/main/CHANGELOG.md id 'com.diffplug.spotless-changelog' version '3.0.2' apply false - // https://github.com/diffplug/goomph/blob/main/CHANGES.md - // DO NOT UPDATE, see https://github.com/diffplug/spotless/pull/874 - id 'com.diffplug.p2.asmaven' version '3.27.0' apply false // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '4.0.0' apply false // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags @@ -98,31 +95,3 @@ def getStartProperty(java.lang.String name) { if (System.getenv('SPOTLESS_EXCLUDE_MAVEN') != 'true' && getStartProperty('SPOTLESS_EXCLUDE_MAVEN') != 'true') { include 'plugin-maven' // maven-specific glue code } - -// include external (_ext) projects from development builds -if (getStartProperty('com.diffplug.spotless.include.ext') == 'true') { - file('_ext').eachDirMatch(~/^(?!(\.|gradle)).*/) { dir -> - include dir.name - project(":${dir.name}").projectDir = dir - } -} - -// include external (_ext) projects from development builds, but disable the p2 parts -if (getStartProperty('com.diffplug.spotless.include.ext.nop2') == 'true') { - file('_ext').eachDirMatch(~/^(?!(\.|gradle)).*/) { dir -> - include dir.name - project(":${dir.name}").projectDir = dir - } -} - -// the p2-based projects are too expensive for routine CI builds, so they have to be invoked explicitly -for (kind in [ - 'cdt', - 'groovy', - 'wtp' - ]) { - if (getStartProperty("com.diffplug.spotless.include.ext.${kind}") == 'true') { - include "eclipse-${kind}" - project(":eclipse-${kind}").projectDir = file("_ext/eclipse-${kind}") - } -} From 2eaec914b17308e39163070f83ba86cf40470259 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 00:09:18 +0000 Subject: [PATCH 1029/1120] Update actions/setup-java action to v4 --- .github/workflows/changelog-print.yml | 2 +- .github/workflows/ci.yml | 4 ++-- .github/workflows/deploy.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/changelog-print.yml b/.github/workflows/changelog-print.yml index 31b6c9aabc..01bbb88afa 100644 --- a/.github/workflows/changelog-print.yml +++ b/.github/workflows/changelog-print.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: jdk 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 11 distribution: 'temurin' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d11b0b1166..c6d1eede5d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: with: fetch-depth: 0 - name: Install JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: "temurin" java-version: 11 @@ -62,7 +62,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: "temurin" java-version: ${{ matrix.jre }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0e36087855..e899a2d270 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -38,7 +38,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: jdk 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 11 distribution: 'temurin' From 83d5bf9924d179044674144171ce27e179d29378 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 19:34:56 -0800 Subject: [PATCH 1030/1120] Bump solstice to 1.7.4 to fix #1860, --- lib-extra/build.gradle | 2 +- .../java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib-extra/build.gradle b/lib-extra/build.gradle index a7a8a0d39f..34cee7e0fd 100644 --- a/lib-extra/build.gradle +++ b/lib-extra/build.gradle @@ -7,7 +7,7 @@ version = rootProject.spotlessChangelog.versionNext apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') -String VER_SOLSTICE = '1.7.3' +String VER_SOLSTICE = '1.7.4' dependencies { api projects.lib // misc useful utilities diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java index 2d62e25355..3d3bb68241 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java @@ -117,7 +117,7 @@ EquoBasedStepBuilder.State get() throws Exception { } var classpath = new ArrayList(); var mavenDeps = new ArrayList(); - mavenDeps.add("dev.equo.ide:solstice:1.7.3"); + mavenDeps.add("dev.equo.ide:solstice:1.7.4"); mavenDeps.add("com.diffplug.durian:durian-swt.os:4.2.0"); mavenDeps.addAll(query.getJarsOnMavenCentral()); classpath.addAll(mavenProvisioner.provisionWithTransitives(false, mavenDeps)); From 38021bf0c146e79e59fbf329b8ce56bbc6185f31 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 19:35:06 -0800 Subject: [PATCH 1031/1120] Bump JDT to latest. --- .../diffplug/spotless/extra/java/EclipseJdtFormatterStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java index cd766fc8c8..fc477ed881 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java @@ -31,7 +31,7 @@ public final class EclipseJdtFormatterStep { private EclipseJdtFormatterStep() {} private static final String NAME = "eclipse jdt formatter"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26").add(17, "4.27"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26").add(17, "4.29"); public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); From cde60a58fce8cc2b7c8231534dea8b1d03451dc7 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 19:35:18 -0800 Subject: [PATCH 1032/1120] Bump GrEclipse to latest. --- .../diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java index b79918d555..0a38ff5e64 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java @@ -32,7 +32,7 @@ public final class GrEclipseFormatterStep { private GrEclipseFormatterStep() {} private static final String NAME = "eclipse groovy formatter"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26").add(17, "4.28"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "4.26").add(17, "4.29"); public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); From e655ef28c253577c360d96f5096475df0f676c8e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 19:35:27 -0800 Subject: [PATCH 1033/1120] Bump CDT to latest. --- .../diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java index 8767b68dfe..569dc05e54 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java @@ -37,7 +37,7 @@ public final class EclipseCdtFormatterStep { private EclipseCdtFormatterStep() {} private static final String NAME = "eclipse cdt formatter"; - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "10.7").add(17, "11.1"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "10.7").add(17, "11.3"); public static String defaultVersion() { return JVM_SUPPORT.getRecommendedFormatterVersion(); From c4da6c40089abe86bfbbd639acc70ae4795b1958 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 19:49:29 -0800 Subject: [PATCH 1034/1120] Update changelogs. --- CHANGES.md | 9 +++++++-- plugin-gradle/CHANGES.md | 14 +++++++++----- plugin-maven/CHANGES.md | 12 ++++++++---- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d64b8861da..ac7da8ba05 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,10 +10,15 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Eclipse-based steps which contained any jars with a `+` in their path were broken, now fixed. ([#1860](https://github.com/diffplug/spotless/issues/1860#issuecomment-1826113332)) ### Changes -* Use palantir-java-format `2.38.0` on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) -* Bump default `ktfmt` version to latest `0.44` -> `0.46`. ([#1927](https://github.com/diffplug/spotless/pull/1927)) +* Bump default `palantir-java-format` version to latest `2.28.0` -> `2.38.0` on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) * Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `ktfmt` version to latest `0.44` -> `0.46`. ([#1927](https://github.com/diffplug/spotless/pull/1927)) +* Bump default `eclipse` version to latest `4.27` -> `4.29`. ([#1939](https://github.com/diffplug/spotless/pull/1939)) +* Bump default `greclipse` version to latest `4.28` -> `4.29`. ([#1939](https://github.com/diffplug/spotless/pull/1939)) +* Bump default `cdt` version to latest `11.1` -> `11.3`. ([#1939](https://github.com/diffplug/spotless/pull/1939)) ## [2.43.0] - 2023-11-27 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 9071ed2bbf..696828dbac 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,15 +3,19 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] -### Changes -* **BREAKING CHANGE** `6.23.0` made breaking changes to the ABI of the `KotlinExtension` and `GroovyExtension`. Those are reflected retroactively now. +**BREAKING CHANGE** `6.23.0` made breaking changes to the ABI of the `KotlinExtension` and `GroovyExtension`. Those are reflected retroactively now. - Previously, we had done semver on the Gradle plugin based only on buildscript compatibility. - From now on, we will consider ABI for the benefit of convention-based plugins. -* Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) -* Bump default `ktfmt` version to latest `0.44` -> `0.46`. ([#1927](https://github.com/diffplug/spotless/pull/1927)) -* Use palantir-java-format 2.38.0 on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ### Fixed +* Eclipse-based steps which contained any jars with a `+` in their path were broken, now fixed. ([#1860](https://github.com/diffplug/spotless/issues/1860#issuecomment-1826113332)) * Make `KtfmtConfig.ConfigurableStyle#configure` public. ([#1926](https://github.com/diffplug/spotless/pull/1926)) +### Changes +* Bump default `palantir-java-format` version to latest `2.28.0` -> `2.38.0` on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `ktfmt` version to latest `0.44` -> `0.46`. ([#1927](https://github.com/diffplug/spotless/pull/1927)) +* Bump default `eclipse` version to latest `4.27` -> `4.29`. ([#1939](https://github.com/diffplug/spotless/pull/1939)) +* Bump default `greclipse` version to latest `4.28` -> `4.29`. ([#1939](https://github.com/diffplug/spotless/pull/1939)) +* Bump default `cdt` version to latest `11.1` -> `11.3`. ([#1939](https://github.com/diffplug/spotless/pull/1939)) ## [6.23.2] - 2023-12-01 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 1160517f6f..07f20d39cb 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,12 +3,16 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -### Changes -* Use palantir-java-format `2.38.0` on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) -* Bump default `ktfmt` version to latest `0.44` -> `0.46`. ([#1927](https://github.com/diffplug/spotless/pull/1927)) -* Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) ### Fixed * Revert [#1846](https://github.com/diffplug/spotless/issues/1846) from 2.41.0 which causes the plugin to format generated sources in the `target` directory. ([#1928](https://github.com/diffplug/spotless/pull/1928)) +* Eclipse-based steps which contained any jars with a `+` in their path were broken, now fixed. ([#1860](https://github.com/diffplug/spotless/issues/1860#issuecomment-1826113332)) +### Changes +* Bump default `palantir-java-format` version to latest `2.28.0` -> `2.38.0` on Java 21. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `googleJavaFormat` version to latest `1.17.0` -> `1.18.1`. ([#1920](https://github.com/diffplug/spotless/pull/1920)) +* Bump default `ktfmt` version to latest `0.44` -> `0.46`. ([#1927](https://github.com/diffplug/spotless/pull/1927)) +* Bump default `eclipse` version to latest `4.27` -> `4.29`. ([#1939](https://github.com/diffplug/spotless/pull/1939)) +* Bump default `greclipse` version to latest `4.28` -> `4.29`. ([#1939](https://github.com/diffplug/spotless/pull/1939)) +* Bump default `cdt` version to latest `11.1` -> `11.3`. ([#1939](https://github.com/diffplug/spotless/pull/1939)) ## [2.41.0] - 2023-11-27 ### Added From d2adc18755fc3bcbbc73bb41477030f364e6317e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 3 Dec 2023 20:11:06 -0800 Subject: [PATCH 1035/1120] Disable a flaky configuration cache issue that started with Gradle 8.5, hopefully we can get rid of JvmLocalCache soon anyway... --- .../com/diffplug/gradle/spotless/GitRatchetGradleTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GitRatchetGradleTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GitRatchetGradleTest.java index 51f4808259..ba85155afa 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GitRatchetGradleTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GitRatchetGradleTest.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. @@ -153,7 +153,8 @@ private BuildResultAssertion assertFail(String... tasks) throws Exception { private static final String BASELINE_DIRTY = "4cfc3358ccbf186738b82a60276b1e5306bc3870"; @ParameterizedTest - @ValueSource(ints = {0, 1}) + //@ValueSource(ints = {0, 1}) // TODO: this is a flaky configuration cache issue that started with Gradle 8.5 + @ValueSource(ints = {0}) void multiProject(int useConfigCache) throws Exception { try (Git git = initRepo()) { if (useConfigCache == 1) { From 053c7aeb6a9c363dea6470e14d54058f513bffa3 Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 4 Dec 2023 04:18:57 +0000 Subject: [PATCH 1036/1120] Published lib/2.43.1 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ac7da8ba05..dd2a1c7999 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.43.1] - 2023-12-04 ### Fixed * Eclipse-based steps which contained any jars with a `+` in their path were broken, now fixed. ([#1860](https://github.com/diffplug/spotless/issues/1860#issuecomment-1826113332)) ### Changes From 29bb75cdb02677e276f4f2acbb961fbb4f290c07 Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 4 Dec 2023 04:20:50 +0000 Subject: [PATCH 1037/1120] Published gradle/6.23.3 --- plugin-gradle/CHANGES.md | 2 ++ plugin-gradle/README.md | 56 ++++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 696828dbac..5c6b219c20 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] + +## [6.23.3] - 2023-12-04 **BREAKING CHANGE** `6.23.0` made breaking changes to the ABI of the `KotlinExtension` and `GroovyExtension`. Those are reflected retroactively now. - Previously, we had done semver on the Gradle plugin based only on buildscript compatibility. - From now on, we will consider ABI for the benefit of convention-based plugins. diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index be694f910a..7ad010567a 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -14,9 +14,9 @@ output = [ ].join('\n'); --> [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.23.2-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.23.3-blue.svg)](CHANGES.md) [![MavenCentral](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -128,10 +128,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -144,7 +144,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer. ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -301,8 +301,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -357,8 +357,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -436,7 +436,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -468,7 +468,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -500,7 +500,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -536,7 +536,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ### buf -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) **WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem. @@ -568,7 +568,7 @@ buf { ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -589,7 +589,7 @@ spotless { ## Flexmark -`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) [homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). @@ -608,7 +608,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -633,7 +633,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -673,7 +673,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -767,7 +767,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -832,7 +832,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -952,7 +952,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -984,7 +984,7 @@ spotless { ## Gherkin -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/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.23.3/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 { @@ -1371,7 +1371,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1451,9 +1451,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1486,11 +1486,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.2/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 6de369e03b36ed96c190dccb122be55e7918553b Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 4 Dec 2023 04:21:55 +0000 Subject: [PATCH 1038/1120] Published maven/2.41.1 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 07f20d39cb..6ed1087a48 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.41.1] - 2023-12-04 ### Fixed * Revert [#1846](https://github.com/diffplug/spotless/issues/1846) from 2.41.0 which causes the plugin to format generated sources in the `target` directory. ([#1928](https://github.com/diffplug/spotless/pull/1928)) * Eclipse-based steps which contained any jars with a `+` in their path were broken, now fixed. ([#1860](https://github.com/diffplug/spotless/issues/1860#issuecomment-1826113332)) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 3709a65cdf..f632d78ea7 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![MavenCentral](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.41.0-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.41.0/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.41.1-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.41.1/index.html) [![Gradle plugin](https://img.shields.io/badge/plugins.gradle.org-com.diffplug.spotless-blue.svg)](https://plugins.gradle.org/plugin/com.diffplug.spotless) -[![Changelog](https://img.shields.io/badge/changelog-6.23.3-blue.svg)](CHANGES.md) +[![Changelog](https://img.shields.io/badge/changelog-6.24.0-blue.svg)](CHANGES.md) [![MavenCentral](https://img.shields.io/badge/mavencentral-here-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-plugin-gradle%22) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/index.html) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/index.html) [![VS Code plugin](https://img.shields.io/badge/IDE-VS_Code-blueviolet.svg)](https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-spotless-gradle) [![IntelliJ plugin](https://img.shields.io/badge/IDE-IntelliJ-blueviolet.svg)](https://plugins.jetbrains.com/plugin/18321-spotless-gradle) @@ -129,10 +129,10 @@ spotless { ``` Spotless consists of a list of formats (in the example above, `misc` and `java`), and each format has: -- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) -- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. +- a `target` (the files to format), which you set with [`target`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#target-java.lang.Object...-) and [`targetExclude`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#targetExclude-java.lang.Object...-) +- a list of `FormatterStep`, which are just `String -> String` functions, such as [`replace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`replaceRegex`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#replaceRegex-java.lang.String-java.lang.String-java.lang.String-), [`trimTrailingWhitespace`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#replace-java.lang.String-java.lang.CharSequence-java.lang.CharSequence-), [`custom`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#custom-java.lang.String-groovy.lang.Closure-), [`prettier`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#prettier--), [`eclipseWtp`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#eclipseWtp-com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep-), [`licenseHeader`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#licenseHeader-java.lang.String-java.lang.String-) etc. -All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. +All the generic steps live in [`FormatExtension`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html), and there are many language-specific steps which live in its language-specific subclasses, which are described below. ### Requirements @@ -145,7 +145,7 @@ Spotless requires JRE 11+ and Gradle 6.1.1 or newer. ## Java -`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) +`com.diffplug.gradle.spotless.JavaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/JavaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java) ```gradle spotless { @@ -302,8 +302,8 @@ spotless { ## Groovy -- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) -- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) +- `com.diffplug.gradle.spotless.GroovyExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/GroovyExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyExtension.java) +- `com.diffplug.gradle.spotless.GroovyGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/GroovyGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GroovyGradleExtension.java) Configuration for Groovy is similar to [Java](#java), in that it also supports `licenseHeader` and `importOrder`. @@ -358,8 +358,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ## Kotlin -- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) -- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) +- `com.diffplug.gradle.spotless.KotlinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/KotlinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java) +- `com.diffplug.gradle.spotless.KotlinGradleExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/KotlinGradleExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java) ```gradle spotless { // if you are using build.gradle.kts, instead of 'spotless {' use: @@ -437,7 +437,7 @@ spotless { ## Scala -`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) +`com.diffplug.gradle.spotless.ScalaExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/ScalaExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ScalaExtension.java) ```gradle spotless { @@ -469,7 +469,7 @@ spotless { ## C/C++ -`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) +`com.diffplug.gradle.spotless.CppExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/CppExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java) ```gradle spotless { @@ -501,7 +501,7 @@ spotles { ## Python -`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) +`com.diffplug.gradle.spotless.PythonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/PythonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/PythonExtension.java) ```gradle spotless { @@ -537,7 +537,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') ### buf -`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) **WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem. @@ -569,7 +569,7 @@ buf { ## FreshMark -`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) +`com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) [homepage](https://github.com/diffplug/freshmark). [changelog](https://github.com/diffplug/freshmark/blob/master/CHANGES.md). FreshMark lets you generate markdown in the comments of your markdown. This helps to keep badges and links up-to-date (see the source for this file), and can also be helpful for generating complex tables (see the source for [the parent readme](../README.md)). @@ -590,7 +590,7 @@ spotless { ## Flexmark -`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) +`com.diffplug.gradle.spotless.FlexmarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FlexmarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FlexmarkExtension.java) [homepage](https://github.com/vsch/flexmark-java). Flexmark is a flexible Commonmark/Markdown parser that can be used to format Markdown files. It supports different [flavors of Markdown](https://github.com/vsch/flexmark-java#markdown-processor-emulation) and [many formatting options](https://github.com/vsch/flexmark-java/wiki/Markdown-Formatter#options). @@ -609,7 +609,7 @@ spotless { ## Antlr4 -`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) +`com.diffplug.gradle.spotless.Antlr4Extension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/Antlr4Extension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/Antlr4Extension.java) ```gradle spotless { @@ -634,7 +634,7 @@ antlr4formatter('1.2.1') // version is optional ## SQL -`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) +`com.diffplug.gradle.spotless.SqlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/SqlExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java) ```gradle spotless { @@ -674,7 +674,7 @@ sql.formatter.indent.size=4 ## Typescript -- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) +- `com.diffplug.gradle.spotless.TypescriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/TypescriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java) ```gradle spotless { @@ -768,7 +768,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## Javascript -- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) +- `com.diffplug.gradle.spotless.JavascriptExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/JavascriptExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java) ```gradle spotless { @@ -833,7 +833,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr ## JSON -- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) +- `com.diffplug.gradle.spotless.JsonExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java) ```gradle spotless { @@ -953,7 +953,7 @@ spotless { ## YAML -- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) +- `com.diffplug.gradle.spotless.YamlExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/JsonExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/YamlExtension.java) ```gradle spotless { @@ -985,7 +985,7 @@ spotless { ## Shell -`com.diffplug.gradle.spotless.ShellExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/ShellExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ShellExtension.java) +`com.diffplug.gradle.spotless.ShellExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/ShellExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ShellExtension.java) ```gradle spotless { @@ -1017,7 +1017,7 @@ shfmt().pathToExe('/opt/homebrew/bin/shfmt') ## Gherkin -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/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.24.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 { @@ -1417,7 +1417,7 @@ Once a file's license header has a valid year, whether it is a year (`2020`) or * `2017` -> `2017-2020` * `2017-2019` -> `2017-2020` -See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. +See the [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.LicenseHeaderConfig.html) for a complete listing of options. @@ -1497,9 +1497,9 @@ spotless { custom 'lowercase', { str -> str.toLowerCase() } ``` -However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. +However, custom rules will disable up-to-date checking and caching, unless you read [this javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#bumpThisNumberIfACustomStepChanges-int-) and follow its instructions carefully. -Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! +Another option is to create proper `FormatterStep` in your `buildSrc`, and then call [`addStep`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#addStep-com.diffplug.spotless.FormatterStep-). The contributing guide describes [how to do this](https://github.com/diffplug/spotless/blob/main/CONTRIBUTING.md#how-to-add-a-new-formatterstep). If the step is generally-useful, we hope you'll open a PR to share it! ```gradle @@ -1532,11 +1532,11 @@ spotless { format 'foo', com.acme.FooLanguageExtension, { ``` -If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). +If you'd like to create a one-off Spotless task outside of the `check`/`apply` framework, see [`FormatExtension.createIndependentApplyTask`](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#createIndependentApplyTask-java.lang.String-). ## Inception (languages within languages within...) -In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.23.3/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. +In very rare cases, you might want to format e.g. javascript which is written inside JSP templates, or maybe java within a markdown file, or something wacky like that. You can specify hunks within a file using either open/close tags or a regex with a single capturing group, and then specify rules within it, like so. See [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.24.0/com/diffplug/gradle/spotless/FormatExtension.html#withinBlocks-java.lang.String-java.lang.String-java.lang.String-org.gradle.api.Action-) for more details. ```gradle import com.diffplug.gradle.spotless.JavaExtension From 797a665465429729b5308ee77f392c170c57242e Mon Sep 17 00:00:00 2001 From: runner Date: Mon, 15 Jan 2024 01:07:02 +0000 Subject: [PATCH 1092/1120] Published maven/2.42.0 --- plugin-maven/CHANGES.md | 2 ++ plugin-maven/README.md | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index cf3ea63b2d..789f4430f4 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.42.0] - 2024-01-15 ### Added * M2E support: Emit file specific errors during incremental build. ([#1960](https://github.com/diffplug/spotless/issues/1960)) ### Fixed diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 593368c7ac..efc15b515f 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -8,8 +8,8 @@ output = [ ].join('\n'); --> [![MavenCentral](https://img.shields.io/badge/mavencentral-com.diffplug.spotless%3Aspotless--maven--plugin-blue.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.diffplug.spotless%22%20AND%20a%3A%22spotless-maven-plugin%22) -[![Changelog](https://img.shields.io/badge/changelog-2.41.1-blue.svg)](CHANGES.md) -[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.41.1/index.html) +[![Changelog](https://img.shields.io/badge/changelog-2.42.0-blue.svg)](CHANGES.md) +[![Javadoc](https://img.shields.io/badge/javadoc-here-blue.svg)](https://javadoc.io/doc/com.diffplug.spotless/spotless-maven-plugin/2.42.0/index.html) + src/**/*.go + + + + + +``` + +### gofmt + +Standard Go formatter, part of Go distribution. + +```xml + + go1.25.1 + /opt/sdks/go1.25.1/bin/go + +``` + ## 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-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index 97a61ddaea..2cecfaa1c1 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 @@ -38,6 +38,7 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; +import com.diffplug.spotless.maven.go.Go; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; @@ -184,6 +185,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Gherkin gherkin; + @Parameter + private Go go; + @Parameter(property = "spotlessFiles") private String filePatterns; @@ -358,7 +362,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, gherkin)) + return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, javascript, antlr4, pom, sql, python, markdown, json, yaml, gherkin, go)) .filter(Objects::nonNull) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Go.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Go.java new file mode 100644 index 0000000000..b69f6652cb --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Go.java @@ -0,0 +1,23 @@ +package com.diffplug.spotless.maven.go; + +import com.diffplug.spotless.maven.FormatterFactory; +import org.apache.maven.project.MavenProject; + +import java.util.Collections; +import java.util.Set; + +public class Go extends FormatterFactory { + @Override + public Set defaultIncludes(MavenProject project) { + return Collections.emptySet(); + } + + @Override + public String licenseHeaderDelimiter() { + return null; + } + + public void addGofmt(Gofmt gofmt) { + addStepFactory(gofmt); + } +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Gofmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Gofmt.java new file mode 100644 index 0000000000..47bb9576c8 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Gofmt.java @@ -0,0 +1,25 @@ +package com.diffplug.spotless.maven.go; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.go.GofmtFormatStep; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; +import org.apache.maven.plugins.annotations.Parameter; + +public class Gofmt implements FormatterStepFactory { + + @Parameter + private String version; + + @Parameter + private String goExecutablePath; + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig config) { + GofmtFormatStep step = GofmtFormatStep.withVersion(version == null ? GofmtFormatStep.defaultVersion() : version); + if (goExecutablePath != null) { + step = step.withGoExecutable(goExecutablePath); + } + return step.create(); + } +} 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 4710874e9f..e9b0233a14 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 @@ -187,6 +187,10 @@ protected void writePomWithGherkinSteps(String... steps) throws IOException { writePom(groupWithSteps("gherkin", including("**/*.feature"), steps)); } + protected void writePomWithGoSteps(String... steps) throws IOException { + writePom(groupWithSteps("go", including("**/*.go"), 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/go/GofmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/go/GofmtTest.java new file mode 100644 index 0000000000..a8ba456325 --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/go/GofmtTest.java @@ -0,0 +1,16 @@ +package com.diffplug.spotless.maven.go; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; +import org.junit.jupiter.api.Test; + +@com.diffplug.spotless.tag.GofmtTest +public class GofmtTest extends MavenIntegrationHarness { + @Test + void testGofmt() throws Exception { + writePomWithGoSteps("go1.21.5"); + + setFile("src/main/go/example.go").toResource("go/gofmt/go.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("src/main/go/example.go").sameAsResource("go/gofmt/go.clean"); + } +} From 2870d069634c5f35f920a560caf96adbda466b74 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Tue, 16 Jan 2024 18:14:55 +0100 Subject: [PATCH 1108/1120] Run `spotlessApply` --- .../spotless/maven/AbstractSpotlessMojo.java | 4 +- .../com/diffplug/spotless/maven/go/Go.java | 44 +++++++++++++------ .../com/diffplug/spotless/maven/go/Gofmt.java | 42 ++++++++++++------ .../maven/MavenIntegrationHarness.java | 2 +- .../diffplug/spotless/maven/go/GofmtTest.java | 32 ++++++++++---- 5 files changed, 86 insertions(+), 38 deletions(-) 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 2cecfaa1c1..35e490b581 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,6 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; -import com.diffplug.spotless.maven.go.Go; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; @@ -63,6 +62,7 @@ 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.go.Go; import com.diffplug.spotless.maven.groovy.Groovy; import com.diffplug.spotless.maven.incremental.UpToDateChecker; import com.diffplug.spotless.maven.incremental.UpToDateChecking; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Go.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Go.java index b69f6652cb..bb26bd0355 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Go.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Go.java @@ -1,23 +1,39 @@ +/* + * Copyright 2024 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.go; -import com.diffplug.spotless.maven.FormatterFactory; -import org.apache.maven.project.MavenProject; - import java.util.Collections; import java.util.Set; +import org.apache.maven.project.MavenProject; + +import com.diffplug.spotless.maven.FormatterFactory; + public class Go extends FormatterFactory { - @Override - public Set defaultIncludes(MavenProject project) { - return Collections.emptySet(); - } + @Override + public Set defaultIncludes(MavenProject project) { + return Collections.emptySet(); + } - @Override - public String licenseHeaderDelimiter() { - return null; - } + @Override + public String licenseHeaderDelimiter() { + return null; + } - public void addGofmt(Gofmt gofmt) { - addStepFactory(gofmt); - } + public void addGofmt(Gofmt gofmt) { + addStepFactory(gofmt); + } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Gofmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Gofmt.java index 47bb9576c8..aaa30efb4f 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Gofmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/go/Gofmt.java @@ -1,25 +1,41 @@ +/* + * Copyright 2024 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.go; +import org.apache.maven.plugins.annotations.Parameter; + import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.go.GofmtFormatStep; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; -import org.apache.maven.plugins.annotations.Parameter; public class Gofmt implements FormatterStepFactory { - @Parameter - private String version; + @Parameter + private String version; - @Parameter - private String goExecutablePath; + @Parameter + private String goExecutablePath; - @Override - public FormatterStep newFormatterStep(FormatterStepConfig config) { - GofmtFormatStep step = GofmtFormatStep.withVersion(version == null ? GofmtFormatStep.defaultVersion() : version); - if (goExecutablePath != null) { - step = step.withGoExecutable(goExecutablePath); - } - return step.create(); - } + @Override + public FormatterStep newFormatterStep(FormatterStepConfig config) { + GofmtFormatStep step = GofmtFormatStep.withVersion(version == null ? GofmtFormatStep.defaultVersion() : version); + if (goExecutablePath != null) { + step = step.withGoExecutable(goExecutablePath); + } + return step.create(); + } } 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 e9b0233a14..45256de6c3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 DiffPlug + * Copyright 2016-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/go/GofmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/go/GofmtTest.java index a8ba456325..5cf4398f70 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/go/GofmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/go/GofmtTest.java @@ -1,16 +1,32 @@ +/* + * Copyright 2024 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.go; -import com.diffplug.spotless.maven.MavenIntegrationHarness; import org.junit.jupiter.api.Test; +import com.diffplug.spotless.maven.MavenIntegrationHarness; + @com.diffplug.spotless.tag.GofmtTest public class GofmtTest extends MavenIntegrationHarness { - @Test - void testGofmt() throws Exception { - writePomWithGoSteps("go1.21.5"); + @Test + void testGofmt() throws Exception { + writePomWithGoSteps("go1.21.5"); - setFile("src/main/go/example.go").toResource("go/gofmt/go.dirty"); - mavenRunner().withArguments("spotless:apply").runNoError(); - assertFile("src/main/go/example.go").sameAsResource("go/gofmt/go.clean"); - } + setFile("src/main/go/example.go").toResource("go/gofmt/go.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("src/main/go/example.go").sameAsResource("go/gofmt/go.clean"); + } } From 5351d784711a9564dc024b526ea2f7f51a78f4db Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 16 Jan 2024 21:32:20 -0800 Subject: [PATCH 1109/1120] Replace @Disabled with @ShfmtTest. --- .../java/com/diffplug/spotless/maven/shell/ShellTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/shell/ShellTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/shell/ShellTest.java index 870de85849..bf0e58fca6 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/shell/ShellTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/shell/ShellTest.java @@ -15,14 +15,14 @@ */ package com.diffplug.spotless.maven.shell; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.diffplug.spotless.maven.MavenIntegrationHarness; +import com.diffplug.spotless.tag.ShfmtTest; -@Disabled // Disabled due to GHA not having shfmt +@ShfmtTest public class ShellTest extends MavenIntegrationHarness { private static final Logger LOGGER = LoggerFactory.getLogger(ShellTest.class); From 4e5fa17209585212ebe8e9e7ed322b1acd2c54e1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Tue, 16 Jan 2024 21:36:52 -0800 Subject: [PATCH 1110/1120] The special tests had a configuration bug at some point where their tag was being simultaneously excluded and included. --- gradle/special-tests.gradle | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gradle/special-tests.gradle b/gradle/special-tests.gradle index ae9da9a06e..f45759294b 100644 --- a/gradle/special-tests.gradle +++ b/gradle/special-tests.gradle @@ -1,4 +1,6 @@ apply plugin: 'com.adarshr.test-logger' + +// See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations def special = [ 'Black', 'Buf', @@ -9,10 +11,6 @@ def special = [ boolean isCiServer = System.getenv().containsKey("CI") tasks.withType(Test).configureEach { - // See com.diffplug.spotless.tag package for available JUnit 5 @Tag annotations - useJUnitPlatform { - excludeTags special as String[] - } if (isCiServer) { retry { maxRetries = 2 @@ -26,7 +24,11 @@ tasks.withType(Test).configureEach { maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 } } - +tasks.named('test').configure { + useJUnitPlatform { + excludeTags special as String[] + } +} special.forEach { tag -> tasks.register("test${tag}", Test) { useJUnitPlatform { includeTags tag } From d3f7680bf7c5e7d4bfa821e5a1e50533edf8defe Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Wed, 17 Jan 2024 18:49:25 +0100 Subject: [PATCH 1111/1120] Introduce `go` extension for plugin-gradle --- .../diffplug/spotless/go/GofmtFormatStep.java | 2 +- .../gradle/spotless/FormatExtension.java | 27 --------- .../diffplug/gradle/spotless/GoExtension.java | 57 +++++++++++++++++++ .../gradle/spotless/SpotlessExtension.java | 5 ++ .../gradle/spotless/GoGradleTest.java | 4 +- 5 files changed, 65 insertions(+), 30 deletions(-) create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GoExtension.java diff --git a/lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java b/lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java index 9b5dac5f48..18e388cf5b 100644 --- a/lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java @@ -43,7 +43,7 @@ public static String name() { } public static String defaultVersion() { - return "1.20.0"; + return "go1.20.0"; } private final String version; diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index a19918796e..73189ba4e0 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -957,33 +957,6 @@ public EclipseWtpConfig eclipseWtp(EclipseWtpFormatterStep type, String version) return new EclipseWtpConfig(type, version); } - public class GofmtConfig { - GofmtFormatStep stepCfg; - - public GofmtConfig(String version) { - stepCfg = (GofmtFormatStep) GofmtFormatStep.withVersion(version).create(); - addStep(createStep()); - } - - public GofmtConfig withGoExecutable(String pathToGo) { - stepCfg = stepCfg.withGoExecutable(pathToGo); - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return stepCfg.create(); - } - } - - public GofmtConfig gofmt() { - return new GofmtConfig(GofmtFormatStep.defaultVersion()); - } - - public GofmtConfig gofmt(String version) { - return new GofmtConfig(version); - } - /** *
       	 * spotless {
      diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GoExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GoExtension.java
      new file mode 100644
      index 0000000000..60aa1aa71d
      --- /dev/null
      +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GoExtension.java
      @@ -0,0 +1,57 @@
      +/*
      + * Copyright 2024 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 com.diffplug.spotless.FormatterStep;
      +import com.diffplug.spotless.go.GofmtFormatStep;
      +
      +import javax.inject.Inject;
      +
      +public class GoExtension extends FormatExtension {
      +    public static final String NAME = "go";
      +
      +    @Inject
      +    public GoExtension(SpotlessExtension spotless) {
      +        super(spotless);
      +    }
      +
      +    public GofmtConfig gofmt() {
      +        return new GofmtConfig(GofmtFormatStep.defaultVersion());
      +    }
      +
      +    public GofmtConfig gofmt(String version) {
      +        return new GofmtConfig(version);
      +    }
      +
      +    public class GofmtConfig {
      +        GofmtFormatStep stepCfg;
      +
      +        public GofmtConfig(String version) {
      +            stepCfg = GofmtFormatStep.withVersion(version);
      +            addStep(createStep());
      +        }
      +
      +        public GofmtConfig withGoExecutable(String pathToGo) {
      +            stepCfg = stepCfg.withGoExecutable(pathToGo);
      +            replaceStep(createStep());
      +            return this;
      +        }
      +
      +        private FormatterStep createStep() {
      +            return stepCfg.create();
      +        }
      +    }
      +}
      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 b4c8e3cc03..f02ac28548 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
      @@ -223,6 +223,11 @@ public void gherkin(Action closure) {
       		format(GherkinExtension.NAME, GherkinExtension.class, closure);
       	}
       
      +	public void go(Action closure) {
      +		requireNonNull(closure);
      +		format(GoExtension.NAME, GoExtension.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/GoGradleTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoGradleTest.java
      index 1d5fea7e41..94bd345854 100644
      --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoGradleTest.java
      +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GoGradleTest.java
      @@ -30,9 +30,9 @@ void gofmt() throws IOException {
       				"  id 'com.diffplug.spotless'",
       				"}",
       				"spotless {",
      -				"  format 'go' {",
      +				"  go {",
       				"    target 'src/**/*.go'",
      -				"    gofmt()",
      +				"    gofmt(\"go1.21.5\")",
       				"  }",
       				"}");
       		setFile("src/test.go").toResource("go/gofmt/go.dirty");
      
      From 163ed2d7987cd6a819cf5f930ba51a9f978c4093 Mon Sep 17 00:00:00 2001
      From: Peter Trifanov 
      Date: Wed, 17 Jan 2024 18:56:19 +0100
      Subject: [PATCH 1112/1120] Run `spotlessApply`
      
      ---
       .../gradle/spotless/FormatExtension.java      |  1 -
       .../diffplug/gradle/spotless/GoExtension.java | 70 +++++++++----------
       2 files changed, 35 insertions(+), 36 deletions(-)
      
      diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
      index 73189ba4e0..6f6630b1b5 100644
      --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
      +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java
      @@ -65,7 +65,6 @@
       import com.diffplug.spotless.generic.ReplaceRegexStep;
       import com.diffplug.spotless.generic.ReplaceStep;
       import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep;
      -import com.diffplug.spotless.go.GofmtFormatStep;
       import com.diffplug.spotless.npm.NpmPathResolver;
       import com.diffplug.spotless.npm.PrettierFormatterStep;
       import com.diffplug.spotless.rome.BiomeFlavor;
      diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GoExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GoExtension.java
      index 60aa1aa71d..145e90c19a 100644
      --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GoExtension.java
      +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GoExtension.java
      @@ -15,43 +15,43 @@
        */
       package com.diffplug.gradle.spotless;
       
      +import javax.inject.Inject;
      +
       import com.diffplug.spotless.FormatterStep;
       import com.diffplug.spotless.go.GofmtFormatStep;
       
      -import javax.inject.Inject;
      -
       public class GoExtension extends FormatExtension {
      -    public static final String NAME = "go";
      -
      -    @Inject
      -    public GoExtension(SpotlessExtension spotless) {
      -        super(spotless);
      -    }
      -
      -    public GofmtConfig gofmt() {
      -        return new GofmtConfig(GofmtFormatStep.defaultVersion());
      -    }
      -
      -    public GofmtConfig gofmt(String version) {
      -        return new GofmtConfig(version);
      -    }
      -
      -    public class GofmtConfig {
      -        GofmtFormatStep stepCfg;
      -
      -        public GofmtConfig(String version) {
      -            stepCfg = GofmtFormatStep.withVersion(version);
      -            addStep(createStep());
      -        }
      -
      -        public GofmtConfig withGoExecutable(String pathToGo) {
      -            stepCfg = stepCfg.withGoExecutable(pathToGo);
      -            replaceStep(createStep());
      -            return this;
      -        }
      -
      -        private FormatterStep createStep() {
      -            return stepCfg.create();
      -        }
      -    }
      +	public static final String NAME = "go";
      +
      +	@Inject
      +	public GoExtension(SpotlessExtension spotless) {
      +		super(spotless);
      +	}
      +
      +	public GofmtConfig gofmt() {
      +		return new GofmtConfig(GofmtFormatStep.defaultVersion());
      +	}
      +
      +	public GofmtConfig gofmt(String version) {
      +		return new GofmtConfig(version);
      +	}
      +
      +	public class GofmtConfig {
      +		GofmtFormatStep stepCfg;
      +
      +		public GofmtConfig(String version) {
      +			stepCfg = GofmtFormatStep.withVersion(version);
      +			addStep(createStep());
      +		}
      +
      +		public GofmtConfig withGoExecutable(String pathToGo) {
      +			stepCfg = stepCfg.withGoExecutable(pathToGo);
      +			replaceStep(createStep());
      +			return this;
      +		}
      +
      +		private FormatterStep createStep() {
      +			return stepCfg.create();
      +		}
      +	}
       }
      
      From 602128c203ba22a6209c17809cf4f791c725f332 Mon Sep 17 00:00:00 2001
      From: Andre Wachsmuth 
      Date: Thu, 18 Jan 2024 10:48:21 +0100
      Subject: [PATCH 1113/1120] Implements #1995, flag to format JavaDoc for
       Palantir formatter
      
      ---
       CHANGES.md                                    |  1 +
       CONTRIBUTING.md                               | 11 ++++++
       .../spotless/java/PalantirJavaFormatStep.java | 35 ++++++++++++-----
       .../pjf/PalantirJavaFormatFormatterFunc.java  | 33 +++++++++++++---
       plugin-gradle/CHANGES.md                      |  3 ++
       plugin-gradle/README.md                       |  2 +
       .../gradle/spotless/JavaExtension.java        | 11 +++++-
       .../PalantirJavaFormatIntegrationTest.java    | 24 +++++++++++-
       plugin-maven/CHANGES.md                       |  1 +
       plugin-maven/README.md                        |  3 +-
       .../maven/java/PalantirJavaFormat.java        |  8 +++-
       .../maven/java/PalantirJavaFormatTest.java    | 21 +++++++---
       .../JavaCodeWithJavaDocFormatted.test         | 39 +++++++++++++++++++
       .../JavaCodeWithJavaDocUnformatted.test       | 30 ++++++++++++++
       .../java/PalantirJavaFormatStepTest.java      | 22 ++++++++++-
       15 files changed, 217 insertions(+), 27 deletions(-)
       create mode 100644 testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithJavaDocFormatted.test
       create mode 100644 testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithJavaDocUnformatted.test
      
      diff --git a/CHANGES.md b/CHANGES.md
      index 0e8940dec6..97218538a9 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
       * Maven - Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1998](https://github.com/diffplug/spotless/pull/1998))
      +* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#1995](https://github.com/diffplug/spotless/issues/1995))
       
       ## [2.44.0] - 2024-01-15
       ### Added
      diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
      index 6fb993f419..f0a4b4d59c 100644
      --- a/CONTRIBUTING.md
      +++ b/CONTRIBUTING.md
      @@ -171,6 +171,17 @@ gradlew :plugin-maven:test --tests com.diffplug.spotless.maven.pom.SortPomMavenT
       gradlew :plugin-gradle:test --tests com.diffplug.gradle.spotless.FreshMarkExtensionTest
       ```
       
      +## Check and format code
      +
      +Before creating a pull request, you might want to format (yes, spotless is  formatted by spotless)
      +the code and check for possible bugs
      +
      +* `./gradlew spotlessApply`
      +* `./gradlew spotbugsMain`
      +
      +These checks are also run by the automated pipeline when you submit a pull request, if
      +the pipeline fails, first check if the code is formatted and no bugs were found.
      +
       ## Integration testing
       
       ### Gradle - locally
      diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java
      index 95f7b355f7..c4d06cc731 100644
      --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java
      +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java
      @@ -27,6 +27,7 @@ public class PalantirJavaFormatStep {
       	// prevent direct instantiation
       	private PalantirJavaFormatStep() {}
       
      +	private static final boolean DEFAULT_FORMAT_JAVADOC = false;
       	private static final String DEFAULT_STYLE = "PALANTIR";
       	private static final String NAME = "palantir-java-format";
       	public static final String MAVEN_COORDINATE = "com.palantir.javaformat:palantir-java-format:";
      @@ -42,14 +43,25 @@ public static FormatterStep create(String version, Provisioner provisioner) {
       		return create(version, defaultStyle(), provisioner);
       	}
       
      -	/** Creates a step which formats everything - code, import order, and unused imports. And with the style input. */
      +	/**
      +	 * Creates a step which formats code, import order, and unused imports, but not Java docs. And with the given format
      +	 * style.
      +	 */
       	public static FormatterStep create(String version, String style, Provisioner provisioner) {
      +		return create(version, style, defaultFormatJavadoc(), provisioner);
      +	}
      +
      +	/**
      +	 * Creates a step which formats everything - code, import order, unused imports, and Java docs. And with the given
      +	 * format style.
      +	 */
      +	public static FormatterStep create(String version, String style, boolean formatJavadoc, Provisioner provisioner) {
       		Objects.requireNonNull(version, "version");
       		Objects.requireNonNull(style, "style");
       		Objects.requireNonNull(provisioner, "provisioner");
       
       		return FormatterStep.createLazy(NAME,
      -				() -> new State(JarState.from(MAVEN_COORDINATE + version, provisioner), version, style),
      +				() -> new State(JarState.from(MAVEN_COORDINATE + version, provisioner), version, style, formatJavadoc),
       				State::createFormat);
       	}
       
      @@ -63,6 +75,11 @@ public static String defaultStyle() {
       		return DEFAULT_STYLE;
       	}
       
      +	/** Get default for whether Java docs should be formatted */
      +	public static boolean defaultFormatJavadoc() {
      +		return DEFAULT_FORMAT_JAVADOC;
      +	}
      +
       	private static final class State implements Serializable {
       		private static final long serialVersionUID = 1L;
       
      @@ -71,23 +88,23 @@ private static final class State implements Serializable {
       		/** Version of the formatter jar. */
       		private final String formatterVersion;
       		private final String style;
      +		/** Whether to format Java docs. */
      +		private final boolean formatJavadoc;
       
      -		State(JarState jarState, String formatterVersion) {
      -			this(jarState, formatterVersion, DEFAULT_STYLE);
      -		}
      -
      -		State(JarState jarState, String formatterVersion, String style) {
      +		State(JarState jarState, String formatterVersion, String style, boolean formatJavadoc) {
       			ModuleHelper.doOpenInternalPackagesIfRequired();
       			this.jarState = jarState;
       			this.formatterVersion = formatterVersion;
       			this.style = style;
      +			this.formatJavadoc = formatJavadoc;
       		}
       
       		FormatterFunc createFormat() throws Exception {
       			final ClassLoader classLoader = jarState.getClassLoader();
       			final Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.pjf.PalantirJavaFormatFormatterFunc");
      -			final Constructor constructor = formatterFunc.getConstructor(String.class); // style
      -			return JVM_SUPPORT.suggestLaterVersionOnError(formatterVersion, (FormatterFunc) constructor.newInstance(style));
      +			// 1st arg is "style", 2nd arg is "formatJavadoc"
      +			final Constructor constructor = formatterFunc.getConstructor(String.class, boolean.class);
      +			return JVM_SUPPORT.suggestLaterVersionOnError(formatterVersion, (FormatterFunc) constructor.newInstance(style, formatJavadoc));
       		}
       	}
       }
      diff --git a/lib/src/palantirJavaFormat/java/com/diffplug/spotless/glue/pjf/PalantirJavaFormatFormatterFunc.java b/lib/src/palantirJavaFormat/java/com/diffplug/spotless/glue/pjf/PalantirJavaFormatFormatterFunc.java
      index 189bbb54be..bdec215435 100644
      --- a/lib/src/palantirJavaFormat/java/com/diffplug/spotless/glue/pjf/PalantirJavaFormatFormatterFunc.java
      +++ b/lib/src/palantirJavaFormat/java/com/diffplug/spotless/glue/pjf/PalantirJavaFormatFormatterFunc.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright 2022-2023 DiffPlug
      + * Copyright 2022-2024 DiffPlug
        *
        * Licensed under the Apache License, Version 2.0 (the "License");
        * you may not use this file except in compliance with the License.
      @@ -15,6 +15,9 @@
        */
       package com.diffplug.spotless.glue.pjf;
       
      +import java.lang.reflect.InvocationTargetException;
      +import java.lang.reflect.Method;
      +
       import com.palantir.javaformat.java.Formatter;
       import com.palantir.javaformat.java.ImportOrderer;
       import com.palantir.javaformat.java.JavaFormatterOptions;
      @@ -28,11 +31,20 @@ public class PalantirJavaFormatFormatterFunc implements FormatterFunc {
       
       	private final JavaFormatterOptions.Style formatterStyle;
       
      -	public PalantirJavaFormatFormatterFunc(String style) {
      +	/**
      +	 * Creates a new formatter func that formats code via Palantir.
      +	 * @param style The style to use for formatting.
      +	 * @param formatJavadoc Whether to format Java docs. Requires at least Palantir 2.36.0 or later, otherwise the
      +	 * constructor will throw.
      +	 */
      +	public PalantirJavaFormatFormatterFunc(String style, boolean formatJavadoc) {
       		this.formatterStyle = JavaFormatterOptions.Style.valueOf(style);
      -		formatter = Formatter.createFormatter(JavaFormatterOptions.builder()
      -				.style(formatterStyle)
      -				.build());
      +		JavaFormatterOptions.Builder builder = JavaFormatterOptions.builder();
      +		builder.style(formatterStyle);
      +		if (formatJavadoc) {
      +			applyFormatJavadoc(builder);
      +		}
      +		formatter = Formatter.createFormatter(builder.build());
       	}
       
       	@Override
      @@ -47,4 +59,15 @@ public String apply(String input) throws Exception {
       	public String toString() {
       		return "PalantirJavaFormatFormatterFunc{formatter=" + formatter + '}';
       	}
      +
      +	private static void applyFormatJavadoc(JavaFormatterOptions.Builder builder) {
      +		// The formatJavadoc option is available since Palantir 2.36.0
      +		// To support older versions for now, attempt to invoke the builder method via reflection.
      +		try {
      +			Method formatJavadoc = JavaFormatterOptions.Builder.class.getMethod("formatJavadoc", boolean.class);
      +			formatJavadoc.invoke(builder, true);
      +		} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
      +			throw new IllegalStateException("Cannot enable formatJavadoc option, make sure you are using Palantir with version 2.36.0 or later", e);
      +		}
      +	}
       }
      diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md
      index 593d4a2af8..48d8e515de 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
      +* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#1995](https://github.com/diffplug/spotless/issues/1995))
      +
       ## [6.24.0] - 2024-01-15
       ### Added
       * Support for shell formatting via [shfmt](https://github.com/mvdan/sh). ([#1994](https://github.com/diffplug/spotless/pull/1994))
      diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
      index 730a947d49..7ee996a444 100644
      --- a/plugin-gradle/README.md
      +++ b/plugin-gradle/README.md
      @@ -220,6 +220,8 @@ spotless {
           palantirJavaFormat()
           // optional: you can specify a specific version and/or switch to AOSP/GOOGLE style
           palantirJavaFormat('2.9.0').style("GOOGLE")
      +    // optional: you can also format Javadocs, requires at least Palantir 2.39.0
      +    palantirJavaFormat('2.39.0').formatJavadoc(true)
       ```
       
       ### eclipse jdt
      diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java
      index bb24a716cd..db869dc4e6 100644
      --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java
      +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright 2016-2023 DiffPlug
      + * Copyright 2016-2024 DiffPlug
        *
        * Licensed under the Apache License, Version 2.0 (the "License");
        * you may not use this file except in compliance with the License.
      @@ -256,6 +256,7 @@ public PalantirJavaFormatConfig palantirJavaFormat(String version) {
       	public class PalantirJavaFormatConfig {
       		final String version;
       		String style;
      +		boolean formatJavadoc;
       
       		PalantirJavaFormatConfig(String version) {
       			this.version = Objects.requireNonNull(version);
      @@ -269,8 +270,14 @@ public PalantirJavaFormatConfig style(String style) {
       			return this;
       		}
       
      +		public PalantirJavaFormatConfig formatJavadoc(boolean formatJavadoc) {
      +			this.formatJavadoc = formatJavadoc;
      +			replaceStep(createStep());
      +			return this;
      +		}
      +
       		private FormatterStep createStep() {
      -			return PalantirJavaFormatStep.create(version, style, provisioner());
      +			return PalantirJavaFormatStep.create(version, style, formatJavadoc, provisioner());
       		}
       	}
       
      diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PalantirJavaFormatIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PalantirJavaFormatIntegrationTest.java
      index 2283ce34bf..9990039cd3 100644
      --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PalantirJavaFormatIntegrationTest.java
      +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PalantirJavaFormatIntegrationTest.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright 2022 DiffPlug
      + * Copyright 2022-2024 DiffPlug
        *
        * Licensed under the Apache License, Version 2.0 (the "License");
        * you may not use this file except in compliance with the License.
      @@ -45,4 +45,26 @@ void integration() throws IOException {
       				"palantirJavaFormat('1.0.1')");
       		checkRunsThenUpToDate();
       	}
      +
      +	@Test
      +	void formatJavaDoc() throws IOException {
      +		setFile("build.gradle").toLines(
      +				"plugins {",
      +				"    id 'com.diffplug.spotless'",
      +				"}",
      +				"repositories { mavenCentral() }",
      +				"",
      +				"spotless {",
      +				"    java {",
      +				"        target file('test.java')",
      +				"        palantirJavaFormat('2.39.0').formatJavadoc(true)",
      +				"    }",
      +				"}");
      +
      +		setFile("test.java").toResource("java/palantirjavaformat/JavaCodeWithJavaDocUnformatted.test");
      +		gradleRunner().withArguments("spotlessApply").build();
      +		assertFile("test.java").sameAsResource("java/palantirjavaformat/JavaCodeWithJavaDocFormatted.test");
      +
      +		checkRunsThenUpToDate();
      +	}
       }
      diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md
      index f056aadf6e..c13abc2511 100644
      --- a/plugin-maven/CHANGES.md
      +++ b/plugin-maven/CHANGES.md
      @@ -5,6 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
       ## [Unreleased]
       ### Added
       * Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1998](https://github.com/diffplug/spotless/issues/1998))
      +* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#1995](https://github.com/diffplug/spotless/issues/1995))
       
       ## [2.42.0] - 2024-01-15
       ### Added
      diff --git a/plugin-maven/README.md b/plugin-maven/README.md
      index efc15b515f..7785412a32 100644
      --- a/plugin-maven/README.md
      +++ b/plugin-maven/README.md
      @@ -246,8 +246,9 @@ any other maven phase (i.e. compile) then it can be configured as below;
       
       ```xml
       
      -  2.10.0                     
      +  2.39.0                     
                                
      +  false          
       
       ```
       
      diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java
      index 192588d85d..674238d2e8 100644
      --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java
      +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/PalantirJavaFormat.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright 2016-2023 DiffPlug
      + * Copyright 2016-2024 DiffPlug
        *
        * Licensed under the Apache License, Version 2.0 (the "License");
        * you may not use this file except in compliance with the License.
      @@ -30,10 +30,14 @@ public class PalantirJavaFormat implements FormatterStepFactory {
       	@Parameter
       	private String style;
       
      +	@Parameter
      +	private Boolean formatJavadoc;
      +
       	@Override
       	public FormatterStep newFormatterStep(FormatterStepConfig config) {
       		String version = this.version != null ? this.version : PalantirJavaFormatStep.defaultVersion();
       		String style = this.style != null ? this.style : PalantirJavaFormatStep.defaultStyle();
      -		return PalantirJavaFormatStep.create(version, style, config.getProvisioner());
      +		boolean formatJavadoc = this.formatJavadoc != null ? this.formatJavadoc : PalantirJavaFormatStep.defaultFormatJavadoc();
      +		return PalantirJavaFormatStep.create(version, style, formatJavadoc, config.getProvisioner());
       	}
       }
      diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java
      index 685f00595c..eee4fab8c5 100644
      --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java
      +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/PalantirJavaFormatTest.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright 2022-2023 DiffPlug
      + * Copyright 2022-2024 DiffPlug
        *
        * Licensed under the Apache License, Version 2.0 (the "License");
        * you may not use this file except in compliance with the License.
      @@ -27,7 +27,7 @@ void specificVersionDefaultStyle() throws Exception {
       				"  1.1.0",
       				"");
       
      -		runTest("java/palantirjavaformat/JavaCodeFormatted.test");
      +		runTest("java/palantirjavaformat/JavaCodeFormatted.test", "java/palantirjavaformat/JavaCodeUnformatted.test");
       	}
       
       	@Test
      @@ -37,12 +37,23 @@ void specificJava11Version2() throws Exception {
       				"  2.39.0",
       				"");
       
      -		runTest("java/palantirjavaformat/JavaCodeFormatted.test");
      +		runTest("java/palantirjavaformat/JavaCodeFormatted.test", "java/palantirjavaformat/JavaCodeUnformatted.test");
       	}
       
      -	private void runTest(String targetResource) throws Exception {
      +	@Test
      +	void formatJavaDoc() throws Exception {
      +		writePomWithJavaSteps(
      +				"",
      +				"  2.39.0",
      +				"  true",
      +				"");
      +
      +		runTest("java/palantirjavaformat/JavaCodeWithJavaDocFormatted.test", "java/palantirjavaformat/JavaCodeWithJavaDocUnformatted.test");
      +	}
      +
      +	private void runTest(String targetResource, String sourceResource) throws Exception {
       		String path = "src/main/java/test.java";
      -		setFile(path).toResource("java/palantirjavaformat/JavaCodeUnformatted.test");
      +		setFile(path).toResource(sourceResource);
       		mavenRunner().withArguments("spotless:apply").runNoError();
       		assertFile(path).sameAsResource(targetResource);
       	}
      diff --git a/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithJavaDocFormatted.test b/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithJavaDocFormatted.test
      new file mode 100644
      index 0000000000..9cff5e17a1
      --- /dev/null
      +++ b/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithJavaDocFormatted.test
      @@ -0,0 +1,39 @@
      +import mylib.Unused;
      +import mylib.UsedA;
      +import mylib.UsedB;
      +
      +/**
      + * This is a test class with a long unformatted JavaDoc description. Lorem ipsum dolor sit amet, consectetur adipiscing
      + * elit. Vestibulum pulvinar condimentum elit, eget mollis magna sollicitudin in. Aenean pharetra nunc nec luctus
      + * consequat. Donec nec tincidunt quam, in auctor ipsum. Nam in sem orci. Maecenas interdum posuere orci a semper. Cras
      + * vulputate blandit metus, nec semper urna porttitor at. Praesent velit turpis, consequat in cursus eget, posuere eget
      + * magna. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque ante eros, sagittis sed tempus nec,
      + * rutrum ac arcu. Sed porttitor quam at enim commodo dictum. Sed fringilla tincidunt ex in aliquet.
      + *
      + * @author https://www.lipsum.com/
      + * @since 0.0.2
      + */
      +public class Java {
      +    /**
      +     * A very simple method that I really like a lot?
      +     *
      +     * 

      Care for more details? + * + *

        + *
      • Too + *
      • bad + *
      • I + *
      • don't + *
      • have + *
      • any + *
      + * + * @param args Useless args, but see {@link Unused}, perhaps even {@link UsedA} or even {@link UsedB b }? + */ + public static void main(String[] args) { + System.out.println( + "A very very very very very very very very very very very very very very very very very very very very very long string that goes beyond the 100-character line length."); + UsedB.someMethod(); + UsedA.someMethod(); + } +} diff --git a/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithJavaDocUnformatted.test b/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithJavaDocUnformatted.test new file mode 100644 index 0000000000..fcb3ad660c --- /dev/null +++ b/testlib/src/main/resources/java/palantirjavaformat/JavaCodeWithJavaDocUnformatted.test @@ -0,0 +1,30 @@ + +import mylib.Unused; +import mylib.UsedB; +import mylib.UsedA; + +/** This is a test class with a long unformatted JavaDoc description. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pulvinar condimentum elit, eget mollis magna sollicitudin in. Aenean pharetra nunc nec luctus consequat. Donec nec tincidunt quam, in auctor ipsum. Nam in sem orci. Maecenas interdum posuere orci a semper. Cras vulputate blandit metus, nec semper urna porttitor at. Praesent velit turpis, consequat in cursus eget, posuere eget magna. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque ante eros, sagittis sed tempus nec, rutrum ac arcu. Sed porttitor quam at enim commodo dictum. Sed fringilla tincidunt ex in aliquet. + * @author https://www.lipsum.com/ + * @since 0.0.2 + */ +public class Java { + /** + * A very simple method that I + * really + * like + * a lot? + * + * Care for more details?
      • Too
      • bad
      • + *
      • I
      • don't
      • have
      • + *
      • any
      • + *
      + * + * @param args Useless args, but + * see {@link Unused}, perhaps even {@link UsedA} or even {@link UsedB b }? + */ +public static void main(String[] args) { +System.out.println("A very very very very very very very very very very very very very very very very very very very very very long string that goes beyond the 100-character line length."); +UsedB.someMethod(); +UsedA.someMethod(); +} +} \ No newline at end of file diff --git a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java index 7cd1aad438..cb8777728b 100644 --- a/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/java/PalantirJavaFormatStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 DiffPlug + * Copyright 2022-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,14 @@ void behavior() throws Exception { .testResource("java/palantirjavaformat/JavaCodeWithPackageUnformatted.test", "java/palantirjavaformat/JavaCodeWithPackageFormatted.test"); } + @Test + void formatJavadoc() throws Exception { + FormatterStep step = PalantirJavaFormatStep.create("2.39.0", "PALANTIR", true, TestProvisioner.mavenCentral()); + StepHarness.forStep(step) + .testResource("java/palantirjavaformat/JavaCodeWithJavaDocUnformatted.test", "java/palantirjavaformat/JavaCodeWithJavaDocFormatted.test") + .testResource("java/palantirjavaformat/JavaCodeWithPackageUnformatted.test", "java/palantirjavaformat/JavaCodeWithPackageFormatted.test"); + } + @Test void behaviorWithGoogleStyle() throws Exception { FormatterStep step = PalantirJavaFormatStep.create("1.1.0", "GOOGLE", TestProvisioner.mavenCentral()); @@ -68,23 +76,33 @@ void equality() { new SerializableEqualityTester() { String version = "1.1.0"; String style = ""; + boolean formatJavadoc = false; @Override protected void setupTest(API api) { // same version == same api.areDifferentThan(); + // change the version, and it's different version = "1.0.0"; api.areDifferentThan(); + version = "1.1.0"; + // change the style, and it's different style = "AOSP"; api.areDifferentThan(); + style = ""; + + // change the format Java doc flag, and it's different + formatJavadoc = true; + api.areDifferentThan(); + formatJavadoc = false; } @Override protected FormatterStep create() { String finalVersion = this.version; - return PalantirJavaFormatStep.create(finalVersion, style, TestProvisioner.mavenCentral()); + return PalantirJavaFormatStep.create(finalVersion, style, formatJavadoc, TestProvisioner.mavenCentral()); } }.testEquals(); } From 1cb7f0a0b197c1e7b0ddd3ee66656ed411251a53 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Thu, 18 Jan 2024 14:06:52 +0100 Subject: [PATCH 1114/1120] Add reference to PR in changelog, minor code style fix Co-authored-by: Zongle Wang --- CHANGES.md | 2 +- .../java/com/diffplug/spotless/java/PalantirJavaFormatStep.java | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 97218538a9..cbe48b5235 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Maven - Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1998](https://github.com/diffplug/spotless/pull/1998)) -* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#1995](https://github.com/diffplug/spotless/issues/1995)) +* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#2009](https://github.com/diffplug/spotless/pull/2009)) ## [2.44.0] - 2024-01-15 ### Added diff --git a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java index c4d06cc731..a670a6fea7 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/PalantirJavaFormatStep.java @@ -48,7 +48,7 @@ public static FormatterStep create(String version, Provisioner provisioner) { * style. */ public static FormatterStep create(String version, String style, Provisioner provisioner) { - return create(version, style, defaultFormatJavadoc(), provisioner); + return create(version, style, DEFAULT_FORMAT_JAVADOC, provisioner); } /** diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 48d8e515de..132ad16ebc 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#1995](https://github.com/diffplug/spotless/issues/1995)) +* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#2009](https://github.com/diffplug/spotless/pull/2009)) ## [6.24.0] - 2024-01-15 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index c13abc2511..b95f2e998e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1998](https://github.com/diffplug/spotless/issues/1998)) -* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#1995](https://github.com/diffplug/spotless/issues/1995)) +* Maven / Gradle - Support for formatting Java Docs for the Palantir formatter ([#2009](https://github.com/diffplug/spotless/pull/2009)) ## [2.42.0] - 2024-01-15 ### Added From 9d71e6d7c3a00437a1e838d1949066d2ebce367b Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Sat, 20 Jan 2024 17:30:49 +0100 Subject: [PATCH 1115/1120] Fixes according to review --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- .../main/java/com/diffplug/gradle/spotless/FormatExtension.java | 2 +- plugin-maven/CHANGES.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 272735a791..e13eed2745 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,7 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Maven - Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1998](https://github.com/diffplug/spotless/pull/1998)) -* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/issues/2001)) +* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/pull/2001)) ## [2.44.0] - 2024-01-15 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 4a0ac12a5b..b712a4e3d8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,7 +3,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] -* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/issues/2001)) +* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/pull/2001)) ## [6.24.0] - 2024-01-15 ### Added diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 6f6630b1b5..eae8ac667d 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 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. diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index e73ccde66d..b7dd430f8e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,7 +5,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for formatting shell scripts via [shfmt](https://github.com/mvdan/sh). ([#1998](https://github.com/diffplug/spotless/issues/1998)) -* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/issues/2001)) +* Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/pull/2001)) ## [2.42.0] - 2024-01-15 ### Added From 56a019c78ba9b2ef2d6f59283b312821441a897a Mon Sep 17 00:00:00 2001 From: Johannes Ptaszyk Date: Sun, 21 Jan 2024 19:34:45 +0100 Subject: [PATCH 1116/1120] Update README.md Enhance prettier plugin configuration docs to better differentiate v2 and v3. --- plugin-gradle/README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 730a947d49..bfa8733504 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -1086,16 +1086,32 @@ To apply prettier to more kinds of files, just add more formats Since spotless uses the actual npm prettier package behind the scenes, it is possible to use prettier with [plugins](https://prettier.io/docs/en/plugins.html#official-plugins) or [community-plugins](https://www.npmjs.com/search?q=prettier-plugin) in order to support even more file types. +#### prettier version below 3 + ```gradle spotless { java { prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0']).config(['parser': 'java', 'tabWidth': 4]) - // prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']).config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) // Prettier v3 requires additional 'plugins' config } format 'php', { target 'src/**/*.php' prettier(['prettier': '2.8.8', '@prettier/plugin-php': '0.19.6']).config(['parser': 'php', 'tabWidth': 3]) - // prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']).config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) // Prettier v3 requires additional 'plugins' config + } +} +``` + +#### prettier version 3+ + +With version 3 prettier it is required to pass in an additional 'plugins' parameter to the config block with a list of plugins you want to use. + +```gradle +spotless { + java { + prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']).config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) + } + format 'php', { + target 'src/**/*.php' + prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']).config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) } } ``` From d4b102ce1d06ce98886bbd4737cc9b3ca4dddafb Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 21 Jan 2024 22:16:52 -0800 Subject: [PATCH 1117/1120] Apply suggestions from code review Co-authored-by: Zongle Wang --- plugin-gradle/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index bfa8733504..4b57a07f02 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -1107,11 +1107,13 @@ With version 3 prettier it is required to pass in an additional 'plugins' parame ```gradle spotless { java { - prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']).config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) + prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']) + .config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) } format 'php', { target 'src/**/*.php' - prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']).config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) + prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']) + .config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) } } ``` From 9d468eb752c064e5190343648597e0638bbaa9e2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 22 Jan 2024 21:32:10 -0800 Subject: [PATCH 1118/1120] Remove `_ext` from `CONTRIBUTING.md`. --- CONTRIBUTING.md | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f0a4b4d59c..5fce5a9460 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,7 +36,6 @@ For the folders below in monospace text, they are published on MavenCentral at t | `lib-extra` | Contains the optional parts of Spotless which require external dependencies. `LineEnding.GIT_ATTRIBUTES` won't work unless `lib-extra` is available. | | `plugin-gradle` | Integrates spotless and all of its formatters into Gradle. | | `plugin-maven` | Integrates spotless and all of its formatters into Maven. | -| `_ext` | Folder for generating glue jars (specifically packaging Eclipse jars from p2 for consumption using maven). ## How to add a new FormatterStep @@ -119,24 +118,6 @@ There are many great formatters (prettier, clang-format, black, etc.) which live Because of Spotless' up-to-date checking and [git ratcheting](https://github.com/diffplug/spotless/tree/main/plugin-gradle#ratchet), Spotless actually doesn't have to call formatters very often, so even an expensive shell call for every single invocation isn't that bad. Anything that works is better than nothing, and we can always speed things up later if it feels too slow (but it probably won't). -## How to enable the `_ext` projects - -The `_ext` projects are disabled per default, since: - -* some of the projects perform vast downloads at configuration time -* the downloaded content may change on server side and break CI builds - - -The `_ext` can be activated via the root project property `com.diffplug.spotless.include.ext`. - -Activate the property via command line, like for example: - -``` -gradlew -Pcom.diffplug.spotless.include.ext=true build -``` - -Or set the property in your user `gradle.properties` file, which is especially recommended if you like to work with the `_ext` projects using IDEs. - ## How to add a new plugin for a build system The gist of it is that you will have to: From a48a91c92ddb3c6142ed895dcc1b37e17016fda5 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Mon, 22 Jan 2024 21:32:28 -0800 Subject: [PATCH 1119/1120] Remove `_ext` from `.gitignore`. --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8a0bc11e97..ab04bc7021 100644 --- a/.gitignore +++ b/.gitignore @@ -19,9 +19,6 @@ gradle-app.setting # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar -#Gradle-Lock files in _ext just serving as an input for lib-extra -_ext/*/gradle/dependency-locks/*.lockfile - ### Eclipse ### .metadata .gradle From 52654ef8c4a6191d983b10a2370d53b1ca023f7d Mon Sep 17 00:00:00 2001 From: runner Date: Tue, 23 Jan 2024 07:03:59 +0000 Subject: [PATCH 1120/1120] Published lib/2.45.0 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index a94d20dd09..adf6d109e7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] + +## [2.45.0] - 2024-01-23 ### Added * Support for `gofmt` ([#2001](https://github.com/diffplug/spotless/pull/2001)) * Support for formatting Java Docs for the Palantir formatter ([#2009](https://github.com/diffplug/spotless/pull/2009))