mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Get rid of LibraryFinder
This commit is contained in:
8 files changed
+66
-59
No files matched your search
@@ -36,6 +36,13 @@ abstract class BundleList extends DefaultTask {
|
||||
def file = packed.archiveFile.get().asFile
|
||||
entries.put("$info.art.group:$info.art.name:$info.art.classifier", "$file.sha256\t$info.name\t$info.path")
|
||||
}
|
||||
[
|
||||
'client': project.tasks.applyClientBinPatches
|
||||
].forEach { classifier, genned ->
|
||||
def info = Util.getMavenInfoFromTask(genned, classifier)
|
||||
def file = genned.output.get().asFile
|
||||
entries.put("$info.art.group:$info.art.name:$info.art.classifier", "$file.sha256\t$info.name\t$info.path")
|
||||
}
|
||||
|
||||
try (def zip = new java.util.zip.ZipFile(serverBundle.get().asFile)) {
|
||||
def entry = zip.getEntry('META-INF/libraries.list')
|
||||
|
||||
@@ -67,8 +67,8 @@ abstract class InstallerJar extends Zip {
|
||||
].each { task ->
|
||||
def json = task.output.get().asFile.json
|
||||
json.libraries.each { lib ->
|
||||
deps.put(lib.name, lib.downloads.artifact)
|
||||
//println(lib.name)
|
||||
if (lib.downloads?.artifact?.url != null && !lib.downloads.artifact.url.isEmpty())
|
||||
deps.put(lib.name, lib.downloads.artifact)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,10 @@ abstract class LauncherJson extends DefaultTask {
|
||||
dependsOn(packed)
|
||||
input.from packed.archiveFile
|
||||
}
|
||||
|
||||
def patched = project.tasks.applyClientBinPatches
|
||||
dependsOn(patched)
|
||||
input.from patched.output
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +74,22 @@ abstract class LauncherJson extends DefaultTask {
|
||||
]
|
||||
])
|
||||
}
|
||||
[
|
||||
'client': project.tasks.applyClientBinPatches
|
||||
].forEach { classifier, genned ->
|
||||
def info = Util.getMavenInfoFromTask(genned, classifier)
|
||||
json.libraries.add([
|
||||
name: info.name,
|
||||
downloads: [
|
||||
artifact: [
|
||||
path: info.path,
|
||||
url: "",
|
||||
sha1: genned.output.get().asFile.sha1(),
|
||||
size: genned.output.get().asFile.length()
|
||||
]
|
||||
]
|
||||
])
|
||||
}
|
||||
getArtifacts(project, project.configurations.installer).each { key, lib ->
|
||||
json.libraries.add(lib)
|
||||
}
|
||||
|
||||
@@ -108,6 +108,15 @@ public class Util {
|
||||
extension: task.archiveExtension.get()
|
||||
])
|
||||
}
|
||||
public static Map getMavenInfoFromTask(task,classifier) {
|
||||
return getMavenInfoFromMap([
|
||||
group: task.project.group,
|
||||
name: task.project.name,
|
||||
version: task.project.version,
|
||||
classifier: classifier,
|
||||
extension: 'jar'
|
||||
])
|
||||
}
|
||||
|
||||
private static Map getMavenInfoFromMap(art) {
|
||||
def key = "$art.group:$art.name"
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.loading;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class LibraryFinder {
|
||||
private static Path libsPath;
|
||||
static Path findLibsPath() {
|
||||
if (libsPath == null) {
|
||||
libsPath = Path.of(System.getProperty("libraryDirectory", "libraries"));
|
||||
if (!Files.isDirectory(libsPath))
|
||||
throw new IllegalStateException("Library directory: `" + libsPath + "` does not exist. Set it via the `libraryDirectory` system property.");
|
||||
}
|
||||
return libsPath;
|
||||
}
|
||||
|
||||
public static Path findPathForMaven(final String group, final String artifact, final String extension, final String classifier, final String version) {
|
||||
return findLibsPath().resolve(MavenCoordinateResolver.get(group, artifact, extension, classifier, version));
|
||||
}
|
||||
public static Path findPathForMaven(final String maven) {
|
||||
return findLibsPath().resolve(MavenCoordinateResolver.get(maven));
|
||||
}
|
||||
}
|
||||
+18
@@ -19,6 +19,7 @@ import org.slf4j.Logger;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -89,4 +90,21 @@ public abstract class CommonLaunchHandler implements ILaunchHandlerService {
|
||||
if (mtd == null) throw new IllegalStateException("Class " + target + " in module " + module + " does not have a main(String[]) method");
|
||||
mtd.invoke(null, (Object)arguments);
|
||||
}
|
||||
|
||||
protected static Path getPathFromResource(String resource) {
|
||||
var cl = ForgeDevLaunchHandler.class.getClassLoader();
|
||||
var url = cl.getResource(resource);
|
||||
if (url == null)
|
||||
throw new IllegalStateException("Could not find " + resource + " in classloader " + cl);
|
||||
|
||||
var str = url.toString();
|
||||
int len = resource.length();
|
||||
if ("jar".equalsIgnoreCase(url.getProtocol())) {
|
||||
str = url.getFile();
|
||||
len += 2;
|
||||
}
|
||||
str = str.substring(0, str.length() - len);
|
||||
var path = Paths.get(URI.create(str));
|
||||
return path;
|
||||
}
|
||||
}
|
||||
-19
@@ -4,9 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.loading.targets;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@@ -35,23 +33,6 @@ abstract class ForgeDevLaunchHandler extends CommonDevLaunchHandler {
|
||||
return List.of(filtered);
|
||||
}
|
||||
|
||||
static Path getPathFromResource(String resource) {
|
||||
var cl = ForgeDevLaunchHandler.class.getClassLoader();
|
||||
var url = cl.getResource(resource);
|
||||
if (url == null)
|
||||
throw new IllegalStateException("Could not find " + resource + " in classloader " + cl);
|
||||
|
||||
var str = url.toString();
|
||||
int len = resource.length();
|
||||
if ("jar".equalsIgnoreCase(url.getProtocol())) {
|
||||
str = url.getFile();
|
||||
len += 2;
|
||||
}
|
||||
str = str.substring(0, str.length() - len);
|
||||
var path = Paths.get(URI.create(str));
|
||||
return path;
|
||||
}
|
||||
|
||||
public static class Client extends ForgeDevLaunchHandler {
|
||||
public Client() {
|
||||
super(CLIENT);
|
||||
|
||||
+10
-10
@@ -9,9 +9,6 @@ import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.LibraryFinder;
|
||||
|
||||
@ApiStatus.Internal
|
||||
abstract class ForgeProdLaunchHandler extends CommonLaunchHandler {
|
||||
protected ForgeProdLaunchHandler(LaunchType type) {
|
||||
@@ -21,22 +18,25 @@ abstract class ForgeProdLaunchHandler extends CommonLaunchHandler {
|
||||
@Override public String getNaming() { return "srg"; }
|
||||
@Override public boolean isProduction() { return true; }
|
||||
|
||||
@Override
|
||||
public List<Path> getMinecraftPaths() {
|
||||
var vers = FMLLoader.versionInfo();
|
||||
var mc = LibraryFinder.findPathForMaven(vers.forgeGroup(), "forge", "", this.type.name(), vers.mcAndForgeVersion());
|
||||
return List.of(mc);
|
||||
}
|
||||
|
||||
public static class Client extends ForgeProdLaunchHandler {
|
||||
public Client() {
|
||||
super(CLIENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Path> getMinecraftPaths() {
|
||||
return List.of(getPathFromResource("net/minecraft/client/Minecraft.class"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Server extends ForgeProdLaunchHandler {
|
||||
public Server() {
|
||||
super(SERVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Path> getMinecraftPaths() {
|
||||
return List.of(getPathFromResource("net/minecraft/server/MinecraftServer.class"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user