allow stand-alone remapper creation
All checks were successful
Publish to snapshot maven / build (push) Successful in 52s
All checks were successful
Publish to snapshot maven / build (push) Successful in 52s
This commit is contained in:
parent
e08ed69730
commit
f5f4cb1d4f
|
@ -8,7 +8,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "dev.frogmc"
|
||||
version = "0.0.1-alpha.17"
|
||||
version = "0.0.1-alpha.18"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
@ -3,10 +3,7 @@ package dev.frogmc.thyroxine;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -25,6 +22,7 @@ import org.objectweb.asm.ClassReader;
|
|||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.commons.ClassRemapper;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
|
||||
public class Thyroxine {
|
||||
|
||||
|
@ -32,8 +30,9 @@ public class Thyroxine {
|
|||
|
||||
public static void run(String minecraftVersion, Path inputJar, Path outputJar, boolean skipMetaInf, boolean renameParameters) throws IOException, InterruptedException {
|
||||
Path out = outputJar.toAbsolutePath();
|
||||
MappingBundle data = MojmapProvider.get(minecraftVersion, "client",
|
||||
out.resolveSibling("client-" + minecraftVersion + ".txt")).reverse();
|
||||
MappingBundle data = MojmapProvider.get(minecraftVersion,
|
||||
out.resolveSibling("client-" + minecraftVersion + ".txt"),
|
||||
out.resolveSibling("server-" + minecraftVersion + ".txt")).reverse();
|
||||
|
||||
MappingBundle parchment = null;
|
||||
if (renameParameters) {
|
||||
|
@ -81,17 +80,15 @@ public class Thyroxine {
|
|||
FileSystem inFs = FileSystems.newFileSystem(inputJar);
|
||||
FileSystem outFs = FileSystems.newFileSystem(outputJar, Map.of("create", "true"))) {
|
||||
List<Callable<Void>> tasks = new ArrayList<>();
|
||||
FileSystem[] contexts = new FileSystem[context.length+1];
|
||||
contexts[0] = inFs;
|
||||
for (int i = 0, contextLength = context.length; i < contextLength; i++) {
|
||||
Path path = context[i];
|
||||
contexts[i+1] = FileSystems.newFileSystem(path);
|
||||
Map<Path, FileSystem> contexts = new HashMap<>(context.length + 1);
|
||||
contexts.put(inputJar, inFs);
|
||||
for (Path p : context) {
|
||||
if (!contexts.containsKey(p)) {
|
||||
contexts.put(p, FileSystems.newFileSystem(p));
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, List<String>> lazyParents = new ConcurrentHashMap<>();
|
||||
MappingData reverseData = data.reverse();
|
||||
Mapper mapper = new Mapper(data, className -> lazyParents.computeIfAbsent(className, ignored ->
|
||||
computeInheritances(className, reverseData, contexts)));
|
||||
Remapper mapper = createMapper(data, contexts.values());
|
||||
|
||||
Files.walkFileTree(inFs.getPath("/"), new SimpleFileVisitor<>() {
|
||||
|
||||
|
@ -143,7 +140,7 @@ public class Thyroxine {
|
|||
|
||||
exec.invokeAll(tasks);
|
||||
|
||||
for (FileSystem fs : contexts) {
|
||||
for (FileSystem fs : contexts.values()) {
|
||||
fs.close();
|
||||
}
|
||||
|
||||
|
@ -153,6 +150,13 @@ public class Thyroxine {
|
|||
}
|
||||
}
|
||||
|
||||
public static Remapper createMapper(MappingData data, Collection<FileSystem> contexts) {
|
||||
Map<String, List<String>> lazyParents = new ConcurrentHashMap<>();
|
||||
MappingData reverseData = data.reverse();
|
||||
return new Mapper(data, className -> lazyParents.computeIfAbsent(className, ignored ->
|
||||
computeInheritances(className, reverseData, contexts)));
|
||||
}
|
||||
|
||||
public static MappingBundle parse(Path mappings) throws IOException {
|
||||
String data = Files.readString(mappings);
|
||||
String header = data.split("\n", 2)[0];
|
||||
|
@ -190,7 +194,7 @@ public class Thyroxine {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static List<String> computeInheritances(String className, MappingData reverse, FileSystem... jars) {
|
||||
private static List<String> computeInheritances(String className, MappingData reverse, Collection<FileSystem> jars) {
|
||||
try {
|
||||
if (reverse.classes().containsKey(className)) {
|
||||
className = reverse.classes().get(className);
|
||||
|
|
Loading…
Reference in a new issue