Threading
All checks were successful
Publish to snapshot maven / build (push) Successful in 25s

This commit is contained in:
TheKodeToad 2024-05-13 14:26:53 +01:00
parent 8653453644
commit b1a30431f3
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E

View file

@ -3,7 +3,10 @@ package org.ecorous.esnesnon.mojmap_patcher;
import java.io.IOException; import java.io.IOException;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.*;
import org.ecorous.esnesnon.mojmap_patcher.api.Mapper; import org.ecorous.esnesnon.mojmap_patcher.api.Mapper;
import org.ecorous.esnesnon.mojmap_patcher.api.data.MappingData; import org.ecorous.esnesnon.mojmap_patcher.api.data.MappingData;
@ -15,19 +18,27 @@ import org.objectweb.asm.commons.ClassRemapper;
public class MojMapPatcher { public class MojMapPatcher {
public static void run(String minecraftVersion, Path inputJar, Path outputJar) throws IOException { public static void run(String minecraftVersion, Path inputJar, Path outputJar) throws IOException, InterruptedException {
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse(); MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse();
Mapper mapper = new Mapper(data); Mapper mapper = new Mapper(data);
Files.deleteIfExists(outputJar); Files.deleteIfExists(outputJar);
try (FileSystem inFs = FileSystems.newFileSystem(inputJar); System.out.println("Remapping...");
long startTime = System.currentTimeMillis();
try (ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
FileSystem inFs = FileSystems.newFileSystem(inputJar);
FileSystem outFs = FileSystems.newFileSystem(outputJar, Map.of("create", "true"))) { FileSystem outFs = FileSystems.newFileSystem(outputJar, Map.of("create", "true"))) {
List<Callable<Void>> tasks = new ArrayList<>();
Files.walkFileTree(inFs.getPath("/"), new SimpleFileVisitor<>() { Files.walkFileTree(inFs.getPath("/"), new SimpleFileVisitor<>() {
@Override @Override
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
tasks.add(() -> {
try {
if (path.getFileName().toString().endsWith(".class")) { if (path.getFileName().toString().endsWith(".class")) {
String className = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf(".")); String className = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf("."));
Path result = outFs.getPath(path.toString()).resolveSibling(data.classes().getOrDefault(className, className) + ".class"); Path result = outFs.getPath(path.toString()).resolveSibling(data.classes().getOrDefault(className, className) + ".class");
@ -44,14 +55,24 @@ public class MojMapPatcher {
Files.createDirectories(result.getParent()); Files.createDirectories(result.getParent());
Files.copy(path, result); Files.copy(path, result);
} }
} catch (IOException ex) {
throw new Error(ex);
}
return null;
});
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
}); });
exec.invokeAll(tasks);
System.out.printf("Finished remapping (%.2fs)\n", (System.currentTimeMillis() - startTime) / 1000F);
} }
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException, InterruptedException {
// temporary // temporary
if (args.length != 3) { if (args.length != 3) {
System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar]"); System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar]");