Skip to content

Commit

Permalink
feat(zjsonpatch): port flipkart's dependency code to local codebase
Browse files Browse the repository at this point in the history
Since we're already copying most of the codebase, let's just remove the dependency.

Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Sep 3, 2024
1 parent f3de527 commit 4d79a6d
Show file tree
Hide file tree
Showing 27 changed files with 2,765 additions and 54 deletions.
17 changes: 0 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
<maven-core.version>3.9.9</maven-core.version>
<maven-plugin-annotations.version>3.15.0</maven-plugin-annotations.version>
<vertx.version>4.5.9</vertx.version>
<zjsonpatch.version>0.4.16</zjsonpatch.version>
<jandex.version>3.2.2</jandex.version>

<!-- API versions -->
Expand Down Expand Up @@ -905,24 +904,8 @@
<artifactId>jandex</artifactId>
<version>${jandex.version}</version>
</dependency>
<dependency>
<groupId>com.flipkart.zjsonpatch</groupId>
<artifactId>zjsonpatch</artifactId>
<version>${zjsonpatch.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Testing and Mocking -->
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>zjsonpatch</artifactId>
<version>${zjsonpatch.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
8 changes: 1 addition & 7 deletions uberjar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
<artifactId>openshift-server-mock</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>zjsonpatch</artifactId>
Expand Down Expand Up @@ -238,12 +238,6 @@
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

<dependency>
<groupId>com.flipkart.zjsonpatch</groupId>
<artifactId>zjsonpatch</artifactId>
<version>${zjsonpatch.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
18 changes: 7 additions & 11 deletions zjsonpatch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,29 @@
<properties>
<osgi.import>
com.fasterxml.jackson.*,
com.flipkart.zjsonpatch*,
io.fabric8.zjsonpatch.internal.collections4
</osgi.import>
<osgi.export>
io.fabric8.zjsonpatch*,
com.flipkart.zjsonpatch
</osgi.export>
</properties>

<dependencies>
<dependency>
<groupId>com.flipkart.zjsonpatch</groupId>
<artifactId>zjsonpatch</artifactId>
<version>${zjsonpatch.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</exclusion>
</exclusions>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 java.util.EnumSet;

/**
* This class is ported from <a href=
* "https://github.com/flipkart-incubator/zjsonpatch/blob/a446bf598231c06006d4e3df69b846cdb16d8889/src/main/java/com/flipkart/zjsonpatch/CompatibilityFlags.java">FlipKart
* zjsonpatch repository</a>
*/
public enum CompatibilityFlags {
MISSING_VALUES_AS_NULLS,
REMOVE_NONE_EXISTING_ARRAY_ELEMENT,
ALLOW_MISSING_TARGET_OBJECT_ON_REPLACE,
FORBID_REMOVE_MISSING_OBJECT;

public static EnumSet<CompatibilityFlags> defaults() {
return EnumSet.noneOf(CompatibilityFlags.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 java.util.EnumSet;

/**
* This class is ported from <a href=
* "https://github.com/flipkart-incubator/zjsonpatch/blob/a446bf598231c06006d4e3df69b846cdb16d8889/src/main/java/com/flipkart/zjsonpatch/CopyingApplyProcessor.java">FlipKart
* zjsonpatch repository</a>
*/

class CopyingApplyProcessor extends InPlaceApplyProcessor {

CopyingApplyProcessor(JsonNode target, EnumSet<CompatibilityFlags> flags) {
super(target.deepCopy(), flags);
}
}
5 changes: 2 additions & 3 deletions zjsonpatch/src/main/java/io/fabric8/zjsonpatch/Diff.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
package io.fabric8.zjsonpatch;

import com.fasterxml.jackson.databind.JsonNode;
import com.flipkart.zjsonpatch.Operation;

/**
* This class is ported from <a href=
* "https://github.com/flipkart-incubator/zjsonpatch/blob/a446bf598231c06006d4e3df69b846cdb16d8889/src/main/java/com/flipkart/zjsonpatch/Diff.java#L25">FlipKart
* JSONPatch repository</a>
* "https://github.com/flipkart-incubator/zjsonpatch/blob/a446bf598231c06006d4e3df69b846cdb16d8889/src/main/java/com/flipkart/zjsonpatch/Diff.java">FlipKart
* zjsonpatch repository</a>
*/
class Diff {
private final Operation operation;
Expand Down
101 changes: 101 additions & 0 deletions zjsonpatch/src/main/java/io/fabric8/zjsonpatch/DiffFlags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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 java.util.EnumSet;

/**
* This class is ported from <a href=
* "https://github.com/flipkart-incubator/zjsonpatch/blob/a446bf598231c06006d4e3df69b846cdb16d8889/src/main/java/com/flipkart/zjsonpatch/DiffFlags.java">FlipKart
* zjsonpatch repository</a>
*/
public enum DiffFlags {

/**
* This flag omits the <i>value</i> field on remove operations.
* This is a default flag.
*/
OMIT_VALUE_ON_REMOVE,

/**
* This flag omits all {@link Operation#MOVE} operations, leaving only
* {@link Operation#ADD}, {@link Operation#REMOVE}, {@link Operation#REPLACE}
* and {@link Operation#COPY} operations. In other words, without this flag,
* {@link Operation#ADD} and {@link Operation#REMOVE} operations are not normalized
* into {@link Operation#MOVE} operations.
*/
OMIT_MOVE_OPERATION,

/**
* This flag omits all {@link Operation#COPY} operations, leaving only
* {@link Operation#ADD}, {@link Operation#REMOVE}, {@link Operation#REPLACE}
* and {@link Operation#MOVE} operations. In other words, without this flag,
* {@link Operation#ADD} operations are not normalized into {@link Operation#COPY}
* operations.
*/
OMIT_COPY_OPERATION,

/**
* This flag adds a <i>fromValue</i> field to all {@link Operation#REPLACE} operations.
* <i>fromValue</i> represents the the value replaced by a {@link Operation#REPLACE}
* operation, in other words, the original value. This can be useful for debugging
* output or custom processing of the diffs by downstream systems.
* Please note that this is a non-standard extension to RFC 6902 and will not affect
* how patches produced by this library are processed by this or other libraries.
*
* @since 0.4.1
*/
ADD_ORIGINAL_VALUE_ON_REPLACE,

/**
* This flag normalizes a {@link Operation#REPLACE} operation into its respective
* {@link Operation#REMOVE} and {@link Operation#ADD} operations. Although it adds
* a redundant step, this can be useful for auditing systems in which immutability
* is a requirement.
* <p>
* For the flag to work, {@link DiffFlags#ADD_ORIGINAL_VALUE_ON_REPLACE} has to be
* enabled as the new instructions in the patch need to grab the old <i>fromValue</i>
* {@code "op": "replace", "fromValue": "F1", "value": "F2" }
* The above instruction will be split into
* {@code "op":"remove", "value":"F1" } and {@code "op":"add", "value":"F2"} respectively.
* <p>
* Please note that this is a non-standard extension to RFC 6902 and will not affect
* how patches produced by this library are processed by this or other libraries.
*
* @since 0.4.11
*/
ADD_EXPLICIT_REMOVE_ADD_ON_REPLACE,

/**
* This flag instructs the diff generator to emit {@link Operation#TEST} operations
* that validate the state of the source document before each mutation. This can be
* useful if you want to ensure data integrity prior to applying the patch.
* The resulting patches are standard per RFC 6902 and should be processed correctly
* by any compliant library; due to the associated space and performance costs,
* however, this isn't default behavior.
*
* @since 0.4.8
*/
EMIT_TEST_OPERATIONS;

public static EnumSet<DiffFlags> defaults() {
return EnumSet.of(OMIT_VALUE_ON_REMOVE);
}

public static EnumSet<DiffFlags> dontNormalizeOpIntoMoveAndCopy() {
return EnumSet.of(OMIT_MOVE_OPERATION, OMIT_COPY_OPERATION);
}
}
Loading

0 comments on commit 4d79a6d

Please sign in to comment.