Replace a bunch of Guava stuff with Java APIs (#1305)

This commit is contained in:
modmuss
2025-05-06 15:06:52 +01:00
committed by GitHub
parent 9948092cdb
commit eff00a1c30
11 changed files with 23 additions and 30 deletions

View File

@@ -25,9 +25,9 @@
package net.fabricmc.loom;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.gradle.api.Plugin;
@@ -82,8 +82,8 @@ public class LoomGradlePlugin implements Plugin<PluginAware> {
LibraryLocationLogger.logLibraryVersions();
// Apply default plugins
project.apply(ImmutableMap.of("plugin", "java-library"));
project.apply(ImmutableMap.of("plugin", "eclipse"));
project.apply(Map.of("plugin", "java-library"));
project.apply(Map.of("plugin", "eclipse"));
// Setup extensions
project.getExtensions().create(LoomGradleExtensionAPI.class, "loom", LoomGradleExtensionImpl.class, project, LoomFiles.create(project));

View File

@@ -25,10 +25,10 @@
package net.fabricmc.loom.build.mixin;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.google.common.collect.ImmutableList;
import org.gradle.api.Project;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskProvider;
@@ -41,7 +41,7 @@ public class GroovyApInvoker extends AnnotationProcessorInvoker<GroovyCompile> {
public GroovyApInvoker(Project project) {
super(
project,
ImmutableList.of(),
List.of(),
getInvokerTasks(project),
AnnotationProcessorInvoker.GROOVY);
}

View File

@@ -25,10 +25,10 @@
package net.fabricmc.loom.build.mixin;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.google.common.collect.ImmutableList;
import org.gradle.api.Project;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskProvider;
@@ -42,7 +42,7 @@ public class ScalaApInvoker extends AnnotationProcessorInvoker<ScalaCompile> {
super(
project,
// Scala just uses the java AP configuration afaik. This of course assumes the java AP also gets configured.
ImmutableList.of(),
List.of(),
getInvokerTasks(project),
AnnotationProcessorInvoker.SCALA);
}

View File

@@ -35,7 +35,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.inject.Inject;
import com.google.common.collect.ImmutableMap;
import groovy.util.Node;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
@@ -54,7 +53,7 @@ import net.fabricmc.loom.util.gradle.GradleUtils;
public abstract class MavenPublication implements Runnable {
// ImmutableMap is needed since it guarantees ordering
// (compile must go before runtime, or otherwise dependencies might get the "weaker" runtime scope).
private static final Map<String, String> CONFIGURATION_TO_SCOPE = ImmutableMap.of(
private static final Map<String, String> CONFIGURATION_TO_SCOPE = Map.of(
JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME, "compile",
JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME, "runtime"
);

View File

@@ -38,7 +38,6 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import com.google.common.collect.ImmutableMap;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.FileCollectionDependency;
@@ -103,7 +102,7 @@ public class ModConfigurationRemapper {
for (RemapConfigurationSettings entry : remapConfigurationSettings) {
// key: true if runtime, false if compile
final Map<Boolean, Boolean> envToEnabled = ImmutableMap.of(
final Map<Boolean, Boolean> envToEnabled = Map.of(
false, entry.getOnCompileClasspath().get(),
true, entry.getOnRuntimeClasspath().get()
);

View File

@@ -37,8 +37,6 @@ import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.stream.Stream;
import com.google.common.collect.Sets;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.FileSystemUtil;
@@ -79,7 +77,7 @@ public class MinecraftJarSplitter implements AutoCloseable {
}
private Set<String> getJarEntries(Path input) throws IOException {
Set<String> entries = Sets.newHashSet();
Set<String> entries = new HashSet<>();
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(input);
Stream<Path> walk = Files.walk(fs.get().getPath("/"))) {
@@ -154,17 +152,17 @@ public class MinecraftJarSplitter implements AutoCloseable {
this.clientEntries = clientEntries;
this.serverEntries = serverEntries;
this.commonEntries = Sets.newHashSet(clientEntries);
this.commonEntries = new HashSet<>(clientEntries);
this.commonEntries.retainAll(serverEntries);
this.commonEntries.addAll(sharedEntries);
this.commonEntries.removeAll(forcedClientEntries);
this.clientOnlyEntries = Sets.newHashSet(clientEntries);
this.clientOnlyEntries = new HashSet<>(clientEntries);
this.clientOnlyEntries.removeAll(serverEntries);
this.clientOnlyEntries.addAll(sharedEntries);
this.clientOnlyEntries.addAll(forcedClientEntries);
this.serverOnlyEntries = Sets.newHashSet(serverEntries);
this.serverOnlyEntries = new HashSet<>(serverEntries);
this.serverOnlyEntries.removeAll(clientEntries);
}
}

View File

@@ -28,10 +28,10 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.function.Function;
import javax.inject.Inject;
import com.google.common.base.Function;
import org.gradle.api.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -29,8 +29,8 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.mercury.Mercury;
import org.cadixdev.mercury.remapper.MercuryRemapper;
@@ -174,7 +174,7 @@ public class MigrateMappingsService extends Service<MigrateMappingsService.Optio
}
} catch (IllegalDependencyNotation ignored) {
LOGGER.info("Could not locate mappings, presuming V2 Yarn");
return project.getConfigurations().detachedConfiguration(project.getDependencies().create(ImmutableMap.of("group", "net.fabricmc", "name", "yarn", "version", mappings, "classifier", "v2")));
return project.getConfigurations().detachedConfiguration(project.getDependencies().create(Map.of("group", "net.fabricmc", "name", "yarn", "version", mappings, "classifier", "v2")));
} catch (IOException e) {
throw new UncheckedIOException("Failed to resolve mappings", e);
}

View File

@@ -112,7 +112,7 @@ public class SourceRemapper {
source = new File(destination.getAbsolutePath().substring(0, destination.getAbsolutePath().lastIndexOf('.')) + "-dev.jar");
try {
com.google.common.io.Files.move(destination, source);
Files.move(destination.toPath(), source.toPath());
} catch (IOException e) {
throw new RuntimeException("Could not rename " + destination.getName() + "!", e);
}

View File

@@ -30,7 +30,6 @@ import java.util.Map;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import com.google.common.collect.ImmutableMap;
import org.gradle.api.Project;
import net.fabricmc.loom.LoomGradleExtension;
@@ -46,11 +45,11 @@ import net.fabricmc.tinyremapper.TinyRemapper;
* Contains shortcuts to create tiny remappers using the mappings accessibly to the project.
*/
public final class TinyRemapperHelper {
private static final Map<String, String> JSR_TO_JETBRAINS = new ImmutableMap.Builder<String, String>()
.put("javax/annotation/Nullable", "org/jetbrains/annotations/Nullable")
.put("javax/annotation/Nonnull", "org/jetbrains/annotations/NotNull")
.put("javax/annotation/concurrent/Immutable", "org/jetbrains/annotations/Unmodifiable")
.build();
private static final Map<String, String> JSR_TO_JETBRAINS = Map.of(
"javax/annotation/Nullable", "org/jetbrains/annotations/Nullable",
"javax/annotation/Nonnull", "org/jetbrains/annotations/NotNull",
"javax/annotation/concurrent/Immutable", "org/jetbrains/annotations/Unmodifiable"
);
/**
* Matches the new local variable naming format introduced in 21w37a.

View File

@@ -24,8 +24,6 @@
package net.fabricmc.loom.util.download;
import static com.google.common.io.Files.createParentDirs;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -174,7 +172,7 @@ public final class Download {
}
try {
createParentDirs(output.toFile());
Files.createDirectories(output.getParent());
} catch (IOException e) {
throw error(e, "Failed to create parent directories");
}