[FIX][EXPERIMENTAL] Исправление неоднозначности InitPhase

This commit is contained in:
Gravit 2019-08-26 17:37:14 +07:00
parent a980935092
commit 497e07094a
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 17 additions and 17 deletions

View file

@ -3,7 +3,7 @@
import pro.gravit.launcher.modules.LauncherInitContext; import pro.gravit.launcher.modules.LauncherInitContext;
import pro.gravit.launcher.modules.LauncherModule; import pro.gravit.launcher.modules.LauncherModule;
import pro.gravit.launcher.modules.LauncherModuleInfo; import pro.gravit.launcher.modules.LauncherModuleInfo;
import pro.gravit.launchserver.modules.events.LaunchServerInitPhase; import pro.gravit.launcher.modules.events.InitPhase;
import pro.gravit.utils.Version; import pro.gravit.utils.Version;
import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.LogHelper;
@ -14,11 +14,11 @@ public LaunchServerCoreModule() {
@Override @Override
public void init(LauncherInitContext initContext) { public void init(LauncherInitContext initContext) {
registerEvent(this::testEvent, LaunchServerInitPhase.class); registerEvent(this::testEvent, InitPhase.class);
} }
public void testEvent(LaunchServerInitPhase event) public void testEvent(InitPhase event)
{ {
LogHelper.debug("[LaunchServerCore] Event LaunchServerInitPhase passed"); //LogHelper.debug("[LaunchServerCore] Event LaunchServerInitPhase passed");
} }
} }

View file

@ -10,7 +10,7 @@ public abstract class LauncherModule {
protected LauncherModulesManager modulesManager; protected LauncherModulesManager modulesManager;
protected final LauncherModuleInfo moduleInfo; protected final LauncherModuleInfo moduleInfo;
protected ModulesConfigManager modulesConfigManager; protected ModulesConfigManager modulesConfigManager;
protected InitPhase initPhase = InitPhase.CREATED; protected InitStatus initStatus = InitStatus.CREATED;
protected LauncherModule() { protected LauncherModule() {
moduleInfo = new LauncherModuleInfo("UnknownModule"); moduleInfo = new LauncherModuleInfo("UnknownModule");
@ -24,7 +24,7 @@ public LauncherModuleInfo getModuleInfo() {
return moduleInfo; return moduleInfo;
} }
public enum InitPhase public enum InitStatus
{ {
CREATED, CREATED,
INIT, INIT,
@ -49,12 +49,12 @@ public Event cancel() {
protected boolean cancel = false; protected boolean cancel = false;
} }
public InitPhase getInitPhase() { public InitStatus getInitStatus() {
return initPhase; return initStatus;
} }
public LauncherModule setInitPhase(InitPhase initPhase) { public LauncherModule setInitStatus(InitStatus initStatus) {
this.initPhase = initPhase; this.initStatus = initStatus;
return this; return this;
} }

View file

@ -67,13 +67,13 @@ public void initModules(LauncherInitContext initContext) {
isAnyModuleLoad = false; isAnyModuleLoad = false;
for(LauncherModule module : modules) for(LauncherModule module : modules)
{ {
if(!module.getInitPhase().equals(LauncherModule.InitPhase.CREATED)) continue; if(!module.getInitStatus().equals(LauncherModule.InitStatus.CREATED)) continue;
if(checkDepend(module)) if(checkDepend(module))
{ {
isAnyModuleLoad = true; isAnyModuleLoad = true;
module.setInitPhase(LauncherModule.InitPhase.INIT); module.setInitStatus(LauncherModule.InitStatus.INIT);
module.init(initContext); module.init(initContext);
module.setInitPhase(LauncherModule.InitPhase.FINISH); module.setInitStatus(LauncherModule.InitStatus.FINISH);
loaded++; loaded++;
} }
} }
@ -81,13 +81,13 @@ public void initModules(LauncherInitContext initContext) {
} }
for(LauncherModule module : modules) for(LauncherModule module : modules)
{ {
if(module.getInitPhase().equals(LauncherModule.InitPhase.CREATED)) if(module.getInitStatus().equals(LauncherModule.InitStatus.CREATED))
{ {
LauncherModuleInfo info = module.getModuleInfo(); LauncherModuleInfo info = module.getModuleInfo();
LogHelper.warning("Module %s required %s. Cyclic dependencies?", info.name, Arrays.toString(info.dependencies)); LogHelper.warning("Module %s required %s. Cyclic dependencies?", info.name, Arrays.toString(info.dependencies));
module.setInitPhase(LauncherModule.InitPhase.INIT); module.setInitStatus(LauncherModule.InitStatus.INIT);
module.init(initContext); module.init(initContext);
module.setInitPhase(LauncherModule.InitPhase.FINISH); module.setInitStatus(LauncherModule.InitStatus.FINISH);
} }
} }
} }
@ -99,7 +99,7 @@ private boolean checkDepend(LauncherModule module)
{ {
LauncherModule depModule = getModule(dep); LauncherModule depModule = getModule(dep);
if(depModule == null) throw new RuntimeException(String.format("Module %s required %s. %s not found", info.name, dep, dep)); if(depModule == null) throw new RuntimeException(String.format("Module %s required %s. %s not found", info.name, dep, dep));
if(depModule.getInitPhase().equals(LauncherModule.InitPhase.CREATED)) return false; if(depModule.getInitStatus().equals(LauncherModule.InitStatus.CREATED)) return false;
} }
return true; return true;
} }