Skip to content

Commit 24a896d

Browse files
committed
Bump SRGUtils
Bump Srg2Source version, cleaner output file & some mixin processors. Fix TaskApplyPaatches output typo Fix places where MCPConfig v2 wasn't read. Make patch tasks less verbose Support MCPConfig's that don't have static/constructor files.
1 parent cd48d1a commit 24a896d

File tree

12 files changed

+81
-71
lines changed

12 files changed

+81
-71
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ dependencies {
8080
commonImplementation 'net.minecraftforge:artifactural:2.0.3'
8181
commonImplementation 'org.apache.maven:maven-artifact:3.6.3'
8282
commonImplementation 'org.apache.httpcomponents:httpclient:4.5.13'
83-
commonImplementation 'net.minecraftforge:srgutils:0.2.13'
83+
commonImplementation 'net.minecraftforge:srgutils:0.4.1'
8484
commonImplementation 'net.minecraftforge:DiffPatch:2.0.2:all'
8585

8686
mcpImplementation sourceSets.common.output

src/common/java/net/minecraftforge/gradle/common/config/MCPConfigV2.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@
2121
package net.minecraftforge.gradle.common.config;
2222

2323
import java.io.ByteArrayInputStream;
24+
import java.io.File;
25+
import java.io.IOException;
2426
import java.io.InputStream;
27+
import java.util.zip.ZipEntry;
28+
import java.util.zip.ZipFile;
29+
30+
import org.apache.commons.io.IOUtils;
31+
2532
import net.minecraftforge.gradle.common.util.Utils;
2633

2734
public class MCPConfigV2 extends MCPConfigV1 {
@@ -32,6 +39,23 @@ public static MCPConfigV2 get(byte[] data) {
3239
return get(new ByteArrayInputStream(data));
3340
}
3441

42+
public static MCPConfigV2 getFromArchive(File path) throws IOException {
43+
try (ZipFile zip = new ZipFile(path)) {
44+
ZipEntry entry = zip.getEntry("config.json");
45+
if (entry == null)
46+
throw new IllegalStateException("Could not find 'config.json' in " + path.getAbsolutePath());
47+
48+
byte[] data = IOUtils.toByteArray(zip.getInputStream(entry));
49+
int spec = Config.getSpec(data);
50+
if (spec == 2)
51+
return MCPConfigV2.get(data);
52+
if (spec == 1)
53+
return new MCPConfigV2(MCPConfigV1.get(data));
54+
55+
throw new IllegalStateException("Invalid MCP Config: " + path.getAbsolutePath() + " Unknown spec: " + spec);
56+
}
57+
}
58+
3559
private boolean official = false;
3660
private int java_target = 8;
3761
private String encoding = "UTF-8";

src/common/java/net/minecraftforge/gradle/common/task/ExtractMCPData.java

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.io.File;
2424
import java.io.FileOutputStream;
2525
import java.io.IOException;
26-
import java.io.InputStreamReader;
2726
import java.io.OutputStream;
2827
import java.util.function.Supplier;
2928
import java.util.zip.ZipEntry;
@@ -36,51 +35,52 @@
3635
import org.gradle.api.tasks.OutputFile;
3736
import org.gradle.api.tasks.TaskAction;
3837

39-
import com.google.gson.Gson;
40-
import com.google.gson.GsonBuilder;
41-
42-
import net.minecraftforge.gradle.common.config.Config;
4338
import net.minecraftforge.gradle.common.config.MCPConfigV1;
39+
import net.minecraftforge.gradle.common.config.MCPConfigV2;
4440

4541
public class ExtractMCPData extends DefaultTask {
46-
private static final Gson GSON = new GsonBuilder().create();
47-
4842
private String key = "mappings";
4943
private Supplier<File> configSupplier;
5044
private File config;
45+
private boolean allowEmpty = false;
5146
private File output = getProject().file("build/" + getName() + "/output.srg");
5247

53-
5448
@TaskAction
5549
public void run() throws IOException {
50+
MCPConfigV1 cfg = MCPConfigV2.getFromArchive(getConfig());
51+
5652
try (ZipFile zip = new ZipFile(getConfig())) {
57-
ZipEntry entry = zip.getEntry("config.json");
53+
String path = cfg.getData(key.split("/"));
54+
if (path == null && "statics".equals(key))
55+
path = "config/static_methods.txt";
56+
57+
if (path == null) {
58+
error("Could not find data entry for '" + key + "'");
59+
return;
60+
}
61+
62+
ZipEntry entry = zip.getEntry(path);
5863
if (entry == null) {
59-
throw new IllegalStateException("Could not find 'config.json' in " + getConfig().getAbsolutePath());
64+
error("Invalid config zip, Missing path '" + path + "'");
65+
return;
6066
}
61-
int spec = Config.getSpec(zip.getInputStream(entry));
62-
if (spec == 1) {
63-
MCPConfigV1 cfg = GSON.fromJson(new InputStreamReader(zip.getInputStream(entry)), MCPConfigV1.class);
64-
String path = cfg.getData(key.split("/"));
65-
if (path == null && "statics".equals(key)) { //TODO: Remove when I next push MCPConfig
66-
path = "config/static_methods.txt";
67-
}
68-
if (path == null) {
69-
throw new IllegalStateException("Could not find data entry for '" + key + "'");
70-
}
71-
entry = zip.getEntry(path);
72-
if (entry == null) {
73-
throw new IllegalStateException("Invalid config zip, Missing path '" + path + "'");
74-
}
75-
try (OutputStream out = new FileOutputStream(getOutput())) {
76-
IOUtils.copy(zip.getInputStream(entry), out);
77-
}
78-
} else {
79-
throw new IllegalStateException("Unsupported spec version '" + spec + "'");
67+
68+
try (OutputStream out = new FileOutputStream(getOutput())) {
69+
IOUtils.copy(zip.getInputStream(entry), out);
8070
}
8171
}
8272
}
8373

74+
private void error(String message) throws IOException {
75+
if (!isAllowEmpty())
76+
throw new IllegalStateException(message);
77+
78+
if (getOutput().exists())
79+
getOutput().delete();
80+
81+
getOutput().createNewFile();
82+
}
83+
8484
@InputFile
8585
public File getConfig() {
8686
if (config == null && configSupplier != null)
@@ -106,6 +106,14 @@ public void setKey(String value) {
106106
this.key = value;
107107
}
108108

109+
@Input
110+
public boolean isAllowEmpty() {
111+
return this.allowEmpty;
112+
}
113+
public void setAllowEmpty(boolean value) {
114+
this.allowEmpty = value;
115+
}
116+
109117
@OutputFile
110118
public File getOutput() {
111119
return output;

src/common/java/net/minecraftforge/gradle/common/util/MinecraftRepo.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
import com.google.common.base.Joiner;
5151
import com.google.common.base.Strings;
5252

53-
import net.minecraftforge.gradle.common.config.Config;
5453
import net.minecraftforge.gradle.common.config.MCPConfigV1;
54+
import net.minecraftforge.gradle.common.config.MCPConfigV2;
5555
import net.minecraftforge.gradle.common.util.VersionJson.Download;
5656
import net.minecraftforge.gradle.common.util.VersionJson.OS;
5757
import net.minecraftforge.srgutils.MinecraftVersion;
@@ -388,11 +388,7 @@ private static class MCPWrapperSlim {
388388
private final MCPConfigV1 config;
389389
public MCPWrapperSlim(File data) throws IOException {
390390
this.data = data;
391-
byte[] cfg_data = Utils.getZipData(data, "config.json");
392-
int spec = Config.getSpec(cfg_data);
393-
if (spec != 1)
394-
throw new IllegalStateException("Could not load MCP config, Unknown Spec: " + spec + " File: " + data);
395-
this.config = MCPConfigV1.get(cfg_data);
391+
this.config = MCPConfigV2.getFromArchive(data);
396392
}
397393

398394
public void extractData(File target, String... path) throws IOException {

src/common/java/net/minecraftforge/gradle/common/util/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public class Utils {
103103
public static final String BINPATCHER = "net.minecraftforge:binarypatcher:1.+:fatjar";
104104
public static final String ACCESSTRANSFORMER = "net.minecraftforge:accesstransformers:1.0.+:fatjar";
105105
public static final String SPECIALSOURCE = "net.md-5:SpecialSource:1.8.3:shaded";
106-
public static final String SRG2SOURCE = "net.minecraftforge:Srg2Source:5.+:fatjar";
106+
public static final String SRG2SOURCE = "net.minecraftforge:Srg2Source:7.+:fatjar";
107107
public static final String SIDESTRIPPER = "net.minecraftforge:mergetool:1.0.7:fatjar";
108108
public static final String INSTALLERTOOLS = "net.minecraftforge:installertools:1.1.10:fatjar";
109109
public static final long ZIPTIME = 628041600000L;

src/mcp/java/net/minecraftforge/gradle/mcp/task/SetupMCPTask.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
package net.minecraftforge.gradle.mcp.task;
2222

23-
import net.minecraftforge.gradle.common.config.Config;
24-
import net.minecraftforge.gradle.common.config.MCPConfigV1;
2523
import net.minecraftforge.gradle.common.config.MCPConfigV2;
2624
import net.minecraftforge.gradle.common.util.HashStore;
2725
import net.minecraftforge.gradle.common.util.Utils;
@@ -90,13 +88,7 @@ public void setOutput(File output) {
9088

9189
@TaskAction
9290
public void setupMCP() throws Exception {
93-
byte[] config_data = Utils.getZipData(config, "config.json");
94-
int spec = Config.getSpec(config_data);
95-
if (spec != 1 && spec != 2)
96-
throw new IllegalStateException("Invalid MCP Config: " + config + " Unknown spec: " + spec);
97-
MCPConfigV2 mcpconfig = spec == 2 ? MCPConfigV2.get(config_data) :
98-
new MCPConfigV2(MCPConfigV1.get(config_data));
99-
91+
MCPConfigV2 mcpconfig = MCPConfigV2.getFromArchive(config);
10092
MCPRuntime runtime = new MCPRuntime(getProject(), config, mcpconfig, getPipeline(), getProject().file("build/mcp/"), extrasPre);
10193
File out = runtime.execute(getLogger());
10294
if (FileUtils.contentEquals(out, output)) return;

src/mcp/java/net/minecraftforge/gradle/mcp/util/MCPWrapper.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import com.google.common.base.Joiner;
3232
import com.google.common.collect.Maps;
3333

34-
import net.minecraftforge.gradle.common.config.Config;
35-
import net.minecraftforge.gradle.common.config.MCPConfigV1;
3634
import net.minecraftforge.gradle.common.config.MCPConfigV2;
3735
import net.minecraftforge.gradle.common.util.HashFunction;
3836
import net.minecraftforge.gradle.common.util.Utils;
@@ -52,14 +50,7 @@ public MCPWrapper(String hash, File data, File root) throws IOException {
5250
this.hash = hash;
5351
this.data = data;
5452
this.root = root;
55-
byte[] cfg_data = Utils.getZipData(data, "config.json");
56-
int spec = Config.getSpec(cfg_data);
57-
if (spec != 1 && spec != 2)
58-
throw new IllegalStateException("Could not load MCP config, Unknown Spec: " + spec + " File: " + data);
59-
if (spec == 2)
60-
this.config = MCPConfigV2.get(cfg_data);
61-
else
62-
this.config = new MCPConfigV2(MCPConfigV1.get(cfg_data));
53+
this.config = MCPConfigV2.getFromArchive(data);
6354
}
6455

6556
public MCPRuntime getRuntime(Project project, String side) {

src/patcher/java/net/minecraftforge/gradle/patcher/PatcherPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ public void apply(@Nonnull Project project) {
230230
task.dependsOn(jarConfig, dlMappingsConfig);
231231
task.setInput(jarConfig.getArchiveFile().get().getAsFile());
232232
task.setClasspath(project.getConfigurations().getByName(MC_DEP_CONFIG));
233-
//TODO: Extra SRGs
234233
});
235234
genJoinedBinPatches.configure(task -> {
236235
task.dependsOn(reobfJar);
@@ -329,8 +328,6 @@ public void apply(@Nonnull Project project) {
329328
}
330329

331330
project.afterEvaluate(p -> {
332-
MojangLicenseHelper.displayWarning(p, extension.getMappingChannel());
333-
334331
//Add PatchedSrc to a main sourceset and build range tasks
335332
SourceSet mainSource = javaConv.getSourceSets().getByName("main");
336333
applyRangeConfig.get().setSources(mainSource.getJava().getSrcDirs().stream().filter(f -> !f.equals(extension.patchedSrc)).collect(Collectors.toList()));
@@ -373,6 +370,7 @@ public void apply(@Nonnull Project project) {
373370
PatcherPlugin patcher = extension.parent.getPlugins().findPlugin(PatcherPlugin.class);
374371

375372
if (mcp != null) {
373+
MojangLicenseHelper.displayWarning(p, extension.getMappingChannel());
376374
SetupMCPTask setupMCP = (SetupMCPTask) tasks.getByName("setupMCP");
377375

378376
if (procConfig != null) {
@@ -421,6 +419,7 @@ public void apply(@Nonnull Project project) {
421419
ext.get().dependsOn(dlMCP);
422420
ext.get().setConfig(dlMCP.getOutput());
423421
ext.get().setKey("statics");
422+
ext.get().setAllowEmpty(true);
424423
ext.get().setOutput(project.file("build/" + ext.get().getName() + "/output.txt"));
425424
createExc.get().setStatics(ext.get().getOutput());
426425
createExc.get().dependsOn(ext);
@@ -431,6 +430,7 @@ public void apply(@Nonnull Project project) {
431430
ext.get().dependsOn(dlMCP);
432431
ext.get().setConfig(dlMCP.getOutput());
433432
ext.get().setKey("constructors");
433+
ext.get().setAllowEmpty(true);
434434
ext.get().setOutput(project.file("build/" + ext.get().getName() + "/output.txt"));
435435
createExc.get().setConstructors(ext.get().getOutput());
436436
createExc.get().dependsOn(ext);

src/patcher/java/net/minecraftforge/gradle/patcher/task/TaskApplyPatches.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class TaskApplyPatches extends DefaultTask {
4646
private PatchMode patchMode = PatchMode.EXACT;
4747
private String patchesPrefix = "";
4848
private boolean verbose = false;
49-
private boolean printSummary = true;
49+
private boolean printSummary = false;
5050
private boolean failOnError = true;
5151

5252
private String originalPrefix = "a/";
@@ -65,7 +65,7 @@ public void doTask() throws Exception {
6565
outputFormat = ArchiveFormat.findFormat(outputPath.getFileName());
6666
}
6767

68-
Path rejectsPath = getOutput().toPath();
68+
Path rejectsPath = getRejects().toPath();
6969
ArchiveFormat rejectsFormat = getOutputFormat();
7070
if (rejectsFormat == null) {
7171
rejectsFormat = ArchiveFormat.findFormat(rejectsPath.getFileName());

src/patcher/java/net/minecraftforge/gradle/patcher/task/TaskGeneratePatches.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class TaskGeneratePatches extends DefaultTask {
4040
private boolean autoHeader;
4141
private int contextLines = -1;
4242
private boolean verbose = false;
43-
private boolean printSummary = true;
43+
private boolean printSummary = false;
4444

4545
private String originalPrefix = "a/";
4646
private String modifiedPrefix = "b/";

0 commit comments

Comments
 (0)