Skip to content

Commit 9996f71

Browse files
committed
Fix multiple mappings files with reobf
Signed-off-by: SizableShrimp <[email protected]>
1 parent 26b3286 commit 9996f71

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ dependencies {
8181
}
8282
commonImplementation 'org.apache.maven:maven-artifact:3.9.1'
8383
commonImplementation 'org.apache.httpcomponents:httpclient:4.5.14'
84-
commonImplementation 'net.minecraftforge:srgutils:0.4.15'
84+
commonImplementation 'net.minecraftforge:srgutils:0.5.2'
8585
commonImplementation 'net.minecraftforge:DiffPatch:2.0.7:all'
8686

8787
mcpImplementation sourceSets.common.output

src/userdev/java/net/minecraftforge/gradle/userdev/tasks/RenameJar.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,27 @@
88
import net.minecraftforge.gradle.common.tasks.JarExec;
99
import net.minecraftforge.gradle.common.util.Utils;
1010

11+
import net.minecraftforge.srgutils.IMappingFile;
1112
import org.gradle.api.file.ConfigurableFileCollection;
13+
import org.gradle.api.file.RegularFile;
1214
import org.gradle.api.file.RegularFileProperty;
15+
import org.gradle.api.provider.Provider;
1316
import org.gradle.api.tasks.InputFile;
1417
import org.gradle.api.tasks.InputFiles;
1518
import org.gradle.api.tasks.Optional;
1619
import org.gradle.api.tasks.OutputFile;
1720

1821
import com.google.common.collect.ImmutableMap;
1922
import com.google.common.collect.ImmutableMultimap;
23+
import org.gradle.api.tasks.TaskAction;
24+
25+
import java.io.File;
26+
import java.io.IOException;
2027
import java.util.List;
2128

2229
public abstract class RenameJar extends JarExec {
30+
private final Provider<RegularFile> tempMappings = this.workDir.map(s -> s.file("mappings.tsrg"));
31+
2332
public RenameJar() {
2433
getTool().set(Utils.FART);
2534
getArgs().addAll("--input", "{input}", "--output", "{output}", "--names", "{mappings}", "--lib", "{libraries}");
@@ -29,15 +38,39 @@ public RenameJar() {
2938
protected List<String> filterArgs(List<String> args) {
3039
return replaceArgsMulti(args, ImmutableMap.of(
3140
"{input}", getInput().get().getAsFile(),
32-
"{output}", getOutput().get().getAsFile()),
41+
"{output}", getOutput().get().getAsFile(),
42+
"{mappings}", this.tempMappings.get().getAsFile()),
3343
ImmutableMultimap.<String, Object>builder()
34-
.put("{mappings}", getMappings().get().getAsFile())
35-
.putAll("{mappings}", getExtraMappings().getFiles())
3644
.putAll("{libraries}", getLibraries().getFiles())
3745
.build()
3846
);
3947
}
4048

49+
@TaskAction
50+
@Override
51+
public void apply() throws IOException {
52+
File tempMappings = this.tempMappings.get().getAsFile();
53+
54+
if (tempMappings.getParentFile() != null && !tempMappings.getParentFile().exists() && !tempMappings.getParentFile().mkdirs())
55+
getProject().getLogger().warn("Could not create parent directories for temp dir '{}'", tempMappings.getAbsolutePath());
56+
57+
if (tempMappings.exists() && !tempMappings.delete())
58+
throw new IllegalStateException("Could not delete temp mappings file: " + tempMappings.getAbsolutePath());
59+
60+
IMappingFile mappings = IMappingFile.load(getMappings().get().getAsFile());
61+
62+
for (File file : getExtraMappings().getFiles()) {
63+
mappings = mappings.merge(IMappingFile.load(file));
64+
}
65+
66+
mappings.write(tempMappings.toPath(), IMappingFile.Format.TSRG2, false);
67+
68+
super.apply();
69+
70+
tempMappings.delete();
71+
}
72+
73+
4174
// TODO: Make this a ConfigurableFileCollection? (then remove getExtraMappings())
4275
@InputFile
4376
public abstract RegularFileProperty getMappings();

src/userdev/java/net/minecraftforge/gradle/userdev/tasks/RenameJarInPlace.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import net.minecraftforge.gradle.common.tasks.JarExec;
99
import net.minecraftforge.gradle.common.util.Utils;
1010

11+
import net.minecraftforge.srgutils.IMappingFile;
1112
import org.apache.commons.io.FileUtils;
1213
import org.gradle.api.file.ConfigurableFileCollection;
13-
import org.gradle.api.file.Directory;
1414
import org.gradle.api.file.RegularFile;
1515
import org.gradle.api.file.RegularFileProperty;
1616
import org.gradle.api.provider.Provider;
@@ -26,8 +26,8 @@
2626
import java.util.List;
2727

2828
public abstract class RenameJarInPlace extends JarExec {
29-
private final Provider<Directory> workDir = getProject().getLayout().getBuildDirectory().dir(getName());
30-
private final Provider<RegularFile> temp = workDir.map(s -> s.file("output.jar"));
29+
private final Provider<RegularFile> tempOutput = this.workDir.map(s -> s.file("output.jar"));
30+
private final Provider<RegularFile> tempMappings = this.workDir.map(s -> s.file("mappings.tsrg"));
3131

3232
public RenameJarInPlace() {
3333
getTool().set(Utils.FART);
@@ -39,10 +39,9 @@ public RenameJarInPlace() {
3939
protected List<String> filterArgs(List<String> args) {
4040
return replaceArgsMulti(args, ImmutableMap.of(
4141
"{input}", getInput().get().getAsFile(),
42-
"{output}", temp.get().getAsFile()),
42+
"{output}", tempOutput.get().getAsFile(),
43+
"{mappings}", this.tempMappings.get().getAsFile()),
4344
ImmutableMultimap.<String, Object>builder()
44-
.put("{mappings}", getMappings().get().getAsFile())
45-
.putAll("{mappings}", getExtraMappings().getFiles())
4645
.putAll("{libraries}", getLibraries().getFiles())
4746
.build()
4847
);
@@ -51,14 +50,27 @@ protected List<String> filterArgs(List<String> args) {
5150
@Override
5251
@TaskAction
5352
public void apply() throws IOException {
54-
File temp = this.temp.get().getAsFile();
55-
if (temp.getParentFile() != null && !temp.getParentFile().exists() && !temp.getParentFile().mkdirs()) {
56-
getProject().getLogger().warn("Could not create parent directories for temp dir '{}'", temp.getAbsolutePath());
53+
File tempJar = this.tempOutput.get().getAsFile();
54+
File tempMappings = this.tempMappings.get().getAsFile();
55+
56+
if (tempJar.getParentFile() != null && !tempJar.getParentFile().exists() && !tempJar.getParentFile().mkdirs()) {
57+
getProject().getLogger().warn("Could not create parent directories for temp dir '{}'", tempJar.getAbsolutePath());
58+
}
59+
60+
if (tempMappings.exists() && !tempMappings.delete())
61+
throw new IllegalStateException("Could not delete temp mappings file: " + tempMappings.getAbsolutePath());
62+
63+
IMappingFile mappings = IMappingFile.load(getMappings().get().getAsFile());
64+
65+
for (File file : getExtraMappings().getFiles()) {
66+
mappings = mappings.merge(IMappingFile.load(file));
5767
}
5868

69+
mappings.write(tempMappings.toPath(), IMappingFile.Format.TSRG2, false);
70+
5971
super.apply();
6072

61-
FileUtils.copyFile(temp, getInput().get().getAsFile());
73+
FileUtils.copyFile(tempJar, getInput().get().getAsFile());
6274
}
6375

6476
// TODO: Make this a ConfigurableFileCollection? (then remove getExtraMappings())

0 commit comments

Comments
 (0)