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] 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");