From cd202f28045f5c77978c929c8ea5f5fb57d54626 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 1 Jan 2020 19:23:27 +0000 Subject: [PATCH] Revert "Add mixins that target the class as a comment. (#168)" This reverts commit fb3c2c86 --- .../loom/task/fernflower/FernFlowerTask.java | 17 -- .../task/fernflower/ForkedFFExecutor.java | 9 +- .../task/fernflower/TinyJavadocProvider.java | 35 +-- .../loom/util/MixinTargetScanner.java | 216 ------------------ 4 files changed, 3 insertions(+), 274 deletions(-) delete mode 100644 src/main/java/net/fabricmc/loom/util/MixinTargetScanner.java diff --git a/src/main/java/net/fabricmc/loom/task/fernflower/FernFlowerTask.java b/src/main/java/net/fabricmc/loom/task/fernflower/FernFlowerTask.java index 5716657..fa7a2a4 100644 --- a/src/main/java/net/fabricmc/loom/task/fernflower/FernFlowerTask.java +++ b/src/main/java/net/fabricmc/loom/task/fernflower/FernFlowerTask.java @@ -26,8 +26,6 @@ package net.fabricmc.loom.task.fernflower; import static java.text.MessageFormat.format; -import java.io.File; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -35,7 +33,6 @@ import java.util.Map; import java.util.Stack; import java.util.function.Supplier; -import org.apache.commons.io.FileUtils; import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; import org.gradle.api.internal.project.ProjectInternal; import org.gradle.api.logging.LogLevel; @@ -50,9 +47,6 @@ import net.fabricmc.loom.task.AbstractDecompileTask; import net.fabricmc.loom.task.ForkingJavaExecTask; import net.fabricmc.loom.util.ConsumingOutputStream; import net.fabricmc.loom.util.OperatingSystem; -import net.fabricmc.loom.util.Constants; -import net.fabricmc.loom.util.MixinTargetScanner; -import net.fabricmc.loom.util.RemappedConfigurationEntry; /** * Created by covers1624 on 9/02/19. @@ -67,16 +61,6 @@ public class FernFlowerTask extends AbstractDecompileTask implements ForkingJava throw new UnsupportedOperationException("FernFlowerTask requires a 64bit JVM to run due to the memory requirements"); } - MixinTargetScanner mixinTargetScanner = new MixinTargetScanner(getProject()); - - for (RemappedConfigurationEntry modCompileEntry : Constants.MOD_COMPILE_ENTRIES) { - mixinTargetScanner.scan(getProject().getConfigurations().getByName(modCompileEntry.getRemappedConfiguration())); - } - - String mixinTargetJson = mixinTargetScanner.getClassMixinsJson(); - File mixinTargetFile = new File(getExtension().getProjectBuildCache(), "mixin_targets.json"); - FileUtils.writeStringToFile(mixinTargetFile, mixinTargetJson, StandardCharsets.UTF_8); - Map options = new HashMap<>(); options.put(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "1"); options.put(IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1"); @@ -96,7 +80,6 @@ public class FernFlowerTask extends AbstractDecompileTask implements ForkingJava args.add("-t=" + getNumThreads()); args.add("-m=" + getExtension().getMappingsProvider().tinyMappings.getAbsolutePath()); - args.add("-j=" + mixinTargetFile.getAbsolutePath()); //TODO, Decompiler breaks on jemalloc, J9 module-info.class? getLibraries().forEach(f -> args.add("-e=" + f.getAbsolutePath())); diff --git a/src/main/java/net/fabricmc/loom/task/fernflower/ForkedFFExecutor.java b/src/main/java/net/fabricmc/loom/task/fernflower/ForkedFFExecutor.java index 475cfe5..b60de1c 100644 --- a/src/main/java/net/fabricmc/loom/task/fernflower/ForkedFFExecutor.java +++ b/src/main/java/net/fabricmc/loom/task/fernflower/ForkedFFExecutor.java @@ -52,7 +52,6 @@ public class ForkedFFExecutor { File output = null; File lineMap = null; File mappings = null; - File mixins = null; List libraries = new ArrayList<>(); int numThreads = 0; @@ -92,12 +91,6 @@ public class ForkedFFExecutor { } mappings = new File(arg.substring(3)); - } else if (arg.startsWith("-j=")) { - if (mixins != null) { - throw new RuntimeException("Unable to use more than one mixin file."); - } - - mixins = new File(arg.substring(3)); } else if (arg.startsWith("-t=")) { numThreads = Integer.parseInt(arg.substring(3)); } else { @@ -114,7 +107,7 @@ public class ForkedFFExecutor { Objects.requireNonNull(output, "Output not set."); Objects.requireNonNull(mappings, "Mappings not set."); - options.put(IFabricJavadocProvider.PROPERTY_NAME, new TinyJavadocProvider(mappings, mixins)); + options.put(IFabricJavadocProvider.PROPERTY_NAME, new TinyJavadocProvider(mappings)); runFF(options, libraries, input, output, lineMap); } diff --git a/src/main/java/net/fabricmc/loom/task/fernflower/TinyJavadocProvider.java b/src/main/java/net/fabricmc/loom/task/fernflower/TinyJavadocProvider.java index b85af17..0e49d01 100644 --- a/src/main/java/net/fabricmc/loom/task/fernflower/TinyJavadocProvider.java +++ b/src/main/java/net/fabricmc/loom/task/fernflower/TinyJavadocProvider.java @@ -27,14 +27,12 @@ package net.fabricmc.loom.task.fernflower; import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.io.FileUtils; import org.jetbrains.java.decompiler.struct.StructClass; import org.jetbrains.java.decompiler.struct.StructField; import org.jetbrains.java.decompiler.struct.StructMethod; @@ -47,18 +45,15 @@ import net.fabricmc.mapping.tree.ParameterDef; import net.fabricmc.mapping.tree.TinyMappingFactory; import net.fabricmc.mapping.tree.TinyTree; import net.fabricmc.mappings.EntryTriple; -import net.fabricmc.loom.util.MixinTargetScanner; public class TinyJavadocProvider implements IFabricJavadocProvider { private final Map classes = new HashMap<>(); private final Map fields = new HashMap<>(); private final Map methods = new HashMap<>(); - private final Map> mixins; - private final String namespace = "named"; - public TinyJavadocProvider(File tinyFile, File mixinTargetFile) { + public TinyJavadocProvider(File tinyFile) { final TinyTree mappings = readMappings(tinyFile); for (ClassDef classDef : mappings.getClasses()) { @@ -73,38 +68,12 @@ public class TinyJavadocProvider implements IFabricJavadocProvider { methods.put(new EntryTriple(className, methodDef.getName(namespace), methodDef.getDescriptor(namespace)), methodDef); } } - - try { - mixins = MixinTargetScanner.fromJson(FileUtils.readFileToString(mixinTargetFile, StandardCharsets.UTF_8)); - } catch (IOException e) { - throw new RuntimeException("Failed to read mixin target file", e); - } } @Override public String getClassDoc(StructClass structClass) { - StringBuilder comment = new StringBuilder(); ClassDef classDef = classes.get(structClass.qualifiedName); - - if (classDef != null && classDef.getComment() != null) { - comment.append(classDef.getComment()); - } - - if (mixins.containsKey(structClass.qualifiedName)) { - List mixinList = mixins.get(structClass.qualifiedName); - - if (classDef != null && classDef.getComment() != null) { - comment.append("\n"); - } - - comment.append("Mixins:"); - - for (MixinTargetScanner.MixinTargetInfo info : mixinList) { - comment.append(String.format("\n\t%s - {@link %s}", info.getModid(), info.getMixinClass().replaceAll("\\$", "."))); - } - } - - return comment.length() == 0 ? null : comment.toString(); + return classDef != null ? classDef.getComment() : null; } @Override diff --git a/src/main/java/net/fabricmc/loom/util/MixinTargetScanner.java b/src/main/java/net/fabricmc/loom/util/MixinTargetScanner.java deleted file mode 100644 index ec65ad0..0000000 --- a/src/main/java/net/fabricmc/loom/util/MixinTargetScanner.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * This file is part of fabric-loom, licensed under the MIT License (MIT). - * - * Copyright (c) 2016, 2017, 2018 FabricMC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.fabricmc.loom.util; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipFile; - -import com.google.common.reflect.TypeToken; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.apache.commons.io.IOUtils; -import org.gradle.api.Project; -import org.gradle.api.artifacts.Configuration; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.AnnotationNode; -import org.objectweb.asm.tree.ClassNode; - -public class MixinTargetScanner { - private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - - private final Project project; - - private HashMap> classMixins = new HashMap<>(); - private List scannedMods = new ArrayList<>(); - - public MixinTargetScanner(Project project) { - this.project = project; - } - - public void scan(Configuration configuration) { - Set filesToScan = configuration.getResolvedConfiguration().getFiles(); - filesToScan.forEach(this::scanFile); - } - - private void scanFile(File file) { - try (ZipFile zipFile = new ZipFile(file)) { - ZipEntry modJsonEntry = zipFile.getEntry("fabric.mod.json"); - - if (modJsonEntry != null) { - try (InputStream is = zipFile.getInputStream(modJsonEntry)) { - JsonObject jsonObject = GSON.fromJson(new InputStreamReader(is), JsonObject.class); - scanMod(zipFile, jsonObject); - } - } else { - project.getLogger().lifecycle("Could not find mod json in " + file.getName()); - } - } catch (ZipException e) { - // Ignore this, most likely an invalid zip - } catch (IOException e) { - throw new RuntimeException("Failed to scan zip file ", e); - } - } - - private void scanMod(ZipFile zipFile, JsonObject modInfo) throws IOException { - if (!modInfo.has("mixins")) return; - - JsonArray mixinsJsonArray = modInfo.getAsJsonArray("mixins"); - String modId = modInfo.get("id").getAsString(); - List mixins = new ArrayList<>(); - List mixinClasses = new ArrayList<>(); - - //Make sure we dont scan the same mod twice, I dont think this is possible just want to be sure - if (scannedMods.contains(modId)) return; - scannedMods.add(modId); - - for (int i = 0; i < mixinsJsonArray.size(); i++) { - mixins.add(mixinsJsonArray.get(i).getAsString()); - } - - //Find all the mixins in the jar - for (String mixin : mixins) { - ZipEntry mixinZipEntry = zipFile.getEntry(mixin); - if (mixinZipEntry == null) continue; - - try (InputStream is = zipFile.getInputStream(mixinZipEntry)) { - JsonObject jsonObject = GSON.fromJson(new InputStreamReader(is), JsonObject.class); - readMixinClasses(jsonObject, mixinClasses); - } - } - - for (String mixinClass : mixinClasses) { - ZipEntry mixinZipEntry = zipFile.getEntry(mixinClass.replaceAll("\\.", "/") + ".class"); - - if (mixinZipEntry == null) { - project.getLogger().info("Failed to find mixin class: " + mixinClass); - continue; - } - - try (InputStream is = zipFile.getInputStream(mixinZipEntry)) { - byte[] classBytes = IOUtils.toByteArray(is); - List mixinTargets = readMixinClass(classBytes); - - for (String mixinTarget : mixinTargets) { - classMixins.computeIfAbsent(mixinTarget, s -> new ArrayList<>()) - .add(new MixinTargetInfo(mixinClass, modId)); - } - } - } - } - - private void readMixinClasses(JsonObject jsonObject, List mixinClasses) { - String[] sides = new String[]{"mixins", "client", "server"}; - - if (!jsonObject.has("package")) return; - String mixinPackage = jsonObject.getAsJsonPrimitive("package").getAsString(); - - for (String side : sides) { - if (!jsonObject.has(side)) continue; - JsonArray jsonArray = jsonObject.getAsJsonArray(side); - - for (int i = 0; i < jsonArray.size(); i++) { - String mixinClass = jsonArray.get(i).getAsString(); - - mixinClasses.add(String.format("%s.%s", mixinPackage, mixinClass)); - } - } - } - - private List readMixinClass(byte[] bytes) { - ClassNode classNode = new ClassNode(); - ClassReader classReader = new ClassReader(bytes); - classReader.accept(classNode, 0); - - if (classNode.invisibleAnnotations == null) return Collections.emptyList(); - - List mixinTargets = new ArrayList<>(); - - for (AnnotationNode annotationNode : classNode.invisibleAnnotations) { - if (annotationNode.desc.equals("Lorg/spongepowered/asm/mixin/Mixin;")) { - List values = annotationNode.values; - - for (int i = 0; i < values.size(); i++) { - if (values.get(i).equals("value")) { - //noinspection unchecked - List types = (List) values.get(i + 1); - - for (Type type : types) { - mixinTargets.add(type.getInternalName()); - } - } - } - - break; - } - } - - return mixinTargets; - } - - public Map> getClassMixins() { - return classMixins; - } - - public String getClassMixinsJson() { - return GSON.toJson(getClassMixins()); - } - - public static Map> fromJson(String input) { - return GSON.fromJson(input, new TypeToken>>() { - }.getType()); - } - - public static class MixinTargetInfo { - private final String mixinClass; - private final String modid; - - public MixinTargetInfo(String mixinClass, String modid) { - this.mixinClass = mixinClass; - this.modid = modid; - } - - public String getMixinClass() { - return mixinClass; - } - - public String getModid() { - return modid; - } - } -}