Skip to content

Commit

Permalink
Release 1.1.4 (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs authored Aug 16, 2024
2 parents 0acd646 + f5c2ae0 commit 7c3c358
Show file tree
Hide file tree
Showing 54 changed files with 699 additions and 566 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.direnv
146 changes: 30 additions & 116 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,138 +1,52 @@
plugins {
id("org.cadixdev.licenser") version "0.6.1"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("de.chojo.publishdata") version "1.4.0"
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
java
`maven-publish`
}

group = "de.eldoria"
version = "1.1.3"
val shadebase = "de.eldoria." + rootProject.name + ".libs."
group = "de.eldoria.schematic-brush-database"
version = "1.1.4"

repositories {
mavenCentral()
maven("https://eldonexus.de/repository/maven-public/")
maven("https://eldonexus.de/repository/maven-proxies/")
}

dependencies {
bukkitLibrary(libs.bundles.sadu)

compileOnly("de.eldoria", "schematicbrushreborn-api", "2.6.0")
compileOnly("org.spigotmc", "spigot-api", "1.16.5-R0.1-SNAPSHOT")
compileOnly("com.sk89q.worldedit", "worldedit-bukkit", "7.2.18")

bukkitLibrary("org.postgresql", "postgresql", "42.7.1")
bukkitLibrary("org.mariadb.jdbc", "mariadb-java-client", "3.3.2")
bukkitLibrary("mysql", "mysql-connector-java", "8.0.33")
bukkitLibrary("com.zaxxer", "HikariCP", "5.1.0")

testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.10.1")
testImplementation("de.eldoria", "schematicbrushreborn-api", "2.6.0")
testImplementation("org.spigotmc", "spigot-api", "1.16.5-R0.1-SNAPSHOT")
testImplementation("com.fasterxml.jackson.core", "jackson-databind", "2.14.2")

testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine")
}

license {
header(rootProject.file("HEADER.txt"))
include("**/*.java")
}

java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_17
}

publishData {
addBuildData()
useEldoNexusRepos()
publishTask("shadowJar")
publishTask("javadocJar")
publishTask("sourcesJar")
}

publishing {
publications.create<MavenPublication>("maven") {
publishData.configurePublication(this)
allprojects {
apply {
plugin<JavaPlugin>()
}

repositories {
maven {
authentication {
credentials(PasswordCredentials::class) {
username = System.getenv("NEXUS_USERNAME")
password = System.getenv("NEXUS_PASSWORD")
}
}
group = rootProject.group
version = rootProject.version

setUrl(publishData.getRepository())
name = "EldoNexus"
}
}
}

tasks {
compileJava {
options.encoding = "UTF-8"
}

compileTestJava {
options.encoding = "UTF-8"
repositories {
mavenCentral()
maven("https://eldonexus.de/repository/maven-public/")
maven("https://eldonexus.de/repository/maven-proxies/")
}

test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
withSourcesJar()
withJavadocJar()
}

shadowJar {
relocate("de.eldoria.eldoutilities", "de.eldoria.schematicbrush.libs.eldoutilities")
relocate("de.eldoria.messageblocker", "de.eldoria.schematicbrush.libs.messageblocker")
mergeServiceFiles()
archiveClassifier.set("")
archiveBaseName.set("SchematicBrushDatabase")
}

processResources {
from(sourceSets.main.get().resources.srcDirs) {
filesMatching("plugin.yml") {
expand(
"version" to publishData.getVersion(true)
)
}
duplicatesStrategy = DuplicatesStrategy.INCLUDE
tasks {
compileJava {
options.encoding = "UTF-8"
}
}

register<Copy>("copyToServer") {
val path = project.property("targetDir") ?: "";
if (path.toString().isEmpty()) {
println("targetDir is not set in gradle properties")
return@register
compileTestJava {
options.encoding = "UTF-8"
}
println("Copying jar to $path")
from(shadowJar)
destinationDir = File(path.toString())
}

build {
dependsOn(shadowJar)
test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
}
}


bukkit {
name = "SchematicBrushDatabase"
main = "de.eldoria.sbrdatabase.SbrDatabase"
apiVersion = "1.16"
version = publishData.getVersion(true)
authors = listOf("RainbowDashLabs")
depend = listOf("SchematicBrushReborn")
license {
header(rootProject.file("HEADER.txt"))
include("**/*.java")
}
38 changes: 38 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id("java")
alias(libs.plugins.pluginyml)
alias(libs.plugins.publishdata)
}

publishData {
useEldoNexusRepos()
}

dependencies {
bukkitLibrary(libs.bundles.sadu)
bukkitLibrary("org.postgresql", "postgresql", "42.7.3")
bukkitLibrary("org.mariadb.jdbc", "mariadb-java-client", "3.4.1")
bukkitLibrary("mysql", "mysql-connector-java", "8.0.33")
bukkitLibrary("com.zaxxer", "HikariCP", "5.1.0")

compileOnly("de.eldoria", "schematicbrushreborn-api", "2.7.1")
compileOnly("org.spigotmc", "spigot-api", "1.16.5-R0.1-SNAPSHOT")
compileOnly("com.sk89q.worldedit", "worldedit-bukkit", "7.3.6")


testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.11.0")
testImplementation("de.eldoria", "schematicbrushreborn-api", "2.7.1")
testImplementation("org.spigotmc", "spigot-api", "1.16.5-R0.1-SNAPSHOT")
testImplementation("com.fasterxml.jackson.core", "jackson-databind", "2.17.2")

testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine")
}

bukkit {
name = "SchematicBrushDatabase"
main = "de.eldoria.sbrdatabase.SbrDatabase"
apiVersion = "1.16"
version = publishData.getVersion(true)
authors = listOf("RainbowDashLabs")
depend = listOf("SchematicBrushReborn")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.zaxxer.hikari.HikariDataSource;
import de.chojo.sadu.databases.Database;
import de.chojo.sadu.databases.MariaDb;
import de.chojo.sadu.databases.MySql;
import de.chojo.sadu.databases.PostgreSql;
import de.chojo.sadu.core.databases.Database;
import de.chojo.sadu.core.jdbc.RemoteJdbcConfig;
import de.chojo.sadu.core.updater.SqlVersion;
import de.chojo.sadu.core.updater.UpdaterBuilder;
import de.chojo.sadu.datasource.DataSourceCreator;
import de.chojo.sadu.datasource.stage.ConfigurationStage;
import de.chojo.sadu.jdbc.RemoteJdbcConfig;
import de.chojo.sadu.mariadb.databases.MariaDb;
import de.chojo.sadu.mysql.databases.MySql;
import de.chojo.sadu.postgresql.databases.PostgreSql;
import de.chojo.sadu.queries.api.configuration.QueryConfiguration;
import de.chojo.sadu.updater.QueryReplacement;
import de.chojo.sadu.updater.SqlUpdater;
import de.chojo.sadu.updater.SqlVersion;
import de.chojo.sadu.updater.UpdaterBuilder;
import de.chojo.sadu.wrapper.QueryBuilderConfig;
import de.eldoria.eldoutilities.config.template.PluginBaseConfiguration;
import de.eldoria.eldoutilities.plugin.EldoPlugin;
import de.eldoria.eldoutilities.updater.lynaupdater.LynaUpdateChecker;
Expand All @@ -39,13 +39,15 @@
import de.eldoria.schematicbrush.brush.config.util.Nameable;
import de.eldoria.schematicbrush.storage.StorageRegistry;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPluginLoader;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
import java.util.logging.Level;

Expand All @@ -54,27 +56,29 @@ public class SbrDatabase extends EldoPlugin {
private static final Nameable mysql = Nameable.of("mysql");
private static final Nameable postgres = Nameable.of("postgres");
public static final Nameable[] sqlTypes = {mariadb, mysql, postgres};
private final Thread.UncaughtExceptionHandler exceptionHandler = (thread, err) -> logger().log(Level.SEVERE, "Unhandled exception occured in thread " + thread.getName() + "-" + thread.getId(), err);
private ObjectMapper mapper;
private final List<HikariDataSource> sources = new ArrayList<>();
private final ExecutorService executor = Executors.newCachedThreadPool(run -> {
var thread = new Thread(run, "DbThreads");
thread.setUncaughtExceptionHandler(exceptionHandler);
return thread;
});
private JacksonConfiguration configuration;
private SchematicBrushReborn sbr;

public SbrDatabase() {
configuration = new JacksonConfiguration(this);
}

public SbrDatabase(@NotNull JavaPluginLoader loader, @NotNull PluginDescriptionFile description, @NotNull File dataFolder, @NotNull File file) {
super(loader, description, dataFolder, file);
configuration = new JacksonConfiguration(this);
}

@Override
public void onPluginLoad() throws Throwable {
sbr = SchematicBrushReborn.instance();
var builder = JsonMapper.builder();
mapper = sbr.configureMapper(builder);
QueryBuilderConfig.setDefault(QueryBuilderConfig.builder()
.withExceptionHandler(ex -> logger().log(Level.SEVERE, "SQL Exception occured.", ex))
QueryConfiguration.setDefault(QueryConfiguration.builder(null)
.setExceptionHandler(ex -> getLogger().log(Level.SEVERE, "SQL Exception occurred.", ex))
.build());

configuration = new JacksonConfiguration(this);
PluginBaseConfiguration base = configuration.secondary(PluginBaseConfiguration.KEY);
if (base.version() == 0) {
var legacyConfiguration = new LegacyConfiguration(this);
Expand All @@ -96,13 +100,17 @@ public void onPluginLoad() throws Throwable {

@Override
public void onPluginDisable() throws Throwable {
executor.shutdown();
configuration.save();
for (HikariDataSource source : sources) {
source.close();
}
}

@Override
public Level getLogLevel() {
return configuration.secondary(PluginBaseConfiguration.KEY).logLevel();
}

@Override
public List<Class<? extends ConfigurationSerializable>> getConfigSerialization() {
return List.of(Storages.class, BaseDbConfig.class, PostgresDbConfig.class, Cache.class);
Expand All @@ -128,7 +136,7 @@ private void registerStorageTypes() throws IOException, SQLException {

private void setupMariaDb() throws IOException, SQLException {
var source = applyBaseDb(MariaDb.get(), configuration.storages().mariadb()).build();
sbr.storageRegistry().register(SbrDatabase.mariadb, new MariaDbStorage(source, configuration, mapper));
sbr.storageRegistry().register(SbrDatabase.mariadb, new MariaDbStorage(QueryConfiguration.getDefault().edit(source).build(), configuration, mapper));
SqlUpdater.builder(source, MariaDb.get())
.withClassLoader(getClassLoader())
.setVersionTable("sbr_version")
Expand All @@ -139,7 +147,7 @@ private void setupMariaDb() throws IOException, SQLException {

private void setupMySql() throws IOException, SQLException {
var source = applyBaseDb(MySql.get(), configuration.storages().mysql()).build();
sbr.storageRegistry().register(SbrDatabase.mysql, new MySqlStorage(source, configuration, mapper));
sbr.storageRegistry().register(SbrDatabase.mysql, new MySqlStorage(QueryConfiguration.getDefault().edit(source).build(), configuration, mapper));
SqlUpdater.builder(source, MySql.get())
.withClassLoader(getClassLoader())
.setVersionTable("sbr_version")
Expand All @@ -154,9 +162,8 @@ private void setupPostgres() throws IOException, SQLException {
.forSchema(postgres.schema())
.build();


var update = applyBaseDb(PostgreSql.get(), postgres).build();
sbr.storageRegistry().register(SbrDatabase.postgres, new PostgresStorage(source, configuration, mapper));
sbr.storageRegistry().register(SbrDatabase.postgres, new PostgresStorage(QueryConfiguration.getDefault().edit(source).build(), configuration, mapper));
SqlUpdater.builder(update, PostgreSql.get())
.withClassLoader(getClassLoader())
.setReplacements(new QueryReplacement("sbr_database", postgres.schema()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import de.chojo.sadu.base.QueryFactory;
import de.chojo.sadu.queries.api.configuration.QueryConfiguration;
import de.chojo.sadu.queries.api.query.ParsedQuery;
import de.chojo.sadu.queries.configuration.ConnectedQueryConfigurationImpl;
import de.eldoria.sbrdatabase.configuration.Configuration;
import de.eldoria.schematicbrush.storage.brush.BrushContainer;
import de.eldoria.schematicbrush.storage.brush.Brushes;

import javax.sql.DataSource;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public abstract class BaseBrushes extends QueryFactory implements Brushes {
public abstract class BaseBrushes implements Brushes {
private final Cache<UUID, BrushContainer> cache = CacheBuilder.newBuilder()
.expireAfterAccess(5, TimeUnit.MINUTES)
.maximumSize(50)
.build();
private final QueryConfiguration queryConfiguration;
private final Configuration configuration;
private BrushContainer global;

public BaseBrushes(DataSource dataSource, Configuration configuration) {
super(dataSource);
public BaseBrushes(QueryConfiguration queryConfiguration, Configuration configuration) {
this.queryConfiguration = queryConfiguration;
this.configuration = configuration;
}

Expand All @@ -53,4 +55,16 @@ public BrushContainer globalContainer() {
public Configuration configuration() {
return configuration;
}

public ConnectedQueryConfigurationImpl withSingleTransaction() {
return queryConfiguration.withSingleTransaction();
}

public ParsedQuery query(String sql, Object... format) {
return queryConfiguration.query(sql, format);
}

public QueryConfiguration queryConfiguration() {
return queryConfiguration;
}
}
Loading

0 comments on commit 7c3c358

Please sign in to comment.