From 29d2e89bd3de2db50a07427da3b8898485b33562 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Wed, 19 Dec 2018 17:15:18 +0300 Subject: [PATCH] Modules fix. --- .../launcher/client/ClientModuleManager.java | 4 ++-- .../modules/ModulesManagerInterface.java | 8 +++---- .../launcher/modules/SimpleModuleManager.java | 22 +++++-------------- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java index 252300f5..9f88611f 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java @@ -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"); } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java index 87e7eb22..3343fdd7 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java @@ -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 } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java index afbef9c2..d81cc374 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java @@ -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()); } }