diff --git a/build.gradle b/build.gradle index a689a2a2..26942408 100644 --- a/build.gradle +++ b/build.gradle @@ -103,7 +103,7 @@ sourceSets { ap { compileClasspath += main.output ext.languageVersion = 8 - ext.compatibility = '1.6' + ext.compatibility = '1.8' } fernflower { compileClasspath += main.output @@ -177,6 +177,7 @@ dependencies { // Annotation Processor apImplementation "org.ow2.asm:asm-tree:$asmVersion" apImplementation guava + apImplementation gson // Fernflower decompiler fernflowerImplementation 'org.jetbrains:intellij-fernflower:1.0.0.9' diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java b/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java index 1cd2fbad..ad1ffe80 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/TargetMap.java @@ -24,13 +24,14 @@ */ package org.spongepowered.tools.obfuscation; +import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileReader; import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; +import java.io.Reader; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -44,6 +45,7 @@ import org.spongepowered.tools.obfuscation.mirror.TypeHandle; import org.spongepowered.tools.obfuscation.mirror.TypeReference; import com.google.common.io.Files; +import com.google.gson.*; /** * Serialisable map of classes to their associated mixins, used so that we can @@ -52,6 +54,7 @@ import com.google.common.io.Files; public final class TargetMap extends HashMap> { private static final long serialVersionUID = 1L; + private static final Gson GSON = new Gson(); /** * Session ID, used to identify the temp file @@ -203,26 +206,29 @@ public final class TargetMap extends HashMap> * @param temp Set "delete on exit" for the file */ public void write(boolean temp) { - ObjectOutputStream oos = null; - FileOutputStream fout = null; - try { - File sessionFile = TargetMap.getSessionFile(this.sessionId); - if (temp) { - sessionFile.deleteOnExit(); + JsonObject jsonObject = new JsonObject(); + + for (Entry> entry : this.entrySet()) { + final JsonArray array = new JsonArray(); + + for (TypeReference reference : entry.getValue()) { + array.add(new JsonPrimitive(reference.getName())); } - fout = new FileOutputStream(sessionFile, true); - oos = new ObjectOutputStream(fout); - oos.writeObject(this); + + jsonObject.add(entry.getKey().getName(), array); + } + + String json = GSON.toJson(jsonObject); + + File sessionFile = TargetMap.getSessionFile(this.sessionId); + if (temp) { + sessionFile.deleteOnExit(); + } + + try (FileOutputStream outputStream = new FileOutputStream(sessionFile, true)) { + outputStream.write(json.getBytes(StandardCharsets.UTF_8)); } catch (Exception ex) { ex.printStackTrace(); - } finally { - if (oos != null) { - try { - oos.close(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } } } @@ -233,22 +239,21 @@ public final class TargetMap extends HashMap> * @return deserialised map or null if deserialisation failed */ private static TargetMap read(File sessionFile) { - ObjectInputStream objectinputstream = null; - FileInputStream streamIn = null; - try { - streamIn = new FileInputStream(sessionFile); - objectinputstream = new ObjectInputStream(streamIn); - return (TargetMap)objectinputstream.readObject(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (objectinputstream != null) { - try { - objectinputstream .close(); - } catch (IOException ex) { - ex.printStackTrace(); + try (Reader reader = new BufferedReader(new FileReader(sessionFile))) { + final JsonObject jsonObject = GSON.fromJson(reader, JsonObject.class); + final TargetMap targetMap = new TargetMap(); + + for (Entry entry : jsonObject.entrySet()) { + JsonArray array = entry.getValue().getAsJsonArray(); + + for (JsonElement element : array) { + targetMap.addMixin(entry.getKey(), element.getAsString()); } - } + } + + return targetMap; + } catch (Exception ex) { + ex.printStackTrace(); } return null; }