Search in sources :

Example 1 with TableModuleRegistry

use of org.terasology.gestalt.module.TableModuleRegistry in project Terasology by MovingBlocks.

the class BindsSubsystemTest method setUpMockModuleEnvironment.

private void setUpMockModuleEnvironment() {
    ModuleManager moduleManager = mock(ModuleManager.class);
    ModuleRegistry moduleRegistry = new TableModuleRegistry();
    Module module = mock(Module.class);
    when(module.getId()).thenReturn(new Name(TEST_MODULE));
    when(module.getVersion()).thenReturn(new Version(0, 0, 1, true));
    when(module.getMetadata()).thenReturn(new ModuleMetadata());
    moduleRegistry.add(module);
    when(moduleManager.getRegistry()).thenReturn(moduleRegistry);
    ModuleEnvironment environment = mock(ModuleEnvironment.class);
    when(moduleManager.loadEnvironment(any(), anyBoolean())).thenReturn(environment);
    when(moduleManager.getEnvironment()).thenReturn(environment);
    registerBindButtonClasses = new ArrayList<>();
    when(environment.getTypesAnnotatedWith(eq(RegisterBindButton.class))).thenReturn(registerBindButtonClasses);
    when(environment.getTypesAnnotatedWith(eq(RegisterBindButton.class), any())).thenReturn(registerBindButtonClasses);
    registerRealBindAxisClasses = new ArrayList<>();
    when(environment.getTypesAnnotatedWith(eq(RegisterBindAxis.class))).thenReturn(registerRealBindAxisClasses);
    when(environment.getTypesAnnotatedWith(eq(RegisterBindAxis.class), any())).thenReturn(registerRealBindAxisClasses);
    when(environment.getModuleProviding(any())).thenReturn(new Name(TEST_MODULE));
    context.put(ModuleManager.class, moduleManager);
}
Also used : TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) Version(org.terasology.gestalt.naming.Version) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) RegisterBindAxis(org.terasology.engine.input.RegisterBindAxis) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

Example 2 with TableModuleRegistry

use of org.terasology.gestalt.module.TableModuleRegistry in project Terasology by MovingBlocks.

the class ModuleDownloadListGeneratorTest method buildRegistry.

private ModuleRegistry buildRegistry(String engineVersion, Module... modules) {
    ModuleRegistry result = new TableModuleRegistry();
    result.add(buildEngineModule(engineVersion));
    result.addAll(Arrays.asList(modules));
    return result;
}
Also used : TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry)

Example 3 with TableModuleRegistry

use of org.terasology.gestalt.module.TableModuleRegistry in project Terasology by MovingBlocks.

the class ModuleListDownloader method call.

@Override
public ModuleRegistry call() throws IOException {
    logger.info("Downloading modules ..");
    TableModuleRegistry modules = new TableModuleRegistry();
    URL url = new URL("http", serverAddress, "/modules/list/latest");
    try (InputStreamReader reader = new InputStreamReader(url.openStream(), TerasologyConstants.CHARSET)) {
        logger.info("Parsing content ..");
        JsonArray jsonArray = gson.fromJson(reader, JsonArray.class);
        for (JsonElement jObject : jsonArray) {
            String json = gson.toJson(jObject);
            ModuleMetadata meta = metaReader.read(new StringReader(json));
            logger.debug("Read module {} - {}", meta.getId(), meta.getVersion());
            modules.add(new Module(meta, new EmptyFileSource(), Collections.emptyList(), new Reflections(), (c) -> false));
        }
        int count = modules.size();
        logger.info(String.format("Retrieved %d %s", count, (count == 1) ? "entry" : "entries"));
    }
    return modules;
}
Also used : Logger(org.slf4j.Logger) TerasologyConstants(org.terasology.engine.core.TerasologyConstants) URL(java.net.URL) Module(org.terasology.gestalt.module.Module) LoggerFactory(org.slf4j.LoggerFactory) TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Reflections(org.reflections.Reflections) InputStreamReader(java.io.InputStreamReader) JsonElement(com.google.gson.JsonElement) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) JsonArray(com.google.gson.JsonArray) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) StringReader(java.io.StringReader) EmptyFileSource(org.terasology.gestalt.module.resources.EmptyFileSource) Gson(com.google.gson.Gson) ModuleMetadataJsonAdapter(org.terasology.gestalt.module.ModuleMetadataJsonAdapter) Collections(java.util.Collections) InputStreamReader(java.io.InputStreamReader) TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) EmptyFileSource(org.terasology.gestalt.module.resources.EmptyFileSource) URL(java.net.URL) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) StringReader(java.io.StringReader) Module(org.terasology.gestalt.module.Module) Reflections(org.reflections.Reflections)

Aggregations

ModuleRegistry (org.terasology.gestalt.module.ModuleRegistry)3 TableModuleRegistry (org.terasology.gestalt.module.TableModuleRegistry)3 Module (org.terasology.gestalt.module.Module)2 ModuleMetadata (org.terasology.gestalt.module.ModuleMetadata)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 Collections (java.util.Collections)1 Callable (java.util.concurrent.Callable)1 Reflections (org.reflections.Reflections)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 TerasologyConstants (org.terasology.engine.core.TerasologyConstants)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 RegisterBindAxis (org.terasology.engine.input.RegisterBindAxis)1 RegisterBindButton (org.terasology.engine.input.RegisterBindButton)1