Merge remote-tracking branch 'FabricMC/exp/0.10' into dev/future

Signed-off-by: shedaniel <daniel@shedaniel.me>

# Conflicts:
#	src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java
#	src/main/java/net/fabricmc/loom/configuration/providers/mappings/GradleMappingContext.java
#	src/main/java/net/fabricmc/loom/configuration/providers/mappings/LayeredMappingsDependency.java
#	src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java
#	src/main/java/net/fabricmc/loom/configuration/providers/minecraft/MinecraftMappedProvider.java
#	src/main/java/net/fabricmc/loom/extension/LoomGradleExtensionApiImpl.java
This commit is contained in:
shedaniel
2021-08-14 14:48:02 +08:00
22 changed files with 213 additions and 365 deletions

View File

@@ -96,13 +96,13 @@ public class LoomRepositoryPlugin implements Plugin<PluginAware> {
repositories.ivy(repo -> {
repo.setUrl(files.getUserCache());
repo.patternLayout(layout -> layout.artifact("[revision]/[artifact]-[revision](-[classifier])(.[ext])"));
repo.patternLayout(layout -> layout.artifact("[revision]/[artifact](-[classifier])(.[ext])"));
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
});
repositories.ivy(repo -> {
repo.setUrl(files.getRootProjectPersistentCache());
repo.patternLayout(layout -> layout.artifact("[revision]/[artifact]-[revision](-[classifier])(.[ext])"));
repo.patternLayout(layout -> layout.artifact("[revision]/[artifact](-[classifier])(.[ext])"));
repo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
});
}

View File

@@ -82,7 +82,7 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
LoomGradleExtension loom = LoomGradleExtension.get(project);
String refmapName = Objects.requireNonNull(MixinApExtension.getMixinInformationContainer(sourceSet)).refmapNameProvider().get();
Map<String, String> args = new HashMap<>() {{
put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, loom.getMappingsProvider().tinyMappings.getCanonicalPath());
put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, loom.getMappingsProvider().tinyMappings.toFile().getCanonicalPath());
put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, loom.getNextMixinMappings().getCanonicalPath());
put(Constants.MixinArguments.OUT_REFMAP_FILE, getRefmapDestination(task, refmapName));
put(Constants.MixinArguments.DEFAULT_OBFUSCATION_ENV, "named:intermediary");

View File

@@ -49,6 +49,7 @@ import org.zeroturnaround.zip.ZipUtil;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.LoomGradlePlugin;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
import net.fabricmc.loom.extension.LoomFiles;
public abstract class DependencyProvider {
@@ -93,6 +94,10 @@ public abstract class DependencyProvider {
return getExtension().getFiles();
}
public MinecraftProvider getMinecraftProvider() {
return getExtension().getMinecraftProvider();
}
public boolean isRefreshDeps() {
return LoomGradlePlugin.refreshDeps;
}

View File

@@ -140,7 +140,7 @@ public class LoomDependencyManager {
SourceRemapper sourceRemapper = new SourceRemapper(project, true);
String platformSuffix = extension.isForge() ? "_forge" : "";
String mappingsKey = mappingsProvider.getMappingsKey() + platformSuffix;
String mappingsIdentifier = mappingsProvider.mappingsIdentifier() + platformSuffix;
if (extension.getInstallerData() == null && !extension.isForge()) {
//If we've not found the installer JSON we've probably skipped remapping Fabric loader, let's go looking
@@ -169,7 +169,7 @@ public class LoomDependencyManager {
}
}
ModCompileRemapper.remapDependencies(project, mappingsKey, extension, sourceRemapper);
ModCompileRemapper.remapDependencies(project, mappingsIdentifier, extension, sourceRemapper);
long start = System.currentTimeMillis();

View File

@@ -68,11 +68,11 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
}
getProject().getDependencies().add(Constants.Configurations.MINECRAFT_NAMED,
getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString(projectMappedClassifier)));
getProject().getDependencies().module("net.minecraft:minecraft-" + projectMappedClassifier + ":" + getMinecraftProvider().minecraftVersion() + "/" + getExtension().getMappingsProvider().mappingsIdentifier()));
}
private void invalidateJars() {
File dir = getJarDirectory(getExtension().getFiles().getUserCache(), projectMappedClassifier);
File dir = projectMappedJar.getParentFile();
if (dir.exists()) {
getProject().getLogger().warn("Invalidating project jars");
@@ -89,7 +89,8 @@ public class MinecraftProcessedProvider extends MinecraftMappedProvider {
public void initFiles(MinecraftProviderImpl minecraftProvider, MappingsProviderImpl mappingsProvider) {
super.initFiles(minecraftProvider, mappingsProvider);
projectMappedJar = new File(getJarDirectory(getExtension().getFiles().getRootProjectPersistentCache(), projectMappedClassifier), "minecraft-" + getJarVersionString(projectMappedClassifier) + ".jar");
projectMappedJar = new File(getDirectories().getRootProjectPersistentCache(), getMinecraftProvider().minecraftVersion() + "/"
+ getExtension().getMappingsProvider().mappingsIdentifier() + "/minecraft-" + projectMappedClassifier + ".jar");
}
@Override

View File

@@ -59,8 +59,8 @@ public class LaunchProvider extends DependencyProvider {
.property("fabric.remapClasspathFile", getRemapClasspathFile().getAbsolutePath())
.property("log4j.configurationFile", getAllLog4JConfigFiles())
.property("client", "java.library.path", getDirectories().getNativesDirectory(getExtension().getMinecraftProvider()).getAbsolutePath())
.property("client", "org.lwjgl.librarypath", getDirectories().getNativesDirectory(getExtension().getMinecraftProvider()).getAbsolutePath())
.property("client", "java.library.path", getExtension().getMinecraftProvider().nativesDir().getAbsolutePath())
.property("client", "org.lwjgl.librarypath", getExtension().getMinecraftProvider().nativesDir().getAbsolutePath())
.argument("client", "--assetIndex")
.argument("client", getExtension().getMinecraftProvider().getVersionInfo().assetIndex().fabricId(getExtension().getMinecraftProvider().minecraftVersion()))

View File

@@ -24,9 +24,21 @@
package net.fabricmc.loom.configuration.providers;
import java.io.File;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftVersionMeta;
public interface MinecraftProvider {
File workingDir();
boolean hasCustomNatives();
File nativesDir();
File dir(String path);
File file(String path);
String minecraftVersion();
MinecraftVersionMeta getVersionInfo();

View File

@@ -54,6 +54,7 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
private MinecraftVersionMeta versionInfo;
private MinecraftLibraryProvider libraryProvider;
private File workingDir;
private File minecraftJson;
public File minecraftClientJar;
public File minecraftServerJar;
@@ -118,10 +119,12 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
}
private void initFiles() {
minecraftJson = new File(getDirectories().getUserCache(), "minecraft-" + minecraftVersion + "-info.json");
minecraftClientJar = new File(getDirectories().getUserCache(), "minecraft-" + minecraftVersion + "-client.jar");
minecraftServerJar = new File(getDirectories().getUserCache(), "minecraft-" + minecraftVersion + "-server.jar");
minecraftMergedJar = new File(getDirectories().getUserCache(), "minecraft-" + minecraftVersion + "-merged.jar");
workingDir = new File(getDirectories().getUserCache(), minecraftVersion);
workingDir.mkdirs();
minecraftJson = file("minecraft-info.json");
minecraftClientJar = file("minecraft-client.jar");
minecraftServerJar = file("minecraft-server.jar");
minecraftMergedJar = file("minecraft-merged.jar");
versionManifestJson = new File(getDirectories().getUserCache(), "version_manifest.json");
experimentalVersionsJson = new File(getDirectories().getUserCache(), "experimental_version_manifest.json");
}
@@ -274,6 +277,37 @@ public class MinecraftProviderImpl extends DependencyProvider implements Minecra
return minecraftMergedJar;
}
@Override
public File workingDir() {
return workingDir;
}
@Override
public boolean hasCustomNatives() {
return getProject().getProperties().get("fabric.loom.natives.dir") != null;
}
@Override
public File nativesDir() {
if (hasCustomNatives()) {
return new File((String) getProject().property("fabric.loom.natives.dir"));
}
return dir("natives");
}
@Override
public File dir(String path) {
File dir = file(path);
dir.mkdirs();
return dir;
}
@Override
public File file(String path) {
return new File(workingDir(), path);
}
@Override
public String minecraftVersion() {
return minecraftVersion;

View File

@@ -80,10 +80,7 @@ public class GradleMappingContext implements MappingContext {
@Override
public File workingDirectory(String name) {
File file = new File(workingDirectory(), name);
file.mkdirs();
return file;
return new File(minecraftProvider().dir("layered/working_dir/" + workingDirName), name);
}
@Override

View File

@@ -63,7 +63,7 @@ public class LayeredMappingsDependency implements SelfResolvingDependency {
@Override
public Set<File> resolve() {
Path mappingsDir = mappingContext.workingDirectory().toPath();
Path mappingsDir = mappingContext.minecraftProvider().dir("layered").toPath();
Path mappingsFile = mappingsDir.resolve(String.format("%s.%s-%s.tiny", GROUP, MODULE, getVersion()));
if (!Files.exists(mappingsFile) || LoomGradlePlugin.refreshDeps) {

View File

@@ -28,7 +28,7 @@ import java.io.File;
import java.nio.file.Path;
public interface MappingsProvider {
Path getMappingsDir();
Path mappingsWorkingDir();
File intermediaryTinyFile();
}

View File

@@ -32,24 +32,16 @@ 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;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import com.google.common.base.Preconditions;
import com.google.common.base.Stopwatch;
import com.google.common.net.UrlEscapers;
import com.google.gson.JsonObject;
import org.apache.commons.io.FileUtils;
import org.apache.tools.ant.util.StringUtils;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.zeroturnaround.zip.FileSource;
import org.zeroturnaround.zip.ZipEntrySource;
import org.zeroturnaround.zip.ZipUtil;
@@ -61,16 +53,10 @@ import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor;
import net.fabricmc.loom.configuration.processors.JarProcessorManager;
import net.fabricmc.loom.configuration.processors.MinecraftProcessedProvider;
import net.fabricmc.loom.configuration.providers.MinecraftProviderImpl;
import net.fabricmc.loom.configuration.providers.forge.MinecraftPatchedProvider;
import net.fabricmc.loom.configuration.providers.forge.SrgProvider;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.DeletingFileVisitor;
import net.fabricmc.loom.util.DownloadUtil;
import net.fabricmc.loom.util.srg.MCPReader;
import net.fabricmc.loom.util.srg.SrgMerger;
import net.fabricmc.loom.util.srg.SrgNamedWriter;
import net.fabricmc.mapping.reader.v2.TinyMetadata;
import net.fabricmc.mapping.reader.v2.TinyV2Factory;
import net.fabricmc.mapping.tree.TinyTree;
import net.fabricmc.mappingio.adapter.MappingNsCompleter;
@@ -80,79 +66,32 @@ import net.fabricmc.mappingio.format.Tiny2Writer;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import net.fabricmc.stitch.Command;
import net.fabricmc.stitch.commands.CommandProposeFieldNames;
import net.fabricmc.stitch.commands.tinyv2.TinyFile;
import net.fabricmc.stitch.commands.tinyv2.TinyV2Writer;
import net.fabricmc.stitch.commands.tinyv2.CommandMergeTinyV2;
import net.fabricmc.stitch.commands.tinyv2.CommandReorderTinyV2;
public class MappingsProviderImpl extends DependencyProvider implements MappingsProvider {
public MinecraftMappedProvider mappedProvider;
public MinecraftPatchedProvider patchedProvider;
public String mappingsName;
public String minecraftVersion;
public String mappingsVersion;
public String removeSuffix;
public String mappingsIdentifier;
protected final Path mappingsDir;
protected Path mappingsVersionedDir;
private final Path mappingsStepsDir;
private Path mappingsWorkingDir;
private Path intermediaryTiny;
private boolean hasRefreshed = false;
// The mappings that gradle gives us
private Path baseTinyMappings;
// The mappings we use in practice
public File tinyMappings;
// tinyMappings wrapped in a jar
public File tinyMappingsJar;
public Path tinyMappingsWithSrg;
public File mixinTinyMappingsWithSrg; // FORGE: The mixin mappings have srg names in intermediary.
public File srgToNamedSrg; // FORGE: srg to named in srg file format
private File unpickDefinitionsFile;
public Path tinyMappings;
public Path tinyMappingsJar;
private Path unpickDefinitions;
private boolean hasUnpickDefinitions;
private UnpickMetadata unpickMetadata;
public MappingsProviderImpl(Project project) {
super(project);
mappingsDir = getDirectories().getUserCache().toPath().resolve("mappings");
mappingsStepsDir = mappingsDir.resolve("steps");
}
public Path getMappingsVersionedDir() throws IOException {
if (mappingsVersionedDir == null) {
mappingsVersionedDir = mappingsDir.resolve(getExtension().getMinecraftProvider().minecraftVersion());
if (!Files.exists(mappingsVersionedDir)) {
Files.createDirectories(mappingsVersionedDir);
}
}
return mappingsVersionedDir;
}
public Path getMappedVersionedDir(String name) throws IOException {
Path dir = getMappingsVersionedDir().resolve(name);
if (!Files.exists(dir)) {
Files.createDirectories(dir);
}
return dir;
}
public void clean() throws IOException {
FileUtils.deleteDirectory(mappingsDir.toFile());
}
public TinyTree getMappings() throws IOException {
return MappingsCache.INSTANCE.get(tinyMappings.toPath());
}
public TinyTree getMappingsWithSrg() throws IOException {
if (getExtension().shouldGenerateSrgTiny()) {
return MappingsCache.INSTANCE.get(tinyMappingsWithSrg);
}
throw new UnsupportedOperationException("Not running with Forge support / Tiny srg support.");
return MappingsCache.INSTANCE.get(tinyMappings);
}
@Override
@@ -164,85 +103,22 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
String version = dependency.getResolvedVersion();
File mappingsJar = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not find yarn mappings: " + dependency));
this.mappingsName = StringUtils.removeSuffix(dependency.getDependency().getGroup() + "." + dependency.getDependency().getName(), "-unmerged");
this.minecraftVersion = minecraftProvider.minecraftVersion();
boolean isV2;
if (isMCP(mappingsJar.toPath())) {
File old = mappingsJar;
mappingsJar = mappingsDir.resolve(StringUtils.removeSuffix(mappingsJar.getName(), ".zip") + "-" + minecraftVersion + ".jar").toFile();
FileUtils.copyFile(old, mappingsJar);
mappingsName += "-" + minecraftVersion;
}
// Only do this for official yarn, there isn't really a way we can get the mc version for all mappings
if (dependency.getDependency().getGroup() != null && dependency.getDependency().getGroup().equals("net.fabricmc") && dependency.getDependency().getName().equals("yarn") && dependency.getDependency().getVersion() != null) {
String yarnVersion = dependency.getDependency().getVersion();
char separator = yarnVersion.contains("+build.") ? '+' : yarnVersion.contains("-") ? '-' : '.';
String yarnMinecraftVersion = yarnVersion.substring(0, yarnVersion.lastIndexOf(separator));
if (!yarnMinecraftVersion.equalsIgnoreCase(minecraftVersion)) {
throw new RuntimeException(String.format("Minecraft Version (%s) does not match yarn's minecraft version (%s)", minecraftVersion, yarnMinecraftVersion));
}
// We can save reading the zip file + header by checking the file name
isV2 = mappingsJar.getName().endsWith("-v2.jar") || mappingsJar.getName().endsWith("-mergedv2.jar");
} else {
isV2 = doesJarContainV2Mappings(mappingsJar.toPath());
}
this.removeSuffix = StringUtils.removeSuffix(mappingsJar.getName(), ".jar");
this.mappingsVersion = version + (isV2 ? "-v2" : "");
String mappingsName = StringUtils.removeSuffix(dependency.getDependency().getGroup() + "." + dependency.getDependency().getName(), "-unmerged");
boolean isV2 = isV2(dependency, mappingsJar);
this.mappingsIdentifier = createMappingsIdentifier(mappingsName, version, getMappingsClassifier(dependency, isV2));
initFiles();
if (isRefreshDeps()) {
cleanFiles();
}
Files.createDirectories(mappingsDir);
Files.createDirectories(mappingsStepsDir);
String[] depStringSplit = dependency.getDepString().split(":");
String jarClassifier = "final";
if (depStringSplit.length >= 4) {
jarClassifier = jarClassifier + depStringSplit[3];
}
Path mappedVersionedDir = getMappedVersionedDir(removeSuffix);
tinyMappings = mappedVersionedDir.resolve("mappings.tiny").toFile();
unpickDefinitionsFile = mappedVersionedDir.resolve("definitions.unpick").toFile();
tinyMappingsJar = new File(getDirectories().getUserCache(), removeSuffix + "-" + jarClassifier + ".jar");
tinyMappingsWithSrg = mappedVersionedDir.resolve("mappings-srg.tiny");
mixinTinyMappingsWithSrg = mappedVersionedDir.resolve("mappings-mixin-srg.tiny").toFile();
srgToNamedSrg = mappedVersionedDir.resolve("mappings-srg-named.srg").toFile();
if (!tinyMappings.exists() || isRefreshDeps()) {
storeMappings(getProject(), minecraftProvider, mappingsJar.toPath(), postPopulationScheduler);
if (Files.notExists(tinyMappings) || isRefreshDeps()) {
storeMappings(getProject(), minecraftProvider, mappingsJar.toPath());
} else {
try (FileSystem fileSystem = FileSystems.newFileSystem(mappingsJar.toPath(), (ClassLoader) null)) {
extractUnpickDefinitions(fileSystem, unpickDefinitionsFile.toPath());
extractUnpickDefinitions(fileSystem, unpickDefinitions);
}
}
if (getExtension().isForge()) {
patchedProvider = new MinecraftPatchedProvider(getProject());
patchedProvider.provide(dependency, postPopulationScheduler);
}
manipulateMappings(mappingsJar.toPath());
if (getExtension().shouldGenerateSrgTiny()) {
if (Files.notExists(tinyMappingsWithSrg) || isRefreshDeps()) {
// Merge tiny mappings with srg
SrgMerger.mergeSrg(getExtension().getSrgProvider().getSrg().toPath(), tinyMappings.toPath(), tinyMappingsWithSrg, true);
}
}
if (!tinyMappingsJar.exists() || isRefreshDeps()) {
ZipUtil.pack(new ZipEntrySource[] {new FileSource("mappings/mappings.tiny", tinyMappings)}, tinyMappingsJar);
if (Files.notExists(tinyMappingsJar) || isRefreshDeps()) {
ZipUtil.pack(new ZipEntrySource[] {new FileSource("mappings/mappings.tiny", tinyMappings.toFile())}, tinyMappingsJar.toFile());
}
if (hasUnpickDefinitions()) {
@@ -256,24 +132,7 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
populateUnpickClasspath();
}
if (getExtension().isForge()) {
if (!getExtension().shouldGenerateSrgTiny()) {
throw new IllegalStateException("We have to generate srg tiny in a forge environment!");
}
if (!mixinTinyMappingsWithSrg.exists() || isRefreshDeps()) {
List<String> lines = new ArrayList<>(Files.readAllLines(tinyMappingsWithSrg));
lines.set(0, lines.get(0).replace("intermediary", "yraidemretni").replace("srg", "intermediary"));
Files.deleteIfExists(mixinTinyMappingsWithSrg.toPath());
Files.write(mixinTinyMappingsWithSrg.toPath(), lines);
}
if (!srgToNamedSrg.exists() || isRefreshDeps()) {
SrgNamedWriter.writeTo(getProject().getLogger(), srgToNamedSrg.toPath(), getMappingsWithSrg(), "srg", "named");
}
}
addDependency(tinyMappingsJar, Constants.Configurations.MAPPINGS_FINAL);
addDependency(tinyMappingsJar.toFile(), Constants.Configurations.MAPPINGS_FINAL);
LoomGradleExtension extension = getExtension();
@@ -287,11 +146,7 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
extension.setJarProcessorManager(processorManager);
processorManager.setupProcessors();
if (extension.isForge()) {
patchedProvider.finishProvide();
}
if (processorManager.active() || (extension.isForge() && patchedProvider.usesProjectCache())) {
if (processorManager.active()) {
mappedProvider = new MinecraftProcessedProvider(getProject(), processorManager);
getProject().getLogger().lifecycle("Using project based jar storage");
} else {
@@ -302,89 +157,66 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
mappedProvider.provide(dependency, postPopulationScheduler);
}
public void manipulateMappings(Path mappingsJar) throws IOException { }
private String getMappingsClassifier(DependencyInfo dependency, boolean isV2) {
String[] depStringSplit = dependency.getDepString().split(":");
private void storeMappings(Project project, MinecraftProviderImpl minecraftProvider, Path yarnJar, Consumer<Runnable> postPopulationScheduler)
throws Exception {
project.getLogger().info(":extracting " + yarnJar.getFileName());
if (isMCP(yarnJar)) {
readAndMergeMCP(yarnJar, postPopulationScheduler);
return;
if (depStringSplit.length >= 4) {
return "-" + depStringSplit[3] + (isV2 ? "-v2" : "");
}
return isV2 ? "-v2" : "";
}
private boolean isV2(DependencyInfo dependency, File mappingsJar) throws IOException {
String minecraftVersion = getMinecraftProvider().minecraftVersion();
// Only do this for official yarn, there isn't really a way we can get the mc version for all mappings
if (dependency.getDependency().getGroup() != null && dependency.getDependency().getGroup().equals("net.fabricmc") && dependency.getDependency().getName().equals("yarn") && dependency.getDependency().getVersion() != null) {
String yarnVersion = dependency.getDependency().getVersion();
char separator = yarnVersion.contains("+build.") ? '+' : yarnVersion.contains("-") ? '-' : '.';
String yarnMinecraftVersion = yarnVersion.substring(0, yarnVersion.lastIndexOf(separator));
if (!yarnMinecraftVersion.equalsIgnoreCase(minecraftVersion)) {
throw new RuntimeException(String.format("Minecraft Version (%s) does not match yarn's minecraft version (%s)", minecraftVersion, yarnMinecraftVersion));
}
// We can save reading the zip file + header by checking the file name
return mappingsJar.getName().endsWith("-v2.jar");
} else {
return doesJarContainV2Mappings(mappingsJar.toPath());
}
}
private void storeMappings(Project project, MinecraftProviderImpl minecraftProvider, Path yarnJar) throws IOException {
project.getLogger().info(":extracting " + yarnJar.getFileName());
try (FileSystem fileSystem = FileSystems.newFileSystem(yarnJar, (ClassLoader) null)) {
extractMappings(fileSystem, baseTinyMappings);
extractUnpickDefinitions(fileSystem, unpickDefinitionsFile.toPath());
extractUnpickDefinitions(fileSystem, unpickDefinitions);
}
if (baseMappingsAreMergedV2()) {
// Architectury Loom Patch
// If a merged tiny v2 mappings file is provided
// Skip merging, should save a lot of time
Files.copy(baseTinyMappings, tinyMappings.toPath(), StandardCopyOption.REPLACE_EXISTING);
} else if (baseMappingsAreV2()) {
if (areMappingsV2(baseTinyMappings)) {
// These are unmerged v2 mappings
mergeAndSaveMappings(project, yarnJar);
mergeAndSaveMappings(project, baseTinyMappings, tinyMappings);
} else {
// These are merged v1 mappings
if (tinyMappings.exists()) {
tinyMappings.delete();
}
Files.deleteIfExists(tinyMappings);
project.getLogger().lifecycle(":populating field names");
suggestFieldNames(minecraftProvider, baseTinyMappings, tinyMappings.toPath());
suggestFieldNames(minecraftProvider, baseTinyMappings, tinyMappings);
}
}
private void readAndMergeMCP(Path mcpJar, Consumer<Runnable> postPopulationScheduler) throws Exception {
Path intermediaryTinyPath = getIntermediaryTiny();
SrgProvider provider = getExtension().getSrgProvider();
if (provider == null) {
if (!getExtension().shouldGenerateSrgTiny()) {
Configuration srg = getProject().getConfigurations().maybeCreate(Constants.Configurations.SRG);
srg.setTransitive(false);
}
provider = new SrgProvider(getProject());
getProject().getDependencies().add(provider.getTargetConfig(), "de.oceanlabs.mcp:mcp_config:" + minecraftVersion);
Configuration configuration = getProject().getConfigurations().getByName(provider.getTargetConfig());
provider.provide(DependencyInfo.create(getProject(), configuration.getDependencies().iterator().next(), configuration), postPopulationScheduler);
}
Path srgPath = provider.getSrg().toPath();
TinyFile file = new MCPReader(intermediaryTinyPath, srgPath).read(mcpJar);
TinyV2Writer.write(file, tinyMappings.toPath());
}
private boolean isMCP(Path path) throws IOException {
try (FileSystem fs = FileSystems.newFileSystem(path, (ClassLoader) null)) {
return Files.exists(fs.getPath("fields.csv")) && Files.exists(fs.getPath("methods.csv"));
}
}
private boolean baseMappingsAreV2() throws IOException {
try (BufferedReader reader = Files.newBufferedReader(baseTinyMappings)) {
private static boolean areMappingsV2(Path path) throws IOException {
try (BufferedReader reader = Files.newBufferedReader(path)) {
TinyV2Factory.readMetadata(reader);
return true;
} catch (IllegalArgumentException | NoSuchFileException e) {
} catch (IllegalArgumentException e) {
// TODO: just check the mappings version when Parser supports V1 in readMetadata()
return false;
}
}
private boolean baseMappingsAreMergedV2() throws IOException {
try (BufferedReader reader = Files.newBufferedReader(baseTinyMappings)) {
TinyMetadata metadata = TinyV2Factory.readMetadata(reader);
return metadata.getNamespaces().containsAll(Arrays.asList("named", "intermediary", "official"));
} catch (IllegalArgumentException | NoSuchFileException e) {
return false;
}
}
private boolean doesJarContainV2Mappings(Path path) throws IOException {
private static boolean doesJarContainV2Mappings(Path path) throws IOException {
try (FileSystem fs = FileSystems.newFileSystem(path, (ClassLoader) null)) {
try (BufferedReader reader = Files.newBufferedReader(fs.getPath("mappings", "mappings.tiny"))) {
TinyV2Factory.readMetadata(reader);
@@ -395,6 +227,12 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
}
}
private static void extractMappings(Path jar, Path extractTo) throws IOException {
try (FileSystem unmergedIntermediaryFs = FileSystems.newFileSystem(jar, (ClassLoader) null)) {
extractMappings(unmergedIntermediaryFs, extractTo);
}
}
public static void extractMappings(FileSystem jar, Path extractTo) throws IOException {
Files.copy(jar.getPath("mappings/mappings.tiny"), extractTo, StandardCopyOption.REPLACE_EXISTING);
}
@@ -433,24 +271,26 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
);
}
private void extractIntermediary(Path intermediaryJar, Path intermediaryTiny) throws IOException {
getProject().getLogger().info(":extracting " + intermediaryJar.getFileName());
try (FileSystem unmergedIntermediaryFs = FileSystems.newFileSystem(intermediaryJar, (ClassLoader) null)) {
extractMappings(unmergedIntermediaryFs, intermediaryTiny);
}
}
private void mergeAndSaveMappings(Project project, Path unmergedYarnJar) throws IOException {
Path unmergedYarn = Paths.get(mappingsStepsDir.toString(), "unmerged-yarn.tiny");
project.getLogger().info(":extracting " + unmergedYarnJar.getFileName());
try (FileSystem unmergedYarnJarFs = FileSystems.newFileSystem(unmergedYarnJar, (ClassLoader) null)) {
extractMappings(unmergedYarnJarFs, unmergedYarn);
}
private void mergeAndSaveMappings(Project project, Path from, Path out) throws IOException {
Stopwatch stopwatch = Stopwatch.createStarted();
project.getLogger().info(":merging mappings");
MemoryMappingTree tree = new MemoryMappingTree();
MappingSourceNsSwitch sourceNsSwitch = new MappingSourceNsSwitch(tree, MappingNamespace.OFFICIAL.stringValue());
readIntermediaryTree().accept(sourceNsSwitch);
try (BufferedReader reader = Files.newBufferedReader(from, StandardCharsets.UTF_8)) {
Tiny2Reader.read(reader, tree);
}
try (Tiny2Writer writer = new Tiny2Writer(Files.newBufferedWriter(out, StandardCharsets.UTF_8), false)) {
tree.accept(writer);
}
project.getLogger().info(":merged mappings in " + stopwatch.stop());
}
private MemoryMappingTree readIntermediaryTree() throws IOException {
MemoryMappingTree tree = new MemoryMappingTree();
MappingNsCompleter nsCompleter = new MappingNsCompleter(tree, Collections.singletonMap(MappingNamespace.NAMED.stringValue(), MappingNamespace.INTERMEDIARY.stringValue()), true);
@@ -458,21 +298,29 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
Tiny2Reader.read(reader, nsCompleter);
}
MemoryMappingTree tempTree = new MemoryMappingTree();
return tree;
}
MappingSourceNsSwitch sourceNsSwitch = new MappingSourceNsSwitch(tempTree, MappingNamespace.OFFICIAL.stringValue());
tree.accept(sourceNsSwitch);
tree = tempTree;
private void reorderMappings(Path oldMappings, Path newMappings, String... newOrder) {
Command command = new CommandReorderTinyV2();
String[] args = new String[2 + newOrder.length];
args[0] = oldMappings.toAbsolutePath().toString();
args[1] = newMappings.toAbsolutePath().toString();
System.arraycopy(newOrder, 0, args, 2, newOrder.length);
runCommand(command, args);
}
try (BufferedReader reader = Files.newBufferedReader(unmergedYarn, StandardCharsets.UTF_8)) {
Tiny2Reader.read(reader, tree);
private void mergeMappings(Path intermediaryMappings, Path yarnMappings, Path newMergedMappings) {
try {
Command command = new CommandMergeTinyV2();
runCommand(command, intermediaryMappings.toAbsolutePath().toString(),
yarnMappings.toAbsolutePath().toString(),
newMergedMappings.toAbsolutePath().toString(),
"intermediary", "official");
} catch (Exception e) {
throw new RuntimeException("Could not merge mappings from " + intermediaryMappings.toString()
+ " with mappings from " + yarnMappings, e);
}
try (Tiny2Writer writer = new Tiny2Writer(Files.newBufferedWriter(tinyMappings.toPath(), StandardCharsets.UTF_8), false)) {
tree.accept(writer);
}
project.getLogger().info(":merged mappings in " + stopwatch.stop());
}
private void suggestFieldNames(MinecraftProviderImpl minecraftProvider, Path oldMappings, Path newMappings) {
@@ -490,30 +338,22 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
}
}
private void initFiles() throws IOException {
baseTinyMappings = getMappedVersionedDir(removeSuffix).resolve("mappings-base.tiny");
private void initFiles() {
mappingsWorkingDir = getMinecraftProvider().dir(mappingsIdentifier).toPath();
baseTinyMappings = mappingsWorkingDir.resolve("mappings-base.tiny");
tinyMappings = mappingsWorkingDir.resolve("mappings.tiny");
tinyMappingsJar = mappingsWorkingDir.resolve("mappings.jar");
unpickDefinitions = mappingsWorkingDir.resolve("mappings.unpick");
if (Files.exists(mappingsStepsDir)) {
Files.walkFileTree(mappingsStepsDir, new DeletingFileVisitor());
if (isRefreshDeps()) {
cleanFiles();
}
}
public void cleanFiles() {
try {
if (Files.exists(mappingsStepsDir)) {
Files.walkFileTree(mappingsStepsDir, new DeletingFileVisitor());
}
if (Files.exists(baseTinyMappings)) {
Files.deleteIfExists(baseTinyMappings);
}
if (tinyMappings != null) {
tinyMappings.delete();
}
if (tinyMappingsJar != null) {
tinyMappingsJar.delete();
if (Files.exists(mappingsWorkingDir)) {
Files.walkFileTree(mappingsWorkingDir, new DeletingFileVisitor());
}
} catch (IOException e) {
e.printStackTrace();
@@ -525,45 +365,42 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings
return Constants.Configurations.MAPPINGS;
}
@Override
public Path getMappingsDir() {
return mappingsDir;
}
public Path getIntermediaryTiny() throws IOException {
if (intermediaryTiny == null) {
minecraftVersion = getExtension().getMinecraftProvider().minecraftVersion();
Preconditions.checkNotNull(minecraftVersion, "Minecraft version cannot be null");
intermediaryTiny = getMinecraftProvider().file("intermediary-v2.tiny").toPath();
intermediaryTiny = mappingsDir.resolve(String.format("intermediary-%s-v2.tiny", minecraftVersion));
if (isRefreshDeps() && !hasRefreshed) {
Files.deleteIfExists(intermediaryTiny);
}
if (!Files.exists(intermediaryTiny)) {
if (!Files.exists(intermediaryTiny) || (isRefreshDeps() && !hasRefreshed)) {
hasRefreshed = true;
intermediaryTiny = getMappingsVersionedDir().resolve("intermediary-v2.tiny");
// Download and extract intermediary
String encodedMinecraftVersion = UrlEscapers.urlFragmentEscaper().escape(minecraftVersion);
String encodedMinecraftVersion = UrlEscapers.urlFragmentEscaper().escape(getMinecraftProvider().minecraftVersion());
String intermediaryArtifactUrl = getExtension().getIntermediaryUrl(encodedMinecraftVersion);
Path intermediaryJar = getMappingsVersionedDir().resolve("intermediary-v2.jar");
DownloadUtil.downloadIfChanged(new URL(intermediaryArtifactUrl), intermediaryJar.toFile(), getProject().getLogger());
extractIntermediary(intermediaryJar, intermediaryTiny);
File intermediaryJar = getMinecraftProvider().file("intermediary-v2.jar");
DownloadUtil.downloadIfChanged(new URL(intermediaryArtifactUrl), intermediaryJar, getProject().getLogger());
extractMappings(intermediaryJar.toPath(), intermediaryTiny);
}
}
return intermediaryTiny;
}
public String getMappingsKey() {
return mappingsName + "." + minecraftVersion.replace(' ', '_').replace('.', '_').replace('-', '_') + "." + mappingsVersion;
@Override
public Path mappingsWorkingDir() {
return mappingsWorkingDir;
}
private String createMappingsIdentifier(String mappingsName, String version, String classifier) {
// mappingsName . mcVersion . version classifier
// Example: net.fabricmc.yarn . 1_16_5 . 1.16.5+build.5 -v2
return mappingsName + "." + getMinecraftProvider().minecraftVersion().replace(' ', '_').replace('.', '_').replace('-', '_') + "." + version + classifier;
}
public String mappingsIdentifier() {
return mappingsIdentifier;
}
public File getUnpickDefinitionsFile() {
return unpickDefinitionsFile;
return unpickDefinitions.toFile();
}
public boolean hasUnpickDefinitions() {

View File

@@ -86,7 +86,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
@Override
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
if (!getExtension().getMappingsProvider().tinyMappings.exists()) {
if (Files.notExists(getExtension().getMappingsProvider().tinyMappings)) {
throw new RuntimeException("mappings file not found");
}
@@ -347,14 +347,14 @@ public class MinecraftMappedProvider extends DependencyProvider {
protected void addDependencies(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) {
getProject().getDependencies().add(Constants.Configurations.MINECRAFT_NAMED,
getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString("mapped")));
getProject().getDependencies().module("net.minecraft:minecraft-mapped:" + getMinecraftProvider().minecraftVersion() + "/" + getExtension().getMappingsProvider().mappingsIdentifier()));
}
public void initFiles(MinecraftProviderImpl minecraftProvider, MappingsProviderImpl mappingsProvider) {
this.minecraftProvider = minecraftProvider;
minecraftIntermediaryJar = new File(getDirectories().getUserCache(), "minecraft-" + getJarVersionString("intermediary") + ".jar");
minecraftIntermediaryJar = new File(getExtension().getMappingsProvider().mappingsWorkingDir().toFile(), "minecraft-intermediary.jar");
minecraftSrgJar = !getExtension().isForge() ? null : new File(getDirectories().getUserCache(), "minecraft-" + getJarVersionString("srg") + ".jar");
minecraftMappedJar = new File(getJarDirectory(getDirectories().getUserCache(), "mapped"), "minecraft-" + getJarVersionString("mapped") + ".jar");
minecraftMappedJar = new File(getExtension().getMappingsProvider().mappingsWorkingDir().toFile(), "minecraft-mapped.jar");
inputJar = getExtension().isForge() ? mappingsProvider.patchedProvider.getMergedJar() : minecraftProvider.getMergedJar();
if (getExtension().isForge()) {
@@ -370,7 +370,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
}
protected String getJarVersionString(String type) {
return String.format("%s-%s-%s-%s%s", minecraftProvider.minecraftVersion(), type, getExtension().getMappingsProvider().mappingsName, getExtension().getMappingsProvider().mappingsVersion, minecraftProvider.getJarSuffix());
return String.format("%s-%s%s", type, getExtension().getMappingsProvider().mappingsIdentifier(), minecraftProvider.getJarSuffix());
}
public File getIntermediaryJar() {
@@ -398,7 +398,7 @@ public class MinecraftMappedProvider extends DependencyProvider {
}
public File getUnpickedJar() {
return new File(getJarDirectory(getDirectories().getUserCache(), "mapped"), "minecraft-" + getJarVersionString("unpicked") + ".jar");
return new File(getExtension().getMappingsProvider().mappingsWorkingDir().toFile(), "minecraft-unpicked.jar");
}
@Override

View File

@@ -51,7 +51,7 @@ public class MinecraftNativesProvider {
this.project = project;
extension = LoomGradleExtension.get(project);
nativesDir = extension.getFiles().getNativesDirectory(extension.getMinecraftProvider());
nativesDir = extension.getMinecraftProvider().nativesDir();
jarStore = extension.getFiles().getNativesJarStore();
}
@@ -60,7 +60,7 @@ public class MinecraftNativesProvider {
}
private void provide() throws IOException {
if (extension.getFiles().hasCustomNatives()) {
if (extension.getMinecraftProvider().hasCustomNatives()) {
if (!nativesDir.exists()) {
throw new RuntimeException("Could no find custom natives directory at " + nativesDir.getAbsolutePath());
}

View File

@@ -29,8 +29,6 @@ import java.io.File;
import org.gradle.api.Project;
import org.gradle.api.initialization.Settings;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
public interface LoomFiles {
static LoomFiles create(Project project) {
return new LoomFilesProjectImpl(project);
@@ -46,8 +44,6 @@ public interface LoomFiles {
File getProjectBuildCache();
File getRemappedModCache();
File getNativesJarStore();
boolean hasCustomNatives();
File getNativesDirectory(MinecraftProvider minecraftProvider);
File getDefaultLog4jConfigFile();
File getDevLauncherConfig();
File getUnpickLoggingConfigFile();

View File

@@ -29,8 +29,6 @@ import java.util.Objects;
import org.gradle.api.Project;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
public final class LoomFilesProjectImpl extends LoomFilesBaseImpl {
private final Project project;
@@ -57,24 +55,4 @@ public final class LoomFilesProjectImpl extends LoomFilesBaseImpl {
protected File getBuildDir() {
return project.getBuildDir();
}
@Override
public boolean hasCustomNatives() {
return project.getProperties().get("fabric.loom.natives.dir") != null;
}
@Override
public File getNativesDirectory(MinecraftProvider minecraftProvider) {
if (hasCustomNatives()) {
return new File((String) project.property("fabric.loom.natives.dir"));
}
File natives = new File(getUserCache(), "natives/" + minecraftProvider.minecraftVersion());
if (!natives.exists()) {
natives.mkdirs();
}
return natives;
}
}

View File

@@ -29,8 +29,6 @@ import java.util.Objects;
import org.gradle.api.initialization.Settings;
import net.fabricmc.loom.configuration.providers.MinecraftProvider;
public class LoomFilesSettingsImpl extends LoomFilesBaseImpl {
private final Settings settings;
@@ -38,16 +36,6 @@ public class LoomFilesSettingsImpl extends LoomFilesBaseImpl {
this.settings = Objects.requireNonNull(settings);
}
@Override
public boolean hasCustomNatives() {
return false;
}
@Override
public File getNativesDirectory(MinecraftProvider minecraftProvider) {
throw new IllegalStateException("You can not access natives directory from setting stage");
}
@Override
protected File getGradleUserHomeDir() {
return settings.getGradle().getGradleUserHomeDir();

View File

@@ -166,7 +166,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder(this);
action.execute(builder);
LayeredMappingSpec builtSpec = builder.build();
return new LayeredMappingsDependency(new GradleMappingContext(getProject()), builtSpec);
return new LayeredMappingsDependency(new GradleMappingContext(getProject(), builtSpec.getVersion().replace("+", "_").replace(".", "_")), builtSpec, builtSpec.getVersion());
}
protected abstract String getMinecraftVersion();

View File

@@ -81,7 +81,7 @@ public class LoomGradleExtensionImpl extends LoomGradleExtensionApiImpl implemen
@Override
public synchronized File getNextMixinMappings() {
File mixinMapping = new File(getFiles().getProjectBuildCache(), "mixin-map-" + getMinecraftProvider().minecraftVersion() + "-" + getMappingsProvider().mappingsVersion + "." + mixinMappings.size() + ".tiny");
File mixinMapping = new File(getFiles().getProjectBuildCache(), "mixin-map-" + getMappingsProvider().mappingsIdentifier() + "." + mixinMappings.size() + ".tiny");
mixinMappings.add(mixinMapping);
return mixinMapping;
}

View File

@@ -63,7 +63,7 @@ public class GenerateSourcesTask extends AbstractLoomTask {
@TaskAction
public void doTask() throws Throwable {
int threads = Runtime.getRuntime().availableProcessors();
Path javaDocs = getExtension().getMappingsProvider().tinyMappings.toPath();
Path javaDocs = getExtension().getMappingsProvider().tinyMappings;
Collection<Path> libraries = getProject().getConfigurations().getByName(Constants.Configurations.MINECRAFT_DEPENDENCIES).getFiles()
.stream().map(File::toPath).collect(Collectors.toSet());