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 1/4] 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 2/4] 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 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 3/4] 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 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 4/4] 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");