From 7b5f286496a85354815adf4e465e925e1ff7e861 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Tue, 6 Feb 2024 14:04:00 +0100 Subject: [PATCH] Separate LF code from Upstream code + update License headers --- .gitignore | 1 + LF-HEADER | 2 +- LF-ONLY-HEADER | 13 ++++ build.gradle | 14 +++- .../java/net/fabricmc/meta/FabricMeta.java | 3 +- .../fabricmc/meta/data/VersionDatabase.java | 76 +++++++++++++------ .../net/fabricmc/meta/utils/LoaderMeta.java | 7 +- .../meta/utils/MinecraftLauncherMeta.java | 12 ++- .../net/fabricmc/meta/web/EndpointsV1.java | 1 - .../net/fabricmc/meta/web/EndpointsV2.java | 33 +------- .../net/fabricmc/meta/web/ProfileHandler.java | 7 +- .../fabricmc/meta/web/ServerBootstrap.java | 7 +- .../java/net/fabricmc/meta/web/WebServer.java | 23 ------ .../meta/web/models/MavenBuildVersion.java | 1 - .../meta/web/models/MavenUrlVersion.java | 8 +- .../legacyfabric/meta/LegacyConstants.java | 20 +++++ .../meta/data/LegacyVersionDatabase.java | 75 ++++++++++++++++++ .../meta/web/LegacyEndpointsV2.java | 64 ++++++++++++++++ .../meta/web/LegacyWebServer.java | 49 ++++++++++++ .../web/models/LegacyMavenUrlVersion.java | 31 ++++++++ .../meta/web/models/MetaServerInfo.java | 2 +- 21 files changed, 353 insertions(+), 96 deletions(-) create mode 100644 LF-ONLY-HEADER create mode 100644 src/main/java/net/legacyfabric/meta/LegacyConstants.java create mode 100644 src/main/java/net/legacyfabric/meta/data/LegacyVersionDatabase.java create mode 100644 src/main/java/net/legacyfabric/meta/web/LegacyEndpointsV2.java create mode 100644 src/main/java/net/legacyfabric/meta/web/LegacyWebServer.java create mode 100644 src/main/java/net/legacyfabric/meta/web/models/LegacyMavenUrlVersion.java rename src/replaceme/java/net/{fabricmc => legacyfabric}/meta/web/models/MetaServerInfo.java (85%) diff --git a/.gitignore b/.gitignore index c42e7f8..613d366 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ !/gradlew !/gradlew.bat !/LF-HEADER +!/LF-ONLY-HEADER !/HEADER !/LICENSE !/README.md diff --git a/LF-HEADER b/LF-HEADER index 32973ea..4c45c9f 100644 --- a/LF-HEADER +++ b/LF-HEADER @@ -1,4 +1,4 @@ -Copyright (c) 2021-2022 Legacy Fabric +Copyright (c) 2021-2024 Legacy Fabric Copyright (c) 2019 FabricMC Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/LF-ONLY-HEADER b/LF-ONLY-HEADER new file mode 100644 index 0000000..e8bbd5f --- /dev/null +++ b/LF-ONLY-HEADER @@ -0,0 +1,13 @@ +Copyright (c) 2021-2024 Legacy Fabric + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/build.gradle b/build.gradle index b191b65..f16d6bb 100644 --- a/build.gradle +++ b/build.gradle @@ -7,8 +7,11 @@ plugins { id 'org.cadixdev.licenser' version '0.6.1' } +def legacyVersion = "1.7.6" group 'net.legacyfabric' -version '1.7.5+fabricmc.1.5.2' +version '1.5.2' + +version = legacyVersion + "+fabricmc." + project.version def ENV = System.getenv() version = version + (ENV.GITHUB_ACTIONS ? "" : "+local") @@ -59,9 +62,12 @@ tasks.withType(JavaCompile).configureEach { } license { - matching(includes: ['**/VersionDatabase.java', '**/LoaderMeta.java', '**/MavenBuildVersion.java', - '**/MavenUrlVersion.java', '**/ProfileHandler.java', '**/EndpointsV1.java', - '**/EndpointsV2.java']) { + matching(includes: ['**/legacyfabric/**']) { + header = file("LF-ONLY-HEADER") + } + matching(includes: ['**/VersionDatabase.java', '**/MinecraftLauncherMeta.java','**/EndpointsV2.java', + '**/ProfileHandler.java', '**/MavenUrlVersion.java', '**/ServerBootstrap.java' + ]) { header = file('LF-HEADER') } header file('HEADER') diff --git a/src/main/java/net/fabricmc/meta/FabricMeta.java b/src/main/java/net/fabricmc/meta/FabricMeta.java index f381df0..77cc264 100644 --- a/src/main/java/net/fabricmc/meta/FabricMeta.java +++ b/src/main/java/net/fabricmc/meta/FabricMeta.java @@ -18,6 +18,7 @@ import net.fabricmc.meta.data.VersionDatabase; import net.fabricmc.meta.web.WebServer; +import net.legacyfabric.meta.data.LegacyVersionDatabase; import javax.xml.stream.XMLStreamException; import java.io.IOException; @@ -41,7 +42,7 @@ public static void main(String[] args) { private static void update(){ try { - database = VersionDatabase.generate(); + database = VersionDatabase.generate(new LegacyVersionDatabase()); } catch (IOException | XMLStreamException e) { if(database == null){ throw new RuntimeException(e); diff --git a/src/main/java/net/fabricmc/meta/data/VersionDatabase.java b/src/main/java/net/fabricmc/meta/data/VersionDatabase.java index 96f98db..6c1ca77 100644 --- a/src/main/java/net/fabricmc/meta/data/VersionDatabase.java +++ b/src/main/java/net/fabricmc/meta/data/VersionDatabase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Legacy Fabric + * Copyright (c) 2021-2024 Legacy Fabric * Copyright (c) 2019 FabricMC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,6 +21,7 @@ import net.fabricmc.meta.utils.PomParser; import net.fabricmc.meta.web.models.*; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.slf4j.impl.SimpleLoggerFactory; import javax.xml.stream.XMLStreamException; @@ -29,36 +30,33 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.function.Function; import java.util.stream.Collectors; public class VersionDatabase { - public static final String MAVEN_URL = "https://repo.legacyfabric.net/repository/legacyfabric/"; - public static final String UPSTREAM_MAVEN_URL = "https://maven.fabricmc.net/"; + public static final String MAVEN_URL = "https://maven.fabricmc.net/"; - public static final PomParser MAPPINGS_PARSER = new PomParser(MAVEN_URL + "net/legacyfabric/yarn/maven-metadata.xml"); - public static final PomParser INTERMEDIARY_PARSER = new PomParser(MAVEN_URL + "net/legacyfabric/intermediary/maven-metadata.xml"); - public static final PomParser LOADER_PARSER = new PomParser(UPSTREAM_MAVEN_URL + "net/fabricmc/fabric-loader/maven-metadata.xml"); - public static final PomParser INSTALLER_PARSER = new PomParser(MAVEN_URL + "net/legacyfabric/fabric-installer/maven-metadata.xml"); + public static final PomParser MAPPINGS_PARSER = new PomParser(MAVEN_URL + "net/fabricmc/yarn/maven-metadata.xml"); + public static final PomParser INTERMEDIARY_PARSER = new PomParser(MAVEN_URL + "net/fabricmc/intermediary/maven-metadata.xml"); + public static final PomParser LOADER_PARSER = new PomParser(MAVEN_URL + "net/fabricmc/fabric-loader/maven-metadata.xml"); + public static final PomParser INSTALLER_PARSER = new PomParser(MAVEN_URL + "net/fabricmc/fabric-installer/maven-metadata.xml"); + + private static final ArrayList incorrectVersions = new ArrayList<>(); + private static final Logger LOGGER = LoggerFactory.getLogger(VersionDatabase.class); public List game; public List mappings; public List intermediary; - private List loader; + public List loader; public List installer; - public MinecraftLauncherMeta launcherMeta; - - private static final ArrayList incorrectVersions = new ArrayList<>(); - - private static final Logger LOGGER = new SimpleLoggerFactory().getLogger(VersionDatabase.class.getName()); - private VersionDatabase() { + public VersionDatabase() { } - public static VersionDatabase generate() throws IOException, XMLStreamException { + public static VersionDatabase generate(VersionDatabase database) throws IOException, XMLStreamException { long start = System.currentTimeMillis(); - VersionDatabase database = new VersionDatabase(); - database.mappings = MAPPINGS_PARSER.getMeta(MavenBuildGameVersion::new, "net.legacyfabric:yarn:"); - database.intermediary = INTERMEDIARY_PARSER.getMeta(MavenVersion::new, "net.legacyfabric:intermediary:"); + database.mappings = database.getMappingsParser().getMeta(MavenBuildGameVersion::new, database.getMappingsPrefix()); + database.intermediary = database.getIntermediaryParser().getMeta(MavenVersion::new, database.getIntermediaryPrefix()); database.loader = LOADER_PARSER.getMeta(MavenBuildVersion::new, "net.fabricmc:fabric-loader:", list -> { for (BaseVersion version : list) { if (isPublicLoaderVersion(version)) { @@ -67,9 +65,9 @@ public static VersionDatabase generate() throws IOException, XMLStreamException } } }); - database.installer = INSTALLER_PARSER.getMeta(MavenUrlVersion::new, "net.legacyfabric:fabric-installer:"); + database.installer = database.getInstallerParser().getMeta(database.getMavenUrlVersionBuilder(), database.getInstallerPrefix()); database.loadMcData(); - LOGGER.info("DB update took " + (System.currentTimeMillis() - start) + "ms"); + LOGGER.info("DB update took {} ms", (System.currentTimeMillis() - start)); return database; } @@ -89,7 +87,7 @@ private void loadMcData() throws IOException { if (launcherMeta.getVersions().stream().noneMatch(version -> version.getId().equals(o.getVersion()))) { // only print unmatched versions once so that it doesn't spam the console with "Removing ..." messages if (incorrectVersions.stream().noneMatch(o.getVersion()::equals)) { - LOGGER.warn("Removing " + o.getVersion() + " as it doesn't have a valid intermediary match"); + LOGGER.warn("Removing {} as it doesn't match a valid mc version", o.getVersion()); incorrectVersions.add(o.getVersion()); } return true; @@ -112,12 +110,42 @@ public List getLoader() { } private static boolean isPublicLoaderVersion(BaseVersion version) { - String[] ver = version.getVersion().split("\\."); - return Integer.parseInt(ver[1]) >= 13 - || Integer.parseInt(ver[0]) > 0; + return true; } public List getAllLoader() { return Collections.unmodifiableList(loader); } + + + // LegacyFabric extensions + public PomParser getMappingsParser() { + return MAPPINGS_PARSER; + } + + public String getMappingsPrefix() { + return "net.fabricmc:yarn:"; + } + + public PomParser getIntermediaryParser() { + return INTERMEDIARY_PARSER; + } + + public String getIntermediaryPrefix() { + return "net.fabricmc:intermediary:"; + } + + public PomParser getInstallerParser() { + return INSTALLER_PARSER; + } + + public String getInstallerPrefix() { + return "net.fabricmc:fabric-installer:"; + } + + public Function getMavenUrlVersionBuilder() { + return MavenUrlVersion::new; + } + + public MinecraftLauncherMeta launcherMeta; } diff --git a/src/main/java/net/fabricmc/meta/utils/LoaderMeta.java b/src/main/java/net/fabricmc/meta/utils/LoaderMeta.java index c8b11f7..8930625 100644 --- a/src/main/java/net/fabricmc/meta/utils/LoaderMeta.java +++ b/src/main/java/net/fabricmc/meta/utils/LoaderMeta.java @@ -1,5 +1,4 @@ /* - * Copyright (c) 2021-2022 Legacy Fabric * Copyright (c) 2019 FabricMC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,6 +31,7 @@ public class LoaderMeta { public static final File BASE_DIR = new File("metadata"); + public static final String MAVEN_URL = "https://maven.fabricmc.net/"; public static JsonObject getMeta(LoaderInfoBase loaderInfo){ String loaderMaven = loaderInfo.getLoader().getMaven(); @@ -42,7 +42,7 @@ public static JsonObject getMeta(LoaderInfoBase loaderInfo){ File launcherMetaFile = new File(BASE_DIR, path + "/" + filename); if(!launcherMetaFile.exists()){ try { - String url = String.format("%s%s/%s", VersionDatabase.UPSTREAM_MAVEN_URL, path, filename); + String url = String.format("%s%s/%s", MAVEN_URL, path, filename); System.out.println("Downloading " + url); FileUtils.copyURLToFile(new URL(url), launcherMetaFile); } catch (IOException e) { @@ -52,7 +52,8 @@ public static JsonObject getMeta(LoaderInfoBase loaderInfo){ } try { - return WebServer.GSON.fromJson(new FileReader(launcherMetaFile), JsonObject.class); + JsonObject jsonObject = WebServer.GSON.fromJson(new FileReader(launcherMetaFile), JsonObject.class); + return jsonObject; } catch (FileNotFoundException e) { e.printStackTrace(); return null; diff --git a/src/main/java/net/fabricmc/meta/utils/MinecraftLauncherMeta.java b/src/main/java/net/fabricmc/meta/utils/MinecraftLauncherMeta.java index 4848466..69e7d2a 100644 --- a/src/main/java/net/fabricmc/meta/utils/MinecraftLauncherMeta.java +++ b/src/main/java/net/fabricmc/meta/utils/MinecraftLauncherMeta.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2021-2024 Legacy Fabric * Copyright (c) 2019 FabricMC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,8 +45,8 @@ public static MinecraftLauncherMeta getMeta() throws IOException { return GSON.fromJson(json, MinecraftLauncherMeta.class); } - public static MinecraftLauncherMeta getMissingMeta() throws IOException { - String url = "https://raw.githubusercontent.com/Legacy-Fabric/manifests/master/manifest.json"; + public static MinecraftLauncherMeta getExperimentalMeta() throws IOException { + String url = "https://maven.fabricmc.net/net/minecraft/experimental_versions.json"; String json = IOUtils.toString(new URL(url), StandardCharsets.UTF_8); return GSON.fromJson(json, MinecraftLauncherMeta.class); } @@ -53,6 +54,7 @@ public static MinecraftLauncherMeta getMissingMeta() throws IOException { public static MinecraftLauncherMeta getAllMeta() throws IOException { List versions = new ArrayList<>(); versions.addAll(getMeta().versions); +// versions.addAll(getExperimentalMeta().versions); versions.addAll(getMissingMeta().versions); // Order by release time @@ -78,6 +80,12 @@ public List getVersions() { return Collections.unmodifiableList(versions); } + public static MinecraftLauncherMeta getMissingMeta() throws IOException { + String url = "https://raw.githubusercontent.com/Legacy-Fabric/manifests/master/manifest.json"; + String json = IOUtils.toString(new URL(url), StandardCharsets.UTF_8); + return GSON.fromJson(json, MinecraftLauncherMeta.class); + } + public static class Version { String id; diff --git a/src/main/java/net/fabricmc/meta/web/EndpointsV1.java b/src/main/java/net/fabricmc/meta/web/EndpointsV1.java index 8acec3d..d895259 100644 --- a/src/main/java/net/fabricmc/meta/web/EndpointsV1.java +++ b/src/main/java/net/fabricmc/meta/web/EndpointsV1.java @@ -1,5 +1,4 @@ /* - * Copyright (c) 2021-2022 Legacy Fabric * Copyright (c) 2019 FabricMC * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/main/java/net/fabricmc/meta/web/EndpointsV2.java b/src/main/java/net/fabricmc/meta/web/EndpointsV2.java index 0ca6455..acc44f6 100644 --- a/src/main/java/net/fabricmc/meta/web/EndpointsV2.java +++ b/src/main/java/net/fabricmc/meta/web/EndpointsV2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Legacy Fabric + * Copyright (c) 2021-2024 Legacy Fabric * Copyright (c) 2019 FabricMC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,6 +22,7 @@ import net.fabricmc.meta.FabricMeta; import net.fabricmc.meta.utils.MinecraftLauncherMeta; import net.fabricmc.meta.web.models.*; +import net.legacyfabric.meta.web.LegacyEndpointsV2; import org.apache.commons.io.IOUtils; import java.io.IOException; @@ -58,18 +59,16 @@ public static void setup() { WebServer.jsonGet("/v2/versions/loader", context -> withLimitSkip(context, FabricMeta.database.getLoader())); WebServer.jsonGet("/v2/versions/loader/:game_version", context -> withLimitSkip(context, EndpointsV2.getLoaderInfoAll(context))); WebServer.jsonGet("/v2/versions/loader/:game_version/:loader_version", EndpointsV2::getLoaderInfo); - WebServer.jsonGet("/v2/meta", () -> MetaServerInfo.INSTANCE); WebServer.jsonGet("/v2/versions/installer", context -> withLimitSkip(context, FabricMeta.database.installer)); - WebServer.stringGet("/v2/manifest/:game_version", EndpointsV2::getVersionManifest); - WebServer.jsonGet("/v2/versions/manifest", context -> FabricMeta.database.launcherMeta); + LegacyEndpointsV2.setup(); ProfileHandler.setup(); ServerBootstrap.setup(); } - private static List withLimitSkip(Context context, List list) { + protected static List withLimitSkip(Context context, List list) { if(list == null){ return Collections.emptyList(); } @@ -92,30 +91,6 @@ private static > List filter(Context context, Lis return versionList.stream().filter(t -> t.test(context.pathParam("game_version"))).collect(Collectors.toList()); } - - private static String getVersionManifest(Context context) { - if (!context.pathParamMap().containsKey("game_version")) { - return null; - } - - String gameVersion = context.pathParam("game_version"); - - MinecraftLauncherMeta.Version version = FabricMeta.database.launcherMeta.getVersions().stream() - .filter(v -> Objects.equals(v.getId(), gameVersion)) - .findFirst().orElse(null); - - String json = null; - - if (version != null) { - try { - json = IOUtils.toString(new URL(version.getUrl()), StandardCharsets.UTF_8); - } catch (IOException e) { - - } - } - - return json; - } private static Object getLoaderInfo(Context context) { if (!context.pathParamMap().containsKey("game_version")) { diff --git a/src/main/java/net/fabricmc/meta/web/ProfileHandler.java b/src/main/java/net/fabricmc/meta/web/ProfileHandler.java index 2a782b3..6257017 100644 --- a/src/main/java/net/fabricmc/meta/web/ProfileHandler.java +++ b/src/main/java/net/fabricmc/meta/web/ProfileHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Legacy Fabric + * Copyright (c) 2021-2024 Legacy Fabric * Copyright (c) 2019 FabricMC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,6 +35,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import net.fabricmc.meta.data.VersionDatabase; +import net.legacyfabric.meta.data.LegacyVersionDatabase; import org.apache.commons.io.IOUtils; import net.fabricmc.meta.utils.LoaderMeta; @@ -115,8 +116,8 @@ private static JsonObject buildProfileJson(LoaderInfoV2 info, String side) { JsonObject librariesObject = launcherMeta.get("libraries").getAsJsonObject(); // Build the libraries array with the existing libs + loader and intermediary JsonArray libraries = (JsonArray) librariesObject.get("common"); - libraries.add(getLibrary(info.getIntermediary().getMaven(), VersionDatabase.MAVEN_URL)); - libraries.add(getLibrary(info.getLoader().getMaven(), VersionDatabase.UPSTREAM_MAVEN_URL)); + libraries.add(getLibrary(info.getIntermediary().getMaven(), LegacyVersionDatabase.MAVEN_URL)); + libraries.add(getLibrary(info.getLoader().getMaven(), VersionDatabase.MAVEN_URL)); if (librariesObject.has(side)) { libraries.addAll(librariesObject.get(side).getAsJsonArray()); diff --git a/src/main/java/net/fabricmc/meta/web/ServerBootstrap.java b/src/main/java/net/fabricmc/meta/web/ServerBootstrap.java index 6125ba6..901d3f0 100644 --- a/src/main/java/net/fabricmc/meta/web/ServerBootstrap.java +++ b/src/main/java/net/fabricmc/meta/web/ServerBootstrap.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2021-2024 Legacy Fabric * Copyright (c) 2019 FabricMC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -158,7 +159,7 @@ private static Path getInstallerJar(String installerVersion) throws IOException } private static Path downloadInstallerJar(Path jar, String installerVersion) throws IOException { - final String url = String.format("https://maven.legacyfabric.net/net/legacyfabric/fabric-installer/%1$s/fabric-installer-%1$s-server.jar", installerVersion); + final String url = String.format(getInstallerURL(), installerVersion); System.out.println("Downloading: " + url); FileUtils.copyURLToFile(new URL(url), jar.toFile()); @@ -189,4 +190,8 @@ private static int getCacheDuration(Context ctx) { } return 86400; } + + private static String getInstallerURL() { + return "https://maven.legacyfabric.net/net/legacyfabric/fabric-installer/%1$s/fabric-installer-%1$s-server.jar"; + } } diff --git a/src/main/java/net/fabricmc/meta/web/WebServer.java b/src/main/java/net/fabricmc/meta/web/WebServer.java index 24704da..845d71a 100644 --- a/src/main/java/net/fabricmc/meta/web/WebServer.java +++ b/src/main/java/net/fabricmc/meta/web/WebServer.java @@ -64,27 +64,4 @@ private static void handleJson(Context ctx, Object object) { String response = GSON.toJson(object); ctx.contentType("application/json").header(Header.CACHE_CONTROL, "public, max-age=60").result(response); } - - public static void stringGet(String route, Supplier supplier) { - javalin.get(route, ctx -> { - String object = supplier.get(); - handleString(ctx, object); - }); - } - - public static void stringGet(String route, Function supplier) { - javalin.get(route, ctx -> { - String object = supplier.apply(ctx); - handleString(ctx, object); - }); - } - - public static void handleString(Context ctx, String string) { - if (string == null) { - string = ""; - ctx.status(400); - } - - ctx.contentType("application/json").header(Header.CACHE_CONTROL, "public, max-age=60").result(string); - } } diff --git a/src/main/java/net/fabricmc/meta/web/models/MavenBuildVersion.java b/src/main/java/net/fabricmc/meta/web/models/MavenBuildVersion.java index 016ce8b..a223ed0 100644 --- a/src/main/java/net/fabricmc/meta/web/models/MavenBuildVersion.java +++ b/src/main/java/net/fabricmc/meta/web/models/MavenBuildVersion.java @@ -1,5 +1,4 @@ /* - * Copyright (c) 2021-2022 Legacy Fabric * Copyright (c) 2019 FabricMC * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/main/java/net/fabricmc/meta/web/models/MavenUrlVersion.java b/src/main/java/net/fabricmc/meta/web/models/MavenUrlVersion.java index b5e839e..9f60d8f 100644 --- a/src/main/java/net/fabricmc/meta/web/models/MavenUrlVersion.java +++ b/src/main/java/net/fabricmc/meta/web/models/MavenUrlVersion.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Legacy Fabric + * Copyright (c) 2021-2024 Legacy Fabric * Copyright (c) 2019 FabricMC * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,7 +26,7 @@ public class MavenUrlVersion extends MavenVersion { public MavenUrlVersion(String maven) { super(maven); String[] split = maven.split(":"); - this.url = String.format("%s%s/%s/%s/%s-%s.jar", VersionDatabase.MAVEN_URL, + this.url = String.format("%s%s/%s/%s/%s-%s.jar", getMavenUrl(), split[0].replaceAll("\\.", "/"), split[1], split[2], @@ -34,4 +34,8 @@ public MavenUrlVersion(String maven) { split[2] ); } + + public String getMavenUrl() { + return VersionDatabase.MAVEN_URL; + } } diff --git a/src/main/java/net/legacyfabric/meta/LegacyConstants.java b/src/main/java/net/legacyfabric/meta/LegacyConstants.java new file mode 100644 index 0000000..06ad534 --- /dev/null +++ b/src/main/java/net/legacyfabric/meta/LegacyConstants.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2021-2024 Legacy Fabric + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.meta; + +public class LegacyConstants { +} diff --git a/src/main/java/net/legacyfabric/meta/data/LegacyVersionDatabase.java b/src/main/java/net/legacyfabric/meta/data/LegacyVersionDatabase.java new file mode 100644 index 0000000..6aa53a4 --- /dev/null +++ b/src/main/java/net/legacyfabric/meta/data/LegacyVersionDatabase.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021-2024 Legacy Fabric + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.meta.data; + +import net.fabricmc.meta.data.VersionDatabase; +import net.fabricmc.meta.utils.PomParser; +import net.fabricmc.meta.web.models.BaseVersion; +import net.fabricmc.meta.web.models.MavenBuildVersion; +import net.fabricmc.meta.web.models.MavenUrlVersion; +import net.legacyfabric.meta.web.models.LegacyMavenUrlVersion; + +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class LegacyVersionDatabase extends VersionDatabase { + public static final String MAVEN_URL = "https://repo.legacyfabric.net/repository/legacyfabric/"; + + public static final PomParser MAPPINGS_PARSER = new PomParser(MAVEN_URL + "net/legacyfabric/yarn/maven-metadata.xml"); + public static final PomParser INTERMEDIARY_PARSER = new PomParser(MAVEN_URL + "net/legacyfabric/intermediary/maven-metadata.xml"); + public static final PomParser INSTALLER_PARSER = new PomParser(MAVEN_URL + "net/legacyfabric/fabric-installer/maven-metadata.xml"); + + public PomParser getMappingsParser() { + return MAPPINGS_PARSER; + } + + public String getMappingsPrefix() { + return "net.legacyfabric:yarn:"; + } + + public PomParser getIntermediaryParser() { + return INTERMEDIARY_PARSER; + } + + public String getIntermediaryPrefix() { + return "net.legacyfabric:intermediary:"; + } + + public PomParser getInstallerParser() { + return INSTALLER_PARSER; + } + + public String getInstallerPrefix() { + return "net.legacyfabric:fabric-installer:"; + } + + @Override + public Function getMavenUrlVersionBuilder() { + return LegacyMavenUrlVersion::new; + } + + public List getLoader() { + return loader.stream().filter(LegacyVersionDatabase::isPublicLoaderVersion).collect(Collectors.toList()); + } + + private static boolean isPublicLoaderVersion(BaseVersion version) { + String[] ver = version.getVersion().split("\\."); + return Integer.parseInt(ver[1]) >= 13 + || Integer.parseInt(ver[0]) > 0; + } +} diff --git a/src/main/java/net/legacyfabric/meta/web/LegacyEndpointsV2.java b/src/main/java/net/legacyfabric/meta/web/LegacyEndpointsV2.java new file mode 100644 index 0000000..da1e13e --- /dev/null +++ b/src/main/java/net/legacyfabric/meta/web/LegacyEndpointsV2.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021-2024 Legacy Fabric + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.meta.web; + +import io.javalin.http.Context; +import net.fabricmc.meta.FabricMeta; +import net.fabricmc.meta.utils.MinecraftLauncherMeta; +import net.fabricmc.meta.web.EndpointsV2; +import net.fabricmc.meta.web.WebServer; + +import net.legacyfabric.meta.web.models.MetaServerInfo; +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Objects; + +public class LegacyEndpointsV2 extends EndpointsV2 { + public static void setup() { + WebServer.jsonGet("/v2/meta", () -> MetaServerInfo.INSTANCE); + + LegacyWebServer.stringGet("/v2/manifest/:game_version", LegacyEndpointsV2::getVersionManifest); + WebServer.jsonGet("/v2/versions/manifest", context -> FabricMeta.database.launcherMeta); + } + + private static String getVersionManifest(Context context) { + if (!context.pathParamMap().containsKey("game_version")) { + return null; + } + + String gameVersion = context.pathParam("game_version"); + + MinecraftLauncherMeta.Version version = FabricMeta.database.launcherMeta.getVersions().stream() + .filter(v -> Objects.equals(v.getId(), gameVersion)) + .findFirst().orElse(null); + + String json = null; + + if (version != null) { + try { + json = IOUtils.toString(new URL(version.getUrl()), StandardCharsets.UTF_8); + } catch (IOException e) { + + } + } + + return json; + } +} diff --git a/src/main/java/net/legacyfabric/meta/web/LegacyWebServer.java b/src/main/java/net/legacyfabric/meta/web/LegacyWebServer.java new file mode 100644 index 0000000..8fcae66 --- /dev/null +++ b/src/main/java/net/legacyfabric/meta/web/LegacyWebServer.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021-2024 Legacy Fabric + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.meta.web; + +import io.javalin.core.util.Header; +import io.javalin.http.Context; +import net.fabricmc.meta.web.WebServer; + +import java.util.function.Function; +import java.util.function.Supplier; + +public class LegacyWebServer extends WebServer { + public static void stringGet(String route, Supplier supplier) { + javalin.get(route, ctx -> { + String object = supplier.get(); + handleString(ctx, object); + }); + } + + public static void stringGet(String route, Function supplier) { + javalin.get(route, ctx -> { + String object = supplier.apply(ctx); + handleString(ctx, object); + }); + } + + public static void handleString(Context ctx, String string) { + if (string == null) { + string = ""; + ctx.status(400); + } + + ctx.contentType("application/json").header(Header.CACHE_CONTROL, "public, max-age=60").result(string); + } +} diff --git a/src/main/java/net/legacyfabric/meta/web/models/LegacyMavenUrlVersion.java b/src/main/java/net/legacyfabric/meta/web/models/LegacyMavenUrlVersion.java new file mode 100644 index 0000000..49ce510 --- /dev/null +++ b/src/main/java/net/legacyfabric/meta/web/models/LegacyMavenUrlVersion.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021-2024 Legacy Fabric + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.legacyfabric.meta.web.models; + +import net.fabricmc.meta.web.models.MavenUrlVersion; +import net.legacyfabric.meta.data.LegacyVersionDatabase; + +public class LegacyMavenUrlVersion extends MavenUrlVersion { + public LegacyMavenUrlVersion(String maven) { + super(maven); + } + + @Override + public String getMavenUrl() { + return LegacyVersionDatabase.MAVEN_URL; + } +} diff --git a/src/replaceme/java/net/fabricmc/meta/web/models/MetaServerInfo.java b/src/replaceme/java/net/legacyfabric/meta/web/models/MetaServerInfo.java similarity index 85% rename from src/replaceme/java/net/fabricmc/meta/web/models/MetaServerInfo.java rename to src/replaceme/java/net/legacyfabric/meta/web/models/MetaServerInfo.java index d4f7034..5fc88d2 100644 --- a/src/replaceme/java/net/fabricmc/meta/web/models/MetaServerInfo.java +++ b/src/replaceme/java/net/legacyfabric/meta/web/models/MetaServerInfo.java @@ -1,4 +1,4 @@ -package net.fabricmc.meta.web.models; +package net.legacyfabric.meta.web.models; public class MetaServerInfo { public static final MetaServerInfo INSTANCE = new MetaServerInfo();