Modules fix.

This commit is contained in:
zaxar163 2018-12-19 17:15:18 +03:00
parent 43d6d40d94
commit 29d2e89bd3
No known key found for this signature in database
GPG key ID: E3B309DD3852DE06
3 changed files with 11 additions and 23 deletions

View file

@ -13,12 +13,12 @@ public ClientModuleManager(LauncherEngine engine) {
}
@Override
public void loadModule(URL jarpath, boolean preload) {
public void loadModule(URL jarpath) {
throw new SecurityException("Custom JAR's load not allowed here");
}
@Override
public void loadModule(URL jarpath, String classname, boolean preload) {
public void loadModule(URL jarpath, String classname) {
throw new SecurityException("Custom JAR's load not allowed here");
}
}

View file

@ -7,11 +7,9 @@ public interface ModulesManagerInterface {
void load(Module module);
void load(Module module, boolean preload);
void loadModule(URL jarpath) throws Exception;
void loadModule(URL jarpath, boolean preload) throws Exception;
void loadModule(URL jarpath, String classname, boolean preload) throws Exception;
void loadModule(URL jarpath, String classname) throws Exception;
void postInitModules();
@ -21,5 +19,5 @@ public interface ModulesManagerInterface {
void sort();
void registerModule(Module module, boolean preload);
void registerModule(Module module, boolean preload); // hacky method for client
}

View file

@ -25,16 +25,15 @@ private ModulesVisitor() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
try {
JarFile f = new JarFile(file.toString());
JarFile f = new JarFile(file.toFile());
Manifest m = f.getManifest();
String mainclass = m.getMainAttributes().getValue("Main-Class");
loadModule(file.toUri().toURL(), mainclass, true);
loadModule(file.toUri().toURL(), mainclass);
f.close();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
// Return result
return super.visitFile(file, attrs);
}
}
@ -87,21 +86,14 @@ public void load(Module module) {
modules.add(module);
}
@Override
public void load(Module module, boolean preload) {
load(module);
if (!preload) module.init(context);
}
@Override
public void loadModule(URL jarpath, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException, URISyntaxException, IOException {
public void loadModule(URL jarpath) throws ClassNotFoundException, IllegalAccessException, InstantiationException, URISyntaxException, IOException {
JarFile f = new JarFile(Paths.get(jarpath.toURI()).toString());
Manifest m = f.getManifest();
String mainclass = m.getMainAttributes().getValue("Main-Class");
loadModule(jarpath, mainclass, preload);
loadModule(jarpath, mainclass);
f.close();
}
@ -122,13 +114,11 @@ public void loadModuleFull(URL jarpath) throws ClassNotFoundException, IllegalAc
@Override
public void loadModule(URL jarpath, String classname, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
public void loadModule(URL jarpath, String classname) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
classloader.addURL(jarpath);
Class<?> moduleclass = Class.forName(classname, true, classloader);
Module module = (Module) moduleclass.newInstance();
modules.add(module);
module.preInit(context);
if (!preload) module.init(context);
LogHelper.info("Module %s version: %s loaded", module.getName(), module.getVersion());
}
@ -161,7 +151,7 @@ public void printModules() {
@Override
public void registerModule(Module module, boolean preload) {
load(module, preload);
load(module);
LogHelper.info("Module %s version: %s registered", module.getName(), module.getVersion());
}
}