mirror of
https://github.com/CarmJos/MineSQL.git
synced 2026-06-05 00:48:16 +08:00
feat(lib): 独立数据库依赖加载,缩减文件体积。
This commit is contained in:
+9
-21
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>1.3.1</version>
|
||||
<version>1.4.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
@@ -68,10 +68,17 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.byteflux</groupId>
|
||||
<artifactId>libby-core</artifactId>
|
||||
<version>${deps.libby.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.chris2018998</groupId>
|
||||
<artifactId>beecp</artifactId>
|
||||
<scope>compile</scope>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -101,25 +108,6 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -14,12 +14,14 @@ import cc.carm.plugin.minesql.command.MineSQLCommand;
|
||||
import cc.carm.plugin.minesql.command.MineSQLHelpFormatter;
|
||||
import cc.carm.plugin.minesql.conf.PluginConfiguration;
|
||||
import cc.carm.plugin.minesql.conf.SQLSourceGroup;
|
||||
import cc.carm.plugin.minesql.lib.PluginLibraries;
|
||||
import cc.carm.plugin.minesql.util.DBPropertiesUtil;
|
||||
import cn.beecp.BeeDataSource;
|
||||
import cn.beecp.BeeDataSourceConfig;
|
||||
import co.aikar.commands.CommandManager;
|
||||
import co.aikar.commands.InvalidCommandArgument;
|
||||
import co.aikar.commands.Locales;
|
||||
import net.byteflux.libby.Library;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -48,6 +50,17 @@ public class MineSQLCore implements IMineSQL {
|
||||
instance = this;
|
||||
this.platform = platform;
|
||||
|
||||
getLogger().info("加载数据库依赖文件...");
|
||||
getPlatform().getLibraryManager().addMavenLocal();
|
||||
getPlatform().getLibraryManager().addMavenCentral();
|
||||
getPlatform().getLibraryManager().addSonatype();
|
||||
|
||||
for (PluginLibraries value : PluginLibraries.values()) {
|
||||
Library lib = value.getLibrary();
|
||||
getLogger().info(" 加载 " + lib.getArtifactId() + " (" + lib.getVersion() + ") ...");
|
||||
getPlatform().getLibraryManager().loadLibrary(value.getLibrary());
|
||||
}
|
||||
|
||||
getLogger().info("加载配置文件...");
|
||||
this.configProvider = EasyConfiguration.from(new File(platform.getPluginFolder(), "config.yml"));
|
||||
this.config = new PluginConfiguration();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cc.carm.plugin.minesql;
|
||||
|
||||
import co.aikar.commands.CommandManager;
|
||||
import net.byteflux.libby.LibraryManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -15,4 +16,6 @@ public interface MineSQLPlatform {
|
||||
|
||||
@Nullable CommandManager<?, ?, ?, ?, ?, ?> getCommandManager();
|
||||
|
||||
@NotNull LibraryManager getLibraryManager();
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package cc.carm.plugin.minesql.command;
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.SQLQuery;
|
||||
import cc.carm.plugin.minesql.MineSQLCore;
|
||||
import cc.carm.plugin.minesql.lib.PluginLibraries;
|
||||
import cc.carm.plugin.minesql.util.VersionReader;
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.CommandHelp;
|
||||
@@ -42,7 +43,7 @@ public class MineSQLCommand extends BaseCommand {
|
||||
issuer.sendMessage("§c只有后台执行才能使用此命令。");
|
||||
return;
|
||||
}
|
||||
VersionReader reader = new VersionReader();
|
||||
VersionReader reader = PluginLibraries.READER;
|
||||
String pluginVersion = reader.get("plugin", null);
|
||||
if (pluginVersion == null) {
|
||||
issuer.sendMessage("§c无法获取当前版本信息,请保证使用原生版本以避免安全问题。");
|
||||
@@ -50,9 +51,9 @@ public class MineSQLCommand extends BaseCommand {
|
||||
}
|
||||
issuer.sendMessage("§r当前插件版本为 §b" + pluginVersion + "§r。 §7(基于 EasySQL &3" + reader.get("api") + "&7)");
|
||||
issuer.sendMessage("§8 - &f连接池依赖 BeeCP §9" + reader.get("beecp"));
|
||||
issuer.sendMessage("§8 - &f数据库驱动 MySQL §9" + reader.get("mysql-driver"));
|
||||
issuer.sendMessage("§8 - &f数据库驱动 MariaDB §9" + reader.get("mariadb-driver"));
|
||||
issuer.sendMessage("§8 - &f数据库驱动 h2-database §9" + reader.get("h2-driver"));
|
||||
issuer.sendMessage("§8 - &f数据库驱动 MySQL §9" + PluginLibraries.MYSQL_DRIVER.getVersion());
|
||||
issuer.sendMessage("§8 - &f数据库驱动 MariaDB §9" + PluginLibraries.MARIADB_DRIVER.getVersion());
|
||||
issuer.sendMessage("§8 - &f数据库驱动 h2-database §9" + PluginLibraries.H2_DRIVER.getVersion());
|
||||
|
||||
issuer.sendMessage("§r正在检查插件更新,请稍候...");
|
||||
core.checkUpdate(pluginVersion);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package cc.carm.plugin.minesql.lib;
|
||||
|
||||
import cc.carm.plugin.minesql.util.VersionReader;
|
||||
import net.byteflux.libby.Library;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public enum PluginLibraries {
|
||||
|
||||
BEECP("com.github.chris2018998", "beecp"),
|
||||
H2_DRIVER("com.h2database", "h2"),
|
||||
MYSQL_DRIVER("com.mysql", "mysql-connector-j"),
|
||||
MARIADB_DRIVER("org.mariadb.jdbc", "mariadb-java-client");
|
||||
|
||||
public static final VersionReader READER = new VersionReader();
|
||||
|
||||
private final @NotNull String groupID;
|
||||
private final @NotNull String artifactID;
|
||||
|
||||
PluginLibraries(@NotNull String groupID, @NotNull String artifactID) {
|
||||
this.groupID = groupID;
|
||||
this.artifactID = artifactID;
|
||||
}
|
||||
|
||||
public @NotNull Library getLibrary() {
|
||||
return Library.builder().id(name())
|
||||
.groupId(this.groupID).artifactId(this.artifactID)
|
||||
.version(getVersion())
|
||||
.build();
|
||||
}
|
||||
|
||||
public @NotNull String getVersion() {
|
||||
return READER.get(name().toLowerCase().replace('_', '-'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user