Replace usages of FileSystems.newFileSystem with ZipUtils and FSUtil

This commit is contained in:
Juuz
2022-09-06 21:16:48 +03:00
parent 1f859baf93
commit 1f0a71d895
8 changed files with 16 additions and 44 deletions

View File

@@ -26,15 +26,11 @@ package net.fabricmc.loom.configuration.providers.forge;
import java.io.File;
import java.io.Reader;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.List;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.gradle.api.Project;
@@ -63,10 +59,7 @@ public class ForgeUserdevProvider extends DependencyProvider {
if (!userdevJar.exists() || Files.notExists(configJson) || refreshDeps()) {
File resolved = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve Forge userdev"));
Files.copy(resolved.toPath(), userdevJar.toPath(), StandardCopyOption.REPLACE_EXISTING);
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar:" + resolved.toURI()), ImmutableMap.of("create", false))) {
Files.copy(fs.getPath("config.json"), configJson, StandardCopyOption.REPLACE_EXISTING);
}
Files.write(configJson, ZipUtils.unpack(resolved.toPath(), "config.json"));
}
try (Reader reader = Files.newBufferedReader(configJson)) {

View File

@@ -30,9 +30,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
@@ -54,7 +52,6 @@ import java.util.stream.Stream;
import com.google.common.base.Preconditions;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import de.oceanlabs.mcp.mcinjector.adaptors.ParameterAnnotationFixer;
import dev.architectury.tinyremapper.InputTag;
import dev.architectury.tinyremapper.NonClassCopyMode;
@@ -241,7 +238,7 @@ public class MinecraftPatchedProvider {
logger.info(":fixing parameter annotations for " + jarFile.toAbsolutePath());
Stopwatch stopwatch = Stopwatch.createStarted();
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar:" + jarFile.toUri()), ImmutableMap.of("create", false))) {
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(jarFile, false)) {
ThreadingUtils.TaskCompleter completer = ThreadingUtils.taskCompleter();
for (Path file : (Iterable<? extends Path>) Files.walk(fs.getPath("/"))::iterator) {
@@ -275,7 +272,7 @@ public class MinecraftPatchedProvider {
logger.info(":deleting parameter names for " + jarFile.toAbsolutePath());
Stopwatch stopwatch = Stopwatch.createStarted();
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar:" + jarFile.toUri()), ImmutableMap.of("create", false))) {
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(jarFile, false)) {
ThreadingUtils.TaskCompleter completer = ThreadingUtils.taskCompleter();
Pattern vignetteParameters = Pattern.compile("p_[0-9a-zA-Z]+_(?:[0-9a-zA-Z]+_)?");

View File

@@ -26,18 +26,15 @@ package net.fabricmc.loom.configuration.providers.forge;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import com.google.common.collect.ImmutableMap;
import org.gradle.api.Project;
import net.fabricmc.loom.configuration.DependencyInfo;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.FileSystemUtil;
public class PatchProvider extends DependencyProvider {
public Path clientPatches;
@@ -57,7 +54,7 @@ public class PatchProvider extends DependencyProvider {
Path installerJar = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve Forge installer")).toPath();
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar:" + installerJar.toUri()), ImmutableMap.of("create", false))) {
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(installerJar, false)) {
Files.copy(fs.getPath("data", "client.lzma"), clientPatches, StandardCopyOption.REPLACE_EXISTING);
Files.copy(fs.getPath("data", "server.lzma"), serverPatches, StandardCopyOption.REPLACE_EXISTING);
}

View File

@@ -31,19 +31,14 @@ import java.io.IOException;
import java.io.PrintStream;
import java.io.StringReader;
import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.Map;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.NullOutputStream;
import org.gradle.api.Project;
@@ -56,6 +51,7 @@ import net.fabricmc.loom.configuration.providers.mappings.GradleMappingContext;
import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingLayer;
import net.fabricmc.loom.configuration.providers.mappings.mojmap.MojangMappingsSpec;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.ZipUtils;
import net.fabricmc.loom.util.srg.Tsrg2Utils;
import net.fabricmc.loom.util.srg.Tsrg2Writer;
import net.fabricmc.mappingio.MappingReader;
@@ -83,10 +79,7 @@ public class SrgProvider extends DependencyProvider {
if (!Files.exists(srg) || refreshDeps()) {
Path srgZip = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve srg")).toPath();
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar:" + srgZip.toUri()), ImmutableMap.of("create", false))) {
Files.copy(fs.getPath("config", "joined.tsrg"), srg, StandardCopyOption.REPLACE_EXISTING);
}
Files.write(srg, ZipUtils.unpack(srgZip, "config/joined.tsrg"));
}
try (BufferedReader reader = Files.newBufferedReader(srg)) {

View File

@@ -31,7 +31,6 @@ import java.io.Reader;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
@@ -197,8 +196,8 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
if (Files.notExists(tinyMappings) || minecraftProvider.refreshDeps()) {
storeMappings(project, minecraftProvider, inputJar);
} else {
try (FileSystem fileSystem = FileSystems.newFileSystem(inputJar, (ClassLoader) null)) {
extractExtras(fileSystem);
try (FileSystemUtil.Delegate fileSystem = FileSystemUtil.getJarFileSystem(inputJar, false)) {
extractExtras(fileSystem.get());
}
}
@@ -359,7 +358,7 @@ public class MappingsProviderImpl implements MappingsProvider, SharedService {
}
private boolean isMCP(Path path) throws IOException {
try (FileSystem fs = FileSystems.newFileSystem(path, (ClassLoader) null)) {
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(path, false)) {
return Files.exists(fs.getPath("fields.csv")) && Files.exists(fs.getPath("methods.csv"));
}
}

View File

@@ -26,10 +26,7 @@ package net.fabricmc.loom.util.srg;
import java.io.IOException;
import java.io.StringReader;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
@@ -37,10 +34,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.UnaryOperator;
import com.google.common.collect.ImmutableMap;
import org.gradle.api.logging.Logger;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.FileSystemUtil;
import net.fabricmc.loom.util.function.CollectionUtil;
import net.fabricmc.mappingio.tree.MappingTree;
@@ -51,7 +48,7 @@ import net.fabricmc.mappingio.tree.MappingTree;
*/
public final class AtRemapper {
public static void remap(Logger logger, Path jar, MappingTree mappings) throws IOException {
try (FileSystem fs = FileSystems.newFileSystem(URI.create("jar:" + jar.toUri()), ImmutableMap.of("create", false))) {
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(jar, false)) {
Path atPath = fs.getPath(Constants.Forge.ACCESS_TRANSFORMER_PATH);
if (Files.exists(atPath)) {

View File

@@ -27,10 +27,7 @@ package net.fabricmc.loom.util.srg;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
@@ -40,12 +37,12 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.gradle.api.logging.Logger;
import net.fabricmc.loom.util.FileSystemUtil;
import net.fabricmc.loom.util.function.CollectionUtil;
import net.fabricmc.mappingio.tree.MappingTree;
@@ -58,7 +55,7 @@ public final class CoreModClassRemapper {
private static final Pattern CLASS_NAME_PATTERN = Pattern.compile("^(.*')((?:com\\.mojang\\.|net\\.minecraft\\.)[A-Za-z0-9.-_$]+)('.*)$");
public static void remapJar(Path jar, MappingTree mappings, Logger logger) throws IOException {
try (FileSystem fs = FileSystems.newFileSystem(URI.create("jar:" + jar.toUri()), ImmutableMap.of("create", false))) {
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(jar, false)) {
Path coremodsJsonPath = fs.getPath("META-INF", "coremods.json");
if (Files.notExists(coremodsJsonPath)) {

View File

@@ -28,8 +28,6 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -52,6 +50,7 @@ import org.cadixdev.lorenz.model.MethodMapping;
import org.cadixdev.lorenz.model.TopLevelClassMapping;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.loom.util.FileSystemUtil;
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
@@ -237,7 +236,7 @@ public class MCPReader {
}
}
try (FileSystem fs = FileSystems.newFileSystem(mcpJar, (ClassLoader) null)) {
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(mcpJar, false)) {
Path fields = fs.getPath("fields.csv");
Path methods = fs.getPath("methods.csv");
Path params = fs.getPath("params.csv");