[FEATURE] ModulesConfigManager

This commit is contained in:
Gravit 2019-01-12 07:13:24 +07:00
parent fa531a7b55
commit 68540a1c44
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
11 changed files with 99 additions and 8 deletions

View file

@ -189,6 +189,14 @@ public void verify() {
{ {
throw new NullPointerException("TextureProvider must not be null"); throw new NullPointerException("TextureProvider must not be null");
} }
if(permissionsHandler == null)
{
throw new NullPointerException("PermissionsHandler must not be null");
}
if(env == null)
{
throw new NullPointerException("Env must not be null");
}
} }
} }

View file

@ -3,17 +3,20 @@
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import ru.gravit.launcher.modules.SimpleModuleManager; import ru.gravit.launcher.managers.ModulesConfigManager;
import ru.gravit.launcher.managers.SimpleModuleManager;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.modules.CoreModule; import ru.gravit.launchserver.modules.CoreModule;
import ru.gravit.launchserver.modules.LaunchServerModuleContext; import ru.gravit.launchserver.modules.LaunchServerModuleContext;
import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.PublicURLClassLoader;
public class ModulesManager extends SimpleModuleManager { public class ModulesManager extends SimpleModuleManager {
public ModulesConfigManager configManager;
public ModulesManager(LaunchServer lsrv) { public ModulesManager(LaunchServer lsrv) {
modules = new ArrayList<>(1); modules = new ArrayList<>(1);
configManager = new ModulesConfigManager(lsrv.dir.resolve("config"));
classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
context = new LaunchServerModuleContext(lsrv, classloader); context = new LaunchServerModuleContext(lsrv, classloader, configManager);
registerCoreModule(); registerCoreModule();
} }

View file

@ -1,6 +1,8 @@
package ru.gravit.launchserver.modules; package ru.gravit.launchserver.modules;
import ru.gravit.launcher.managers.ModulesConfigManager;
import ru.gravit.launcher.modules.ModuleContext; import ru.gravit.launcher.modules.ModuleContext;
import ru.gravit.launcher.modules.ModulesConfigManagerInterface;
import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launcher.modules.ModulesManagerInterface;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.PublicURLClassLoader;
@ -8,10 +10,12 @@
public class LaunchServerModuleContext implements ModuleContext { public class LaunchServerModuleContext implements ModuleContext {
public final LaunchServer launchServer; public final LaunchServer launchServer;
public final PublicURLClassLoader classloader; public final PublicURLClassLoader classloader;
public final ModulesConfigManager modulesConfigManager;
public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader) { public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader, ModulesConfigManager modulesConfigManager) {
launchServer = server; launchServer = server;
this.classloader = classloader; this.classloader = classloader;
this.modulesConfigManager = modulesConfigManager;
} }
@Override @Override
@ -23,4 +27,9 @@ public Type getType() {
public ModulesManagerInterface getModulesManager() { public ModulesManagerInterface getModulesManager() {
return launchServer.modulesManager; return launchServer.modulesManager;
} }
@Override
public ModulesConfigManagerInterface getModulesConfigManager() {
return modulesConfigManager;
}
} }

View file

@ -3,6 +3,7 @@
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherEngine; import ru.gravit.launcher.LauncherEngine;
import ru.gravit.launcher.modules.ModuleContext; import ru.gravit.launcher.modules.ModuleContext;
import ru.gravit.launcher.modules.ModulesConfigManagerInterface;
import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launcher.modules.ModulesManagerInterface;
public class ClientModuleContext implements ModuleContext { public class ClientModuleContext implements ModuleContext {
@ -21,4 +22,9 @@ public Type getType() {
public ModulesManagerInterface getModulesManager() { public ModulesManagerInterface getModulesManager() {
return Launcher.modulesManager; return Launcher.modulesManager;
} }
@Override
public ModulesConfigManagerInterface getModulesConfigManager() {
return null; // ClientModuleContext не поддерживает modulesConfigManager
}
} }

View file

@ -1,7 +1,7 @@
package ru.gravit.launcher.client; package ru.gravit.launcher.client;
import ru.gravit.launcher.LauncherEngine; import ru.gravit.launcher.LauncherEngine;
import ru.gravit.launcher.modules.SimpleModuleManager; import ru.gravit.launcher.managers.SimpleModuleManager;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;

View file

@ -1,15 +1,19 @@
package ru.gravit.launcher.server; package ru.gravit.launcher.server;
import ru.gravit.launcher.modules.SimpleModuleManager; import ru.gravit.launcher.managers.ModulesConfigManager;
import ru.gravit.launcher.managers.SimpleModuleManager;
import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.PublicURLClassLoader;
import java.net.URL; import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
public class ModulesManager extends SimpleModuleManager { public class ModulesManager extends SimpleModuleManager {
public ModulesConfigManager modulesConfigManager;
public ModulesManager(ServerWrapper wrapper) { public ModulesManager(ServerWrapper wrapper) {
modules = new ArrayList<>(); modules = new ArrayList<>();
modulesConfigManager = new ModulesConfigManager(Paths.get("modules-config"));
classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
context = new ServerModuleContext(wrapper, classloader); context = new ServerModuleContext(wrapper, classloader, modulesConfigManager);
} }
} }

View file

@ -1,17 +1,21 @@
package ru.gravit.launcher.server; package ru.gravit.launcher.server;
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.managers.ModulesConfigManager;
import ru.gravit.launcher.modules.ModuleContext; import ru.gravit.launcher.modules.ModuleContext;
import ru.gravit.launcher.modules.ModulesConfigManagerInterface;
import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launcher.modules.ModulesManagerInterface;
import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.PublicURLClassLoader;
public class ServerModuleContext implements ModuleContext { public class ServerModuleContext implements ModuleContext {
public final PublicURLClassLoader classLoader; public final PublicURLClassLoader classLoader;
public final ServerWrapper wrapper; public final ServerWrapper wrapper;
public final ModulesConfigManager modulesConfigManager;
public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader) { public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader, ModulesConfigManager modulesConfigManager) {
this.classLoader = classLoader; this.classLoader = classLoader;
this.wrapper = wrapper; this.wrapper = wrapper;
this.modulesConfigManager = modulesConfigManager;
} }
@Override @Override
@ -23,4 +27,9 @@ public Type getType() {
public ModulesManagerInterface getModulesManager() { public ModulesManagerInterface getModulesManager() {
return Launcher.modulesManager; return Launcher.modulesManager;
} }
@Override
public ModulesConfigManagerInterface getModulesConfigManager() {
return modulesConfigManager;
}
} }

View file

@ -0,0 +1,40 @@
package ru.gravit.launcher.managers;
import ru.gravit.launcher.modules.ModulesConfigManagerInterface;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class ModulesConfigManager implements ModulesConfigManagerInterface {
public Path configDir;
public ModulesConfigManager(Path configDir) {
this.configDir = configDir;
}
public Path getModuleConfig(String moduleName)
{
if(!IOHelper.isDir(configDir)) {
try {
Files.createDirectories(configDir);
} catch (IOException e) {
LogHelper.error(e);
}
}
return configDir.resolve(moduleName.concat("Config.json"));
}
public Path getModuleConfigDir(String moduleName)
{
if(!IOHelper.isDir(configDir)) {
try {
Files.createDirectories(configDir);
} catch (IOException e) {
LogHelper.error(e);
}
}
return configDir.resolve(moduleName);
}
}

View file

@ -1,5 +1,8 @@
package ru.gravit.launcher.modules; package ru.gravit.launcher.managers;
import ru.gravit.launcher.modules.Module;
import ru.gravit.launcher.modules.ModuleContext;
import ru.gravit.launcher.modules.ModulesManagerInterface;
import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.PublicURLClassLoader;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;

View file

@ -8,4 +8,5 @@ enum Type {
Type getType(); Type getType();
ModulesManagerInterface getModulesManager(); ModulesManagerInterface getModulesManager();
ModulesConfigManagerInterface getModulesConfigManager();
} }

View file

@ -0,0 +1,8 @@
package ru.gravit.launcher.modules;
import java.nio.file.Path;
public interface ModulesConfigManagerInterface {
Path getModuleConfig(String moduleName);
Path getModuleConfigDir(String moduleName);
}