aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net/fabricmc/loom/task
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/fabricmc/loom/task')
-rw-r--r--src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java36
-rw-r--r--src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java33
-rw-r--r--src/main/java/net/fabricmc/loom/task/RemapJarTask.java19
-rw-r--r--src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java3
4 files changed, 60 insertions, 31 deletions
diff --git a/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java b/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java
index c8dbb0ef..e644cb31 100644
--- a/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java
+++ b/src/main/java/net/fabricmc/loom/task/GenerateSourcesTask.java
@@ -30,6 +30,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Collection;
+import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
@@ -42,6 +43,8 @@ import org.gradle.api.tasks.TaskAction;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.decompilers.DecompilationMetadata;
import net.fabricmc.loom.api.decompilers.LoomDecompiler;
+import net.fabricmc.loom.configuration.accesswidener.AccessWidenerFile;
+import net.fabricmc.loom.configuration.accesswidener.TransitiveAccessWidenerMappingsProcessor;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.decompilers.LineNumberRemapper;
import net.fabricmc.loom.util.Constants;
@@ -63,11 +66,10 @@ public class GenerateSourcesTask extends AbstractLoomTask {
@TaskAction
public void doTask() throws Throwable {
int threads = Runtime.getRuntime().availableProcessors();
- Path javaDocs = getExtension().getMappingsProvider().tinyMappings;
Collection<Path> libraries = getProject().getConfigurations().getByName(Constants.Configurations.MINECRAFT_DEPENDENCIES).getFiles()
- .stream().map(File::toPath).collect(Collectors.toSet());
+ .stream().map(File::toPath).collect(Collectors.toSet());
- DecompilationMetadata metadata = new DecompilationMetadata(threads, javaDocs, libraries);
+ DecompilationMetadata metadata = new DecompilationMetadata(threads, getMappings(), libraries);
Path runtimeJar = getExtension().getMappingsProvider().mappedProvider.getMappedJar().toPath();
Path sourcesDestination = getMappedJarFileWithSuffix("-sources.jar").toPath();
Path linemap = getMappedJarFileWithSuffix("-sources.lmap").toPath();
@@ -93,7 +95,7 @@ public class GenerateSourcesTask extends AbstractLoomTask {
progressLogger.start("Adjusting line numbers", "linemap");
try (StitchUtil.FileSystemDelegate inFs = StitchUtil.getJarFileSystem(oldCompiledJar.toFile(), true);
- StitchUtil.FileSystemDelegate outFs = StitchUtil.getJarFileSystem(linemappedJarDestination.toFile(), true)) {
+ StitchUtil.FileSystemDelegate outFs = StitchUtil.getJarFileSystem(linemappedJarDestination.toFile(), true)) {
remapper.process(progressLogger, inFs.get().getPath("/"), outFs.get().getPath("/"));
}
@@ -121,6 +123,32 @@ public class GenerateSourcesTask extends AbstractLoomTask {
return new File(path.substring(0, path.length() - 4) + suffix);
}
+ private Path getMappings() {
+ Path baseMappings = getExtension().getMappingsProvider().tinyMappings;
+
+ if (getExtension().getEnableTransitiveAccessWideners().get()) {
+ List<AccessWidenerFile> accessWideners = getExtension().getTransitiveAccessWideners();
+
+ if (accessWideners.isEmpty()) {
+ return baseMappings;
+ }
+
+ Path outputMappings;
+
+ try {
+ outputMappings = Files.createTempFile("loom-transitive-mappings", ".tiny");
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to create temp file", e);
+ }
+
+ TransitiveAccessWidenerMappingsProcessor.process(baseMappings, outputMappings, accessWideners, getProject().getLogger());
+
+ return outputMappings;
+ }
+
+ return baseMappings;
+ }
+
@InputFile
public File getInputJar() {
return inputJar;
diff --git a/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java b/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java
index 84cee1c9..f7181637 100644
--- a/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java
+++ b/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java
@@ -24,14 +24,12 @@
package net.fabricmc.loom.task;
-import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
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.Set;
import com.google.common.collect.ImmutableMap;
@@ -49,14 +47,15 @@ import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.options.Option;
import net.fabricmc.loom.LoomGradleExtension;
+import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
+import net.fabricmc.loom.api.mappings.layered.spec.LayeredMappingSpecBuilder;
+import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsDependency;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider;
-import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingSpecBuilder;
-import net.fabricmc.loom.configuration.providers.mappings.LayeredMappingsDependency;
import net.fabricmc.loom.util.SourceRemapper;
import net.fabricmc.lorenztiny.TinyMappingsJoiner;
-import net.fabricmc.mapping.tree.TinyMappingFactory;
-import net.fabricmc.mapping.tree.TinyTree;
+import net.fabricmc.mappingio.MappingReader;
+import net.fabricmc.mappingio.tree.MemoryMappingTree;
public class MigrateMappingsTask extends AbstractLoomTask {
private Path inputDir;
@@ -100,8 +99,8 @@ public class MigrateMappingsTask extends AbstractLoomTask {
MappingsProviderImpl mappingsProvider = extension.getMappingsProvider();
try {
- TinyTree currentMappings = mappingsProvider.getMappings();
- TinyTree targetMappings = getMappings(mappings);
+ MemoryMappingTree currentMappings = mappingsProvider.getMappings();
+ MemoryMappingTree targetMappings = getMappings(mappings);
migrateMappings(project, extension, extension.getMinecraftMappedProvider(), inputDir, outputDir, currentMappings, targetMappings);
project.getLogger().lifecycle(":remapped project written to " + outputDir.toAbsolutePath());
} catch (IOException e) {
@@ -148,27 +147,25 @@ public class MigrateMappingsTask extends AbstractLoomTask {
return Iterables.getOnlyElement(files);
}
- private static TinyTree getMappings(File mappings) throws IOException {
- Path temp = Files.createTempFile("mappings", ".tiny");
+ private static MemoryMappingTree getMappings(File mappings) throws IOException {
+ MemoryMappingTree mappingTree = new MemoryMappingTree();
try (FileSystem fileSystem = FileSystems.newFileSystem(mappings.toPath(), (ClassLoader) null)) {
- Files.copy(fileSystem.getPath("mappings/mappings.tiny"), temp, StandardCopyOption.REPLACE_EXISTING);
+ MappingReader.read(fileSystem.getPath("mappings/mappings.tiny"), mappingTree);
}
- try (BufferedReader reader = Files.newBufferedReader(temp)) {
- return TinyMappingFactory.loadWithDetection(reader);
- }
+ return mappingTree;
}
private static void migrateMappings(Project project, LoomGradleExtension extension, MinecraftMappedProvider minecraftMappedProvider,
- Path inputDir, Path outputDir, TinyTree currentMappings, TinyTree targetMappings
+ Path inputDir, Path outputDir, MemoryMappingTree currentMappings, MemoryMappingTree targetMappings
) throws IOException {
project.getLogger().info(":joining mappings");
MappingSet mappingSet = new TinyMappingsJoiner(
- currentMappings, "named",
- targetMappings, "named",
- "intermediary"
+ currentMappings, MappingsNamespace.NAMED.toString(),
+ targetMappings, MappingsNamespace.NAMED.toString(),
+ MappingsNamespace.INTERMEDIARY.toString()
).read();
project.getLogger().lifecycle(":remapping");
diff --git a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java
index 48b9e9bd..5e395a02 100644
--- a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java
+++ b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java
@@ -86,6 +86,7 @@ import org.zeroturnaround.zip.transform.StreamZipEntryTransformer;
import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry;
import net.fabricmc.loom.LoomGradleExtension;
+import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.build.JarRemapper;
import net.fabricmc.loom.build.MixinRefmapHelper;
import net.fabricmc.loom.build.nesting.EmptyNestedJarProvider;
@@ -95,12 +96,13 @@ import net.fabricmc.loom.build.nesting.NestedDependencyProvider;
import net.fabricmc.loom.build.nesting.NestedJarPathProvider;
import net.fabricmc.loom.build.nesting.NestedJarProvider;
import net.fabricmc.loom.configuration.JarManifestConfiguration;
+import net.fabricmc.loom.configuration.accesswidener.AccessWidenerFile;
import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.FileSystemUtil;
import net.fabricmc.loom.util.SourceRemapper;
-import net.fabricmc.loom.util.TinyRemapperMappingsHelper;
+import net.fabricmc.loom.util.TinyRemapperHelper;
import net.fabricmc.loom.util.ZipReprocessorUtil;
import net.fabricmc.loom.util.aw2at.Aw2At;
import net.fabricmc.lorenztiny.TinyMappingsReader;
@@ -247,7 +249,7 @@ public class RemapJarTask extends Jar {
if (isMainRemapTask) {
jarRemapper.addToClasspath(getRemapClasspath());
- jarRemapper.addMappings(TinyRemapperMappingsHelper.create(extension.shouldGenerateSrgTiny() ? mappingsProvider.getMappingsWithSrg() : mappingsProvider.getMappings(), fromM, toM, false));
+ jarRemapper.addMappings(TinyRemapperHelper.create(extension.shouldGenerateSrgTiny() ? mappingsProvider.getMappingsWithSrg() : mappingsProvider.getMappings(), fromM, toM, false));
}
for (File mixinMapFile : extension.getAllMixinMappings()) {
@@ -272,15 +274,15 @@ public class RemapJarTask extends Jar {
byte[] data;
try {
- data = accessWidenerJarProcessor.getRemappedAccessWidener(remapper);
+ data = accessWidenerJarProcessor.getRemappedAccessWidener(remapper, toM);
} catch (IOException e) {
- throw new RuntimeException("Failed to remap access widener");
+ throw new RuntimeException("Failed to remap access widener", e);
}
- String awPath = accessWidenerJarProcessor.getAccessWidenerPath(remapData.input);
- Preconditions.checkNotNull(awPath, "Failed to find accessWidener in fabric.mod.json: " + remapData.input);
+ AccessWidenerFile awFile = AccessWidenerFile.fromModJar(remapData.input);
+ Preconditions.checkNotNull(awFile, "Failed to find accessWidener in fabric.mod.json: " + remapData.input);
- return Pair.of(awPath, data);
+ return Pair.of(awFile.name(), data);
}
return null;
@@ -559,7 +561,8 @@ public class RemapJarTask extends Jar {
return this;
}
- @ApiStatus.Experimental // This only allows mod jars, proceed with care when trying to pass in configurations with projects, or something that depends on a task.
+ @ApiStatus.Experimental
+ // This only allows mod jars, proceed with care when trying to pass in configurations with projects, or something that depends on a task.
public RemapJarTask include(Object... paths) {
Collections.addAll(nestedPaths, paths);
this.addNestedDependencies.set(true);
diff --git a/src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java b/src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java
index d8cb2e13..97556c13 100644
--- a/src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java
+++ b/src/main/java/net/fabricmc/loom/task/RemapSourcesJarTask.java
@@ -32,6 +32,7 @@ import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
+import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.util.SourceRemapper;
public class RemapSourcesJarTask extends AbstractLoomTask {
@@ -53,7 +54,7 @@ public class RemapSourcesJarTask extends AbstractLoomTask {
if (sourceRemapper == null) {
if (sourceNamespace.get().equals(targetNamespace.get())) {
SourceRemapper.remapSources(getProject(), getInput().get().getAsFile(), getOutput().get().getAsFile(),
- targetNamespace.get().equals("named") ? SourceRemapper.intermediary(getProject()) : "named", targetNamespace.get(), reproducibleFileOrder.get(), preserveFileTimestamps.get());
+ targetNamespace.get().equals(MappingsNamespace.NAMED.toString()) ? SourceRemapper.intermediary(getProject()) : "named", targetNamespace.get(), reproducibleFileOrder.get(), preserveFileTimestamps.get());
} else {
SourceRemapper.remapSources(getProject(), getInput().get().getAsFile(), getOutput().get().getAsFile(), sourceNamespace.get(), targetNamespace.get(), reproducibleFileOrder.get(), preserveFileTimestamps.get());
}