Search in sources :

Example 11 with Module

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

the class ModulesMetric method createTelemetryFieldToValue.

@Override
public Map<String, ?> createTelemetryFieldToValue() {
    updateModules();
    telemetryFieldToValue = new HashMap();
    for (Module module : modules) {
        telemetryFieldToValue.put(module.getId().toString(), module.getVersion().toString());
    }
    return telemetryFieldToValue;
}
Also used : HashMap(java.util.HashMap) Module(org.terasology.module.Module)

Example 12 with Module

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

the class ModuleInstaller method getDownloadUrls.

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

Example 13 with Module

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

the class ModuleManagerImpl method loadModulesFromClassPath.

/**
 * Overrides modules in modules/ with those specified via -classpath in the JVM
 */
private void loadModulesFromClassPath() {
    // Only attempt this if we're using the standard URLClassLoader
    if (ClassLoader.getSystemClassLoader() instanceof URLClassLoader) {
        URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
        ModuleLoader loader = new ModuleLoader(metadataReader);
        Enumeration<URL> moduleInfosInClassPath;
        loader.setModuleInfoPath(TerasologyConstants.MODULE_INFO_FILENAME);
        // We're looking for jars on the classpath with a module.txt
        try {
            moduleInfosInClassPath = urlClassLoader.findResources(TerasologyConstants.MODULE_INFO_FILENAME.toString());
        } catch (IOException e) {
            logger.warn("Failed to search for classpath modules: {}", e);
            return;
        }
        for (URL url : Collections.list(moduleInfosInClassPath)) {
            if (!url.getProtocol().equalsIgnoreCase("jar")) {
                continue;
            }
            try {
                Reader reader = new InputStreamReader(url.openStream(), TerasologyConstants.CHARSET);
                ModuleMetadata metaData = metadataReader.read(reader);
                String displayName = metaData.getDisplayName().toString();
                Name id = metaData.getId();
                // if the display name is empty or the id is null, this probably isn't a Terasology module
                if (null == id || displayName.equalsIgnoreCase("")) {
                    logger.warn("Found a module-like JAR on the class path with no id or display name. Skipping");
                    logger.warn("{}", url);
                }
                logger.info("Loading module {} from class path at {}", displayName, url.getFile());
                // the url contains a protocol, and points to the module.txt
                // we need to trim both of those away to get the module's path
                Path path = Paths.get(url.getFile().replace("file:", "").replace("!/" + TerasologyConstants.MODULE_INFO_FILENAME, "").replace("/" + TerasologyConstants.MODULE_INFO_FILENAME, ""));
                Module module = loader.load(path);
                registry.add(module);
            } catch (IOException e) {
                logger.warn("Failed to load module.txt for classpath module {}", url);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) ModuleLoader(org.terasology.module.ModuleLoader) InputStreamReader(java.io.InputStreamReader) URLClassLoader(java.net.URLClassLoader) ModuleMetadata(org.terasology.module.ModuleMetadata) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) ClasspathModule(org.terasology.module.ClasspathModule) Module(org.terasology.module.Module) URL(java.net.URL) Name(org.terasology.naming.Name)

Example 14 with Module

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

the class ModuleManagerImpl method loadEnvironment.

@Override
public ModuleEnvironment loadEnvironment(Set<Module> modules, boolean asPrimary) {
    Set<Module> finalModules = Sets.newLinkedHashSet(modules);
    finalModules.addAll(registry.stream().filter(Module::isOnClasspath).collect(Collectors.toList()));
    ModuleEnvironment newEnvironment = new ModuleEnvironment(finalModules, permissionProviderFactory, Collections.<BytecodeInjector>emptyList());
    if (asPrimary) {
        environment = newEnvironment;
    }
    return newEnvironment;
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) ClasspathModule(org.terasology.module.ClasspathModule) Module(org.terasology.module.Module)

Example 15 with Module

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

the class ComponentSystemManager method loadSystems.

public void loadSystems(ModuleEnvironment environment, NetworkMode netMode) {
    DisplayDevice display = context.get(DisplayDevice.class);
    boolean isHeadless = display.isHeadless();
    ListMultimap<Name, Class<?>> systemsByModule = ArrayListMultimap.create();
    for (Class<?> type : environment.getTypesAnnotatedWith(RegisterSystem.class)) {
        if (!ComponentSystem.class.isAssignableFrom(type)) {
            logger.error("Cannot load {}, must be a subclass of ComponentSystem", type.getSimpleName());
            continue;
        }
        Name moduleId = environment.getModuleProviding(type);
        RegisterSystem registerInfo = type.getAnnotation(RegisterSystem.class);
        if (registerInfo.value().isValidFor(netMode, isHeadless) && areOptionalRequirementsContained(registerInfo, environment)) {
            systemsByModule.put(moduleId, type);
        }
    }
    for (Module module : environment.getModulesOrderedByDependencies()) {
        for (Class<?> system : systemsByModule.get(module.getId())) {
            String id = module.getId() + ":" + system.getSimpleName();
            logger.debug("Registering system {}", id);
            try {
                ComponentSystem newSystem = (ComponentSystem) system.newInstance();
                InjectionHelper.share(newSystem);
                register(newSystem, id);
                logger.debug("Loaded system {}", id);
            } catch (RuntimeException | IllegalAccessException | InstantiationException | NoClassDefFoundError e) {
                logger.error("Failed to load system {}", id, e);
            }
        }
    }
}
Also used : DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) ComponentSystem(org.terasology.entitySystem.systems.ComponentSystem) Name(org.terasology.naming.Name) RegisterSystem(org.terasology.entitySystem.systems.RegisterSystem) Module(org.terasology.module.Module)

Aggregations

Module (org.terasology.module.Module)32 Name (org.terasology.naming.Name)15 ModuleManager (org.terasology.engine.module.ModuleManager)11 DependencyResolver (org.terasology.module.DependencyResolver)11 ModuleEnvironment (org.terasology.module.ModuleEnvironment)9 ResolutionResult (org.terasology.module.ResolutionResult)8 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ModuleMetadata (org.terasology.module.ModuleMetadata)4 IOException (java.io.IOException)3 URL (java.net.URL)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 SimpleUri (org.terasology.engine.SimpleUri)3 GameManifest (org.terasology.game.GameManifest)3 Vector2i (org.terasology.math.geom.Vector2i)3 DependencyInfo (org.terasology.module.DependencyInfo)3 ModuleRegistry (org.terasology.module.ModuleRegistry)3