allow specifying remapping steps
All checks were successful
Publish to snapshot maven / build (push) Successful in 19s

This commit is contained in:
moehreag 2024-07-06 01:58:48 +02:00
parent 068928ad3d
commit 25fefae245
3 changed files with 27 additions and 11 deletions

View file

@ -8,7 +8,7 @@ plugins {
}
group = "dev.frogmc"
version = "0.0.1-alpha.6"
version = "0.0.1-alpha.7"
repositories {
mavenCentral()

View file

@ -0,0 +1,8 @@
package dev.frogmc.thyroxine;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.commons.Remapper;
public interface RemappingStep {
ClassVisitor run(ClassVisitor previous, Remapper remapper);
}

View file

@ -3,18 +3,21 @@ package dev.frogmc.thyroxine;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import dev.frogmc.thyroxine.api.Mapper;
import dev.frogmc.thyroxine.api.ParameterClassRemapper;
import dev.frogmc.thyroxine.api.data.MappingBundle;
import dev.frogmc.thyroxine.api.data.MappingData;
import dev.frogmc.thyroxine.provider.MojmapProvider;
import dev.frogmc.thyroxine.provider.ParchmentProvider;
import dev.frogmc.thyroxine.api.Mapper;
import dev.frogmc.thyroxine.api.data.MappingData;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
@ -51,6 +54,14 @@ public class Thyroxine {
}
public static void remap(MappingData data, Path inputJar, Path outputJar, boolean skipMetaInf, boolean renameParameters) throws IOException, InterruptedException {
List<RemappingStep> steps = List.of(
ClassRemapper::new,
(cv, mapper) -> renameParameters ? new ParameterClassRemapper(cv, mapper, data) : cv
);
remap(data, inputJar, outputJar, skipMetaInf, steps);
}
public static void remap(MappingData data, Path inputJar, Path outputJar, boolean skipMetaInf, List<RemappingStep> steps) throws IOException, InterruptedException {
Files.deleteIfExists(outputJar);
System.out.println("Remapping...");
@ -88,12 +99,9 @@ public class Thyroxine {
byte[] bytes = Files.readAllBytes(path);
ClassReader reader = new ClassReader(bytes);
ClassWriter writer = new ClassWriter(0);
ClassVisitor remapper = new ClassRemapper(writer, mapper);
ClassVisitor visitor;
if (renameParameters) {
visitor = new ParameterClassRemapper(remapper, mapper, data);
} else {
visitor = remapper;
ClassVisitor visitor = writer;
for (RemappingStep pass : steps) {
visitor = pass.run(visitor, mapper);
}
reader.accept(visitor, 0);