Skip to content

Commit

Permalink
use java-diff-utils
Browse files Browse the repository at this point in the history
Signed-off-by: bachmanity1 <[email protected]>
  • Loading branch information
bachmanity1 committed Oct 2, 2024
1 parent 611ecdb commit 57a0ee2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions operator-framework-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<description>Core framework for implementing Kubernetes operators</description>

<dependencies>
<dependency>
<groupId>io.github.java-diff-utils</groupId>
<artifactId>java-diff-utils</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
Expand Down Expand Up @@ -58,6 +62,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.SortedMap;
import java.util.TreeMap;

import org.assertj.core.util.diff.DiffUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -27,6 +26,9 @@
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.processing.LoggingUtils;

import com.github.difflib.DiffUtils;
import com.github.difflib.UnifiedDiffUtils;

/**
* Matches the actual state on the server vs the desired state. Based on the managedFields of SSA.
*
Expand Down Expand Up @@ -123,12 +125,13 @@ private String getDiff(Map<String, Object> prunedActualMap, Map<String, Object>
var actualYaml = serialization.asYaml(sortMap(prunedActualMap));
var desiredYaml = serialization.asYaml(sortMap(desiredMap));
if (log.isTraceEnabled()) {
log.trace("Pruned actual resource: \n{} \ndesired resource: \n{} ", actualYaml, desiredYaml);
log.trace("Pruned actual resource: \n {} \ndesired resource: \n {} ", actualYaml,
desiredYaml);
}

var patch = DiffUtils.diff(actualYaml.lines().toList(), desiredYaml.lines().toList());
List<String> unifiedDiff =
DiffUtils.generateUnifiedDiff("", "", actualYaml.lines().toList(), patch, 1);
UnifiedDiffUtils.generateUnifiedDiff("", "", actualYaml.lines().toList(), patch, 1);
return String.join("\n", unifiedDiff);
}

Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<caffeine.version>3.1.8</caffeine.version>
<mustache.version>0.9.11</mustache.version>
<commons.io.version>2.16.1</commons.io.version>
<java.diff.version>4.12</java.diff.version>

<fmt-maven-plugin.version>2.11</fmt-maven-plugin.version>
<maven-compiler-plugin.version>3.12.1</maven-compiler-plugin.version>
Expand Down Expand Up @@ -161,6 +162,11 @@
<version>${mokito.version}</version>
</dependency>

<dependency>
<groupId>io.github.java-diff-utils</groupId>
<artifactId>java-diff-utils</artifactId>
<version>${java.diff.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down

0 comments on commit 57a0ee2

Please sign in to comment.