Skip to content

Commit 802f213

Browse files
OC-258: replace GSON by custom serializer methods (#259)
* OC-258: replace GSON by custom serializer methods; remove all references of GSON (pom.xml, license files, about boxes) * OC-258: bug fix (objects and arrays were in escaped strings inside quotes)
1 parent 0634312 commit 802f213

File tree

12 files changed

+43
-266
lines changed

12 files changed

+43
-266
lines changed

clover-all/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@
8888
<groupId>it.unimi.dsi</groupId>
8989
<artifactId>fastutil</artifactId>
9090
</dependency>
91-
<dependency>
92-
<groupId>com.google.code.gson</groupId>
93-
<artifactId>gson</artifactId>
94-
</dependency>
9591
<dependency>
9692
<groupId>com.lowagie</groupId>
9793
<artifactId>itext</artifactId>

clover-core-libs/versions.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<property name="commons-collections.ver" value="3.2.2"/>
88
<property name="commons-lang3.ver" value="3.3.2"/>
99
<property name="fastutil.ver" value="4.4.3"/>
10-
<property name="gson.ver" value="1.3"/>
1110
<property name="itext.ver" value="2.0.1"/> <!-- Don't use higher than 2.1.7. Later are based on GPL! -->
1211
<property name="jcommon.ver" value="1.0.23"/>
1312
<property name="jdom.ver" value="1.0"/>

clover-core/pom.xml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@
7474
<groupId>jdom</groupId>
7575
<artifactId>jdom</artifactId>
7676
</dependency>
77-
<dependency>
78-
<groupId>com.google.code.gson</groupId>
79-
<artifactId>gson</artifactId>
80-
</dependency>
8177
<dependency>
8278
<groupId>com.lowagie</groupId>
8379
<artifactId>itext</artifactId>
@@ -345,7 +341,6 @@
345341
<include>commons-lang:commons-lang</include>
346342
<include>org.apache.commons:commons-lang3</include>
347343
<include>it.unimi.dsi:fastutil</include>
348-
<include>com.google.code.gson:gson</include>
349344
<include>com.lowagie:itext</include>
350345
<include>org.jfree:jcommon</include>
351346
<include>jdom:jdom</include>
@@ -409,13 +404,6 @@
409404
<exclude>build.xml</exclude>
410405
</excludes>
411406
</filter>
412-
<filter>
413-
<artifact>com.google.code.gson:gson</artifact>
414-
<excludes>
415-
<exclude>META-INF/MANIFEST.MF</exclude>
416-
<exclude>**/assembly-descriptor.xml</exclude>
417-
</excludes>
418-
</filter>
419407
<filter>
420408
<artifact>org.jfree:jcommon</artifact>
421409
<excludes>
@@ -449,13 +437,6 @@
449437
<include>antlr.**</include>
450438
</includes>
451439
</relocation>
452-
<relocation>
453-
<pattern>com.google.gson</pattern>
454-
<shadedPattern>clover.com.google.gson</shadedPattern>
455-
<includes>
456-
<include>com.google.gson.**</include>
457-
</includes>
458-
</relocation>
459440
<relocation>
460441
<pattern>com.lowagie</pattern>
461442
<shadedPattern>clover.com.lowagie</shadedPattern>

clover-core/src/main/java/org/openclover/core/reporters/json/RenderTreeMapJsonAction.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.openclover.core.reporters.json;
22

3-
import com.google.gson.Gson;
4-
import com.google.gson.GsonBuilder;
3+
import org.apache.commons.lang3.StringEscapeUtils;
54
import org.openclover.core.api.registry.BlockMetrics;
65
import org.openclover.core.api.registry.ClassInfo;
76
import org.openclover.core.api.registry.HasMetrics;
@@ -16,10 +15,10 @@
1615
import java.util.Collections;
1716
import java.util.Iterator;
1817
import java.util.List;
18+
import java.util.stream.Collectors;
1919

2020
public class RenderTreeMapJsonAction {
2121
public static String generateJson(ProjectInfo project, HtmlRenderingSupportImpl renderSupport, boolean classLevel) {
22-
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
2322

2423
final List<PackageInfo> pkgInfos = project.getAllPackages();
2524

@@ -44,7 +43,46 @@ public static String generateJson(ProjectInfo project, HtmlRenderingSupportImpl
4443
}
4544
}
4645

47-
return gson.toJson(projectNode);
46+
return toJsonObject(projectNode);
47+
}
48+
49+
private static String toJsonObject(Node projectNode) {
50+
return "{" +
51+
toJsonAttr("id", projectNode.id, true) + "," +
52+
toJsonAttr("name", projectNode.name, true) + "," +
53+
toJsonAttr("data", toJsonObject(projectNode.data), false) + "," +
54+
toJsonAttr("children", toJsonArray(projectNode.children), false)
55+
+ "}";
56+
}
57+
58+
private static String toJsonObject(Data projectNodeData) {
59+
return "{" +
60+
toJsonAttr("$area", projectNodeData.$area) + "," +
61+
toJsonAttr("$color", projectNodeData.$color) + "," +
62+
toJsonAttr("path", projectNodeData.path, true) + "," +
63+
toJsonAttr("title", projectNodeData.title, true) +
64+
"}";
65+
}
66+
67+
private static String toJsonAttr(String name, float value) {
68+
return "\"" + name + "\":" + value;
69+
}
70+
71+
private static String toJsonAttr(String name, String value, boolean valueInQuotes) {
72+
if (valueInQuotes) {
73+
return "\"" + name + "\":\"" + StringEscapeUtils.escapeJson(value) + "\"";
74+
} else {
75+
return "\"" + name + "\":" + value;
76+
}
77+
}
78+
79+
private static String toJsonArray(Collection<Node> projectNodes) {
80+
return "[" +
81+
projectNodes
82+
.stream()
83+
.map(RenderTreeMapJsonAction::toJsonObject)
84+
.collect(Collectors.joining(",")) +
85+
"]";
4886
}
4987

5088
private static Node createNode(HtmlRenderingSupportImpl renderSupport, int index, String nodeName,

clover-core/src/main/resources/licenses/GSON-1.3-LICENSE.TXT

Lines changed: 0 additions & 210 deletions
This file was deleted.

0 commit comments

Comments
 (0)