add updateMappings task
This commit is contained in:
parent
eff108344f
commit
64c21c01b8
16 changed files with 165 additions and 36 deletions
|
@ -64,6 +64,10 @@ public class LoomGradlePlugin extends AbstractPlugin {
|
|||
tasks.register("cleanLoomBinaries", CleanLoomBinaries.class);
|
||||
tasks.register("cleanLoomMappings", CleanLoomMappings.class);
|
||||
|
||||
tasks.register("updateMappings", UpdateMappingsTask.class, t -> {
|
||||
t.getOutputs().upToDateWhen((o) -> false);
|
||||
});
|
||||
|
||||
tasks.register("remapJar", RemapJar.class);
|
||||
|
||||
tasks.register("genSourcesDecompile", FernFlowerTask.class, t -> {
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.gradle.api.tasks.OutputFile;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class AbstractDecompileTask extends DefaultLoomTask {
|
||||
public abstract class AbstractDecompileTask extends AbstractLoomTask {
|
||||
private Object input;
|
||||
private Object output;
|
||||
private Object lineMapFile;
|
||||
|
|
|
@ -26,9 +26,9 @@ package net.fabricmc.loom.task;
|
|||
|
||||
import org.gradle.api.DefaultTask;
|
||||
|
||||
public abstract class DefaultLoomTask extends DefaultTask {
|
||||
public abstract class AbstractLoomTask extends DefaultTask {
|
||||
|
||||
public DefaultLoomTask() {
|
||||
public AbstractLoomTask() {
|
||||
setGroup("fabric");
|
||||
}
|
||||
|
|
@ -39,11 +39,11 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class RunTaskBase extends JavaExec {
|
||||
public abstract class AbstractRunTask extends JavaExec {
|
||||
private final Function<Project, RunConfig> configProvider;
|
||||
private RunConfig config;
|
||||
|
||||
public RunTaskBase(Function<Project, RunConfig> config) {
|
||||
public AbstractRunTask(Function<Project, RunConfig> config) {
|
||||
super();
|
||||
setGroup("fabric");
|
||||
this.configProvider = config;
|
|
@ -28,7 +28,7 @@ import net.fabricmc.loom.LoomGradleExtension;
|
|||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
public class CleanLoomBinaries extends DefaultLoomTask {
|
||||
public class CleanLoomBinaries extends AbstractLoomTask {
|
||||
@TaskAction
|
||||
public void run() {
|
||||
Project project = this.getProject();
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.gradle.api.tasks.TaskAction;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class CleanLoomMappings extends DefaultLoomTask {
|
||||
public class CleanLoomMappings extends AbstractLoomTask {
|
||||
@TaskAction
|
||||
public void run() {
|
||||
Project project = this.getProject();
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.gradle.api.tasks.TaskAction;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DownloadAssetsTask extends DefaultLoomTask {
|
||||
public class DownloadAssetsTask extends AbstractLoomTask {
|
||||
@TaskAction
|
||||
public void downloadAssets() throws IOException {
|
||||
Project project = this.getProject();
|
||||
|
|
|
@ -33,7 +33,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class GenEclipseRunsTask extends DefaultLoomTask {
|
||||
public class GenEclipseRunsTask extends AbstractLoomTask {
|
||||
|
||||
@TaskAction
|
||||
public void genRuns() throws IOException {
|
||||
|
|
|
@ -46,7 +46,7 @@ import javax.xml.transform.stream.StreamResult;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class GenIdeaProjectTask extends DefaultLoomTask {
|
||||
public class GenIdeaProjectTask extends AbstractLoomTask {
|
||||
|
||||
@TaskAction
|
||||
public void genIdeaRuns() throws IOException, ParserConfigurationException, SAXException, TransformerException {
|
||||
|
|
|
@ -41,7 +41,7 @@ import java.util.List;
|
|||
// https://marketplace.visualstudio.com/items?itemName=redhat.java
|
||||
// https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug
|
||||
// https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack
|
||||
public class GenVsCodeProjectTask extends DefaultLoomTask {
|
||||
public class GenVsCodeProjectTask extends AbstractLoomTask {
|
||||
|
||||
@TaskAction
|
||||
public void genRuns() {
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.gradle.api.tasks.TaskAction;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class RemapJar extends DefaultLoomTask {
|
||||
public class RemapJar extends AbstractLoomTask {
|
||||
public File jar;
|
||||
public File destination;
|
||||
public boolean nestJar = true;
|
||||
|
|
|
@ -29,7 +29,6 @@ import net.fabricmc.loom.util.LineNumberRemapper;
|
|||
import net.fabricmc.loom.util.progress.ProgressLogger;
|
||||
import net.fabricmc.stitch.util.StitchUtil;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.tasks.Input;
|
||||
import org.gradle.api.tasks.InputFile;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
|
@ -37,10 +36,8 @@ import org.gradle.api.tasks.TaskAction;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class RemapLineNumbersTask extends DefaultLoomTask {
|
||||
public class RemapLineNumbersTask extends AbstractLoomTask {
|
||||
private Object input;
|
||||
private Object output;
|
||||
private Object lineMapFile;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.gradle.api.tasks.TaskAction;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
public class RemapSourcesJar extends DefaultLoomTask {
|
||||
public class RemapSourcesJar extends AbstractLoomTask {
|
||||
public File jar;
|
||||
public File destinationJar;
|
||||
public String direction = "intermediary";
|
||||
|
|
|
@ -24,19 +24,9 @@
|
|||
|
||||
package net.fabricmc.loom.task;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.providers.MappingsProvider;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.MinecraftVersionInfo;
|
||||
import net.fabricmc.loom.util.OperatingSystem;
|
||||
import net.fabricmc.loom.util.RunConfig;
|
||||
import org.gradle.api.tasks.JavaExec;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RunClientTask extends RunTaskBase {
|
||||
public class RunClientTask extends AbstractRunTask {
|
||||
public RunClientTask() {
|
||||
super(RunConfig::clientRunConfig);
|
||||
}
|
||||
|
|
|
@ -24,16 +24,9 @@
|
|||
|
||||
package net.fabricmc.loom.task;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.RunConfig;
|
||||
import org.gradle.api.tasks.JavaExec;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RunServerTask extends RunTaskBase {
|
||||
public class RunServerTask extends AbstractRunTask {
|
||||
public RunServerTask() {
|
||||
super(RunConfig::serverRunConfig);
|
||||
}
|
||||
|
|
145
src/main/java/net/fabricmc/loom/task/UpdateMappingsTask.java
Normal file
145
src/main/java/net/fabricmc/loom/task/UpdateMappingsTask.java
Normal file
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.task;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.mappings.*;
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.lorenz.io.MappingsReader;
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
import org.cadixdev.mercury.remapper.MercuryRemapper;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class UpdateMappingsTask extends AbstractLoomTask {
|
||||
@TaskAction
|
||||
public void doTask() throws Throwable {
|
||||
Project project = getProject();
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
|
||||
project.getLogger().lifecycle(":loading mappings");
|
||||
|
||||
File mappingsFile = new File((String) project.getProperties().get("targetMappingsFile"));
|
||||
File inputDir = new File((String) project.getProperties().get("inputDir"));
|
||||
File outputDir = new File((String) project.getProperties().get("outputDir"));
|
||||
|
||||
Mappings sourceMappings = extension.getMappingsProvider().getMappings();
|
||||
Mappings targetMappings;
|
||||
|
||||
try (FileInputStream stream = new FileInputStream(mappingsFile)) {
|
||||
targetMappings = net.fabricmc.mappings.MappingsProvider.readTinyMappings(stream, false);
|
||||
}
|
||||
|
||||
project.getLogger().lifecycle(":joining mappings");
|
||||
MappingSet mappingSet = new MappingsJoiner(sourceMappings, targetMappings, "intermediary", "named").read();
|
||||
|
||||
project.getLogger().lifecycle(":remapping");
|
||||
Mercury mercury = new Mercury();
|
||||
|
||||
for (File file : project.getConfigurations().getByName(Constants.MINECRAFT_DEPENDENCIES).getFiles()) {
|
||||
mercury.getClassPath().add(file.toPath());
|
||||
}
|
||||
|
||||
for (File file : project.getConfigurations().getByName(Constants.COMPILE_MODS_MAPPED).getFiles()) {
|
||||
mercury.getClassPath().add(file.toPath());
|
||||
}
|
||||
|
||||
mercury.getClassPath().add(extension.getMinecraftMappedProvider().MINECRAFT_MAPPED_JAR.toPath());
|
||||
mercury.getClassPath().add(extension.getMinecraftMappedProvider().MINECRAFT_INTERMEDIARY_JAR.toPath());
|
||||
|
||||
mercury.getProcessors().add(MercuryRemapper.create(mappingSet));
|
||||
|
||||
try {
|
||||
mercury.rewrite(inputDir.toPath(), outputDir.toPath());
|
||||
} catch (Exception e) {
|
||||
project.getLogger().warn("Could not remap fully!", e);
|
||||
}
|
||||
|
||||
project.getLogger().lifecycle(":cleaning file descriptors");
|
||||
System.gc();
|
||||
}
|
||||
|
||||
public static class MappingsJoiner extends MappingsReader {
|
||||
private final Mappings sourceMappings, targetMappings;
|
||||
private final String fromNamespace, toNamespace;
|
||||
|
||||
public MappingsJoiner(Mappings sourceMappings, Mappings targetMappings, String fromNamespace, String toNamespace) {
|
||||
this.sourceMappings = sourceMappings;
|
||||
this.targetMappings = targetMappings;
|
||||
this.fromNamespace = fromNamespace;
|
||||
this.toNamespace = toNamespace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingSet read(MappingSet mappings) throws IOException {
|
||||
Map<String, ClassEntry> targetClasses = new HashMap<>();
|
||||
Map<EntryTriple, FieldEntry> targetFields = new HashMap<>();
|
||||
Map<EntryTriple, MethodEntry> targetMethods = new HashMap<>();
|
||||
|
||||
targetMappings.getClassEntries().forEach((c) -> targetClasses.put(c.get(fromNamespace), c));
|
||||
targetMappings.getFieldEntries().forEach((c) -> targetFields.put(c.get(fromNamespace), c));
|
||||
targetMappings.getMethodEntries().forEach((c) -> targetMethods.put(c.get(fromNamespace), c));
|
||||
|
||||
for (ClassEntry entry : sourceMappings.getClassEntries()) {
|
||||
String from = entry.get(toNamespace);
|
||||
String to = targetClasses.getOrDefault(entry.get(fromNamespace), entry).get(toNamespace);
|
||||
|
||||
mappings.getOrCreateClassMapping(from).setDeobfuscatedName(to);
|
||||
}
|
||||
|
||||
for (FieldEntry entry : sourceMappings.getFieldEntries()) {
|
||||
EntryTriple fromEntry = entry.get(toNamespace);
|
||||
EntryTriple toEntry = targetFields.getOrDefault(entry.get(fromNamespace), entry).get(toNamespace);
|
||||
|
||||
mappings.getOrCreateClassMapping(fromEntry.getOwner())
|
||||
.getOrCreateFieldMapping(fromEntry.getName(), fromEntry.getDesc())
|
||||
.setDeobfuscatedName(toEntry.getName());
|
||||
}
|
||||
|
||||
for (MethodEntry entry : sourceMappings.getMethodEntries()) {
|
||||
EntryTriple fromEntry = entry.get(toNamespace);
|
||||
EntryTriple toEntry = targetMethods.getOrDefault(entry.get(fromNamespace), entry).get(toNamespace);
|
||||
|
||||
mappings.getOrCreateClassMapping(fromEntry.getOwner())
|
||||
.getOrCreateMethodMapping(fromEntry.getName(), fromEntry.getDesc())
|
||||
.setDeobfuscatedName(toEntry.getName());
|
||||
}
|
||||
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue