From 38fd83a65167a77248a1490adf1e718a0d8a28f3 Mon Sep 17 00:00:00 2001 From: Lucwousin Date: Sun, 4 Aug 2019 01:10:01 +0200 Subject: [PATCH] deob: print all missing annotations before failing --- .../deob/updater/AnnotationCleaner.java | 61 ++++++++++++++----- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/deobfuscator/src/test/java/net/runelite/deob/updater/AnnotationCleaner.java b/deobfuscator/src/test/java/net/runelite/deob/updater/AnnotationCleaner.java index f2b9d153b4..97c82e6734 100644 --- a/deobfuscator/src/test/java/net/runelite/deob/updater/AnnotationCleaner.java +++ b/deobfuscator/src/test/java/net/runelite/deob/updater/AnnotationCleaner.java @@ -2,6 +2,8 @@ package net.runelite.deob.updater; import com.google.common.base.Strings; import java.io.File; +import java.util.ArrayList; +import java.util.List; import net.runelite.asm.ClassFile; import net.runelite.asm.ClassGroup; import net.runelite.asm.Field; @@ -11,8 +13,6 @@ import net.runelite.deob.Deob; import net.runelite.deob.DeobAnnotations; import net.runelite.deob.DeobTestProperties; import net.runelite.deob.util.JarUtil; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -29,6 +29,7 @@ public class AnnotationCleaner @Test public void checkMappings() throws Exception { + final List missing = new ArrayList<>(); File client = new File(properties.getRsClient()); ClassGroup group = JarUtil.loadJar(client); @@ -38,17 +39,21 @@ public class AnnotationCleaner { continue; } + final String className = c.getClassName(); log.debug("Checking {}", c.toString()); String implementingName = DeobAnnotations.getImplements(c); if (!Strings.isNullOrEmpty(implementingName)) { - assertEquals(c + " implements " + implementingName + " but is called " + c.getClassName(), implementingName, c.getClassName()); + if (!implementingName.equals(className)) + { + missing.add("Implements: " + className + " != " + implementingName); + } } - else + else if (!Deob.isObfuscated(c.getClassName())) { - assertTrue(c + " isn't obfuscated but doesn't have @Implements", Deob.isObfuscated(c.getClassName())); + missing.add("Implements: " + className + " == missing"); } for (Field f : c.getFields()) @@ -60,29 +65,50 @@ public class AnnotationCleaner if (exportedName == null) { - assertTrue("Field " + c.getClassName() + '.' + fieldName + " isn't obfuscated but doesn't have @Export.", Deob.isObfuscated(fieldName) || fieldName.equals(DeobAnnotations.getObfuscatedName(an)) || DeobAnnotations.getObfuscatedName(an) == null); - continue; + if (!Deob.isObfuscated(fieldName) && DeobAnnotations.getObfuscatedName(an) != null) + { + missing.add("Export: (field) " + className + '.' + fieldName + " == missing"); + } + } + else if (!fieldName.equals(exportedName)) + { + missing.add("Export: (field) " + className + '.' + fieldName + " != " + exportedName); } - - assertEquals("Field " + c.getClassName() + '.' + fieldName + " has " + exportedName + " in @Export", fieldName, exportedName); } for (Method m : c.getMethods()) { Annotations an = m.getAnnotations(); - String fieldName = m.getName(); + String methodName = m.getName(); String exportedName = DeobAnnotations.getExportedName(an); if (exportedName == null) { - assertTrue("Method " + c.getClassName() + '.' + fieldName + " isn't obfuscated but doesn't have @Export.", Deob.isObfuscated(fieldName) || fieldName.equals(DeobAnnotations.getObfuscatedName(an)) || DeobAnnotations.getObfuscatedName(an) == null); - continue; + if (!Deob.isObfuscated(methodName) && DeobAnnotations.getObfuscatedName(an) != null) + { + missing.add("Export: (method) " + className + '.' + methodName + " == missing"); + } + } + else if (!methodName.equals(exportedName)) + { + missing.add("Export: (method) " + className + '.' + methodName + " != " + exportedName); } - - assertEquals("Method " + c.getClassName() + '.' + fieldName + " has " + exportedName + " in @Export", fieldName, exportedName); } } + + if (missing.isEmpty()) + { + return; + } + + log.error("{} missing annotations!", missing.size()); + for (String s : missing) + { + log.error(s); + } + + throw new OhNoException(); } @Test @@ -97,4 +123,11 @@ public class AnnotationCleaner JarUtil.saveJar(group, new File("C:/Users/Lucas/Desktop/niec.jar")); } + + private class OhNoException extends Exception + { + private OhNoException() + { + } + } }