From 787f4fd384e185ad461f3d7d8d0ebfc826c91b08 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Tue, 6 Feb 2024 14:22:50 +0100 Subject: [PATCH] Fix BuildConstants --- build.gradle | 20 +++++++++---------- settings.gradle | 11 ++++++++++ .../meta/web/LegacyEndpointsV2.java | 4 ++-- .../meta/web/models/MetaServerInfo.java | 13 ------------ 4 files changed, 23 insertions(+), 25 deletions(-) delete mode 100644 src/replaceme/java/net/legacyfabric/meta/web/models/MetaServerInfo.java diff --git a/build.gradle b/build.gradle index f16d6bb..e23ce3c 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ plugins { id 'application' id 'maven-publish' id 'org.cadixdev.licenser' version '0.6.1' + id "com.github.gmazzo.buildconfig" version "5.2.0" } def legacyVersion = "1.7.6" @@ -32,16 +33,14 @@ dependencies { implementation group: 'commons-io', name: 'commons-io', version: '2.8.0' } -task generateSources(type: Copy) { - from 'src/replaceme/java/net/fabricmc/meta/web/models/MetaServerInfo.java' - into "$buildDir/generated-src" - filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [ - 'VERSION': project.version - ]) +buildConfig { + className("BuildConstants") + packageName("net.legacyfabric.meta") + + useJavaOutput() + + buildConfigField(String.class, "VERSION", "$project.version") } -// the following lines are important to wire the task in with the compileJava task -compileJava.source "$buildDir/generated-src" -compileJava.dependsOn generateSources jar { manifest { @@ -62,7 +61,7 @@ tasks.withType(JavaCompile).configureEach { } license { - matching(includes: ['**/legacyfabric/**']) { + matching(excludes: ['**/BuildConstants.java'], includes: ['**/legacyfabric/**']) { header = file("LF-ONLY-HEADER") } matching(includes: ['**/VersionDatabase.java', '**/MinecraftLauncherMeta.java','**/EndpointsV2.java', @@ -72,6 +71,7 @@ license { } header file('HEADER') include '**/*.java' + exclude '**/BuildConstants.java' } publishing { diff --git a/settings.gradle b/settings.gradle index 2481e5c..9bd4fcf 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,13 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal { + content { + excludeGroup("org.apache.logging.log4j") + } + } + } +} + rootProject.name = 'legacy-meta' diff --git a/src/main/java/net/legacyfabric/meta/web/LegacyEndpointsV2.java b/src/main/java/net/legacyfabric/meta/web/LegacyEndpointsV2.java index da1e13e..4a21c3f 100644 --- a/src/main/java/net/legacyfabric/meta/web/LegacyEndpointsV2.java +++ b/src/main/java/net/legacyfabric/meta/web/LegacyEndpointsV2.java @@ -22,7 +22,7 @@ import net.fabricmc.meta.web.EndpointsV2; import net.fabricmc.meta.web.WebServer; -import net.legacyfabric.meta.web.models.MetaServerInfo; +import net.legacyfabric.meta.BuildConstants; import org.apache.commons.io.IOUtils; import java.io.IOException; @@ -32,7 +32,7 @@ public class LegacyEndpointsV2 extends EndpointsV2 { public static void setup() { - WebServer.jsonGet("/v2/meta", () -> MetaServerInfo.INSTANCE); + WebServer.jsonGet("/v2/meta", () -> BuildConstants.VERSION); LegacyWebServer.stringGet("/v2/manifest/:game_version", LegacyEndpointsV2::getVersionManifest); WebServer.jsonGet("/v2/versions/manifest", context -> FabricMeta.database.launcherMeta); diff --git a/src/replaceme/java/net/legacyfabric/meta/web/models/MetaServerInfo.java b/src/replaceme/java/net/legacyfabric/meta/web/models/MetaServerInfo.java deleted file mode 100644 index 5fc88d2..0000000 --- a/src/replaceme/java/net/legacyfabric/meta/web/models/MetaServerInfo.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.legacyfabric.meta.web.models; - -public class MetaServerInfo { - public static final MetaServerInfo INSTANCE = new MetaServerInfo(); - - private static final String VERSION = "@VERSION@"; - - String version; - - private MetaServerInfo() { - this.version = VERSION; - } -}