From 2d06628a747516b9076cd7985bfe8aa7d1e55902 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Thu, 17 Jan 2019 19:38:27 +0300 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20Modules=20=D1=8D=D1=82=D0=B0=D0=BF?= =?UTF-8?q?=20finish.=20+=20[FIX]=20=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= =?UTF-8?q?=20LauncherEngine.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/handler/StdCommandHandler.java | 1 - .../manangers/ModulesManager.java | 6 +-- .../manangers/hook/BuildHookManager.java | 2 - .../modules/LaunchServerModuleContext.java | 14 +++---- .../ru/gravit/launcher/LauncherEngine.java | 5 +-- .../launcher/client/ClientModuleContext.java | 8 ++-- .../launcher/gui/JSRuntimeProvider.java | 4 +- .../launcher/server/ModulesManager.java | 6 +-- .../launcher/server/ServerModuleContext.java | 14 +++---- .../java/ru/gravit/launcher/Launcher.java | 4 +- .../managers/SimpleModuleManager.java | 12 +++++- ...r.java => SimpleModulesConfigManager.java} | 6 +-- .../ru/gravit/launcher/modules/Module.java | 4 ++ .../launcher/modules/ModuleContext.java | 4 +- ...terface.java => ModulesConfigManager.java} | 2 +- ...agerInterface.java => ModulesManager.java} | 4 +- .../launcher/modules/TestClientModule.java | 42 ------------------- 17 files changed, 53 insertions(+), 85 deletions(-) rename libLauncher/src/main/java/ru/gravit/launcher/managers/{ModulesConfigManager.java => SimpleModulesConfigManager.java} (82%) rename libLauncher/src/main/java/ru/gravit/launcher/modules/{ModulesConfigManagerInterface.java => ModulesConfigManager.java} (76%) rename libLauncher/src/main/java/ru/gravit/launcher/modules/{ModulesManagerInterface.java => ModulesManager.java} (82%) delete mode 100644 libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java index 8593cccb..7f77b039 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java @@ -16,7 +16,6 @@ public StdCommandHandler(LaunchServer server, boolean readCommands) { @Override public void bell() { - // Do nothing, unsupported } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java index a0314530..d50eda93 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java @@ -1,6 +1,6 @@ package ru.gravit.launchserver.manangers; -import ru.gravit.launcher.managers.ModulesConfigManager; +import ru.gravit.launcher.managers.SimpleModulesConfigManager; import ru.gravit.launcher.managers.SimpleModuleManager; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.modules.CoreModule; @@ -11,11 +11,11 @@ import java.util.ArrayList; public class ModulesManager extends SimpleModuleManager { - public ModulesConfigManager configManager; + public SimpleModulesConfigManager configManager; public ModulesManager(LaunchServer lsrv) { modules = new ArrayList<>(1); - configManager = new ModulesConfigManager(lsrv.dir.resolve("config")); + configManager = new SimpleModulesConfigManager(lsrv.dir.resolve("config")); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); context = new LaunchServerModuleContext(lsrv, classloader, configManager); registerCoreModule(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java index 703caeeb..ba82805d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java @@ -1,7 +1,6 @@ package ru.gravit.launchserver.manangers.hook; import ru.gravit.launcher.AutogenConfig; -import ru.gravit.launcher.modules.TestClientModule; import ru.gravit.launchserver.binary.BuildContext; import ru.gravit.launchserver.binary.JAConfigurator; import ru.gravit.launchserver.binary.tasks.MainBuildTask; @@ -41,7 +40,6 @@ public BuildHookManager() { registerIgnoredClass("META-INF/DEPENDENCIES"); registerIgnoredClass("META-INF/LICENSE"); registerIgnoredClass("META-INF/NOTICE"); - registerClientModuleClass(TestClientModule.class.getName()); } public void autoRegisterIgnoredClass(String clazz) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java index 1e43c23e..26bd9e1f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java @@ -1,18 +1,18 @@ package ru.gravit.launchserver.modules; -import ru.gravit.launcher.managers.ModulesConfigManager; +import ru.gravit.launcher.managers.SimpleModulesConfigManager; import ru.gravit.launcher.modules.ModuleContext; -import ru.gravit.launcher.modules.ModulesConfigManagerInterface; -import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.modules.ModulesConfigManager; +import ru.gravit.launcher.modules.ModulesManager; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.PublicURLClassLoader; public class LaunchServerModuleContext implements ModuleContext { public final LaunchServer launchServer; public final PublicURLClassLoader classloader; - public final ModulesConfigManager modulesConfigManager; + public final SimpleModulesConfigManager modulesConfigManager; - public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader, ModulesConfigManager modulesConfigManager) { + public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader, SimpleModulesConfigManager modulesConfigManager) { launchServer = server; this.classloader = classloader; this.modulesConfigManager = modulesConfigManager; @@ -24,12 +24,12 @@ public Type getType() { } @Override - public ModulesManagerInterface getModulesManager() { + public ModulesManager getModulesManager() { return launchServer.modulesManager; } @Override - public ModulesConfigManagerInterface getModulesConfigManager() { + public ModulesConfigManager getModulesConfigManager() { return modulesConfigManager; } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index f05970ed..4b1bca74 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -59,7 +59,7 @@ private LauncherEngine() { public void start(String... args) throws Throwable { LogHelper.debug("%d", LauncherSettings.settingsMagic); Launcher.modulesManager = new ClientModuleManager(this); - LauncherConfig.getAutogenConfig().initModules(); //INIT + LauncherConfig.getAutogenConfig().initModules(); Launcher.modulesManager.preInitModules(); if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider(); runtimeProvider.init(false); @@ -67,10 +67,9 @@ public void start(String... args) throws Throwable { if (started.getAndSet(true)) throw new IllegalStateException("Launcher has been already started"); Launcher.modulesManager.initModules(); - // Load init.js script runtimeProvider.preLoad(); FunctionalBridge.worker = new RequestWorker(); - CommonHelper.newThread("FX Task Worker", true, FunctionalBridge.worker).start(); + CommonHelper.newThread("Task Worker", true, FunctionalBridge.worker).start(); FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID); FunctionalBridge.getHWID.start(); LogHelper.debug("Dir: %s", DirBridge.dir); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java index 2328565c..1253b764 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java @@ -3,8 +3,8 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherEngine; import ru.gravit.launcher.modules.ModuleContext; -import ru.gravit.launcher.modules.ModulesConfigManagerInterface; -import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.modules.ModulesConfigManager; +import ru.gravit.launcher.modules.ModulesManager; public class ClientModuleContext implements ModuleContext { public final LauncherEngine engine; @@ -19,12 +19,12 @@ public Type getType() { } @Override - public ModulesManagerInterface getModulesManager() { + public ModulesManager getModulesManager() { return Launcher.modulesManager; } @Override - public ModulesConfigManagerInterface getModulesConfigManager() { + public ModulesConfigManager getModulesConfigManager() { return null; // ClientModuleContext не поддерживает modulesConfigManager } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java index bcd63969..a3109c43 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java @@ -147,9 +147,9 @@ private void setScriptBindings() { public void run(String[] args) throws ScriptException, NoSuchMethodException, IOException { loadScript(Launcher.INIT_SCRIPT_FILE); LogHelper.info("Invoking start() function"); - Invocable invoker = (Invocable) engine; Launcher.modulesManager.postInitModules(); - invoker.invokeFunction("start", (Object) args); + ((Invocable) engine).invokeFunction("start", (Object) args); + Launcher.modulesManager.finishModules(); } @Override diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java index edbacbfd..de21f7f5 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java @@ -1,6 +1,6 @@ package ru.gravit.launcher.server; -import ru.gravit.launcher.managers.ModulesConfigManager; +import ru.gravit.launcher.managers.SimpleModulesConfigManager; import ru.gravit.launcher.managers.SimpleModuleManager; import ru.gravit.utils.PublicURLClassLoader; @@ -9,11 +9,11 @@ import java.util.ArrayList; public class ModulesManager extends SimpleModuleManager { - public ModulesConfigManager modulesConfigManager; + public SimpleModulesConfigManager modulesConfigManager; public ModulesManager(ServerWrapper wrapper) { modules = new ArrayList<>(); - modulesConfigManager = new ModulesConfigManager(Paths.get("modules-config")); + modulesConfigManager = new SimpleModulesConfigManager(Paths.get("modules-config")); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); context = new ServerModuleContext(wrapper, classloader, modulesConfigManager); } diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java index 93802a0d..f1e47397 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java @@ -1,18 +1,18 @@ package ru.gravit.launcher.server; import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.managers.ModulesConfigManager; +import ru.gravit.launcher.managers.SimpleModulesConfigManager; import ru.gravit.launcher.modules.ModuleContext; -import ru.gravit.launcher.modules.ModulesConfigManagerInterface; -import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.modules.ModulesConfigManager; +import ru.gravit.launcher.modules.ModulesManager; import ru.gravit.utils.PublicURLClassLoader; public class ServerModuleContext implements ModuleContext { public final PublicURLClassLoader classLoader; public final ServerWrapper wrapper; - public final ModulesConfigManager modulesConfigManager; + public final SimpleModulesConfigManager modulesConfigManager; - public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader, ModulesConfigManager modulesConfigManager) { + public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader, SimpleModulesConfigManager modulesConfigManager) { this.classLoader = classLoader; this.wrapper = wrapper; this.modulesConfigManager = modulesConfigManager; @@ -24,12 +24,12 @@ public Type getType() { } @Override - public ModulesManagerInterface getModulesManager() { + public ModulesManager getModulesManager() { return Launcher.modulesManager; } @Override - public ModulesConfigManagerInterface getModulesConfigManager() { + public ModulesConfigManager getModulesConfigManager() { return modulesConfigManager; } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index c6db3d48..9d235d96 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -2,7 +2,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.modules.ModulesManager; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.utils.Version; @@ -36,7 +36,7 @@ public final class Launcher { private static final AtomicReference CONFIG = new AtomicReference<>(); @LauncherAPI - public static ModulesManagerInterface modulesManager = null; + public static ModulesManager modulesManager = null; @LauncherAPI public static final int PROTOCOL_MAGIC_LEGACY = 0x724724_00 + 24; @LauncherAPI diff --git a/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java index fcf9e0e1..effa9adf 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java @@ -2,7 +2,7 @@ import ru.gravit.launcher.modules.Module; import ru.gravit.launcher.modules.ModuleContext; -import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.modules.ModulesManager; import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -15,7 +15,7 @@ import java.util.ArrayList; import java.util.jar.JarFile; -public class SimpleModuleManager implements ModulesManagerInterface { +public class SimpleModuleManager implements ModulesManager { protected final class ModulesVisitor extends SimpleFileVisitor { private ModulesVisitor() { } @@ -134,4 +134,12 @@ public void registerModule(Module module) { load(module); LogHelper.info("Module %s version: %s registered", module.getName(), module.getVersion()); } + + @Override + public void finishModules() { + for (Module m : modules) { + m.finish(context); + LogHelper.info("Module %s version: %s finished initialization", m.getName(), m.getVersion()); + } + } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModulesConfigManager.java similarity index 82% rename from libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java rename to libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModulesConfigManager.java index f8561247..7a588ece 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModulesConfigManager.java @@ -1,6 +1,6 @@ package ru.gravit.launcher.managers; -import ru.gravit.launcher.modules.ModulesConfigManagerInterface; +import ru.gravit.launcher.modules.ModulesConfigManager; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -8,10 +8,10 @@ import java.nio.file.Files; import java.nio.file.Path; -public class ModulesConfigManager implements ModulesConfigManagerInterface { +public class SimpleModulesConfigManager implements ModulesConfigManager { public Path configDir; - public ModulesConfigManager(Path configDir) { + public SimpleModulesConfigManager(Path configDir) { this.configDir = configDir; } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java index f696c036..408f498d 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java @@ -15,4 +15,8 @@ public interface Module extends AutoCloseable { void postInit(ModuleContext context); void preInit(ModuleContext context); + + default void finish(ModuleContext context) { + // NOP + }; } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java index 3161434a..2284593d 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java @@ -7,7 +7,7 @@ enum Type { Type getType(); - ModulesManagerInterface getModulesManager(); + ModulesManager getModulesManager(); - ModulesConfigManagerInterface getModulesConfigManager(); + ModulesConfigManager getModulesConfigManager(); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManager.java similarity index 76% rename from libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java rename to libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManager.java index f49e4406..cbf70ce8 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManager.java @@ -2,7 +2,7 @@ import java.nio.file.Path; -public interface ModulesConfigManagerInterface { +public interface ModulesConfigManager { Path getModuleConfig(String moduleName); Path getModuleConfigDir(String moduleName); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManager.java similarity index 82% rename from libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java rename to libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManager.java index 78eceb76..5ff7b7bc 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManager.java @@ -2,7 +2,7 @@ import java.net.URL; -public interface ModulesManagerInterface extends AutoCloseable { +public interface ModulesManager extends AutoCloseable { void initModules(); void load(Module module); @@ -15,6 +15,8 @@ public interface ModulesManagerInterface extends AutoCloseable { void preInitModules(); + void finishModules(); + void printModules(); void sort(); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java deleted file mode 100644 index 49efd84c..00000000 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java +++ /dev/null @@ -1,42 +0,0 @@ -package ru.gravit.launcher.modules; - - -import ru.gravit.launcher.Launcher; -import ru.gravit.utils.Version; - -public class TestClientModule implements Module { - @Override - public void close() { - - } - - @Override - public String getName() { - return "TestClientModule"; - } - - @Override - public Version getVersion() { - return Launcher.getVersion(); - } - - @Override - public int getPriority() { - return 0; - } - - @Override - public void init(ModuleContext context) { - - } - - @Override - public void postInit(ModuleContext context) { - - } - - @Override - public void preInit(ModuleContext context) { - - } -}