Search in sources :

Example 1 with ModuleRegistry

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

the class ModuleDownloadListGeneratorTest method testSingleModuleNoUpdate.

@Test
public void testSingleModuleNoUpdate() throws DependencyResolutionFailedException {
    ModuleRegistry localRegistry = buildRegistry("1.0.0", buildSimpleModule("myModule", "1.0.0"));
    DependencyResolver resolver = mockResolver(true, buildSimpleModule("myModule", "1.0.0"), buildEngineModule("1.0.0"));
    ModuleDownloadListGenerator listGenerator = new ModuleDownloadListGenerator(localRegistry, resolver);
    assertEquals(Collections.emptySet(), buildList(listGenerator));
}
Also used : TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Test(org.junit.jupiter.api.Test)

Example 2 with ModuleRegistry

use of org.terasology.gestalt.module.ModuleRegistry 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 3 with ModuleRegistry

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

the class JoinGameScreen method getModulesText.

private String getModulesText(Future<ServerInfoMessage> info) {
    try {
        ServerInfoMessage serverInfoMessage = info.get();
        if (serverInfoMessage == null) {
            return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
        }
        List<String> codedModInfo = new ArrayList<>();
        ModuleRegistry reg = moduleManager.getRegistry();
        for (NameVersion entry : serverInfoMessage.getModuleList()) {
            boolean isInstalled = reg.getModule(entry.getName(), entry.getVersion()) != null;
            Color color = isInstalled ? Color.GREEN : Color.RED;
            codedModInfo.add(FontColor.getColored(entry.toString(), color));
        }
        Collections.sort(codedModInfo, String.CASE_INSENSITIVE_ORDER);
        return Joiner.on('\n').join(codedModInfo);
    } catch (ExecutionException | InterruptedException e) {
        return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
    }
}
Also used : NameVersion(org.terasology.gestalt.naming.NameVersion) Color(org.terasology.nui.Color) FontColor(org.terasology.nui.FontColor) ArrayList(java.util.ArrayList) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) ServerInfoMessage(org.terasology.engine.network.ServerInfoMessage) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with ModuleRegistry

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

the class ModuleDownloadListGeneratorTest method testResolverFailed.

@Test
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);
    Assertions.assertThrows(DependencyResolutionFailedException.class, () -> buildList(listGenerator));
}
Also used : TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Test(org.junit.jupiter.api.Test)

Example 5 with ModuleRegistry

use of org.terasology.gestalt.module.ModuleRegistry 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));
}
Also used : TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) Module(org.terasology.gestalt.module.Module) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Test(org.junit.jupiter.api.Test)

Aggregations

ModuleRegistry (org.terasology.gestalt.module.ModuleRegistry)8 TableModuleRegistry (org.terasology.gestalt.module.TableModuleRegistry)7 Test (org.junit.jupiter.api.Test)4 Module (org.terasology.gestalt.module.Module)4 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)4 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 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 Reflections (org.reflections.Reflections)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1