Skip to content

Commit

Permalink
OC-258: replace GSON by custom serializer methods; remove all referen…
Browse files Browse the repository at this point in the history
…ces of GSON (pom.xml, license files, about boxes)
  • Loading branch information
marek-parfianowicz committed Jul 1, 2024
1 parent 0634312 commit 530ab9f
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 266 deletions.
4 changes: 0 additions & 4 deletions clover-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
Expand Down
1 change: 0 additions & 1 deletion clover-core-libs/versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<property name="commons-collections.ver" value="3.2.2"/>
<property name="commons-lang3.ver" value="3.3.2"/>
<property name="fastutil.ver" value="4.4.3"/>
<property name="gson.ver" value="1.3"/>
<property name="itext.ver" value="2.0.1"/> <!-- Don't use higher than 2.1.7. Later are based on GPL! -->
<property name="jcommon.ver" value="1.0.23"/>
<property name="jdom.ver" value="1.0"/>
Expand Down
19 changes: 0 additions & 19 deletions clover-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
Expand Down Expand Up @@ -345,7 +341,6 @@
<include>commons-lang:commons-lang</include>
<include>org.apache.commons:commons-lang3</include>
<include>it.unimi.dsi:fastutil</include>
<include>com.google.code.gson:gson</include>
<include>com.lowagie:itext</include>
<include>org.jfree:jcommon</include>
<include>jdom:jdom</include>
Expand Down Expand Up @@ -409,13 +404,6 @@
<exclude>build.xml</exclude>
</excludes>
</filter>
<filter>
<artifact>com.google.code.gson:gson</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>**/assembly-descriptor.xml</exclude>
</excludes>
</filter>
<filter>
<artifact>org.jfree:jcommon</artifact>
<excludes>
Expand Down Expand Up @@ -449,13 +437,6 @@
<include>antlr.**</include>
</includes>
</relocation>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>clover.com.google.gson</shadedPattern>
<includes>
<include>com.google.gson.**</include>
</includes>
</relocation>
<relocation>
<pattern>com.lowagie</pattern>
<shadedPattern>clover.com.lowagie</shadedPattern>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.openclover.core.reporters.json;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.lang3.StringEscapeUtils;
import org.openclover.core.api.registry.BlockMetrics;
import org.openclover.core.api.registry.ClassInfo;
import org.openclover.core.api.registry.HasMetrics;
Expand All @@ -16,10 +15,10 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

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

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

Expand All @@ -44,7 +43,42 @@ public static String generateJson(ProjectInfo project, HtmlRenderingSupportImpl
}
}

return gson.toJson(projectNode);
return toJsonObject(projectNode);
}

private static String toJsonObject(Node projectNode) {
return "{" +
toJsonAttr("id", projectNode.id) + "," +
toJsonAttr("name", projectNode.name) + "," +
toJsonAttr("data", toJsonObject(projectNode.data)) + "," +
toJsonAttr("children", toJsonArray(projectNode.children))
+ "}";
}

private static String toJsonObject(Data projectNodeData) {
return "{" +
toJsonAttr("$area", projectNodeData.$area) + "," +
toJsonAttr("$color", projectNodeData.$color) + "," +
toJsonAttr("path", projectNodeData.path) + "," +
toJsonAttr("title", projectNodeData.title) +
"}";
}

private static String toJsonAttr(String name, float value) {
return "\"" + name + "\":" + value;
}

private static String toJsonAttr(String name, String value) {
return "\"" + name + "\":\"" + StringEscapeUtils.escapeJson(value) + "\"";
}

private static String toJsonArray(Collection<Node> projectNodes) {
return "[" +
projectNodes
.stream()
.map(RenderTreeMapJsonAction::toJsonObject)
.collect(Collectors.joining(",")) +
"]";
}

private static Node createNode(HtmlRenderingSupportImpl renderSupport, int index, String nodeName,
Expand Down
210 changes: 0 additions & 210 deletions clover-core/src/main/resources/licenses/GSON-1.3-LICENSE.TXT

This file was deleted.

Loading

0 comments on commit 530ab9f

Please sign in to comment.