Skip to content

Commit

Permalink
Swap from jackson to minimal-json. Drops about 2MB of dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
LunNova committed May 18, 2017
1 parent d24e30d commit 196b0d0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ configurations.all {
}

dependencies {
libLoader 'org.codehaus.jackson:jackson-core-lgpl:1.9.13'
libLoader 'org.codehaus.jackson:jackson-mapper-lgpl:1.9.13'
libLoader "com.eclipsesource.minimal-json:minimal-json:0.9.4"
libLoader "org.minimallycorrect.modpatcher:ModPatcher:$mcVersion-SNAPSHOT"
compileOnly 'org.projectlombok:lombok:1.16.16'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.minimallycorrect.tickprofiler.minecraft.profiling;

import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.WriterConfig;
import lombok.val;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import org.codehaus.jackson.map.ObjectMapper;
import org.minimallycorrect.modpatcher.api.UsedByPatch;
import org.minimallycorrect.tickprofiler.Log;
import org.minimallycorrect.tickprofiler.minecraft.TickProfiler;
Expand All @@ -16,6 +20,7 @@
import org.minimallycorrect.tickprofiler.util.stringfillers.StringFiller;

import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.atomic.*;

Expand Down Expand Up @@ -193,14 +198,27 @@ public void writeJSONData(File file) throws IOException {
TableFormatter tf = new TableFormatter(StringFiller.FIXED_WIDTH);
tf.recordTables();
writeData(tf, 20);
ObjectMapper objectMapper = new ObjectMapper();
List<Object> tables = tf.getTables();
long timeProfiled = System.currentTimeMillis() - startTime;
float tps = ticks * 1000f / timeProfiled;
tables.add(0, CollectionsUtil.map(
"TPS", tps
));
objectMapper.writerWithDefaultPrettyPrinter().writeValue(file, tables);
val result = Json.object();
result.add("TPS", tps);
List<List<Map<String, String>>> tables = tf.getTables();
val jsonTable = (JsonArray) Json.array();
for (val table : tables) {
val l = (JsonArray) Json.array();
for (Map<String, String> map : table) {
val o = Json.object();
for (Map.Entry<String, String> entry : map.entrySet()) {
o.add(entry.getKey(), entry.getValue());
}
l.add(o);
}
jsonTable.add(l);
}
result.add("tables", jsonTable);
try (val writer = Files.newBufferedWriter(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
result.writeTo(writer, WriterConfig.PRETTY_PRINT);
}
}

public TableFormatter writeStringData(TableFormatter tf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TableFormatter {
private String headingSplitter = " | ";
private String headingColour = "";
private boolean recordTables = false;
private ArrayList<List<Map<String, String>>> tables;
private List<List<Map<String, String>>> tables;

public TableFormatter(ICommandSender commandSender) {
boolean chat = commandSender instanceof Entity;
Expand Down Expand Up @@ -146,7 +146,7 @@ public void recordTables() {
tables = new ArrayList<>();
}

public List getTables() {
public List<List<Map<String, String>>> getTables() {
return tables;
}
}

0 comments on commit 196b0d0

Please sign in to comment.