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);
}
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;
}
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;
}
Aggregations