use of org.terasology.module.DependencyResolver in project Terasology by MovingBlocks.
the class WorldGeneratorManager method createGenerator.
/**
* @param uri uri of the world generator to create.
* @param context objects from this context will be injected into the
* @return The instantiated world generator.
*/
public static WorldGenerator createGenerator(SimpleUri uri, Context context) throws UnresolvedWorldGeneratorException {
ModuleManager moduleManager = context.get(ModuleManager.class);
Module module = moduleManager.getEnvironment().get(uri.getModuleName());
if (module == null) {
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(uri.getModuleName());
if (!result.isSuccess()) {
if (moduleManager.getRegistry().getLatestModuleVersion(uri.getModuleName()) == null) {
throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - not found");
} else {
throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - unable to resolve module dependencies");
}
}
try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
return createWorldGenerator(uri, context, environment);
}
} else {
return createWorldGenerator(uri, context, moduleManager.getEnvironment());
}
}
use of org.terasology.module.DependencyResolver in project Terasology by MovingBlocks.
the class RegisterMods method step.
@Override
public boolean step() {
if (applyModulesThread != null) {
if (!applyModulesThread.isAlive()) {
if (oldEnvironment != null) {
oldEnvironment.close();
}
return true;
}
return false;
} else {
ModuleManager moduleManager = context.get(ModuleManager.class);
List<Name> moduleIds = gameManifest.getModules().stream().map(NameVersion::getName).collect(Collectors.toCollection(ArrayList::new));
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(moduleIds);
if (result.isSuccess()) {
oldEnvironment = moduleManager.getEnvironment();
ModuleEnvironment env = moduleManager.loadEnvironment(result.getModules(), true);
for (Module moduleInfo : env.getModulesOrderedByDependencies()) {
logger.info("Activating module: {}:{}", moduleInfo.getId(), moduleInfo.getVersion());
}
EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
applyModulesThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
applyModulesThread.start();
return false;
} else {
logger.warn("Missing at least one required module or dependency: {}", moduleIds);
context.get(GameEngine.class).changeState(new StateMainMenu("Missing required module or dependency"));
return true;
}
}
}
use of org.terasology.module.DependencyResolver in project Terasology by MovingBlocks.
the class BindsSubsystem method updateDefaultBinds.
private void updateDefaultBinds(Context passedContext, BindsConfiguration config) {
ModuleManager moduleManager = passedContext.get(ModuleManager.class);
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
if (moduleManager.getRegistry().getLatestModuleVersion(moduleId).isCodeModule()) {
ResolutionResult result = resolver.resolve(moduleId);
if (result.isSuccess()) {
try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
FromModule filter = new FromModule(environment, moduleId);
Iterable<Class<?>> buttons = environment.getTypesAnnotatedWith(RegisterBindButton.class, filter);
Iterable<Class<?>> axes = environment.getTypesAnnotatedWith(RegisterRealBindAxis.class, filter);
addButtonDefaultsFor(moduleId, buttons, config);
addAxisDefaultsFor(moduleId, axes, config);
}
}
}
}
}
use of org.terasology.module.DependencyResolver in project Terasology by MovingBlocks.
the class ModuleDownloadListGeneratorTest method testResolverFailed.
@Test(expected = DependencyResolutionFailedException.class)
public void testResolverFailed() throws DependencyResolutionFailedException {
ModuleRegistry localRegistry = buildRegistry("1.0.0", buildSimpleModule("myModule", "1.0.0"));
DependencyResolver resolver = mockResolver(false);
ModuleDownloadListGenerator listGenerator = new ModuleDownloadListGenerator(localRegistry, resolver);
buildList(listGenerator);
}
use of org.terasology.module.DependencyResolver in project Terasology by MovingBlocks.
the class ModuleDownloadListGeneratorTest method testMultipleModulesPartialUpdate.
@Test
public void testMultipleModulesPartialUpdate() throws DependencyResolutionFailedException {
Module moduleAV1 = buildSimpleModule("myModuleA", "1.0.0");
Module moduleBV1 = buildSimpleModule("myModuleB", "1.0.0");
Module moduleBV2 = buildSimpleModule("myModuleB", "2.0.0");
ModuleRegistry localRegistry = buildRegistry("1.0.0", moduleAV1, moduleBV1);
DependencyResolver resolver = mockResolver(true, moduleBV1, moduleBV2, buildEngineModule("1.0.0"));
ModuleDownloadListGenerator listGenerator = new ModuleDownloadListGenerator(localRegistry, resolver);
assertEquals(Collections.singleton(moduleBV2), buildList(listGenerator));
}
Aggregations