Skip to content

Commit e6fad85

Browse files
committed
feat(lib): 独立数据库依赖加载,缩减文件体积。
1 parent 6331cf2 commit e6fad85

File tree

16 files changed

+192
-107
lines changed

16 files changed

+192
-107
lines changed

api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>minesql-parent</artifactId>
77
<groupId>cc.carm.plugin</groupId>
8-
<version>1.3.1</version>
8+
<version>1.4.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

core/pom.xml

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>minesql-parent</artifactId>
77
<groupId>cc.carm.plugin</groupId>
8-
<version>1.3.1</version>
8+
<version>1.4.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<properties>
@@ -68,10 +68,17 @@
6868
<scope>provided</scope>
6969
</dependency>
7070

71+
<dependency>
72+
<groupId>net.byteflux</groupId>
73+
<artifactId>libby-core</artifactId>
74+
<version>${deps.libby.version}</version>
75+
<scope>compile</scope>
76+
</dependency>
77+
7178
<dependency>
7279
<groupId>com.github.chris2018998</groupId>
7380
<artifactId>beecp</artifactId>
74-
<scope>compile</scope>
81+
<scope>provided</scope>
7582
</dependency>
7683

7784
<dependency>
@@ -101,25 +108,6 @@
101108
<scope>compile</scope>
102109
</dependency>
103110

104-
<dependency>
105-
<groupId>org.mariadb.jdbc</groupId>
106-
<artifactId>mariadb-java-client</artifactId>
107-
<scope>compile</scope>
108-
</dependency>
109-
110-
<dependency>
111-
<groupId>mysql</groupId>
112-
<artifactId>mysql-connector-java</artifactId>
113-
<scope>compile</scope>
114-
</dependency>
115-
116-
<!--suppress VulnerableLibrariesLocal -->
117-
<dependency>
118-
<groupId>com.h2database</groupId>
119-
<artifactId>h2</artifactId>
120-
<scope>compile</scope>
121-
</dependency>
122-
123111
</dependencies>
124112

125113
<build>

core/src/main/java/cc/carm/plugin/minesql/MineSQLCore.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
import cc.carm.plugin.minesql.command.MineSQLHelpFormatter;
1515
import cc.carm.plugin.minesql.conf.PluginConfiguration;
1616
import cc.carm.plugin.minesql.conf.SQLSourceGroup;
17+
import cc.carm.plugin.minesql.lib.PluginLibraries;
1718
import cc.carm.plugin.minesql.util.DBPropertiesUtil;
1819
import cn.beecp.BeeDataSource;
1920
import cn.beecp.BeeDataSourceConfig;
2021
import co.aikar.commands.CommandManager;
2122
import co.aikar.commands.InvalidCommandArgument;
2223
import co.aikar.commands.Locales;
24+
import net.byteflux.libby.Library;
2325
import org.jetbrains.annotations.NotNull;
2426
import org.jetbrains.annotations.Nullable;
2527

@@ -48,6 +50,17 @@ public MineSQLCore(MineSQLPlatform platform) {
4850
instance = this;
4951
this.platform = platform;
5052

53+
getLogger().info("加载数据库依赖文件...");
54+
getPlatform().getLibraryManager().addMavenLocal();
55+
getPlatform().getLibraryManager().addMavenCentral();
56+
getPlatform().getLibraryManager().addSonatype();
57+
58+
for (PluginLibraries value : PluginLibraries.values()) {
59+
Library lib = value.getLibrary();
60+
getLogger().info(" 加载 " + lib.getArtifactId() + " (" + lib.getVersion() + ") ...");
61+
getPlatform().getLibraryManager().loadLibrary(value.getLibrary());
62+
}
63+
5164
getLogger().info("加载配置文件...");
5265
this.configProvider = EasyConfiguration.from(new File(platform.getPluginFolder(), "config.yml"));
5366
this.config = new PluginConfiguration();

core/src/main/java/cc/carm/plugin/minesql/MineSQLPlatform.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.carm.plugin.minesql;
22

33
import co.aikar.commands.CommandManager;
4+
import net.byteflux.libby.LibraryManager;
45
import org.jetbrains.annotations.NotNull;
56
import org.jetbrains.annotations.Nullable;
67

@@ -15,4 +16,6 @@ public interface MineSQLPlatform {
1516

1617
@Nullable CommandManager<?, ?, ?, ?, ?, ?> getCommandManager();
1718

19+
@NotNull LibraryManager getLibraryManager();
20+
1821
}

core/src/main/java/cc/carm/plugin/minesql/command/MineSQLCommand.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cc.carm.lib.easysql.api.SQLManager;
44
import cc.carm.lib.easysql.api.SQLQuery;
55
import cc.carm.plugin.minesql.MineSQLCore;
6+
import cc.carm.plugin.minesql.lib.PluginLibraries;
67
import cc.carm.plugin.minesql.util.VersionReader;
78
import co.aikar.commands.BaseCommand;
89
import co.aikar.commands.CommandHelp;
@@ -42,17 +43,17 @@ public void version(CommandIssuer issuer) {
4243
issuer.sendMessage("§c只有后台执行才能使用此命令。");
4344
return;
4445
}
45-
VersionReader reader = new VersionReader();
46+
VersionReader reader = PluginLibraries.READER;
4647
String pluginVersion = reader.get("plugin", null);
4748
if (pluginVersion == null) {
4849
issuer.sendMessage("§c无法获取当前版本信息,请保证使用原生版本以避免安全问题。");
4950
return;
5051
}
5152
issuer.sendMessage("§r当前插件版本为 §b" + pluginVersion + "§r。 §7(基于 EasySQL &3" + reader.get("api") + "&7)");
5253
issuer.sendMessage("§8 - &f连接池依赖 BeeCP §9" + reader.get("beecp"));
53-
issuer.sendMessage("§8 - &f数据库驱动 MySQL §9" + reader.get("mysql-driver"));
54-
issuer.sendMessage("§8 - &f数据库驱动 MariaDB §9" + reader.get("mariadb-driver"));
55-
issuer.sendMessage("§8 - &f数据库驱动 h2-database §9" + reader.get("h2-driver"));
54+
issuer.sendMessage("§8 - &f数据库驱动 MySQL §9" + PluginLibraries.MYSQL_DRIVER.getVersion());
55+
issuer.sendMessage("§8 - &f数据库驱动 MariaDB §9" + PluginLibraries.MARIADB_DRIVER.getVersion());
56+
issuer.sendMessage("§8 - &f数据库驱动 h2-database §9" + PluginLibraries.H2_DRIVER.getVersion());
5657

5758
issuer.sendMessage("§r正在检查插件更新,请稍候...");
5859
core.checkUpdate(pluginVersion);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cc.carm.plugin.minesql.lib;
2+
3+
import cc.carm.plugin.minesql.util.VersionReader;
4+
import net.byteflux.libby.Library;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
public enum PluginLibraries {
8+
9+
BEECP("com.github.chris2018998", "beecp"),
10+
H2_DRIVER("com.h2database", "h2"),
11+
MYSQL_DRIVER("com.mysql", "mysql-connector-j"),
12+
MARIADB_DRIVER("org.mariadb.jdbc", "mariadb-java-client");
13+
14+
public static final VersionReader READER = new VersionReader();
15+
16+
private final @NotNull String groupID;
17+
private final @NotNull String artifactID;
18+
19+
PluginLibraries(@NotNull String groupID, @NotNull String artifactID) {
20+
this.groupID = groupID;
21+
this.artifactID = artifactID;
22+
}
23+
24+
public @NotNull Library getLibrary() {
25+
return Library.builder().id(name())
26+
.groupId(this.groupID).artifactId(this.artifactID)
27+
.version(getVersion())
28+
.build();
29+
}
30+
31+
public @NotNull String getVersion() {
32+
return READER.get(name().toLowerCase().replace('_', '-'));
33+
}
34+
35+
36+
}

platforms/bukkit/pom.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>minesql-parent</artifactId>
77
<groupId>cc.carm.plugin</groupId>
8-
<version>1.3.1</version>
8+
<version>1.4.0</version>
99
<relativePath>../../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
@@ -79,17 +79,24 @@
7979
<scope>provided</scope>
8080
</dependency>
8181

82+
<dependency>
83+
<groupId>net.byteflux</groupId>
84+
<artifactId>libby-bukkit</artifactId>
85+
<version>${deps.libby.version}</version>
86+
<scope>compile</scope>
87+
</dependency>
88+
8289
<dependency>
8390
<groupId>org.bstats</groupId>
8491
<artifactId>bstats-bukkit</artifactId>
85-
<version>3.0.0</version>
92+
<version>${deps.bstats.version}</version>
8693
<scope>compile</scope>
8794
</dependency>
8895

8996
<dependency>
9097
<groupId>co.aikar</groupId>
9198
<artifactId>acf-paper</artifactId>
92-
<version>0.5.1-SNAPSHOT</version>
99+
<version>${deps.acf.version}</version>
93100
<scope>compile</scope>
94101
</dependency>
95102

platforms/bukkit/src/main/java/cc/carm/plugin/minesql/MineSQLBukkit.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,30 @@
44
import cc.carm.plugin.minesql.conf.PluginConfiguration;
55
import co.aikar.commands.CommandManager;
66
import co.aikar.commands.PaperCommandManager;
7+
import net.byteflux.libby.BukkitLibraryManager;
8+
import net.byteflux.libby.LibraryManager;
79
import org.bstats.bukkit.Metrics;
810
import org.bstats.charts.SimplePie;
911
import org.jetbrains.annotations.NotNull;
10-
import org.jetbrains.annotations.Nullable;
1112

1213
import java.io.File;
1314

1415
public class MineSQLBukkit extends EasyPlugin implements MineSQLPlatform {
1516

1617
protected static MineSQLBukkit instance;
1718

19+
protected BukkitLibraryManager libraryManager;
20+
1821
protected MineSQLCore core;
1922
protected PaperCommandManager commandManager;
2023

2124
@Override
2225
protected void load() {
2326
MineSQLBukkit.instance = this;
2427

28+
log("加载依赖管理器...");
29+
this.libraryManager = new BukkitLibraryManager(this);
30+
2531
log("加载基础核心...");
2632
this.core = new MineSQLCore(this);
2733
}
@@ -75,10 +81,15 @@ public boolean isDebugging() {
7581
return this.core.getConfig();
7682
}
7783

78-
public @Nullable CommandManager<?, ?, ?, ?, ?, ?> getCommandManager() {
84+
public @NotNull CommandManager<?, ?, ?, ?, ?, ?> getCommandManager() {
7985
return commandManager;
8086
}
8187

88+
@Override
89+
public @NotNull LibraryManager getLibraryManager() {
90+
return this.libraryManager;
91+
}
92+
8293
@Override
8394
public @NotNull File getPluginFolder() {
8495
return getDataFolder();

platforms/bungee/pom.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>minesql-parent</artifactId>
77
<groupId>cc.carm.plugin</groupId>
8-
<version>1.3.1</version>
8+
<version>1.4.0</version>
99
<relativePath>../../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
@@ -90,17 +90,24 @@
9090
<scope>provided</scope>
9191
</dependency>
9292

93+
<dependency>
94+
<groupId>net.byteflux</groupId>
95+
<artifactId>libby-bungee</artifactId>
96+
<version>${deps.libby.version}</version>
97+
<scope>compile</scope>
98+
</dependency>
99+
93100
<dependency>
94101
<groupId>org.bstats</groupId>
95102
<artifactId>bstats-bungeecord</artifactId>
96-
<version>3.0.0</version>
103+
<version>${deps.bstats.version}</version>
97104
<scope>compile</scope>
98105
</dependency>
99106

100107
<dependency>
101108
<groupId>co.aikar</groupId>
102109
<artifactId>acf-bungee</artifactId>
103-
<version>0.5.1-SNAPSHOT</version>
110+
<version>${deps.acf.version}</version>
104111
<scope>compile</scope>
105112
</dependency>
106113

platforms/bungee/src/main/java/cc/carm/plugin/minesql/MineSQLBungee.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import cc.carm.plugin.minesql.conf.PluginConfiguration;
66
import co.aikar.commands.BungeeCommandManager;
77
import co.aikar.commands.CommandManager;
8+
import net.byteflux.libby.BungeeLibraryManager;
9+
import net.byteflux.libby.LibraryManager;
810
import net.md_5.bungee.api.ProxyServer;
911
import net.md_5.bungee.api.plugin.Plugin;
1012
import org.bstats.bungeecord.Metrics;
1113
import org.bstats.charts.SimplePie;
1214
import org.jetbrains.annotations.NotNull;
13-
import org.jetbrains.annotations.Nullable;
1415

1516
import java.io.File;
1617
import java.util.Arrays;
@@ -21,13 +22,18 @@ public class MineSQLBungee extends Plugin implements MineSQLPlatform {
2122

2223
protected static MineSQLBungee instance;
2324

25+
protected BungeeLibraryManager libraryManager;
26+
2427
protected MineSQLCore core;
2528
protected BungeeCommandManager commandManager;
2629

2730
@Override
2831
public void onLoad() {
2932
MineSQLBungee.instance = this;
3033

34+
getLogger().info("加载依赖管理器...");
35+
this.libraryManager = new BungeeLibraryManager(this);
36+
3137
getLogger().info("加载基础核心...");
3238
this.core = new MineSQLCore(this);
3339
}
@@ -89,10 +95,15 @@ public static MineSQLBungee getInstance() {
8995
}
9096

9197
@Override
92-
public @Nullable CommandManager<?, ?, ?, ?, ?, ?> getCommandManager() {
98+
public @NotNull CommandManager<?, ?, ?, ?, ?, ?> getCommandManager() {
9399
return this.commandManager;
94100
}
95101

102+
@Override
103+
public @NotNull LibraryManager getLibraryManager() {
104+
return this.libraryManager;
105+
}
106+
96107
@SuppressWarnings("deprecation")
97108
public void outputInfo() {
98109
Optional.ofNullable(JarResourceUtils.readResource(this.getResourceAsStream("PLUGIN_INFO")))

0 commit comments

Comments
 (0)