Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ dependencies {
implementation gradleApi()

// libraries
implementation libs.commons.io
implementation libs.gson
implementation libs.guava
implementation libs.bundles.asm

// game handling utils
Expand Down Expand Up @@ -228,13 +226,6 @@ checkstyle {
toolVersion = libs.versions.checkstyle.get()
}

// Workaround https://github.com/gradle/gradle/issues/27035
configurations.checkstyle {
resolutionStrategy.capabilitiesResolution.withCapability("com.google.collections:google-collections") {
select("com.google.guava:guava:0")
}
}

codenarc {
toolVersion = libs.versions.codenarc.get()
configFile = file("codenarc.groovy")
Expand Down
4 changes: 0 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[versions]
kotlin = "2.0.21"
asm = "9.8"
commons-io = "2.15.1"
gson = "2.10.1"
guava = "33.0.0-jre"

stitch = "0.6.2"
tiny-remapper = "0.11.2"
Expand All @@ -28,9 +26,7 @@ asm-commons = { module = "org.ow2.asm:asm-commons", version.ref = "asm" }
asm-tree = { module = "org.ow2.asm:asm-tree", version.ref = "asm" }
asm-util = { module = "org.ow2.asm:asm-util", version.ref = "asm" }

commons-io = { module = "commons-io:commons-io", version.ref = "commons-io" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }

fabric-stitch = { module = "net.fabricmc:stitch", version.ref = "stitch" }
fabric-tiny-remapper = { module = "net.fabricmc:tiny-remapper", version.ref = "tiny-remapper" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
import java.io.Serializable;
import java.util.Map;

import com.google.common.base.Preconditions;
import org.gradle.api.Named;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Property;

import net.fabricmc.loom.util.Check;

public abstract class DecompilerOptions implements Named {
/**
* Class name for to the {@link LoomDecompiler}.
Expand Down Expand Up @@ -75,7 +76,7 @@ public String getFormattedName() {
public record Dto(String className, Map<String, String> options, int maxThreads) implements Serializable { }

public Dto toDto() {
Preconditions.checkArgument(getDecompilerClassName().isPresent(), "No decompiler classname specified for decompiler: " + getName());
Check.require(getDecompilerClassName().isPresent(), "No decompiler classname specified for decompiler: " + getName());
return new Dto(
getDecompilerClassName().get(),
getOptions().get(),
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/fabricmc/loom/build/nesting/JarNester.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.google.common.base.Preconditions;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.gradle.api.UncheckedIOException;
import org.slf4j.Logger;

import net.fabricmc.loom.util.Check;
import net.fabricmc.loom.util.Pair;
import net.fabricmc.loom.util.ZipUtils;
import net.fabricmc.loom.util.fmj.FabricModJsonFactory;
Expand All @@ -50,7 +50,7 @@ public static void nestJars(Collection<File> jars, File modJar, Logger logger) {
return;
}

Preconditions.checkArgument(FabricModJsonFactory.isModJar(modJar), "Cannot nest jars into none mod jar " + modJar.getName());
Check.require(FabricModJsonFactory.isModJar(modJar), "Cannot nest jars into none mod jar " + modJar.getName());

// Ensure deterministic ordering of entries in fabric.mod.json
Collection<File> sortedJars = jars.stream().sorted(Comparator.comparing(File::getName)).toList();
Expand All @@ -73,7 +73,7 @@ public static void nestJars(Collection<File> jars, File modJar, Logger logger) {

for (File file : sortedJars) {
String nestedJarPath = "META-INF/jars/" + file.getName();
Preconditions.checkArgument(FabricModJsonFactory.isModJar(file), "Cannot nest none mod jar: " + file.getName());
Check.require(FabricModJsonFactory.isModJar(file), "Cannot nest none mod jar: " + file.getName());

for (JsonElement nestedJar : nestedJars) {
JsonObject jsonObject = nestedJar.getAsJsonObject();
Expand All @@ -95,7 +95,7 @@ public static void nestJars(Collection<File> jars, File modJar, Logger logger) {
return json;
})));

Preconditions.checkState(count > 0, "Failed to transform fabric.mod.json");
Check.require(count > 0, "Failed to transform fabric.mod.json");
} catch (IOException e) {
throw new java.io.UncheckedIOException("Failed to nest jars into " + modJar.getName(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.Serializable;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand All @@ -38,7 +39,6 @@
import java.util.regex.Pattern;

import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;
import org.gradle.api.artifacts.ArtifactView;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.component.ComponentIdentifier;
Expand All @@ -61,6 +61,7 @@
import net.fabricmc.loom.LoomGradlePlugin;
import net.fabricmc.loom.task.AbstractLoomTask;
import net.fabricmc.loom.util.Checksum;
import net.fabricmc.loom.util.DeletingFileVisitor;
import net.fabricmc.loom.util.ZipReprocessorUtil;
import net.fabricmc.loom.util.fmj.FabricModJsonFactory;

Expand Down Expand Up @@ -88,7 +89,7 @@ void makeNestableJars() {

try {
File targetDir = getOutputDirectory().get().getAsFile();
FileUtils.deleteDirectory(targetDir);
DeletingFileVisitor.deleteDirectory(targetDir.toPath());
targetDir.mkdirs();
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down Expand Up @@ -215,7 +216,7 @@ private static boolean validSemVer(String version) {

private void makeNestableJar(final File input, final File output, final String modJsonFile) {
try {
FileUtils.copyFile(input, output);
Files.copy(input.toPath(), output.toPath());
} catch (IOException e) {
throw new UncheckedIOException("Failed to copy mod file %s".formatted(input), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import com.google.common.collect.Iterables;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.apache.commons.io.FilenameUtils;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
Expand All @@ -64,12 +62,12 @@ private FileDependencyInfo(Project project, Dependency dependency, Configuration
case 0 -> //Don't think Gradle would ever let you do this
throw new IllegalStateException("Empty dependency?");
case 1 -> //Single file dependency
classifierToFile.put("", Iterables.getOnlyElement(files));
classifierToFile.put("", getOnlyElement(files));
default -> { //File collection, try work out the classifiers
List<File> sortedFiles = files.stream().sorted(Comparator.comparing(File::getName, Comparator.comparingInt(String::length))).collect(Collectors.toList());
//First element in sortedFiles is the one with the shortest name, we presume all the others are different classifier types of this
File shortest = sortedFiles.remove(0);
String shortestName = FilenameUtils.removeExtension(shortest.getName()); //name.jar -> name
File shortest = sortedFiles.removeFirst();
String shortestName = removeExtension(shortest); //name.jar -> name

for (File file : sortedFiles) {
if (!file.getName().startsWith(shortestName)) {
Expand All @@ -84,7 +82,7 @@ private FileDependencyInfo(Project project, Dependency dependency, Configuration

for (File file : sortedFiles) {
//Now we just have to work out what classifier type the other files are, this shouldn't even return an empty string
String classifier = FilenameUtils.removeExtension(file.getName()).substring(start);
String classifier = removeExtension(file).substring(start);

//The classifier could well be separated with a dash (thing name.jar and name-sources.jar), we don't want that leading dash
if (classifierToFile.put(classifier.charAt(0) == '-' ? classifier.substring(1) : classifier, file) != null) {
Expand All @@ -104,7 +102,7 @@ private FileDependencyInfo(Project project, Dependency dependency, Configuration
byte[] modJson;

try {
if ("jar".equals(FilenameUtils.getExtension(root.getName())) && (modJson = ZipUtils.unpackNullable(root.toPath(), "fabric.mod.json")) != null) {
if ("jar".equals(getExtension(root)) && (modJson = ZipUtils.unpackNullable(root.toPath(), "fabric.mod.json")) != null) {
//It's a Fabric mod, see how much we can extract out
JsonObject json = new Gson().fromJson(new String(modJson, StandardCharsets.UTF_8), JsonObject.class);

Expand All @@ -121,7 +119,7 @@ private FileDependencyInfo(Project project, Dependency dependency, Configuration
version = json.get("version").getAsString();
} else {
//Not a Fabric mod, just have to make something up
name = FilenameUtils.removeExtension(root.getName());
name = removeExtension(root);
version = "1.0";
}
} catch (IOException e) {
Expand Down Expand Up @@ -150,4 +148,36 @@ public String getResolvedDepString() {
public Set<File> resolve() {
return this.resolvedFiles;
}

private static <T> T getOnlyElement(Set<T> set) {
if (set.size() != 1) {
throw new IllegalArgumentException("Expected exactly one element but got " + set.size());
}

return set.iterator().next();
}

private static String removeExtension(File file) {
String filename = file.getName();
int lastDot = filename.lastIndexOf('.');
int lastSeparator = Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));

if (lastDot > lastSeparator) {
return filename.substring(0, lastDot);
}

return filename;
}

private static String getExtension(File file) {
String filename = file.getName();
int lastDot = filename.lastIndexOf('.');
int lastSeparator = Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));

if (lastDot > lastSeparator && lastDot != filename.length() - 1) {
return filename.substring(lastDot + 1);
}

return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
package net.fabricmc.loom.configuration.providers.mappings;

import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

import javax.inject.Inject;

import com.google.common.net.UrlEscapers;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void provide(Path tinyMappings, @Nullable Project project) throws IOExcep

// Download and extract intermediary
final Path intermediaryJarPath = Files.createTempFile(getName(), ".jar");
final String encodedMcVersion = UrlEscapers.urlFragmentEscaper().escape(getMinecraftVersion().get());
final String encodedMcVersion = URLEncoder.encode(getMinecraftVersion().get(), StandardCharsets.UTF_8);
final String urlRaw = getIntermediaryUrl().get();

if (project != null && urlRaw.equals(LoomGradleExtensionApiImpl.DEFAULT_INTERMEDIARY_URL)) {
Expand Down Expand Up @@ -108,7 +109,7 @@ public void execute(final DependencyArtifact dependencyArtifact) {

@Override
public @NotNull String getName() {
final String encodedMcVersion = UrlEscapers.urlFragmentEscaper().escape(getMinecraftVersion().get());
final String encodedMcVersion = URLEncoder.encode(getMinecraftVersion().get(), StandardCharsets.UTF_8);
final String urlRaw = getIntermediaryUrl().get();

if (!LoomGradleExtensionApiImpl.DEFAULT_INTERMEDIARY_URL.equals(urlRaw)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Collections;
import java.util.function.Supplier;

import com.google.common.base.Suppliers;
import org.gradle.api.Project;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Property;
Expand All @@ -48,6 +47,7 @@
import net.fabricmc.loom.api.mappings.intermediate.IntermediateMappingsProvider;
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftProvider;
import net.fabricmc.loom.util.Lazy;
import net.fabricmc.loom.util.service.Service;
import net.fabricmc.loom.util.service.ServiceFactory;
import net.fabricmc.loom.util.service.ServiceType;
Expand All @@ -68,7 +68,7 @@ public interface Options extends Service.Options {
Property<String> getMinecraftVersion();
}

private final Supplier<MemoryMappingTree> memoryMappingTree = Suppliers.memoize(this::createMemoryMappingTree);
private final Supplier<MemoryMappingTree> memoryMappingTree = Lazy.of(this::createMemoryMappingTree);

public IntermediateMappingsService(Options options, ServiceFactory serviceFactory) {
super(options, serviceFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.nio.file.Path;
import java.util.function.Supplier;

import com.google.common.base.Suppliers;
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileCollection;
Expand All @@ -41,6 +40,7 @@
import org.jetbrains.annotations.Nullable;

import net.fabricmc.loom.util.FileSystemUtil;
import net.fabricmc.loom.util.Lazy;
import net.fabricmc.loom.util.service.Service;
import net.fabricmc.loom.util.service.ServiceFactory;
import net.fabricmc.loom.util.service.ServiceType;
Expand Down Expand Up @@ -80,7 +80,7 @@ public TinyMappingsService(Options options, ServiceFactory serviceFactory) {
super(options, serviceFactory);
}

private final Supplier<MemoryMappingTree> mappingTree = Suppliers.memoize(() -> {
private final Supplier<MemoryMappingTree> mappingTree = Lazy.of(() -> {
Path mappings = getOptions().getMappings().getSingleFile().toPath();

if (getOptions().getZipEntryPath().isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Map;
import java.util.regex.Pattern;

import com.google.common.base.Stopwatch;
import org.jetbrains.annotations.VisibleForTesting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -51,7 +50,7 @@ public final class MappingsMerger {
private static final Logger LOGGER = LoggerFactory.getLogger(MappingsMerger.class);

public static void mergeAndSaveMappings(Path from, Path out, MinecraftProvider minecraftProvider, IntermediateMappingsService intermediateMappingsService) throws IOException {
Stopwatch stopwatch = Stopwatch.createStarted();
long start = System.currentTimeMillis();
LOGGER.info(":merging mappings");

if (minecraftProvider.isLegacySplitOfficialNamespaceVersion()) {
Expand All @@ -60,7 +59,7 @@ public static void mergeAndSaveMappings(Path from, Path out, MinecraftProvider m
mergeAndSaveMappings(from, out, intermediateMappingsService);
}

LOGGER.info(":merged mappings in " + stopwatch.stop());
LOGGER.info(":merged mappings in {}ms", System.currentTimeMillis() - start);
}

@VisibleForTesting
Expand Down
Loading