Skip to content

Commit

Permalink
Separate LF code from Upstream code + update License headers
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Feb 6, 2024
1 parent 0d8e69c commit 7b5f286
Show file tree
Hide file tree
Showing 21 changed files with 353 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
!/gradlew
!/gradlew.bat
!/LF-HEADER
!/LF-ONLY-HEADER
!/HEADER
!/LICENSE
!/README.md
Expand Down
2 changes: 1 addition & 1 deletion LF-HEADER
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
13 changes: 13 additions & 0 deletions LF-ONLY-HEADER
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 10 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/fabricmc/meta/FabricMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
76 changes: 52 additions & 24 deletions src/main/java/net/fabricmc/meta/data/VersionDatabase.java
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand All @@ -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<String> incorrectVersions = new ArrayList<>();
private static final Logger LOGGER = LoggerFactory.getLogger(VersionDatabase.class);

public List<BaseVersion> game;
public List<MavenBuildGameVersion> mappings;
public List<MavenVersion> intermediary;
private List<MavenBuildVersion> loader;
public List<MavenBuildVersion> loader;
public List<MavenUrlVersion> installer;
public MinecraftLauncherMeta launcherMeta;

private static final ArrayList<String> 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)) {
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -112,12 +110,42 @@ public List<MavenBuildVersion> 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<MavenBuildVersion> 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<String, MavenUrlVersion> getMavenUrlVersionBuilder() {
return MavenUrlVersion::new;
}

public MinecraftLauncherMeta launcherMeta;
}
7 changes: 4 additions & 3 deletions src/main/java/net/fabricmc/meta/utils/LoaderMeta.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* Copyright (c) 2021-2022 Legacy Fabric
* Copyright (c) 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/net/fabricmc/meta/utils/MinecraftLauncherMeta.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2021-2024 Legacy Fabric
* Copyright (c) 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -44,15 +45,16 @@ 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);
}

public static MinecraftLauncherMeta getAllMeta() throws IOException {
List<Version> versions = new ArrayList<>();
versions.addAll(getMeta().versions);
// versions.addAll(getExperimentalMeta().versions);
versions.addAll(getMissingMeta().versions);

// Order by release time
Expand All @@ -78,6 +80,12 @@ public List<Version> 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;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/fabricmc/meta/web/EndpointsV1.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* Copyright (c) 2021-2022 Legacy Fabric
* Copyright (c) 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
33 changes: 4 additions & 29 deletions src/main/java/net/fabricmc/meta/web/EndpointsV2.java
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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 <T> List<T> withLimitSkip(Context context, List<T> list) {
protected static <T> List<T> withLimitSkip(Context context, List<T> list) {
if(list == null){
return Collections.emptyList();
}
Expand All @@ -92,30 +91,6 @@ private static <T extends Predicate<String>> List<T> 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")) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/fabricmc/meta/web/ProfileHandler.java
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Loading

0 comments on commit 7b5f286

Please sign in to comment.