deob: print all missing annotations before failing
This commit is contained in:
@@ -2,6 +2,8 @@ package net.runelite.deob.updater;
|
|||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import net.runelite.asm.ClassFile;
|
import net.runelite.asm.ClassFile;
|
||||||
import net.runelite.asm.ClassGroup;
|
import net.runelite.asm.ClassGroup;
|
||||||
import net.runelite.asm.Field;
|
import net.runelite.asm.Field;
|
||||||
@@ -11,8 +13,6 @@ import net.runelite.deob.Deob;
|
|||||||
import net.runelite.deob.DeobAnnotations;
|
import net.runelite.deob.DeobAnnotations;
|
||||||
import net.runelite.deob.DeobTestProperties;
|
import net.runelite.deob.DeobTestProperties;
|
||||||
import net.runelite.deob.util.JarUtil;
|
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.Ignore;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -29,6 +29,7 @@ public class AnnotationCleaner
|
|||||||
@Test
|
@Test
|
||||||
public void checkMappings() throws Exception
|
public void checkMappings() throws Exception
|
||||||
{
|
{
|
||||||
|
final List<String> missing = new ArrayList<>();
|
||||||
File client = new File(properties.getRsClient());
|
File client = new File(properties.getRsClient());
|
||||||
ClassGroup group = JarUtil.loadJar(client);
|
ClassGroup group = JarUtil.loadJar(client);
|
||||||
|
|
||||||
@@ -38,17 +39,21 @@ public class AnnotationCleaner
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
final String className = c.getClassName();
|
||||||
|
|
||||||
log.debug("Checking {}", c.toString());
|
log.debug("Checking {}", c.toString());
|
||||||
|
|
||||||
String implementingName = DeobAnnotations.getImplements(c);
|
String implementingName = DeobAnnotations.getImplements(c);
|
||||||
if (!Strings.isNullOrEmpty(implementingName))
|
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())
|
for (Field f : c.getFields())
|
||||||
@@ -60,29 +65,50 @@ public class AnnotationCleaner
|
|||||||
|
|
||||||
if (exportedName == null)
|
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);
|
if (!Deob.isObfuscated(fieldName) && DeobAnnotations.getObfuscatedName(an) != null)
|
||||||
continue;
|
{
|
||||||
|
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())
|
for (Method m : c.getMethods())
|
||||||
{
|
{
|
||||||
Annotations an = m.getAnnotations();
|
Annotations an = m.getAnnotations();
|
||||||
|
|
||||||
String fieldName = m.getName();
|
String methodName = m.getName();
|
||||||
String exportedName = DeobAnnotations.getExportedName(an);
|
String exportedName = DeobAnnotations.getExportedName(an);
|
||||||
|
|
||||||
if (exportedName == null)
|
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);
|
if (!Deob.isObfuscated(methodName) && DeobAnnotations.getObfuscatedName(an) != null)
|
||||||
continue;
|
{
|
||||||
|
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
|
@Test
|
||||||
@@ -97,4 +123,11 @@ public class AnnotationCleaner
|
|||||||
|
|
||||||
JarUtil.saveJar(group, new File("C:/Users/Lucas/Desktop/niec.jar"));
|
JarUtil.saveJar(group, new File("C:/Users/Lucas/Desktop/niec.jar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class OhNoException extends Exception
|
||||||
|
{
|
||||||
|
private OhNoException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user