Embed the SQLite driver inside the plugin

This commit is contained in:
lax1dude 2025-05-22 13:00:34 -07:00
parent 45b242be1e
commit 47424c0852
6 changed files with 78 additions and 21 deletions

View File

@ -8,6 +8,7 @@ configurations {
platformBukkit
platformBungee
platformVelocity
sqliteDriver
}
dependencies {
@ -27,6 +28,18 @@ dependencies {
compileOnly(libs.guava)
compileOnly(libs.slf4j)
compileOnly(libs.skinsrestorer.api)
sqliteDriver project(":skin-cache:sqlite-jdbc-jar")
}
def embedSQLiteJar(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar taskIn) {
taskIn.dependsOn ":skin-cache:sqlite-jdbc-jar:jar"
configurations.sqliteDriver.each {
def phile = it
taskIn.from(phile.parentFile.absolutePath) {
include phile.name
rename phile.name, "net/lax1dude/eaglercraft/backend/skin_cache/libs/sqlite-jdbc.library"
}
}
}
tasks.named("shadowJar", com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
@ -38,6 +51,7 @@ tasks.named("shadowJar", com.github.jengelman.gradle.plugins.shadow.tasks.Shadow
project.configurations.platformBungee,
project.configurations.platformVelocity
]
embedSQLiteJar(it)
archiveFileName = "EaglerXServer.jar"
relocate "org.objectweb.asm", "net.lax1dude.eaglercraft.backend.server.libs.asm"
}
@ -49,6 +63,7 @@ tasks.register("shadowJarBukkit", com.github.jengelman.gradle.plugins.shadow.tas
project.configurations.runtimeClasspath,
project.configurations.platformBukkit
]
embedSQLiteJar(it)
archiveFileName = "EaglerXServer-Bukkit.jar"
relocate "org.objectweb.asm", "net.lax1dude.eaglercraft.backend.server.libs.asm"
}
@ -60,6 +75,7 @@ tasks.register("shadowJarBungee", com.github.jengelman.gradle.plugins.shadow.tas
project.configurations.runtimeClasspath,
project.configurations.platformBungee
]
embedSQLiteJar(it)
archiveFileName = "EaglerXServer-Bungee.jar"
relocate "org.objectweb.asm", "net.lax1dude.eaglercraft.backend.server.libs.asm"
}
@ -71,6 +87,7 @@ tasks.register("shadowJarVelocity", com.github.jengelman.gradle.plugins.shadow.t
project.configurations.runtimeClasspath,
project.configurations.platformVelocity
]
embedSQLiteJar(it)
archiveFileName = "EaglerXServer-Velocity.jar"
relocate "org.objectweb.asm", "net.lax1dude.eaglercraft.backend.server.libs.asm"
}

View File

@ -32,6 +32,7 @@ hppc = "com.carrotsearch:hppc:0.10.0"
jsr305 = "com.google.code.findbugs:jsr305:3.0.2"
skinsrestorer-api = "net.skinsrestorer:skinsrestorer-api:15.3.1"
asm = "org.ow2.asm:asm:9.8"
jdbc-sqlite = "org.xerial:sqlite-jdbc:3.49.1.0"
[bundles]
netty-all = [

View File

@ -18,6 +18,7 @@ include "core:core-platform-adventure-chat"
include "core-config"
include "protocol-game"
include "skin-cache"
include "skin-cache:sqlite-jdbc-jar"
include "stubs"
include "rewind_v1_5"
include "rewind_v1_5:rewind_v1_5-platform-bukkit"

View File

@ -0,0 +1,31 @@
plugins {
id "java"
}
configurations {
sqliteDriver
}
dependencies {
sqliteDriver(libs.jdbc.sqlite)
}
jar {
entryCompression = ZipEntryCompression.STORED
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from {
configurations.sqliteDriver.collect { it.isDirectory() ? it : zipTree(it) }
}
exclude "org/sqlite/native/FreeBSD/x86/*"
exclude "org/sqlite/native/Linux/arm/*"
exclude "org/sqlite/native/Linux/armv6/*"
exclude "org/sqlite/native/Linux/ppc64/*"
exclude "org/sqlite/native/Linux/riscv64/*"
exclude "org/sqlite/native/Linux/x86/*"
exclude "org/sqlite/native/Linux-Android/x86/*"
exclude "org/sqlite/native/Linux-Android/x86_64/*"
exclude "org/sqlite/native/Linux-Musl/x86/*"
exclude "org/sqlite/native/Windows/armv7/*"
exclude "org/sqlite/native/Windows/x86/*"
}

View File

@ -45,16 +45,17 @@ public class EaglerDrivers {
if (address.equalsIgnoreCase("internal")) {
driver = new File(baseFolder, "drivers/sqlite-jdbc.jar");
driver.getParentFile().mkdirs();
if (!driver.exists()) {
try {
URL u = new URL(
"https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.48.0.0/sqlite-jdbc-3.48.0.0.jar");
logger.info("Downloading from maven: " + u);
copyURLToFile(u, driver);
} catch (Throwable ex) {
logger.error("Could not download sqlite-jdbc.jar from repo1.maven.org!");
logger.error("Please download \"org.xerial:sqlite-jdbc:3.48.0.0\" jar to file: "
+ driver.getAbsolutePath());
if (!driver.isFile()) {
try (InputStream is = EaglerDrivers.class.getResourceAsStream(
"/net/lax1dude/eaglercraft/backend/skin_cache/libs/sqlite-jdbc.library")) {
if (is == null) {
throw new IOException(
"Missing classpath resource: net/lax1dude/eaglercraft/backend/skin_cache/libs/sqlite-jdbc.library");
}
try (OutputStream os = new FileOutputStream(driver)) {
is.transferTo(os);
}
} catch (IOException ex) {
throw new ExceptionInInitializerError(ex);
}
}
@ -117,15 +118,4 @@ public class EaglerDrivers {
}
}
private static void copyURLToFile(URL url, File file) throws IOException {
try (InputStream is = url.openStream()) {
try (OutputStream os = new FileOutputStream(file)) {
byte[] buf = new byte[32768];
int i;
while ((i = is.read(buf)) != -1) {
os.write(buf, 0, i);
}
}
}
}
}

View File

@ -4,6 +4,10 @@ plugins {
id "com.gradleup.shadow" version "8.3.6"
}
configurations {
sqliteDriver
}
dependencies {
implementation project(":supervisor-protocol")
implementation project(":skin-cache")
@ -12,13 +16,26 @@ dependencies {
implementation(libs.slf4j)
implementation(libs.bundles.netty.supervisor)
runtimeOnly(libs.logback)
sqliteDriver project(":skin-cache:sqlite-jdbc-jar")
}
application {
mainClass = "net.lax1dude.eaglercraft.backend.supervisor.EaglerXSupervisorServer"
}
def embedSQLiteJar(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar taskIn) {
taskIn.dependsOn ":skin-cache:sqlite-jdbc-jar:jar"
configurations.sqliteDriver.each {
def phile = it
taskIn.from(phile.parentFile.absolutePath) {
include phile.name
rename phile.name, "net/lax1dude/eaglercraft/backend/skin_cache/libs/sqlite-jdbc.library"
}
}
}
tasks.named("shadowJar", com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
embedSQLiteJar(it)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveFileName = "EaglerXSupervisor.jar"
}