Search in sources :

Example 36 with Module

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

the class ModuleManager method ensureModulesDependOnEngine.

/**
 * Ensure all modules declare a dependency on the engine module.
 * <p>
 * This is to ensure that the set of modules is a graph with a single root.
 * We need this to ensure the engine is loaded <em>before</em> other modules
 * when things iterate over the module list in dependency order.
 * <p>
 * See <a href="https://github.com/MovingBlocks/Terasology/issues/1450">#1450</a>.
 */
private void ensureModulesDependOnEngine() {
    DependencyInfo engineDep = new DependencyInfo();
    engineDep.setId(engineModule.getId());
    engineDep.setMinVersion(engineModule.getVersion());
    Set<Name> engineModules = Sets.newHashSet(engineModule.getId());
    engineModules.addAll(engineModule.getMetadata().getDependencies().stream().map(DependencyInfo::getId).collect(Collectors.toList()));
    registry.stream().filter(mod -> !engineModules.contains(mod.getId())).forEach(mod -> mod.getMetadata().getDependencies().add(engineDep));
}
Also used : Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) SystemConfig(org.terasology.engine.config.SystemConfig) PermissionProviderFactory(org.terasology.gestalt.module.sandbox.PermissionProviderFactory) Reflections(org.reflections.Reflections) Jvm(org.terasology.engine.utilities.Jvm) StandardPermissionProviderFactory(org.terasology.gestalt.module.sandbox.StandardPermissionProviderFactory) PropertyPermission(java.util.PropertyPermission) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) Map(java.util.Map) ModuleMetadataLoader(org.terasology.gestalt.module.ModuleMetadataLoader) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) JarURLConnection(java.net.JarURLConnection) Path(java.nio.file.Path) Policy(java.security.Policy) ReflectPermission(java.lang.reflect.ReflectPermission) Scanner(org.reflections.scanners.Scanner) Module(org.terasology.gestalt.module.Module) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Collection(java.util.Collection) TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ClasspathHelper(org.reflections.util.ClasspathHelper) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) List(java.util.List) ModuleSecurityPolicy(org.terasology.gestalt.module.sandbox.ModuleSecurityPolicy) Name(org.terasology.gestalt.naming.Name) TerasologyConstants(org.terasology.engine.core.TerasologyConstants) APIScanner(org.terasology.gestalt.module.sandbox.APIScanner) WarnOnlyProviderFactory(org.terasology.gestalt.module.sandbox.WarnOnlyProviderFactory) HashSet(java.util.HashSet) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) ModuleSecurityManager(org.terasology.gestalt.module.sandbox.ModuleSecurityManager) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Logger(org.slf4j.Logger) PermissionProvider(org.terasology.gestalt.module.sandbox.PermissionProvider) PermissionSet(org.terasology.gestalt.module.sandbox.PermissionSet) IOException(java.io.IOException) File(java.io.File) Config(org.terasology.engine.config.Config) ModulePathScanner(org.terasology.gestalt.module.ModulePathScanner) ModuleMetadataJsonAdapter(org.terasology.gestalt.module.ModuleMetadataJsonAdapter) Collections(java.util.Collections) PathManager(org.terasology.engine.core.PathManager) ModuleFactory(org.terasology.gestalt.module.ModuleFactory) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) Name(org.terasology.gestalt.naming.Name)

Example 37 with Module

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

the class ModuleManager method registerArchiveModule.

/**
 * Load and register a new module for this file.
 */
@SuppressWarnings("UnusedReturnValue")
public Module registerArchiveModule(Path path) throws IOException {
    Module module = moduleFactory.createArchiveModule(path.toFile());
    registry.add(module);
    ensureModulesDependOnEngine();
    return module;
}
Also used : Module(org.terasology.gestalt.module.Module)

Example 38 with Module

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

the class ModuleInstaller method getDownloadUrls.

private Map<URI, Path> getDownloadUrls(Iterable<Module> modules) {
    Map<URI, Path> result = new HashMap<>();
    for (Module module : modules) {
        ModuleMetadata metadata = module.getMetadata();
        String version = metadata.getVersion().toString();
        String id = metadata.getId().toString();
        URI uri = null;
        try {
            uri = RemoteModuleExtension.getDownloadUrl(metadata).toURI();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        String fileName = String.format("%s-%s.jar", id, version);
        Path folder = PathManager.getInstance().getHomeModPath().normalize();
        Path target = folder.resolve(fileName);
        result.put(uri, target);
    }
    return result;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) URISyntaxException(java.net.URISyntaxException) Module(org.terasology.gestalt.module.Module) URI(java.net.URI)

Example 39 with Module

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

Example 40 with Module

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

the class ServerConnectionHandler method sendModules.

private void sendModules(List<NetData.ModuleRequest> moduleRequestList) {
    for (NetData.ModuleRequest request : moduleRequestList) {
        NetData.ModuleDataHeader.Builder result = NetData.ModuleDataHeader.newBuilder();
        result.setId(request.getModuleId());
        Module module = moduleManager.getEnvironment().get(new Name(request.getModuleId()));
        if (!(module.getResources() instanceof ArchiveFileSource)) {
            // TODO: gestaltv7 restore module downloading for maximum possibles
            result.setError("Module not available for download");
        } else {
            FileReference fileReference = module.getResources().getFiles().iterator().next();
            try (InputStream stream = fileReference.open()) {
                ByteString byteString = ByteString.readFrom(stream, 1024);
                channelHandlerContext.channel().write(NetData.NetMessage.newBuilder().setModuleData(NetData.ModuleData.newBuilder().setModule(byteString)).build());
                result.setVersion(module.getVersion().toString());
                result.setSize(byteString.size());
                channelHandlerContext.channel().write(NetData.NetMessage.newBuilder().setModuleDataHeader(result).build());
            } catch (IOException e) {
                logger.error("Error sending module", e);
                channelHandlerContext.channel().close();
                break;
            }
        }
    }
}
Also used : NetData(org.terasology.protobuf.NetData) InputStream(java.io.InputStream) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) Module(org.terasology.gestalt.module.Module) FileReference(org.terasology.gestalt.module.resources.FileReference) ArchiveFileSource(org.terasology.gestalt.module.resources.ArchiveFileSource) Name(org.terasology.gestalt.naming.Name)

Aggregations

Module (org.terasology.gestalt.module.Module)51 ModuleManager (org.terasology.engine.core.module.ModuleManager)18 Name (org.terasology.gestalt.naming.Name)17 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)13 ModuleMetadata (org.terasology.gestalt.module.ModuleMetadata)11 List (java.util.List)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 SimpleUri (org.terasology.engine.core.SimpleUri)9 UILabel (org.terasology.nui.widgets.UILabel)9 UIText (org.terasology.nui.widgets.UIText)9 DependencyInfo (org.terasology.gestalt.module.dependencyresolution.DependencyInfo)8 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)8 Canvas (org.terasology.nui.Canvas)8 Collection (java.util.Collection)7 Comparator (java.util.Comparator)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 TranslationSystem (org.terasology.engine.i18n.TranslationSystem)7 In (org.terasology.engine.registry.In)7