Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fabric-api to meta #10

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/net/fabricmc/meta/data/VersionDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ public class VersionDatabase {
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");
public static final PomParser API_PARSER = new PomParser(MAVEN_URL + "net/fabricmc/fabric-api/fabric-api/maven-metadata.xml");

public List<BaseVersion> game;
public List<MavenBuildGameVersion> mappings;
public List<MavenVersion> intermediary;
public List<MavenBuildVersion> loader;
public List<MavenUrlVersion> installer;
public List<MavenBuildApiGameVersion> api;

private VersionDatabase() {
}
Expand All @@ -52,6 +54,7 @@ public static VersionDatabase generate() throws IOException, XMLStreamException
database.intermediary = INTERMEDIARY_PARSER.getMeta(MavenVersion::new, "net.fabricmc:intermediary:");
database.loader = LOADER_PARSER.getMeta(MavenBuildVersion::new, "net.fabricmc:fabric-loader:");
database.installer = INSTALLER_PARSER.getMeta(MavenUrlVersion::new, "net.fabricmc:fabric-installer:");
database.api = API_PARSER.getMeta(MavenBuildApiGameVersion::new, "net.fabricmc:fabric-api:fabric-api:");
database.loadMcData();
System.out.println("DB update took " + (System.currentTimeMillis() - start) + "ms");
return database;
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/net/fabricmc/meta/utils/ApiVersionParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package net.fabricmc.meta.utils;

public class ApiVersionParser {

private String apiVersion;
private String minecraftVersion;

private String version;
private int build;

public ApiVersionParser(String version) {
this.version = version;

// Fix old API versions not having MC version
// Recreated from curseforge version index
if (version.contains("0.3.1") || version.contains("0.3.0")) {
version = version + "-1.14";
}

if (version.contains("+build.")) {
//TODO legacy remove when no longer needed
this.minecraftVersion = version.substring(version.lastIndexOf('-'));
this.apiVersion = version.substring(0, version.lastIndexOf('+') - 1);
this.build = Integer.parseInt(version.substring(version.lastIndexOf("+build.")+7, version.lastIndexOf('-')));
} else {
this.minecraftVersion = version.substring(version.lastIndexOf('+'));
this.apiVersion = version.substring(0, version.lastIndexOf('+') - 1);
this.build = 999; // Build number is no longer appended to versions, use dummy version
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isnt going to be accrate and it needs to be if provided via an api. I've been over this a few times in detail in discord.

The only way to provide good data is to have a manually managed database of what mc versions fabric api will work with. Some API versions work across a number of versions (Think pre-releases espeacially). this seems to just be using the branch provided in the version witch doesnt help decided between 1.16.1 and 1.16.2 in any way.

If launchers/installers are going to install fabric api they need to be 100% sure its going to work, this doesnt provide that.

Copy link
Author

@dexman545 dexman545 Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where should this database exist, and how should it be added to?

Example in progress mc->api: https://gist.github.com/dexman545/478d9ca5598a48ed2960fbb5d06ef0be

}

public String getApiVersion() {
return apiVersion;
}

public String getMinecraftVersion() {
return minecraftVersion;
}

@Override
public String toString() {
return version;
}

public int getBuild() {
return build;
}
}
3 changes: 3 additions & 0 deletions src/main/java/net/fabricmc/meta/web/EndpointsV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public static void setup() {
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/versions/fabric-api", context -> withLimitSkip(context, FabricMeta.database.api));
WebServer.jsonGet("/v2/versions/fabric-api/:game_version", context -> withLimitSkip(context, filter(context, FabricMeta.database.api)));

WebServer.jsonGet("/v2/versions/installer", context -> withLimitSkip(context, FabricMeta.database.installer));

ProfileHandler.setup();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.fabricmc.meta.web.models;

import net.fabricmc.meta.utils.ApiVersionParser;

public class MavenBuildApiGameVersion extends MavenBuildVersion{

String gameVersion;

public MavenBuildApiGameVersion(String maven) {
super(maven);

String[] mavenP = maven.split(":");
String version = mavenP[mavenP.length-1];
ApiVersionParser parser = new ApiVersionParser(version);
gameVersion = parser.getMinecraftVersion();
this.build = parser.getBuild();
System.out.println(version);
this.version = version.substring(0, version.lastIndexOf(gameVersion.charAt(0)) != -1 ? version.lastIndexOf(gameVersion.charAt(0)) : version.length() - 1);
this.gameVersion = gameVersion.replaceAll("[+-]", ""); // Remove prefix character
}

public String getGameVersion() {
return gameVersion;
}

@Override
public boolean test(String s) {
return getGameVersion().equals(s);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ public class MavenBuildVersion extends MavenVersion {

public MavenBuildVersion(String maven) {
super(maven);
String version = maven.split(":")[2];
String[] mavenP = maven.split(":");
String version = mavenP[mavenP.length-1];

if (version.contains("+build.")) {
separator = "+build.";
} else {
separator = ".";
}
build = Integer.parseInt(version.substring(version.lastIndexOf(".") + 1));
// Fix parser for oddball 20w14infinite api version (0.5.7+build.2-20w14infinite)
if (version.contains("+build.2-20w14infinite")) {
build = Integer.parseInt(version.substring(version.lastIndexOf(".") + 1, version.lastIndexOf('-')));
} else {
build = Integer.parseInt(version.substring(version.lastIndexOf(".") + 1));
}

}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/fabricmc/meta/web/models/MavenVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ public class MavenVersion extends BaseVersion {
String maven;

public MavenVersion(String maven, boolean stable) {
super(maven.split(":")[2], stable);
super(getMavenParsed(maven), stable);
this.maven = maven;
}

public MavenVersion(String maven) {
this(maven, false);
}

private static String getMavenParsed(String maven) {
String[] mavenP = maven.split(":");
return mavenP[mavenP.length-1];
}

public String getMaven() {
return maven;
}
Expand Down