Skip to content

Commit 51241b7

Browse files
committed
Added parchment support
1 parent fe538a7 commit 51241b7

File tree

15 files changed

+528
-36
lines changed

15 files changed

+528
-36
lines changed

src/main/java/net/minecraftforge/mcmaven/cli/MavenTask.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import joptsimple.OptionSpecBuilder;
1313
import net.minecraftforge.mcmaven.impl.GlobalOptions;
1414
import net.minecraftforge.mcmaven.impl.MinecraftMaven;
15+
import net.minecraftforge.mcmaven.impl.mappings.Mappings;
16+
import net.minecraftforge.mcmaven.impl.mappings.ParchmentMappings;
17+
import net.minecraftforge.mcmaven.impl.util.Artifact;
1518
import net.minecraftforge.mcmaven.impl.util.Constants;
1619
import net.minecraftforge.util.logging.Log;
1720

@@ -63,6 +66,10 @@ static void run(String[] args) throws Exception {
6366
var cacheOnlyO = parser.accepts("cache-only",
6467
"Only use caches, fail if any downloads need to occur or if a task needs to do work");
6568

69+
var parchmentO = parser.accepts("parchment",
70+
"Version of parchment mappings to use, snapshots are not supported")
71+
.withRequiredArg();
72+
6673
var shorthandOptions = new HashMap<String, OptionSpecBuilder>();
6774
var artifacts = Map.of(
6875
"forge", Constants.FORGE_ARTIFACT,
@@ -108,15 +115,25 @@ static void run(String[] args) throws Exception {
108115
? options.valueOf(jdkCacheO)
109116
: new File(cache, "jdks");
110117

111-
var artifact = options.valueOf(artifactO);
118+
Artifact artifact = null;
112119
for (var entry : artifacts.entrySet()) {
113-
if (options.has(entry.getKey()))
114-
artifact = entry.getValue();
120+
if (options.has(entry.getKey())) {
121+
artifact = Artifact.from(entry.getValue());
122+
break;
123+
}
115124
}
116125

117-
var version = options.valueOf(versionO);
126+
if (artifact == null)
127+
artifact = Artifact.from(options.valueOf(artifactO));
128+
129+
if (artifact.getVersion() == null)
130+
artifact = artifact.withVersion(options.valueOf(versionO));
131+
132+
var mappings = options.has(parchmentO)
133+
? new ParchmentMappings(options.valueOf(parchmentO))
134+
: new Mappings("official", null);
118135

119-
var mcmaven = new MinecraftMaven(output, cache, jdkCache);
120-
mcmaven.run(artifact, version);
136+
var mcmaven = new MinecraftMaven(output, cache, jdkCache, mappings);
137+
mcmaven.run(artifact);
121138
}
122139
}

src/main/java/net/minecraftforge/mcmaven/impl/MinecraftMaven.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
*/
55
package net.minecraftforge.mcmaven.impl;
66

7-
import com.google.gson.Gson;
8-
import com.google.gson.GsonBuilder;
97
import net.minecraftforge.mcmaven.impl.cache.Cache;
108
import net.minecraftforge.mcmaven.impl.data.GradleModule;
119
import net.minecraftforge.mcmaven.impl.mappings.Mappings;
@@ -23,17 +21,18 @@
2321

2422
import java.io.File;
2523
import java.util.ArrayList;
24+
import java.util.HashMap;
2625
import java.util.HashSet;
2726
import java.util.List;
2827

2928
// TODO [MCMavenizer][Deobf] ADD DEOBF
3029
// use single detached configuration to resolve individual configurations
3130
// pass in downloaded files to mcmaven (absolute path)
32-
public record MinecraftMaven(File output, Cache cache) {
31+
public record MinecraftMaven(File output, Cache cache, Mappings mappings) {
3332
private static final ComparableVersion MIN_SUPPORTED_FORGE = new ComparableVersion("1.14.4"); // Only 1.14.4+ has official mappings, we can support more when we add more mappings
3433

35-
public MinecraftMaven(File output, File cacheRoot, File jdkCacheRoot) {
36-
this(output, new Cache(cacheRoot, jdkCacheRoot));
34+
public MinecraftMaven(File output, File cacheRoot, File jdkCacheRoot, Mappings mappings) {
35+
this(output, new Cache(cacheRoot, jdkCacheRoot), mappings);
3736
}
3837

3938
public MinecraftMaven {
@@ -42,21 +41,24 @@ public MinecraftMaven(File output, File cacheRoot, File jdkCacheRoot) {
4241
Log.info(" JDK Cache: " + cache.jdks().root().getAbsolutePath());
4342
Log.info(" Offline: " + GlobalOptions.isOffline());
4443
Log.info(" Cache Only: " + GlobalOptions.isCacheOnly());
44+
Log.info(" Mappings: " + mappings);
4545
Log.info();
4646
}
4747

48-
public void run(String module, String version) {
49-
var artifact = Artifact.from(module).withVersion(version);
48+
public void run(Artifact artifact) {
49+
var module = artifact.getGroup() + ':' + artifact.getName();
50+
var version = artifact.getVersion();
5051
Log.info("Processing Minecraft dependency: %s:%s".formatted(module, version));
5152
var mcprepo = new MCPConfigRepo(this.cache);
5253

5354
if (Constants.FORGE_GROUP.equals(artifact.getGroup()) && Constants.FORGE_NAME.equals(artifact.getName())) {
5455
var repo = new ForgeRepo(this.cache, mcprepo);
55-
if (version == null)
56+
if (artifact.getVersion() == null)
5657
throw new IllegalArgumentException("No version specified for Forge");
5758

5859
if ("all".equals(version)) {
5960
var versions = this.cache.maven().getVersions(artifact);
61+
var mappingCache = new HashMap<String, Mappings>();
6062
for (var ver : versions.reversed()) {
6163
var cver = new ComparableVersion(ver);
6264
if (cver.compareTo(MIN_SUPPORTED_FORGE) < 0)
@@ -66,21 +68,22 @@ public void run(String module, String version) {
6668
if (fg == null || fg.ordinal() < FGVersion.v3.ordinal()) // Unsupported
6769
continue;
6870

69-
var mappings = new Mappings("official", forgeToMcVersion(ver));
70-
var artifacts = repo.process(module, ver, mappings);
71-
finalize(artifact.withVersion(ver), mappings, artifacts);
71+
var mappings = mappingCache.computeIfAbsent(forgeToMcVersion(ver), this.mappings()::withMCVersion);
72+
var art = artifact.withVersion(ver);
73+
var artifacts = repo.process(art, mappings);
74+
finalize(art, mappings, artifacts);
7275
}
7376
} else {
74-
var mappings = new Mappings("official", forgeToMcVersion(version));
75-
var artifacts = repo.process(module, version, mappings);
77+
var mappings = this.mappings().withMCVersion(forgeToMcVersion(version));
78+
var artifacts = repo.process(artifact, mappings);
7679
finalize(artifact, mappings, artifacts);
7780
}
7881
} else if (Constants.MC_GROUP.equals(artifact.getGroup())) {
7982
if (artifact.getVersion() == null)
8083
throw new IllegalArgumentException("No version specified for MCPConfig");
8184

82-
var mappings = new Mappings("official", mcpToMcVersion(version));
83-
var artifacts = mcprepo.process(module, version, mappings);
85+
var mappings = this.mappings().withMCVersion(mcpToMcVersion(version));
86+
var artifacts = mcprepo.process(artifact, mappings);
8487
finalize(artifact, mappings, artifacts);
8588
} else {
8689
throw new IllegalArgumentException("Artifact '%s' is currently Unsupported. Will add later".formatted(module));

src/main/java/net/minecraftforge/mcmaven/impl/mappings/Mappings.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Mappings {
2323
public static final String CHANNEL_ATTR = "net.minecraftforge.mappings.channel";
2424
public static final String VERSION_ATTR = "net.minecraftforge.mappings.version";
2525

26-
private final Map<MCPSide, Task> tasks = new HashMap<>();
26+
protected final Map<MCPSide, Task> tasks = new HashMap<>();
2727
private final String channel;
2828
private final String version;
2929

@@ -42,7 +42,7 @@ public String version() {
4242

4343
@Override
4444
public String toString() {
45-
return channel() + '-' + version();
45+
return channel() + (version() == null ? "" : '-' + version());
4646
}
4747

4848
public File getFolder(File root) {
@@ -56,6 +56,10 @@ public boolean isPrimary() {
5656
return true;
5757
}
5858

59+
public Mappings withMCVersion(String version) {
60+
return new Mappings(channel(), version);
61+
}
62+
5963
public Artifact getArtifact(MCPSide side) {
6064
//net.minecraft:mappings_{CHANNEL}:{MCP_VERSION}[-{VERSION}]@zip
6165
var mcpVersion = side.getMCP().getName().getVersion();
@@ -89,7 +93,7 @@ public Task getCsvZip(MCPSide side) {
8993
private File getMappings(MCPSide side, Task srgMappings, Task clientTask, Task serverTask) {
9094
var tool = side.getMCP().getCache().maven().download(Constants.INSTALLER_TOOLS);
9195

92-
var root = getFolder(new File(side.getBuildFolder(), "data/mapings"));
96+
var root = getFolder(new File(side.getMCP().getBuildFolder(), "data/mapings"));
9397
var output = new File(root, "official.zip");
9498
var log = new File(root, "official.log");
9599

@@ -103,7 +107,7 @@ private File getMappings(MCPSide side, Task srgMappings, Task clientTask, Task s
103107
cache.add("client", client);
104108
cache.add("server", server);
105109

106-
if (output.exists() && cache.exists())
110+
if (output.exists() && cache.isSame())
107111
return output;
108112

109113
GlobalOptions.assertNotCacheOnly();
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) Forge Development LLC and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
package net.minecraftforge.mcmaven.impl.mappings;
6+
7+
import java.io.InputStream;
8+
import java.util.Collections;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
import java.util.function.Function;
13+
import java.util.stream.Collectors;
14+
15+
import net.minecraftforge.util.data.json.JsonData;
16+
17+
class ParchmentData {
18+
public static ParchmentData load(InputStream stream) {
19+
return JsonData.fromJson(stream, ParchmentData.class);
20+
}
21+
22+
String version;
23+
List<Package> packages;
24+
List<Clazz> classes;
25+
26+
transient Map<String, Package> packageMap;
27+
transient Map<String, Clazz> classMap;
28+
29+
void bake() {
30+
if (packages == null)
31+
packageMap = Collections.emptyMap();
32+
else
33+
packageMap = packages.stream().collect(Collectors.toMap(p -> p.name, Function.identity()));
34+
35+
if (classes == null)
36+
classMap = Collections.emptyMap();
37+
else {
38+
classMap = new HashMap<>();
39+
for (var cls : classes) {
40+
classMap.put(cls.name, cls);
41+
cls.bake();
42+
}
43+
}
44+
}
45+
46+
static class Element {
47+
String name;
48+
List<String> javadoc;
49+
50+
public Element() { }
51+
private Element(String name, List<String> javadoc) {
52+
this.name = name;
53+
this.javadoc = javadoc;
54+
}
55+
}
56+
57+
static class Package extends Element {
58+
}
59+
60+
static class Clazz extends Element {
61+
List<Field> fields;
62+
List<Method> methods;
63+
64+
transient Map<String, Field> fieldMap;
65+
transient Map<String, Method> methodMap;
66+
67+
void bake() {
68+
if (fields == null)
69+
fieldMap = Collections.emptyMap();
70+
else
71+
fieldMap = fields.stream().collect(Collectors.toMap(p -> p.name, Function.identity()));
72+
73+
if (methods == null)
74+
methodMap = Collections.emptyMap();
75+
else {
76+
methodMap = new HashMap<>();
77+
for (var mtd : methods) {
78+
methodMap.put(mtd.name + mtd.descriptor, mtd);
79+
mtd.bake();
80+
}
81+
}
82+
}
83+
}
84+
85+
static class Field extends Element {
86+
String descriptor;
87+
}
88+
89+
static class Method extends Element {
90+
String descriptor;
91+
List<Parameter> parameters;
92+
93+
transient Map<Integer, Element> paramMap;
94+
95+
void bake() {
96+
if (parameters == null)
97+
paramMap = Collections.emptyMap();
98+
else {
99+
paramMap = new HashMap<>();
100+
for (var param : parameters) {
101+
paramMap.put(param.index, new Element(param.name, param.javadoc == null ? null : List.of(param.javadoc)));
102+
}
103+
}
104+
}
105+
}
106+
107+
static class Parameter {
108+
int index;
109+
String name;
110+
String javadoc;
111+
}
112+
}

0 commit comments

Comments
 (0)