Search in sources :

Example 1 with EmptyFileSource

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

the class ModuleDownloadListGeneratorTest method buildSimpleModule.

private Module buildSimpleModule(String id, String version) {
    ModuleMetadata metadata = new ModuleMetadata();
    metadata.setId(new Name(id));
    if (version != null) {
        metadata.setVersion(new Version(version));
    }
    return new Module(metadata, new EmptyFileSource(), Collections.emptyList(), new Reflections(), (c) -> false);
}
Also used : Version(org.terasology.gestalt.naming.Version) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) EmptyFileSource(org.terasology.gestalt.module.resources.EmptyFileSource) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name) Reflections(org.reflections.Reflections)

Example 2 with EmptyFileSource

use of org.terasology.gestalt.module.resources.EmptyFileSource 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

Reflections (org.reflections.Reflections)2 Module (org.terasology.gestalt.module.Module)2 ModuleMetadata (org.terasology.gestalt.module.ModuleMetadata)2 EmptyFileSource (org.terasology.gestalt.module.resources.EmptyFileSource)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 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 TerasologyConstants (org.terasology.engine.core.TerasologyConstants)1 ModuleMetadataJsonAdapter (org.terasology.gestalt.module.ModuleMetadataJsonAdapter)1 ModuleRegistry (org.terasology.gestalt.module.ModuleRegistry)1 TableModuleRegistry (org.terasology.gestalt.module.TableModuleRegistry)1 Name (org.terasology.gestalt.naming.Name)1