Skip to content

Commit 460ca69

Browse files
Merge pull request #8 from ChillyCheesy/dev
Dev
2 parents 1fe16e4 + cd01f86 commit 460ca69

File tree

25 files changed

+155
-95
lines changed

25 files changed

+155
-95
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
allprojects {
2-
version = modulo_version as Object
2+
version = modulo_version
33
group = 'com.chillycheesy'
44
repositories {
55
mavenCentral()

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
modulo_modulename=Modulo
2-
modulo_version=BINKS-0.1.0
1+
modulo_modulename=ModuloServer
2+
modulo_version=BINKS-0.1.1

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Thu Dec 03 16:10:48 CET 2020
2-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
33
distributionBase=GRADLE_USER_HOME
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists

modulo-api/build.gradle

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ archivesBaseName = 'modulo-api'
77
sourceCompatibility = 11
88

99
dependencies {
10-
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.1'
11-
compile 'commons-io:commons-io:2.11.0'
12-
compile 'org.apache.tomcat.embed:tomcat-embed-core:9.0.39'
10+
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.3'
11+
implementation 'org.apache.tomcat.embed:tomcat-embed-websocket:9.0.39'
1312

14-
testCompile 'org.junit.jupiter:junit-jupiter-api:5.8.2'
15-
testCompile 'org.junit.jupiter:junit-jupiter-params:5.8.2'
16-
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
17-
testCompile 'org.mockito:mockito-core:4.3.1'
13+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
14+
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
15+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
16+
testImplementation 'org.mockito:mockito-core:4.5.1'
1817
}
1918

2019
java {
2120
withSourcesJar()
2221
withJavadocJar()
2322
}
2423

24+
test {
25+
useJUnitPlatform()
26+
}
27+
2528
final deployPropertiesFile = rootProject.file('deploy.properties')
2629
final deployProperty = new Properties()
2730
if (deployPropertiesFile.exists()) {
@@ -61,7 +64,3 @@ publishing {
6164
}
6265
}
6366
}
64-
65-
test {
66-
useJUnitPlatform()
67-
}

modulo-api/src/main/java/com/chillycheesy/modulo/commands/Command.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.chillycheesy.modulo.commands;
22

3+
import java.util.Arrays;
4+
35
/**
46
* This class represents a command that can be executed by the {@link CommandManager}.
57
* A command contain a label, a description, and an example of how to use it named usage.
@@ -123,4 +125,15 @@ public void setLabel(String label) {
123125
public void setUsage(String usage) {
124126
this.usage = usage;
125127
}
128+
129+
@Override
130+
public String toString() {
131+
return "Command{" +
132+
"label='" + label + '\'' +
133+
", alias=" + Arrays.toString(alias) +
134+
", description='" + description + '\'' +
135+
", usage='" + usage + '\'' +
136+
", commandListener=" + commandListener +
137+
'}';
138+
}
126139
}

modulo-api/src/main/java/com/chillycheesy/modulo/commands/natif/HelpCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ public CommandFlow onCommand(Module caller, String label, String[] args, Command
3030

3131
private String getAllCommand(){
3232
final StringBuilder commands = new StringBuilder();
33-
for(Command c: ModuloAPI.getCommand().getCommandManager().getAllItems()){
33+
for (Command c: ModuloAPI.getCommand().getCommandManager().getAllItems()) {
3434
commands.append(getCommandByLabel(c.getLabel()));
3535
}
3636
return commands.toString();
3737
}
3838

3939
private String getCommandByLabel(String label){
40-
final StringBuilder command = new StringBuilder();
41-
Command c = ModuloAPI.getCommand().getCommandManager().getCommandByLabel(label);
42-
command.append("\t"+c.getLabel()+" : "+c.getDescription()+"\n");
43-
return command.toString();
40+
final StringBuilder builder = new StringBuilder();
41+
final Command command = ModuloAPI.getCommand().getCommandManager().getCommandByLabel(label);
42+
builder.append("\t").append(command.getLabel()).append(" : ").append(command.getDescription()).append("\n");
43+
return builder.toString();
4444
}
4545
}

modulo-api/src/main/java/com/chillycheesy/modulo/modules/Module.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ public Module() {
6464
/**
6565
* Method called when the {@link #load()} method is called
6666
*/
67-
protected abstract void onLoad() throws Exception;
67+
protected abstract <E extends Throwable> void onLoad() throws E;
6868

6969
/**
7070
* Method called when the {@link #start()} method is called
7171
*/
72-
protected abstract void onStart() throws Exception;
72+
protected abstract <E extends Throwable> void onStart() throws E;
7373

7474
/**
7575
* Method called when the {@link #stop()} method is called
7676
*/
77-
protected abstract void onStop() throws Exception;
77+
protected abstract <E extends Throwable> void onStop() throws E;
7878

7979
/**
8080
* Method calls to load the module<br>
@@ -88,6 +88,7 @@ public void load() {
8888
this.onLoad();
8989
} catch (Exception e) {
9090
ModuloAPI.getLogger().error(this, e.getMessage());
91+
e.printStackTrace();
9192
}
9293
});
9394
ModuloAPI.getEvent().getEventManager().emitEvent(this, onLoadEvent);
@@ -104,6 +105,7 @@ public void start() {
104105
this.onStart();
105106
} catch (Exception e) {
106107
ModuloAPI.getLogger().error(this, e.getMessage());
108+
e.printStackTrace();
107109
}
108110
});
109111
ModuloAPI.getEvent().getEventManager().emitEvent(this, onStartEvent);
@@ -122,6 +124,7 @@ public void stop() {
122124
this.onStop();
123125
} catch (Exception e) {
124126
ModuloAPI.getLogger().error(this, e.getMessage());
127+
e.printStackTrace();
125128
}
126129
});
127130
ModuloAPI.getEvent().getEventManager().emitEvent(this, onStopEvent);

modulo-api/src/main/java/com/chillycheesy/modulo/modules/ModuleAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ public ModuleAdapter() { }
3535
/**
3636
* Method called when the {@link Module#load()} method is called
3737
*/
38-
protected void onLoad() throws Exception { }
38+
protected <E extends Throwable> void onLoad() throws E { }
3939

4040
/**
4141
* Method called when the {@link Module#start()} method is called
4242
*/
43-
protected void onStart() throws Exception { }
43+
protected <E extends Throwable> void onStart() throws E { }
4444

4545
/**
4646
* Method called when the {@link Module#stop()} method is called
4747
*/
4848
@Override
49-
protected void onStop() throws Exception { }
49+
protected <E extends Throwable> void onStop() throws E { }
5050
}

modulo-api/src/main/java/com/chillycheesy/modulo/modules/ModuleBuilder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public static ModuleConfig readYml(File file, InputStream inputStream) throws IO
114114
* <li>Name of your {@link Module}</li>
115115
* </ul>
116116
*
117-
* @param file
118-
* @param config
117+
* @param file the jar file of your {@link Module}
118+
* @param config the configuration of your {@link Module}
119119
* @throws InvalidModuleConfigurationException
120120
*/
121121
private static void checkField(File file, ModuleConfig config) throws InvalidModuleConfigurationException {
@@ -133,8 +133,7 @@ private Module build() throws ClassNotFoundException, NoSuchMethodException, Ill
133133
final InputStream is = jar.getInputStream(jarEntry);
134134
final ModuleConfig config = readYml(file, is);
135135
final Class<?> moduleClass = Class.forName(config.getMain(), true, urlClassLoader);
136-
final Object object = moduleClass.getConstructor().newInstance();
137-
final Module module = (Module) object;
136+
final Module module = (Module) moduleClass.getConstructor().newInstance();
138137
module.setConfig(config);
139138
module.setJarFile(jar);
140139
return module;

modulo-api/src/main/java/com/chillycheesy/modulo/modules/ModuleLoader.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.net.URL;
1010
import java.net.URLClassLoader;
1111
import java.util.ArrayList;
12+
import java.util.HashSet;
1213
import java.util.List;
1314
import java.util.Objects;
1415
import java.util.jar.JarFile;
@@ -44,7 +45,8 @@ public List<Module> loadModules(File file) throws FileIsNotAModuleDirectoryExcep
4445
if (!file.isDirectory()) throw new FileIsNotAModuleDirectoryException(file);
4546
final List<Module> loadedModules = new ArrayList<>();
4647
for (File jarFile : Objects.requireNonNull(file.listFiles())) {
47-
loadedModules.add(this.loadModule(jarFile));
48+
final Module loadedModule = loadModule(jarFile);
49+
if (loadedModule != null) loadedModules.add(loadedModule);
4850
}
4951
return loadedModules;
5052
}
@@ -84,7 +86,10 @@ public Module loadModule(Module module) {
8486
* @throws IOException If the file was not a JarFile.
8587
*/
8688
public Module loadModule(File file) throws IOException {
87-
return loadModule(file, URLClassLoader.newInstance(new URL[]{file.toURI().toURL()}));
89+
final URL[] urls = new URL[]{file.toURI().toURL()};
90+
final ClassLoader classLoader = this.getClass().getClassLoader();
91+
final URLClassLoader urlClassLoader = URLClassLoader.newInstance(urls, classLoader);
92+
return loadModule(file, urlClassLoader);
8893
}
8994

9095
/**
@@ -110,12 +115,11 @@ public List<Module> startModules() throws MissingDependenciesModuleException {
110115
}
111116

112117
public List<Module> startModules(List<Module> modules) throws MissingDependenciesModuleException {
113-
for (Module module : modules)
114-
module = startModule(module);
118+
for (Module module : modules) startModule(module);
115119
return modules;
116120
}
117121

118-
private Module startModule(Module module) throws MissingDependenciesModuleException {
122+
public Module startModule(Module module) throws MissingDependenciesModuleException {
119123
if (!startedModule.contains(module)) {
120124
final ModuleManager moduleManager = ModuloAPI.getModule().getModuleManager();
121125
final List<String> dependencies = module.getDependencies();
@@ -126,7 +130,7 @@ private Module startModule(Module module) throws MissingDependenciesModuleExcept
126130
.filter(Objects::nonNull)
127131
.collect(Collectors.toList());
128132
for (Module dependency : allDependencies) this.startModule(dependency);
129-
if (!startedModule.containsAll(dependencies.stream().map(this::getLoadedModuleByName).collect(Collectors.toList())))
133+
if (!new HashSet<>(startedModule).containsAll(dependencies.stream().map(this::getLoadedModuleByName).collect(Collectors.toList())))
130134
throw new MissingDependenciesModuleException(module, getMissingDependenciesList(dependencies));
131135
moduleManager.addModule(module);
132136
startedModule.add(module);
@@ -182,7 +186,7 @@ public boolean isValid(JarFile file) {
182186
* @throws IOException If the file was not a JarFile.
183187
*/
184188
public boolean isValid(File file) throws IOException {
185-
return isValid(new JarFile(file));
189+
return file.getName().endsWith(".jar") && isValid(new JarFile(file));
186190
}
187191

188192
/**

0 commit comments

Comments
 (0)