Search in sources :

Example 6 with ModuleManager

use of org.terasology.engine.module.ModuleManager in project Terasology by MovingBlocks.

the class HeadlessEnvironment method setupModuleManager.

@Override
protected void setupModuleManager(Set<Name> moduleNames) throws Exception {
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ModuleRegistry registry = moduleManager.getRegistry();
    DependencyResolver resolver = new DependencyResolver(registry);
    ResolutionResult result = resolver.resolve(moduleNames);
    if (result.isSuccess()) {
        ModuleEnvironment modEnv = moduleManager.loadEnvironment(result.getModules(), true);
        logger.debug("Loaded modules: " + modEnv.getModuleIdsOrderedByDependencies());
    } else {
        logger.error("Could not resolve module dependencies for " + moduleNames);
    }
    context.put(ModuleManager.class, moduleManager);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) ResolutionResult(org.terasology.module.ResolutionResult) ModuleRegistry(org.terasology.module.ModuleRegistry) ModuleManager(org.terasology.engine.module.ModuleManager) DependencyResolver(org.terasology.module.DependencyResolver)

Example 7 with ModuleManager

use of org.terasology.engine.module.ModuleManager in project Terasology by MovingBlocks.

the class TerasologyTestingEnvironment method setupEnvironment.

@BeforeClass
public static void setupEnvironment() throws Exception {
    final JavaArchive homeArchive = ShrinkWrap.create(JavaArchive.class);
    final FileSystem vfs = ShrinkWrapFileSystems.newFileSystem(homeArchive);
    PathManager.getInstance().useOverrideHomePath(vfs.getPath(""));
    /*
         * Create at least for each class a new headless environemnt as it is fast and prevents side effects
         * (Reusing a headless environment after other tests have modified the core registry isn't really clean)
         */
    env = new HeadlessEnvironment(new Name("engine"));
    context = env.getContext();
    assetManager = context.get(AssetManager.class);
    blockManager = context.get(BlockManager.class);
    config = context.get(Config.class);
    audioManager = context.get(AudioManager.class);
    collisionGroupManager = context.get(CollisionGroupManager.class);
    moduleManager = context.get(ModuleManager.class);
}
Also used : AudioManager(org.terasology.audio.AudioManager) AssetManager(org.terasology.assets.management.AssetManager) BlockManager(org.terasology.world.block.BlockManager) Config(org.terasology.config.Config) FileSystem(java.nio.file.FileSystem) CollisionGroupManager(org.terasology.physics.CollisionGroupManager) ModuleManager(org.terasology.engine.module.ModuleManager) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Name(org.terasology.naming.Name) BeforeClass(org.junit.BeforeClass)

Example 8 with ModuleManager

use of org.terasology.engine.module.ModuleManager in project Terasology by MovingBlocks.

the class ModuleManagerFactory method create.

public static ModuleManager create() throws Exception {
    ModuleManager moduleManager = new ModuleManagerImpl("");
    try (Reader reader = new InputStreamReader(ModuleManagerFactory.class.getResourceAsStream("/module.txt"), TerasologyConstants.CHARSET)) {
        ModuleMetadata metadata = new ModuleMetadataReader().read(reader);
        moduleManager.getRegistry().add(ClasspathModule.create(metadata, ModuleManagerFactory.class));
    }
    moduleManager.loadEnvironment(Sets.newHashSet(moduleManager.getRegistry().getLatestModuleVersion(new Name("engine"))), true);
    return moduleManager;
}
Also used : ModuleManagerImpl(org.terasology.engine.module.ModuleManagerImpl) InputStreamReader(java.io.InputStreamReader) ModuleMetadata(org.terasology.module.ModuleMetadata) Reader(java.io.Reader) ModuleMetadataReader(org.terasology.module.ModuleMetadataReader) InputStreamReader(java.io.InputStreamReader) ModuleManager(org.terasology.engine.module.ModuleManager) ModuleMetadataReader(org.terasology.module.ModuleMetadataReader) Name(org.terasology.naming.Name)

Example 9 with ModuleManager

use of org.terasology.engine.module.ModuleManager in project Terasology by MovingBlocks.

the class ApiScraper method main.

/**
 * @param args (ignored)
 * @throws Exception if the module environment cannot be loaded
 */
public static void main(String[] args) throws Exception {
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ModuleEnvironment environment = moduleManager.getEnvironment();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    SortedSetMultimap<String, String> sortedApi = Multimaps.newSortedSetMultimap(new HashMap<>(), TreeSet::new);
    for (Class<?> apiClass : environment.getTypesAnnotatedWith(API.class)) {
        // System.out.println("Processing: " + apiClass);
        boolean isPackage = apiClass.isSynthetic();
        URL location;
        String category;
        String apiPackage = "";
        if (isPackage) {
            apiPackage = apiClass.getPackage().getName();
            location = classLoader.getResource(apiPackage.replace('.', '/'));
        } else {
            location = apiClass.getResource('/' + apiClass.getName().replace('.', '/') + ".class");
        }
        if (location == null) {
            System.out.println("Failed to get a class/package location, skipping " + apiClass);
            continue;
        }
        switch(location.getProtocol()) {
            case "jar":
                // Find out what jar it came from and consider that the category
                String categoryFragment = location.getPath();
                // System.out.println("category fragment as path: " + categoryFragment);
                int bang = categoryFragment.lastIndexOf("!");
                int hyphen = categoryFragment.lastIndexOf("-", bang);
                int slash = categoryFragment.lastIndexOf("/", hyphen);
                category = categoryFragment.substring(slash + 1, hyphen);
                if (isPackage) {
                    // System.out.println("Jar-based Package: " + apiPackage + ", came from " + location);
                    sortedApi.put(category, apiPackage + " (PACKAGE)");
                } else {
                    // System.out.println("Jar-based Class: " + apiClass + ", came from " + location);
                    sortedApi.put(category, apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)"));
                }
                break;
            case "file":
                // If file based we know it is local so organize it like that
                category = "terasology engine";
                if (isPackage) {
                    // System.out.println("Local Package: " + apiPackage + ", came from " + location);
                    sortedApi.put(category, apiPackage + " (PACKAGE)");
                } else {
                    // System.out.println("Local Class: " + apiClass + ", came from " + location);
                    sortedApi.put(category, apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)"));
                }
                break;
            default:
                System.out.println("Unknown protocol for: " + apiClass + ", came from " + location);
        }
    }
    sortedApi.putAll("external", ExternalApiWhitelist.CLASSES.stream().map(clazz -> clazz.getName() + " (CLASS)").collect(Collectors.toSet()));
    sortedApi.putAll("external", ExternalApiWhitelist.PACKAGES.stream().map(packagee -> packagee + " (PACKAGE)").collect(Collectors.toSet()));
    System.out.println("# Modding API:\n");
    for (String key : sortedApi.keySet()) {
        System.out.println("## " + key + "\n");
        for (String value : sortedApi.get(key)) {
            System.out.println("* " + value);
        }
        System.out.println("");
    }
}
Also used : ModuleEnvironment(org.terasology.module.ModuleEnvironment) TreeSet(java.util.TreeSet) ModuleManager(org.terasology.engine.module.ModuleManager) URL(java.net.URL)

Example 10 with ModuleManager

use of org.terasology.engine.module.ModuleManager in project Terasology by MovingBlocks.

the class BindingScraper method main.

/**
 * @param args (ignored)
 * @throws Exception if the module environment cannot be loaded
 */
public static void main(String[] args) throws Exception {
    ModuleManager moduleManager = ModuleManagerFactory.create();
    // Holds normal input mappings where there is only one key
    Multimap<InputCategory, String> categories = ArrayListMultimap.create();
    Multimap<String, Input> keys = ArrayListMultimap.create();
    Map<String, String> desc = new HashMap<>();
    for (Class<?> holdingType : moduleManager.getEnvironment().getTypesAnnotatedWith(InputCategory.class)) {
        InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
        categories.put(inputCategory, null);
        for (String button : inputCategory.ordering()) {
            categories.put(inputCategory, button);
        }
    }
    for (Class<?> buttonEvent : moduleManager.getEnvironment().getTypesAnnotatedWith(RegisterBindButton.class)) {
        DefaultBinding defBinding = buttonEvent.getAnnotation(DefaultBinding.class);
        RegisterBindButton info = buttonEvent.getAnnotation(RegisterBindButton.class);
        String cat = info.category();
        String id = "engine:" + info.id();
        desc.put(id, info.description());
        if (cat.isEmpty()) {
            InputCategory inputCategory = findEntry(categories, id);
            if (inputCategory == null) {
                System.out.println("Invalid category for: " + info.id());
            }
        } else {
            InputCategory inputCategory = findCategory(categories, cat);
            if (inputCategory != null) {
                categories.put(inputCategory, id);
            } else {
                System.out.println("Invalid category for: " + info.id());
            }
        }
        if (defBinding != null) {
            // This handles bindings with just one key
            Input input = defBinding.type().getInput(defBinding.id());
            keys.put(id, input);
        } else {
            // See if there is a multi-mapping for this button
            DefaultBindings multiBinding = buttonEvent.getAnnotation(DefaultBindings.class);
            // Annotation math magic. We're expecting a DefaultBindings containing one DefaultBinding pair
            if (multiBinding != null && multiBinding.value().length == 2) {
                DefaultBinding[] bindings = multiBinding.value();
                Input primary = bindings[0].type().getInput(bindings[0].id());
                Input secondary = bindings[1].type().getInput(bindings[1].id());
                keys.put(id, primary);
                keys.put(id, secondary);
            }
        }
    }
    for (InputCategory row : categories.keySet()) {
        System.out.println("# " + row.displayName());
        categories.get(row).stream().filter(entry -> entry != null).forEach(entry -> System.out.println(desc.get(entry) + ": " + keys.get(entry)));
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) InputCategory(org.terasology.input.InputCategory) ModuleManagerFactory(org.terasology.testUtil.ModuleManagerFactory) DefaultBinding(org.terasology.input.DefaultBinding) RegisterBindButton(org.terasology.input.RegisterBindButton) DefaultBindings(org.terasology.input.DefaultBindings) Map(java.util.Map) Input(org.terasology.input.Input) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) ModuleManager(org.terasology.engine.module.ModuleManager) DefaultBinding(org.terasology.input.DefaultBinding) HashMap(java.util.HashMap) RegisterBindButton(org.terasology.input.RegisterBindButton) ModuleManager(org.terasology.engine.module.ModuleManager) Input(org.terasology.input.Input) InputCategory(org.terasology.input.InputCategory) DefaultBindings(org.terasology.input.DefaultBindings)

Aggregations

ModuleManager (org.terasology.engine.module.ModuleManager)25 ModuleEnvironment (org.terasology.module.ModuleEnvironment)10 Name (org.terasology.naming.Name)8 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)7 Module (org.terasology.module.Module)7 DependencyResolver (org.terasology.module.DependencyResolver)6 ResolutionResult (org.terasology.module.ResolutionResult)6 ContextImpl (org.terasology.context.internal.ContextImpl)5 Prefab (org.terasology.entitySystem.prefab.Prefab)5 PrefabData (org.terasology.entitySystem.prefab.PrefabData)5 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)5 BeforeClass (org.junit.BeforeClass)4 TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)4 Before (org.junit.Before)3 Config (org.terasology.config.Config)3 GameEngine (org.terasology.engine.GameEngine)3 Map (java.util.Map)2 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)2 SimpleUri (org.terasology.engine.SimpleUri)2 EnvironmentSwitchHandler (org.terasology.engine.bootstrap.EnvironmentSwitchHandler)2