Search in sources :

Example 6 with ModuleRegistry

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

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

the class ModuleDownloadListGeneratorTest method testSingleModuleNeedsUpdate.

@Test
public void testSingleModuleNeedsUpdate() throws DependencyResolutionFailedException {
    Module moduleV1 = buildSimpleModule("myModule", "1.0.0");
    Module moduleV2 = buildSimpleModule("myModule", "2.0.0");
    ModuleRegistry localRegistry = buildRegistry("1.0.0", moduleV1);
    DependencyResolver resolver = mockResolver(true, moduleV2, buildEngineModule("1.0.0"));
    ModuleDownloadListGenerator listGenerator = new ModuleDownloadListGenerator(localRegistry, resolver);
    assertEquals(Collections.singleton(moduleV2), 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)

Example 8 with ModuleRegistry

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