44 */
55package net .minecraftforge .mcmaven .impl .repo .mcpconfig ;
66
7+ import net .minecraftforge .mcmaven .impl .repo .mcpconfig .MinecraftTasks .ArtifactFile ;
78import net .minecraftforge .mcmaven .impl .util .Artifact ;
89import net .minecraftforge .mcmaven .impl .util .Task ;
10+
911import org .jetbrains .annotations .Nullable ;
1012
1113import java .io .File ;
@@ -72,16 +74,19 @@ private void forAllLibrariesInternal(Consumer<? super Artifact> consumer, @Nulla
7274 }
7375 }
7476
75- public List <Artifact > getMCLibraries () {
76- var artifacts = new ArrayList <Artifact >();
77-
78- // minecraft version.json libs + mcpconfig libs + userdev libs
79- // also for module metadata (same order)
80- for (var lib : this .getTasks ().getLibraries ()) {
81- artifacts .add (lib .name ());
82- }
77+ private List <ArtifactFile > getVanillaLibraries () {
78+ var tasks = this .getMCP ().getMinecraftTasks ();
79+ if (SERVER .equals (this .side ))
80+ return tasks .getServerLibraries ();
81+ return tasks .getClientLibraries ();
82+ }
8383
84- return artifacts ;
84+ public List <Artifact > getMCLibraries () {
85+ var list = getVanillaLibraries ();
86+ var ret = new ArrayList <Artifact >(list .size ());
87+ for (var lib : list )
88+ ret .add (lib .artifact ());
89+ return ret ;
8590 }
8691
8792 public List <Artifact > getMCPConfigLibraries () {
@@ -102,9 +107,8 @@ public Task getSources() {
102107 public List <File > getClasspath () {
103108 var classpath = new ArrayList <File >();
104109
105- // minecraft version.json libs + mcpconfig libs + userdev libs
106- // also for module metadata (same order)
107- for (var lib : this .factory .getLibraries ()) {
110+ // minecraft version.json(or bundle) libs + mcpconfig libs
111+ for (var lib : this .getVanillaLibraries ()) {
108112 classpath .add (lib .file ());
109113 }
110114
@@ -114,240 +118,4 @@ public List<File> getClasspath() {
114118
115119 return classpath ;
116120 }
117-
118- // TODO delete this after we've implemented the alternative
119- /*
120- List<RepositoryArtifact> buildArtifacts(Dependency dep, boolean sources) {
121- var metadata = metadata(dep);
122- SingleFileOutput bin = null;
123- SingleFileOutput src = null;
124- if (Util.isSourceDisabled()) {
125- /*
126- * Sources are disabled so take the pre-decomp jar
127- * Make intermediate -> named mapping file
128- * Run through Jar Renamer
129- *
130- * TODO: [FG][MCP] Compile injected code in a seperate smaller jar then merge
131- * /
132- var namedJar = renameJar(predecomp(), mappings().srg2names());
133- bin = mergeExtra("mergeExtraSourceDisabled", namedJar, mappings().obf2srg());
134- } else {
135- /*
136- * Sources are enabled, to take the output of the last step
137- * Load Intermediate -> Human names, and javadocs
138- * Inject into last output
139- * Compile new jar
140- * Merge any assets/data from the original minecraft jar.
141- * /
142- src = renameSources(last(), mappings().names());
143- var compile = compile(src);
144- var packJar = packageCompiled(compile);
145- bin = mergeExtra("mergeExtra", packJar, mappings().obf2srg());
146- }
147-
148- return List.of(new RepositoryArtifact(dep, metadata, bin, src));
149- }
150-
151- private SingleFileOutput metadata(Dependency dep) {
152- var task = task("metadata", CreateIvyMetadata.class);
153- task.getOrganization().convention(dep.getGroup());
154- task.getArtifact().convention(dep.getName());
155- task.getVersion().convention(dep.getVersion());
156- task.getLauncherMeta().convention(mcp.fg.getMcTasks().getVersionJson(mcp.config.version).getOutput());
157- mcp.config.getLibraries(side).forEach(task.getAdditionalDeps()::add);
158- task.getOutput().convention(local.file("ivy.xml"));
159- return task;
160- }
161-
162- private SingleFileOutput renameJar(SingleFileOutput jar, SingleFileOutput mappings) {
163- var task = task("srg2named", RenameJarFile.class);
164- task.getInput().convention(jar.getOutput());
165- task.getMapping().convention(mappings.getOutput());
166- task.getOutput().convention(local.file("named.jar"));
167- return task;
168- }
169-
170- private SingleFileOutput mergeExtra(String name, SingleFileOutput binary, SingleFileOutput mappings) {
171- var base = "joined".equals(side) ? "client" : side;
172- var baseTask = mcp.fg.getMcTasks().getVersionFile(mcp.config.version, base, "jar");
173-
174- var task = task(name, MergeExtra.class);
175- task.getInput().convention(binary.getOutput());
176- task.getBase().convention(baseTask.getOutput());
177- task.getMappings().convention(mappings.getOutput());
178- task.getOutput().convention(local.file(name + ".jar"));
179- return task;
180- }
181-
182- private SingleFileOutput renameSources(SingleFileOutput sources, SingleFileOutput names) {
183- var task = task("renameSource", RenameSources.class);
184- task.getInput().convention(sources.getOutput());
185- task.names().convention(names.getOutput());
186- task.getJavadocs().convention(true);
187- task.getEncoding().convention(mcp.config.encoding);
188- task.getOutput().convention(local.file("renamed-sources.jar"));
189- return task;
190- }
191-
192- private JavaCompile compile(SingleFileOutput sources) {
193- var task = task("recompile", JavaCompile.class);
194- var config = task("recompileConfig", DefaultTask.class);
195-
196- var jsonTask = mcp.fg.getMcTasks().getVersionJson(mcp.config.version);
197- config.dependsOn(jsonTask);
198- config.doFirst(t -> {
199- var deps = new ArrayList<Dependency>();
200- for (var lib : mcp.config.getLibraries(side))
201- deps.add(project.getDependencies().create(lib));
202- var json = JsonData.minecraftVersion(jsonTask.getOutputFile());
203- for (var lib : json.libraries)
204- deps.add(project.getDependencies().create(lib.name));
205- var cfg = project.getConfigurations().detachedConfiguration(deps.toArray(Dependency[]::new));
206- task.setClasspath(cfg);
207- });
208-
209- var toolchainService = project.getExtensions().getByType(JavaToolchainService.class);
210- var javaCompiler = toolchainService.compilerFor(cfg -> cfg.getLanguageVersion().set(JavaLanguageVersion.of(mcp.config.java_target)));
211- task.getOptions().setWarnings(false);
212- task.dependsOn(sources, config);
213- task.getJavaCompiler().set(javaCompiler);
214- task.setSource(project.zipTree(sources.getOutputFile()));
215- task.getDestinationDirectory().set(local.dir("recompile-classes"));
216- mcp.fg.getRepo().blacklist(task);
217- return task;
218- }
219-
220- private SingleFileOutput packageCompiled(JavaCompile compile) {
221- var task = task("recompileJar", JarWithOutput.class);
222- task.from(compile.getDestinationDirectory());
223- task.getDestinationDirectory().convention(local.dir());
224- task.getArchiveFileName().set("recompile.jar");
225- return task;
226- }
227-
228- private class MappingTasks implements MappingTaskHelper {
229- private final MappingsExtension ext;
230- private SingleFileOutput obf2srg;
231- private SingleFileOutput srg2obf;
232- private SingleFileOutput srg2srg;
233- private Map<Key, SingleFileOutput> srg2names = new HashMap<>();
234- private Map<Key, SingleFileOutput> names2srg = new HashMap<>();
235- private Map<Key, SingleFileOutput> obf2names = new HashMap<>();
236- private Map<Key, SingleFileOutput> names2obf = new HashMap<>();
237-
238- private record Key(String channel, String version) {
239- private String clean() {
240- return Util.sanitizeTaskName(Util.capitalize(channel) + version);
241- }
242- }
243-
244- private MappingTasks(SingleFileOutput base) {
245- this.obf2srg = base;
246- this.ext = mcp.fg.getMappings();
247- }
248-
249- @Override
250- public SingleFileOutput obf2srg() {
251- return this.obf2srg;
252- }
253-
254- private SingleFileOutput reverse(SingleFileOutput input, String name, String filename) {
255- var task = task(name, ConvertMappingFile.class);
256- task.getInput().set(input.getOutput());
257- task.getFormat().set(IMappingFile.Format.TSRG);
258- task.getReverse().set(true);
259- task.getOutput().convention(local.file(filename));
260- return task;
261- }
262-
263- @Override
264- public SingleFileOutput srg2obf() {
265- if (this.srg2obf == null)
266- this.srg2obf = reverse(obf2srg(), "makeSrg2Obf", "srg2obf.tsrg");
267- return this.srg2obf;
268- }
269-
270- private SingleFileOutput srg2srg() {
271- if (this.srg2srg == null) {
272- var task = task("makeSrg2Srg", ChainMappingFiles.class);
273- task.getLeft().convention(obf2srg().getOutput());
274- task.getReverseLeft().convention(true);
275- task.getRight().convention(obf2srg().getOutput());
276- task.getOutput().convention(local.file("srg2srg.tsrg"));
277- this.srg2srg = task;
278- }
279- return this.srg2srg;
280- }
281-
282- @Override
283- public SingleFileOutput names() {
284- return names(ext.getCannel(), ext.getVersion(mcp.config.version));
285- }
286-
287- @Override
288- public SingleFileOutput names(String channel, String version) {
289- var ext = mcp.fg.getMappings();
290- var provider = ext.getProvider(channel);
291- if (provider == null)
292- throw new IllegalStateException("Could not find mapping channel `" + channel + "`");
293- return provider.getMappings(channel, version, obf2srg());
294- }
295-
296- @Override
297- public SingleFileOutput srg2names() {
298- return srg2names(ext.getCannel(), ext.getVersion(mcp.config.version));
299- }
300-
301- @Override
302- public SingleFileOutput srg2names(String channel, String version) {
303- return this.srg2names.computeIfAbsent(new Key(channel, version), key -> {
304- var task = task("makeSrg2Names" + key.clean(), RenameMappingFile.class);
305- task.getMappings().convention(srg2srg().getOutput());
306- task.names().convention(names(channel, version).getOutput());
307- task.getOutput().convention(local.file("srg2named" + key.clean() + ".tsrg"));
308- return task;
309- });
310- }
311-
312- @Override
313- public SingleFileOutput names2srg() {
314- return names2srg(ext.getCannel(), ext.getVersion(mcp.config.version));
315- }
316-
317- @Override
318- public SingleFileOutput names2srg(String channel, String version) {
319- return this.names2srg.computeIfAbsent(new Key(channel, version), key ->
320- reverse(srg2names(channel, version), "makeNames2Srg" + key.clean(), "named2srg" + key.clean() + ".tsrg")
321- );
322- }
323-
324- @Override
325- public SingleFileOutput obf2names() {
326- return obf2names(ext.getCannel(), ext.getVersion(mcp.config.version));
327- }
328-
329- @Override
330- public SingleFileOutput obf2names(String channel, String version) {
331- return this.obf2names.computeIfAbsent(new Key(channel, version), key -> {
332- var task = task("makeObf2Names" + key.clean(), RenameMappingFile.class);
333- task.getMappings().convention(obf2srg().getOutput());
334- task.names().convention(names(channel, version).getOutput());
335- task.getOutput().convention(local.file("obf2named" + key.clean() + ".tsrg"));
336- return task;
337- });
338- }
339-
340- @Override
341- public SingleFileOutput names2obf() {
342- return names2obf(ext.getCannel(), ext.getVersion(mcp.config.version));
343- }
344-
345- @Override
346- public SingleFileOutput names2obf(String channel, String version) {
347- return this.names2obf.computeIfAbsent(new Key(channel, version), key ->
348- reverse(obf2names(channel, version), "makeNames2Obf" + key.clean(), "named2obf" + key.clean() + ".tsrg")
349- );
350- }
351- }
352- */
353121}
0 commit comments