summaryrefslogtreecommitdiffstats
path: root/abi-check-plugin
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2022-10-21 14:19:40 +0200
committerjonmv <venstad@gmail.com>2022-10-21 14:19:40 +0200
commitb50442af088764830a19e93dfead9ce2441da997 (patch)
tree9a580971feba513d8c0d817e6b1a392b5ab25686 /abi-check-plugin
parentfe4c6158a9d9a33cbe6024916bf96dd7474fc391 (diff)
Replace gson with jackson in abi-check plugin
Diffstat (limited to 'abi-check-plugin')
-rw-r--r--abi-check-plugin/pom.xml5
-rw-r--r--abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java42
-rw-r--r--abi-check-plugin/src/main/java/com/yahoo/abicheck/signature/JavaClassSignature.java13
3 files changed, 33 insertions, 27 deletions
diff --git a/abi-check-plugin/pom.xml b/abi-check-plugin/pom.xml
index 253bf8e0a60..87350af8289 100644
--- a/abi-check-plugin/pom.xml
+++ b/abi-check-plugin/pom.xml
@@ -35,9 +35,8 @@
<artifactId>asm</artifactId>
</dependency>
<dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>${gson.version}</version>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
diff --git a/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java b/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java
index bbf5876b57c..c064bb5d918 100644
--- a/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java
+++ b/abi-check-plugin/src/main/java/com/yahoo/abicheck/mojo/AbiCheck.java
@@ -1,9 +1,8 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.abicheck.mojo;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.reflect.TypeToken;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.abicheck.classtree.ClassFileTree;
import com.yahoo.abicheck.classtree.ClassFileTree.ClassFile;
import com.yahoo.abicheck.classtree.ClassFileTree.Package;
@@ -11,12 +10,26 @@ import com.yahoo.abicheck.collector.AnnotationCollector;
import com.yahoo.abicheck.collector.PublicSignatureCollector;
import com.yahoo.abicheck.setmatcher.SetMatcher;
import com.yahoo.abicheck.signature.JavaClassSignature;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.annotations.InstantiationStrategy;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.MavenProject;
+import org.objectweb.asm.ClassReader;
+
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -24,18 +37,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.logging.Log;
-import org.apache.maven.plugins.annotations.InstantiationStrategy;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.plugins.annotations.ResolutionScope;
-import org.apache.maven.project.MavenProject;
-import org.objectweb.asm.ClassReader;
@Mojo(
name = "abicheck",
@@ -63,11 +64,9 @@ public class AbiCheck extends AbstractMojo {
// Testing that Gson can read JSON files is not very useful
private static Map<String, JavaClassSignature> readSpec(File file) throws IOException {
try (FileReader reader = new FileReader(file)) {
- TypeToken<Map<String, JavaClassSignature>> typeToken =
- new TypeToken<Map<String, JavaClassSignature>>() {
- };
- Gson gson = new GsonBuilder().create();
- return gson.fromJson(reader, typeToken.getType());
+ ObjectMapper mapper = new ObjectMapper();
+ JavaType typeToken = mapper.getTypeFactory().constructMapType(HashMap.class, String.class, JavaClassSignature.class);
+ return mapper.readValue(reader, typeToken);
}
}
// CLOVER:ON
@@ -76,9 +75,8 @@ public class AbiCheck extends AbstractMojo {
// Testing that Gson can write JSON files is not very useful
private static void writeSpec(Map<String, JavaClassSignature> signatures, File file)
throws IOException {
- Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
try (FileWriter writer = new FileWriter(file)) {
- gson.toJson(signatures, writer);
+ new ObjectMapper().writeValue(writer, signatures);
}
}
// CLOVER:ON
diff --git a/abi-check-plugin/src/main/java/com/yahoo/abicheck/signature/JavaClassSignature.java b/abi-check-plugin/src/main/java/com/yahoo/abicheck/signature/JavaClassSignature.java
index e7f661b8aa8..16574b2b516 100644
--- a/abi-check-plugin/src/main/java/com/yahoo/abicheck/signature/JavaClassSignature.java
+++ b/abi-check-plugin/src/main/java/com/yahoo/abicheck/signature/JavaClassSignature.java
@@ -1,6 +1,11 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.abicheck.signature;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -12,12 +17,16 @@ public class JavaClassSignature {
public final Set<String> methods;
public final Set<String> fields;
- public JavaClassSignature(String superClass, Set<String> interfaces, List<String> attributes,
- Set<String> methods, Set<String> fields) {
+ public JavaClassSignature(@JsonProperty("superClass") String superClass,
+ @JsonProperty("interfaces") Set<String> interfaces,
+ @JsonProperty("attributes") List<String> attributes,
+ @JsonProperty("methods") Set<String> methods,
+ @JsonProperty("fields") Set<String> fields) {
this.superClass = superClass;
this.interfaces = interfaces;
this.attributes = attributes;
this.methods = methods;
this.fields = fields;
}
+
}