[FEATURE] Modules этап finish. + [FIX] Правки LauncherEngine.

This commit is contained in:
zaxar163 2019-01-17 19:38:27 +03:00
parent bb317432d0
commit 2d06628a74
No known key found for this signature in database
GPG key ID: E3B309DD3852DE06
17 changed files with 53 additions and 85 deletions

View file

@ -16,7 +16,6 @@ public StdCommandHandler(LaunchServer server, boolean readCommands) {
@Override
public void bell() {
// Do nothing, unsupported
}
@Override

View file

@ -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();

View file

@ -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) {

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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
}
}

View file

@ -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

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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<LauncherConfig> 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

View file

@ -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<Path> {
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());
}
}
}

View file

@ -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;
}

View file

@ -15,4 +15,8 @@ public interface Module extends AutoCloseable {
void postInit(ModuleContext context);
void preInit(ModuleContext context);
default void finish(ModuleContext context) {
// NOP
};
}

View file

@ -7,7 +7,7 @@ enum Type {
Type getType();
ModulesManagerInterface getModulesManager();
ModulesManager getModulesManager();
ModulesConfigManagerInterface getModulesConfigManager();
ModulesConfigManager getModulesConfigManager();
}

View file

@ -2,7 +2,7 @@
import java.nio.file.Path;
public interface ModulesConfigManagerInterface {
public interface ModulesConfigManager {
Path getModuleConfig(String moduleName);
Path getModuleConfigDir(String moduleName);

View file

@ -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();

View file

@ -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) {
}
}