diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsJsonWriter.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsJsonWriter.java | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsJsonWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsJsonWriter.java deleted file mode 100644 index db95322..0000000 --- a/src/main/java/cuchaz/enigma/mapping/MappingsJsonWriter.java +++ /dev/null | |||
| @@ -1,101 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.mapping; | ||
| 12 | |||
| 13 | import com.google.common.base.Charsets; | ||
| 14 | import com.google.gson.Gson; | ||
| 15 | import com.google.gson.GsonBuilder; | ||
| 16 | |||
| 17 | import java.io.*; | ||
| 18 | import java.util.ArrayList; | ||
| 19 | import java.util.Collections; | ||
| 20 | import java.util.List; | ||
| 21 | |||
| 22 | import cuchaz.enigma.json.*; | ||
| 23 | |||
| 24 | public class MappingsJsonWriter { | ||
| 25 | |||
| 26 | public void write(File file, Mappings mappings) throws IOException { | ||
| 27 | if (!file.isDirectory()) { | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | String[] entries = file.list(); | ||
| 32 | for (String s : entries) { | ||
| 33 | File currentFile = new File(file.getPath(), s); | ||
| 34 | deleteDirectory(currentFile); | ||
| 35 | } | ||
| 36 | |||
| 37 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); | ||
| 38 | for (ClassMapping classMapping : sorted(mappings.classes())) { | ||
| 39 | if (classMapping.getDeobfName() != null && !classMapping.getDeobfName().equalsIgnoreCase("") && !classMapping.getDeobfName().equalsIgnoreCase("null")) { | ||
| 40 | JsonClass jsonClass = new JsonClass(classMapping.getObfSimpleName(), classMapping.getDeobfName()); | ||
| 41 | write(jsonClass, classMapping); | ||
| 42 | |||
| 43 | File f = new File(file, jsonClass.getName() + ".json"); | ||
| 44 | f.getParentFile().mkdirs(); | ||
| 45 | f.createNewFile(); | ||
| 46 | PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(f), Charsets.UTF_8)); | ||
| 47 | writer.write(gson.toJson(jsonClass)); | ||
| 48 | writer.close(); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | private void write(JsonClass jsonClass, ClassMapping classMapping) { | ||
| 54 | for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { | ||
| 55 | JsonClass innerClass = new JsonClass(classMapping.getObfSimpleName() + "$" + innerClassMapping.getObfSimpleName().replace("nome/", ""), innerClassMapping.getDeobfName()); | ||
| 56 | write(innerClass, innerClassMapping); | ||
| 57 | jsonClass.addInnerClass(innerClass); | ||
| 58 | } | ||
| 59 | |||
| 60 | for (FieldMapping fieldMapping : sorted(classMapping.fields())) { | ||
| 61 | jsonClass.addField(new JsonField(fieldMapping.getObfName(), fieldMapping.getDeobfName(), fieldMapping.getObfType().toString())); | ||
| 62 | } | ||
| 63 | |||
| 64 | for (MethodMapping methodMapping : sorted(classMapping.methods())) { | ||
| 65 | List<JsonArgument> args = new ArrayList<>(); | ||
| 66 | for (ArgumentMapping argumentMapping : sorted(methodMapping.arguments())) { | ||
| 67 | args.add(new JsonArgument(argumentMapping.getIndex(), argumentMapping.getName())); | ||
| 68 | } | ||
| 69 | if (methodMapping.getObfName().contains("<init>") || methodMapping.getObfName().contains("<clinit>")) { | ||
| 70 | jsonClass.addConstructor(new JsonConstructor(methodMapping.getObfSignature().toString(), args, methodMapping.getObfName().contains("<clinit>"))); | ||
| 71 | } else { | ||
| 72 | jsonClass.addMethod(new JsonMethod(methodMapping.getObfName(), methodMapping.getDeobfName(), methodMapping.getObfSignature().toString(), args)); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | private <T extends Comparable<T>> List<T> sorted(Iterable<T> classes) { | ||
| 78 | List<T> out = new ArrayList<>(); | ||
| 79 | for (T t : classes) { | ||
| 80 | out.add(t); | ||
| 81 | } | ||
| 82 | Collections.sort(out); | ||
| 83 | return out; | ||
| 84 | } | ||
| 85 | |||
| 86 | public static boolean deleteDirectory(File directory) { | ||
| 87 | if (directory.exists()) { | ||
| 88 | File[] files = directory.listFiles(); | ||
| 89 | if (null != files) { | ||
| 90 | for (int i = 0; i < files.length; i++) { | ||
| 91 | if (files[i].isDirectory()) { | ||
| 92 | deleteDirectory(files[i]); | ||
| 93 | } else { | ||
| 94 | files[i].delete(); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | return (directory.delete()); | ||
| 100 | } | ||
| 101 | } | ||