mirror of
https://github.com/PaperMC/Paper.git
synced 2025-11-18 12:44:27 +01:00
Improve API versioning file (#13204)
This commit is contained in:
parent
65daa7962b
commit
75a5a4311e
@ -1,6 +1,9 @@
|
||||
group=io.papermc.paper
|
||||
version=25w42a-R0.1-SNAPSHOT
|
||||
mcVersion=25w42a
|
||||
# This is the current API version for use in (paper-)plugin.yml files
|
||||
# During snapshot cycles this should be the anticipated version of the release target
|
||||
apiVersion=1.21.11
|
||||
|
||||
# Set to true while updating Minecraft version
|
||||
updatingMinecraft=true
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import paper.libs.com.google.gson.Gson
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
@ -136,20 +138,36 @@ configure<PublishingExtension> {
|
||||
}
|
||||
}
|
||||
|
||||
val generateApiVersioningFile by tasks.registering {
|
||||
inputs.property("version", project.version)
|
||||
val pomProps = layout.buildDirectory.file("pom.properties")
|
||||
outputs.file(pomProps)
|
||||
val projectVersion = project.version
|
||||
doLast {
|
||||
pomProps.get().asFile.writeText("version=$projectVersion")
|
||||
abstract class GenerateApiVersioningFile : DefaultTask() {
|
||||
@get:OutputFile
|
||||
abstract val outputFile: RegularFileProperty
|
||||
|
||||
@get:Input
|
||||
abstract val projectVersion: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val apiVersion: Property<String>
|
||||
|
||||
@TaskAction
|
||||
fun generate() {
|
||||
val file = outputFile.get().asFile
|
||||
file.parentFile.mkdirs()
|
||||
val map = mapOf(
|
||||
"version" to projectVersion.get(),
|
||||
"currentApiVersion" to apiVersion.get()
|
||||
)
|
||||
file.writeText(Gson().toJson(map))
|
||||
}
|
||||
}
|
||||
|
||||
val generateApiVersioningFile = tasks.register<GenerateApiVersioningFile>("generateApiVersioningFile") {
|
||||
outputFile.set(layout.buildDirectory.file("apiVersioning.json"))
|
||||
projectVersion.set(project.version.toString())
|
||||
apiVersion.set(rootProject.providers.gradleProperty("apiVersion"))
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
from(generateApiVersioningFile.map { it.outputs.files.singleFile }) {
|
||||
into("META-INF/maven/${project.group}/${project.name}")
|
||||
}
|
||||
from(generateApiVersioningFile.flatMap { it.outputFile })
|
||||
manifest {
|
||||
attributes(
|
||||
"Automatic-Module-Name" to "org.bukkit"
|
||||
|
||||
@ -17,7 +17,7 @@ public final class ApiVersion implements Comparable<ApiVersion>, Serializable {
|
||||
|
||||
static {
|
||||
versions = new HashMap<>();
|
||||
CURRENT = getOrCreateVersion("1.21.11");
|
||||
CURRENT = getOrCreateVersion(Versioning.getCurrentApiVersion());
|
||||
FLATTENING = getOrCreateVersion("1.13");
|
||||
FIELD_NAME_PARITY = getOrCreateVersion("1.20.5");
|
||||
ABSTRACT_COW = getOrCreateVersion("1.21.5");
|
||||
|
||||
@ -1,29 +1,52 @@
|
||||
package org.bukkit.craftbukkit.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.SharedConstants;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public final class Versioning {
|
||||
public static String getBukkitVersion() {
|
||||
String result = "Unknown-Version";
|
||||
private static final String BUKKIT_VERSION;
|
||||
private static final String API_VERSION;
|
||||
|
||||
InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/io.papermc.paper/paper-api/pom.properties");
|
||||
Properties properties = new Properties();
|
||||
|
||||
if (stream != null) {
|
||||
try {
|
||||
properties.load(stream);
|
||||
|
||||
result = properties.getProperty("version");
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Versioning.class.getName()).log(Level.SEVERE, "Could not get Bukkit version!", ex);
|
||||
static {
|
||||
String bukkitVersion = "Unknown-Version";
|
||||
String apiVersion = null;
|
||||
try (final InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("apiVersioning.json")) {
|
||||
if (stream == null) {
|
||||
throw new IOException("apiVersioning.json not found in classpath");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
final JsonObject jsonObject = new Gson()
|
||||
.fromJson(new BufferedReader(new InputStreamReader(stream)), JsonObject.class);
|
||||
|
||||
if (jsonObject == null) {
|
||||
throw new IOException("apiVersioning.json is not a valid JSON file");
|
||||
}
|
||||
|
||||
bukkitVersion = jsonObject.get("version").getAsString();
|
||||
apiVersion = jsonObject.get("currentApiVersion").getAsString();
|
||||
} catch (final IOException ex) {
|
||||
Logger.getLogger(Versioning.class.getName()).log(Level.SEVERE, "Could not get Bukkit version!", ex);
|
||||
}
|
||||
BUKKIT_VERSION = bukkitVersion;
|
||||
if (apiVersion == null) {
|
||||
apiVersion = SharedConstants.getCurrentVersion().id();
|
||||
}
|
||||
API_VERSION = apiVersion;
|
||||
}
|
||||
|
||||
public static String getBukkitVersion() {
|
||||
return BUKKIT_VERSION;
|
||||
}
|
||||
|
||||
public static String getCurrentApiVersion() {
|
||||
return API_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,14 +5,9 @@ dependencies {
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
var apiVersion = rootProject.providers.gradleProperty("mcVersion").get()
|
||||
// Bukkit api versioning does not support suffixed versions
|
||||
apiVersion = apiVersion.substringBefore('-')
|
||||
apiVersion = "1.21.11" // TODO - snapshot - remove once pre-releases hit
|
||||
|
||||
val props = mapOf(
|
||||
"version" to project.version,
|
||||
"apiversion" to "\"$apiVersion\"",
|
||||
"apiversion" to "\"${rootProject.providers.gradleProperty("apiVersion").get()}\"",
|
||||
)
|
||||
inputs.properties(props)
|
||||
filesMatching("paper-plugin.yml") {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user