mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-03 05:57:42 -05:00
Simplify RemapJarTask remapRefmap
This commit is contained in:
@@ -99,6 +99,10 @@ public class NestedJars {
|
||||
private static List<File> getContainedJars(Project project) {
|
||||
List<File> fileList = new ArrayList<>();
|
||||
|
||||
if (project.getExtensions().getByType(LoomGradleExtension.class).isForge()) {
|
||||
return fileList;
|
||||
}
|
||||
|
||||
Configuration configuration = project.getConfigurations().getByName(Constants.Configurations.INCLUDE);
|
||||
ResolvedConfiguration resolvedConfiguration = configuration.getResolvedConfiguration();
|
||||
Set<ResolvedDependency> dependencies = resolvedConfiguration.getFirstLevelModuleDependencies();
|
||||
|
||||
@@ -118,8 +118,10 @@ public final class CompileConfiguration {
|
||||
extendsFrom(Constants.Configurations.MINECRAFT_DEPENDENCIES, Constants.Configurations.FORGE_DEPENDENCIES, project);
|
||||
}
|
||||
|
||||
Configuration includeConfig = project.getConfigurations().maybeCreate(Constants.Configurations.INCLUDE);
|
||||
includeConfig.setTransitive(false); // Dont get transitive deps
|
||||
if (!project.getExtensions().getByType(LoomGradleExtension.class).isForge()) {
|
||||
Configuration includeConfig = project.getConfigurations().maybeCreate(Constants.Configurations.INCLUDE);
|
||||
includeConfig.setTransitive(false); // Dont get transitive deps
|
||||
}
|
||||
|
||||
project.getConfigurations().maybeCreate(Constants.Configurations.MAPPINGS);
|
||||
project.getConfigurations().maybeCreate(Constants.Configurations.MAPPINGS_FINAL);
|
||||
@@ -292,7 +294,7 @@ public final class CompileConfiguration {
|
||||
project1.getTasks().getByName("build").dependsOn(remapJarTask);
|
||||
|
||||
project.getTasks().withType(RemapJarTask.class).forEach(task -> {
|
||||
if (task.getAddNestedDependencies().getOrElse(false)) {
|
||||
if (!extension.isForge() && task.getAddNestedDependencies().getOrElse(false)) {
|
||||
NestedJars.getRequiredTasks(project1).forEach(task::dependsOn);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -187,36 +187,10 @@ public class RemapJarTask extends Jar {
|
||||
}
|
||||
|
||||
if (extension.isForge()) {
|
||||
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, toM);
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
try {
|
||||
remapRefmap(extension, output);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to remap refmap jar", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,6 +333,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)) {
|
||||
if (NestedJars.addNestedJars(project, output)) {
|
||||
project.getLogger().debug("Added nested jar paths to mod json");
|
||||
@@ -372,6 +354,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 IMappingProvider remapToSrg(LoomGradleExtension extension, IMappingProvider parent, String fromM, String toM) throws IOException {
|
||||
TinyTree mappings = extension.shouldGenerateSrgTiny() ? extension.getMappingsProvider().getMappingsWithSrg() : extension.getMappingsProvider().getMappings();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user