Skip to content

Commit 56778a7

Browse files
author
TheProgramSrc
committed
Working on Dependency Manager to make the plugin file size lower
1 parent 2b91b69 commit 56778a7

File tree

15 files changed

+653
-21
lines changed

15 files changed

+653
-21
lines changed

SuperCoreAPI.iml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,5 @@
4545
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.6" level="project" />
4646
<orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" />
4747
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
48-
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.5" level="project" />
4948
</component>
5049
</module>

dependency-reduced-pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@
3434
<goal>shade</goal>
3535
</goals>
3636
<configuration>
37+
<createDependencyReducedPom>true</createDependencyReducedPom>
3738
<transformers>
3839
<transformer>
3940
<resource>META-INF/services/java.sql.Driver</resource>
4041
</transformer>
4142
</transformers>
42-
<createDependencyReducedPom>true</createDependencyReducedPom>
43-
<minimizeJar>true</minimizeJar>
4443
</configuration>
4544
</execution>
4645
</executions>

pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@
4646
<goal>shade</goal>
4747
</goals>
4848
<configuration>
49-
<transformers>
50-
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
51-
<resource>META-INF/services/java.sql.Driver</resource>
52-
</transformer>
53-
</transformers>
5449
<createDependencyReducedPom>true</createDependencyReducedPom>
5550
<minimizeJar>true</minimizeJar>
5651
</configuration>
@@ -155,11 +150,5 @@
155150
<version>2.8.6</version>
156151
<scope>compile</scope>
157152
</dependency>
158-
<!-- HikariCP -->
159-
<dependency>
160-
<groupId>com.zaxxer</groupId>
161-
<artifactId>HikariCP</artifactId>
162-
<version>3.4.5</version>
163-
</dependency>
164153
</dependencies>
165154
</project>

src/main/java/xyz/theprogramsrc/supercoreapi/SuperPlugin.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package xyz.theprogramsrc.supercoreapi;
77

8+
import xyz.theprogramsrc.supercoreapi.global.dependencies.DependencyManager;
89
import xyz.theprogramsrc.supercoreapi.global.translations.TranslationManager;
910
import xyz.theprogramsrc.supercoreapi.global.translations.TranslationPack;
1011

@@ -147,4 +148,10 @@ default void addDisableHook(Runnable runnable){
147148
default String getPluginMessagingChannelName(){
148149
return this.getPluginName() + "_MessagingChannel";
149150
}
151+
152+
/**
153+
* Gets the dependency manager
154+
* @return Dependency Manager
155+
*/
156+
DependencyManager getDependencyManager();
150157
}

src/main/java/xyz/theprogramsrc/supercoreapi/bungee/BungeePlugin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import xyz.theprogramsrc.supercoreapi.bungee.events.BungeeEventManager;
1414
import xyz.theprogramsrc.supercoreapi.bungee.storage.Settings;
1515
import xyz.theprogramsrc.supercoreapi.bungee.utils.BungeeUtils;
16+
import xyz.theprogramsrc.supercoreapi.global.dependencies.BaseDependencies;
17+
import xyz.theprogramsrc.supercoreapi.global.dependencies.DependencyManager;
18+
import xyz.theprogramsrc.supercoreapi.global.dependencies.classloader.PluginClassLoader;
19+
import xyz.theprogramsrc.supercoreapi.global.dependencies.classloader.ReflectionClassLoader;
1620
import xyz.theprogramsrc.supercoreapi.global.translations.Base;
1721
import xyz.theprogramsrc.supercoreapi.global.translations.TranslationManager;
1822
import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
@@ -30,6 +34,7 @@ public abstract class BungeePlugin extends Plugin implements SuperPlugin<Plugin>
3034

3135
private Settings settings;
3236
private TranslationManager translationManager;
37+
private DependencyManager dependencyManager;
3338

3439
@Override
3540
public void onLoad() {
@@ -50,6 +55,9 @@ public void onEnable() {
5055
this.translationManager = new TranslationManager(this);
5156
this.getTranslationManager().registerTranslation(Base.class);
5257
new BungeeEventManager(this);
58+
PluginClassLoader classLoader = new ReflectionClassLoader(this);
59+
this.dependencyManager = new DependencyManager(this, classLoader);
60+
Arrays.stream(BaseDependencies.values()).forEach(d-> dependencyManager.loadDependencies(d.getDependency()));
5361
this.onPluginEnable();
5462
this.log("Enabled plugin");
5563
if(this.isFirstStart()){
@@ -148,4 +156,9 @@ public void listener(Listener... listeners) {
148156
public Settings getSettings() {
149157
return this.settings;
150158
}
159+
160+
@Override
161+
public DependencyManager getDependencyManager() {
162+
return dependencyManager;
163+
}
151164
}

src/main/java/xyz/theprogramsrc/supercoreapi/bungee/commands/BungeeCommand.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public abstract class BungeeCommand extends BungeeModule {
1616

1717
/**
18-
* Creates a new command for bungeecord and registers it
18+
* Creates a new command for BungeeCord and registers it
1919
*
2020
* @param plugin The BungeeCord plugin
2121
*/
@@ -53,20 +53,40 @@ private void onResult(CommandSender sender, CommandResult result){
5353
}
5454

5555
/**
56-
*
57-
* @return
56+
* Gets the command
57+
* @return the command
5858
*/
5959
public abstract String getCommand();
6060

61+
/**
62+
* Gets the permission to use the command
63+
* @return the permission
64+
*/
6165
public String getPermission(){
6266
return null;
6367
}
6468

69+
/**
70+
* Gets all the available aliases
71+
* @return the aliases
72+
*/
6573
public String[] getAliases(){
6674
return new String[0];
6775
}
6876

77+
/**
78+
* Executed when a player executes the command
79+
* @param player Who execute the command
80+
* @param args Arguments of the command
81+
* @return The CommandResult
82+
*/
6983
public abstract CommandResult onPlayerExecute(ProxiedPlayer player, String[] args);
7084

85+
/**
86+
* Executed when the console executes the command
87+
* @param console The console
88+
* @param args the arguments of the command
89+
* @return The CommandResult
90+
*/
7191
public abstract CommandResult onConsoleExecute(BungeeConsole console, String[] args);
7292
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package xyz.theprogramsrc.supercoreapi.global.dependencies;
2+
3+
import xyz.theprogramsrc.supercoreapi.global.dependencies.classloader.LoaderType;
4+
5+
public enum BaseDependencies {
6+
7+
SQLITE_DRIVER(
8+
"org.xerial",
9+
"sqlite-jdbc",
10+
"3.25.2",
11+
"pF2mGr7WFWilM/3s4SUJMYCCjt6w1Lb21XLgz0V0ZfY=",
12+
LoaderType.ISOLATED
13+
),
14+
HIKARI(
15+
"com{}zaxxer",
16+
"HikariCP",
17+
"3.3.1",
18+
"SIaA1yzGHOZNpZNoIt903f5ScJrIB3u8CT2cNkaLcy0=",
19+
LoaderType.REFLECTION
20+
),
21+
22+
;
23+
24+
private final Dependency dependency;
25+
26+
BaseDependencies(String groupId, String artifactId, String version, String checksum, LoaderType loaderType) {
27+
this.dependency = new Dependency(name(), groupId, artifactId, version, checksum, loaderType);
28+
}
29+
30+
public Dependency getDependency() {
31+
return dependency;
32+
}
33+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* This file is part of LuckPerms, licensed under the MIT License.
3+
*
4+
* Copyright (c) lucko (Luck) <[email protected]>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
package xyz.theprogramsrc.supercoreapi.global.dependencies;
26+
27+
import com.google.common.collect.ImmutableList;
28+
import xyz.theprogramsrc.supercoreapi.global.dependencies.classloader.LoaderType;
29+
30+
import java.net.URL;
31+
import java.util.Base64;
32+
import java.util.List;
33+
34+
public class Dependency {
35+
36+
private static final String MAVEN_CENTRAL_REPO = "https://repo1.maven.org/maven2/";
37+
private static final String LUCK_MIRROR_REPO = "https://nexus.lucko.me/repository/maven-central/";
38+
private static final String MAVEN_FORMAT = "%s/%s/%s/%s-%s.jar";
39+
40+
private final String name;
41+
private final List<URL> urls;
42+
private final String version;
43+
private final byte[] checksum;
44+
private boolean autoLoad;
45+
private LoaderType loaderType;
46+
47+
public Dependency(String name, String groupId, String artifactId, String version, String checksum, LoaderType loaderType) {
48+
this.name = name;
49+
this.autoLoad = true;
50+
this.loaderType = loaderType;
51+
52+
String path = String.format(MAVEN_FORMAT,
53+
rewriteEscaping(groupId).replace(".", "/"),
54+
rewriteEscaping(artifactId),
55+
version,
56+
rewriteEscaping(artifactId),
57+
version
58+
);
59+
try {
60+
this.urls = ImmutableList.of(
61+
new URL(LUCK_MIRROR_REPO + path),
62+
new URL(MAVEN_CENTRAL_REPO + path)
63+
);
64+
} catch (Exception e) {
65+
throw new RuntimeException(e); // propagate
66+
}
67+
this.version = version;
68+
this.checksum = Base64.getDecoder().decode(checksum);
69+
}
70+
71+
private static String rewriteEscaping(String s) {
72+
return s.replace("{}", ".");
73+
}
74+
75+
public static String getMavenCentralRepo() {
76+
return MAVEN_CENTRAL_REPO;
77+
}
78+
79+
public static String getLuckMirrorRepo() {
80+
return LUCK_MIRROR_REPO;
81+
}
82+
83+
public static String getMavenFormat() {
84+
return MAVEN_FORMAT;
85+
}
86+
87+
public String getName() {
88+
return name;
89+
}
90+
91+
public List<URL> getUrls() {
92+
return urls;
93+
}
94+
95+
public String getVersion() {
96+
return version;
97+
}
98+
99+
public byte[] getChecksum() {
100+
return checksum;
101+
}
102+
103+
public boolean isAutoLoad() {
104+
return autoLoad;
105+
}
106+
107+
public LoaderType getLoaderType() {
108+
return loaderType;
109+
}
110+
111+
public void setAutoLoad(boolean autoLoad) {
112+
this.autoLoad = autoLoad;
113+
}
114+
115+
public void setLoaderType(LoaderType loaderType) {
116+
this.loaderType = loaderType;
117+
}
118+
}

0 commit comments

Comments
 (0)