From aa83feea05c76b2ecadd008e0abac4ba1c77baa7 Mon Sep 17 00:00:00 2001 From: CarmJos Date: Thu, 24 Feb 2022 05:58:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E7=94=A8=E7=8B=AC=E7=AB=8B=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=96=B9=E5=BC=8F=E8=AF=BB=E5=8F=96=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- easysql-plugin-api/pom.xml | 2 +- .../easysql/command/EasySQLCommand.java | 19 +++++---- .../plugin/easysql/util/VersionReader.java | 39 +++++++++++++++++++ .../src/main/resources/versions.properties | 11 ++++++ pom.xml | 16 +++++--- 5 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 easysql-plugin-core/src/main/java/cc/carm/plugin/easysql/util/VersionReader.java create mode 100644 easysql-plugin-core/src/main/resources/versions.properties diff --git a/easysql-plugin-api/pom.xml b/easysql-plugin-api/pom.xml index c5b752f..e7f5614 100644 --- a/easysql-plugin-api/pom.xml +++ b/easysql-plugin-api/pom.xml @@ -90,7 +90,7 @@ zh_CN true - cc.carm.lib:* + cc.carm.lib:easysql-api cc.carm.plugin:* ${project.parent.basedir}/api-docs/ diff --git a/easysql-plugin-core/src/main/java/cc/carm/plugin/easysql/command/EasySQLCommand.java b/easysql-plugin-core/src/main/java/cc/carm/plugin/easysql/command/EasySQLCommand.java index 871b0ca..13e2943 100644 --- a/easysql-plugin-core/src/main/java/cc/carm/plugin/easysql/command/EasySQLCommand.java +++ b/easysql-plugin-core/src/main/java/cc/carm/plugin/easysql/command/EasySQLCommand.java @@ -3,6 +3,7 @@ package cc.carm.plugin.easysql.command; import cc.carm.lib.easysql.api.SQLManager; import cc.carm.lib.easysql.api.SQLQuery; import cc.carm.plugin.easysql.EasySQLRegistryImpl; +import cc.carm.plugin.easysql.util.VersionReader; import co.aikar.commands.BaseCommand; import co.aikar.commands.CommandHelp; import co.aikar.commands.CommandIssuer; @@ -11,8 +12,6 @@ import co.aikar.commands.annotation.*; import java.util.Map; import java.util.UUID; -import static cc.carm.plugin.easysql.util.MavenReadUtil.getVersion; - @SuppressWarnings("unused") @CommandAlias("EasySQL") @@ -37,15 +36,19 @@ public class EasySQLCommand extends BaseCommand { issuer.sendMessage("§c只有后台执行才能使用此命令。"); return; } - String pluginVersion = getVersion(this, "cc.carm.plugin", "easysql-plugin-core"); - String apiVersion = getVersion(this, "cc.carm.lib", "easysql-api"); - String poolVersion = getVersion(this, "com.github.chris2018998", "beecp"); - if (pluginVersion == null || apiVersion == null) { + VersionReader reader = new VersionReader(); + String pluginVersion = reader.get("plugin", null); + if (pluginVersion == null) { issuer.sendMessage("§c无法获取当前版本信息,请保证使用原生版本以避免安全问题。"); return; } - issuer.sendMessage("§r当前插件版本为 §b" + pluginVersion + " §r,核心接口版本为 §9" + apiVersion + "§r。 §7(基于 BeeCP " + poolVersion + ")"); - issuer.sendMessage("§r正在检查更新,请稍候..."); + 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("§r正在检查插件更新,请稍候..."); EasySQLRegistryImpl.getInstance().checkUpdate(pluginVersion); } diff --git a/easysql-plugin-core/src/main/java/cc/carm/plugin/easysql/util/VersionReader.java b/easysql-plugin-core/src/main/java/cc/carm/plugin/easysql/util/VersionReader.java new file mode 100644 index 0000000..a628b20 --- /dev/null +++ b/easysql-plugin-core/src/main/java/cc/carm/plugin/easysql/util/VersionReader.java @@ -0,0 +1,39 @@ +package cc.carm.plugin.easysql.util; + +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.InputStream; +import java.util.Properties; + +public class VersionReader { + + String versionsFileName; + + + public VersionReader() { + this("versions.properties"); + } + + public VersionReader(String versionsFileName) { + this.versionsFileName = versionsFileName; + } + + public synchronized @NotNull String get(@NotNull String artifactID) { + return get(artifactID, "unknown"); + } + + @Contract("_,!null->!null") + public synchronized @Nullable String get(@NotNull String artifactID, + @Nullable String defaultValue) { + try (InputStream is = this.getClass().getResourceAsStream("/" + versionsFileName)) { + Properties p = new Properties(); + p.load(is); + return p.getProperty(artifactID, defaultValue); + } catch (Exception ignore) { + } + return defaultValue; + } + +} diff --git a/easysql-plugin-core/src/main/resources/versions.properties b/easysql-plugin-core/src/main/resources/versions.properties new file mode 100644 index 0000000..31b3885 --- /dev/null +++ b/easysql-plugin-core/src/main/resources/versions.properties @@ -0,0 +1,11 @@ +# suppress inspection "SpellCheckingInspection" for whole file + +plugin=${project.version} +api=${easysql.version} + +beecp=${beecp.version} + +mysql-driver=${mysql-driver.version} +mariadb-driver=${mariadb-driver.version} +h2-driver=${h2-driver.version} + diff --git a/pom.xml b/pom.xml index 54cdbb6..561db9c 100644 --- a/pom.xml +++ b/pom.xml @@ -10,9 +10,15 @@ ${java.version} UTF-8 UTF-8 + 0.3.8 1.3.8 - 4.0.3 + + 3.3.2 + 8.0.28 + 3.0.3 + 2.1.210 + cc.carm.plugin @@ -118,7 +124,7 @@ com.github.chris2018998 beecp - 3.3.2 + ${beecp.version} @@ -150,21 +156,21 @@ org.mariadb.jdbc mariadb-java-client - 3.0.3 + ${mariadb-driver.version} mysql mysql-connector-java - 8.0.28 + ${mysql-driver.version} com.h2database h2 - 2.1.210 + ${h2-driver.version}