From ee932876adbe55321423e27b33bf3dfd3d76380a Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Fri, 16 Aug 2024 16:32:27 +0530 Subject: [PATCH] fix : Add `io.fabric8.zjsonpatch.Json*` classes for backward compatibility After migrating to upstream zjsonpatch dependency, KubernetesMutationHookHandlingTest started failing. Upon checking the failures I found that this module depends on Java Operator SDK that also uses zjsonpatch library to calculate JSON diff from KubernetesClient. Adding back the `io.fabric8.zjsonpatch.JsonDiff` and `io.fabric8.zjsonpatch.JsonPatch` classes. Signed-off-by: Rohan Kumar --- zjsonpatch/pom.xml | 1 + .../java/io/fabric8/zjsonpatch/JsonDiff.java | 27 +++++++++++ .../java/io/fabric8/zjsonpatch/JsonPatch.java | 45 +++++++++++++++++++ .../commons/collections4/ListUtils.java | 3 ++ .../io/fabric8/zjsonpatch/JsonDiffTest.java | 1 - 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 zjsonpatch/src/main/java/io/fabric8/zjsonpatch/JsonDiff.java create mode 100644 zjsonpatch/src/main/java/io/fabric8/zjsonpatch/JsonPatch.java diff --git a/zjsonpatch/pom.xml b/zjsonpatch/pom.xml index 52da9ac10ca..95d86ff4b95 100644 --- a/zjsonpatch/pom.xml +++ b/zjsonpatch/pom.xml @@ -34,6 +34,7 @@ * + io.fabric8.zjsonpatch, com.flipkart.zjsonpatch, org.apache.commons.collections4* diff --git a/zjsonpatch/src/main/java/io/fabric8/zjsonpatch/JsonDiff.java b/zjsonpatch/src/main/java/io/fabric8/zjsonpatch/JsonDiff.java new file mode 100644 index 00000000000..c99cedb9c35 --- /dev/null +++ b/zjsonpatch/src/main/java/io/fabric8/zjsonpatch/JsonDiff.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * 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.fabric8.zjsonpatch; + +import com.fasterxml.jackson.databind.JsonNode; + +public class JsonDiff { + private JsonDiff() { + } + + public static JsonNode asJson(final JsonNode source, final JsonNode target) { + return com.flipkart.zjsonpatch.JsonDiff.asJson(source, target); + } +} diff --git a/zjsonpatch/src/main/java/io/fabric8/zjsonpatch/JsonPatch.java b/zjsonpatch/src/main/java/io/fabric8/zjsonpatch/JsonPatch.java new file mode 100644 index 00000000000..4e676685299 --- /dev/null +++ b/zjsonpatch/src/main/java/io/fabric8/zjsonpatch/JsonPatch.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * 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.fabric8.zjsonpatch; + +import com.fasterxml.jackson.databind.JsonNode; +import com.flipkart.zjsonpatch.CompatibilityFlags; +import com.flipkart.zjsonpatch.InvalidJsonPatchException; +import com.flipkart.zjsonpatch.JsonPatchApplicationException; + +import java.util.EnumSet; + +public class JsonPatch { + private JsonPatch() { + } + + public static void validate(JsonNode patch, EnumSet flags) throws InvalidJsonPatchException { + com.flipkart.zjsonpatch.JsonPatch.validate(patch, flags); + } + + public static void validate(JsonNode patch) throws InvalidJsonPatchException { + com.flipkart.zjsonpatch.JsonPatch.validate(patch, CompatibilityFlags.defaults()); + } + + public static JsonNode apply(JsonNode patch, JsonNode source, EnumSet flags) + throws JsonPatchApplicationException { + return com.flipkart.zjsonpatch.JsonPatch.apply(patch, source, flags); + } + + public static JsonNode apply(JsonNode patch, JsonNode source) throws JsonPatchApplicationException { + return apply(patch, source, CompatibilityFlags.defaults()); + } +} diff --git a/zjsonpatch/src/main/java/org/apache/commons/collections4/ListUtils.java b/zjsonpatch/src/main/java/org/apache/commons/collections4/ListUtils.java index 936bdb4426c..1be9f65345c 100644 --- a/zjsonpatch/src/main/java/org/apache/commons/collections4/ListUtils.java +++ b/zjsonpatch/src/main/java/org/apache/commons/collections4/ListUtils.java @@ -29,6 +29,9 @@ * Commons Collections */ public class ListUtils { + private ListUtils() { + } + /** * Returns the longest common subsequence (LCS) of two sequences (lists). * diff --git a/zjsonpatch/src/test/java/io/fabric8/zjsonpatch/JsonDiffTest.java b/zjsonpatch/src/test/java/io/fabric8/zjsonpatch/JsonDiffTest.java index 8adc5e0737d..595eba41dd4 100644 --- a/zjsonpatch/src/test/java/io/fabric8/zjsonpatch/JsonDiffTest.java +++ b/zjsonpatch/src/test/java/io/fabric8/zjsonpatch/JsonDiffTest.java @@ -18,7 +18,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; -import com.flipkart.zjsonpatch.JsonDiff; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test;