Fix merge conflicts

This commit is contained in:
shedaniel
2021-04-13 16:22:58 +08:00
parent a0b84aaf17
commit 897806572e
2 changed files with 45 additions and 3 deletions

View File

@@ -267,6 +267,14 @@ public class RemapJarTask extends Jar {
project.getLogger().debug("Transformed mixin reference maps in output JAR!");
}
if (extension.isForge()) {
try {
remapRefmap(extension, output);
} catch (IOException e) {
throw new RuntimeException("Failed to remap refmap jar", e);
}
}
if (getAddNestedDependencies().getOrElse(false)) {
JarNester.nestJars(nestedJarProvider.provide(), output.toFile(), project.getLogger());
}
@@ -286,6 +294,40 @@ public class RemapJarTask extends Jar {
});
}
private void remapRefmap(LoomGradleExtension extension, Path output) throws IOException {
try (FileSystem fs = FileSystems.newFileSystem(URI.create("jar:" + output.toUri()), ImmutableMap.of("create", false))) {
Path refmapPath = fs.getPath(extension.getRefmapName());
if (Files.exists(refmapPath)) {
try (Reader refmapReader = Files.newBufferedReader(refmapPath, StandardCharsets.UTF_8)) {
Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
JsonObject refmapElement = gson.fromJson(refmapReader, JsonObject.class);
refmapElement = RefmapRemapper.remap(new Remapper() {
ReferenceRemapper remapper = createReferenceRemapper(extension, fromM.get(), toM.get());
@Override
@Nullable
public MappingsRemapper remapMappings() {
return className -> remapper;
}
@Override
@Nullable
public Map.Entry<String, @Nullable MappingsRemapper> remapMappingsData(String data) {
if (Objects.equals(data, "named:intermediary")) {
return new AbstractMap.SimpleEntry<>("searge", remapMappings());
}
return null;
}
}, refmapElement);
Files.delete(refmapPath);
Files.write(refmapPath, gson.toJson(refmapElement).getBytes(StandardCharsets.UTF_8));
}
}
}
}
private NestedJarProvider getNestedJarProvider() {
Configuration includeConfiguration = getProject().getConfigurations().getByName(Constants.Configurations.INCLUDE);