Search in sources :

Example 16 with ModuleManager

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

the class CompleteApiScraper method getApi.

/**
 * @return Project's Packages, Interfaces, Classes and Methods
 * @throws Exception if the module environment cannot be loaded
 */
static StringBuffer getApi() throws Exception {
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ModuleEnvironment environment = moduleManager.getEnvironment();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    Multimap<String, String> api = Multimaps.newMultimap(new HashMap<String, Collection<String>>(), ArrayList::new);
    for (Class<?> apiClass : environment.getTypesAnnotatedWith(API.class)) {
        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) {
            logger.error("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();
                int bang = categoryFragment.lastIndexOf("!");
                int hyphen = categoryFragment.lastIndexOf("-", bang);
                int slash = categoryFragment.lastIndexOf("/", hyphen);
                category = categoryFragment.substring(slash + 1, hyphen);
                if (isPackage) {
                    api.put(category, apiPackage + " (PACKAGE)");
                } else {
                    addToApi(category, apiClass, api);
                }
                break;
            case "file":
                // If file based we know it is local so organize it like that
                category = TERASOLOGY_API_CLASS_CATEGORY;
                if (isPackage) {
                    api.put(category, apiPackage + " (PACKAGE)");
                } else {
                    addToApi(category, apiClass, api);
                }
                break;
            default:
                logger.error("Unknown protocol for: " + apiClass + ", came from " + location);
        }
    }
    api.putAll(EXTERNAL, ExternalApiWhitelist.CLASSES.stream().map(clazz -> clazz.getName() + " (CLASS)").collect(Collectors.toSet()));
    api.putAll(EXTERNAL, ExternalApiWhitelist.PACKAGES.stream().map(packagee -> packagee + " (PACKAGE)").collect(Collectors.toSet()));
    // Puts the information in the StringBuffer
    StringBuffer stringApi = new StringBuffer();
    stringApi.append("# Modding API:\n");
    for (String key : api.keySet()) {
        stringApi.append("## ");
        stringApi.append(key);
        stringApi.append("\n");
        for (String value : api.get(key)) {
            stringApi.append("* ");
            stringApi.append(value);
            stringApi.append("\n");
        }
        stringApi.append("\n");
    }
    return stringApi;
}
Also used : ArrayList(java.util.ArrayList) ModuleManager(org.terasology.engine.core.module.ModuleManager) URL(java.net.URL) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Collection(java.util.Collection)

Example 17 with ModuleManager

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

the class PojoPrefabManagerTest method setup.

@BeforeEach
public void setup() throws Exception {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
    assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    prefabManager = new PojoPrefabManager(context);
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) ModuleAwareAssetTypeManagerImpl(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with ModuleManager

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

the class PrefabTest method setup.

@BeforeEach
public void setup() throws Exception {
    ContextImpl context = new ContextImpl();
    context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
    CoreRegistry.setContext(context);
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
    AssetType<Prefab, PrefabData> prefabDataAssetType = assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    ComponentLibrary componentLibrary = context.get(ComponentLibrary.class);
    TypeHandlerLibrary typeHandlerLibrary = context.get(TypeHandlerLibrary.class);
    PrefabFormat prefabFormat = new PrefabFormat(componentLibrary, typeHandlerLibrary);
    assetTypeManager.getAssetFileDataProducer(prefabDataAssetType).addAssetFormat(prefabFormat);
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    prefabManager = new PojoPrefabManager(context);
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) PojoPrefabManager(org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager) PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) NetworkSystem(org.terasology.engine.network.NetworkSystem) PrefabFormat(org.terasology.engine.entitySystem.prefab.internal.PrefabFormat) ModuleAwareAssetTypeManagerImpl(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with ModuleManager

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

the class PojoEntityManagerTest method setupClass.

@BeforeAll
public static void setupClass() throws Exception {
    context = new ContextImpl();
    ModuleManager moduleManager = ModuleManagerFactory.create();
    context.put(ModuleManager.class, moduleManager);
    ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
    assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
    CoreRegistry.setContext(context);
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) ModuleAwareAssetTypeManagerImpl(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ModuleManager(org.terasology.engine.core.module.ModuleManager) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 20 with ModuleManager

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

the class BindsSubsystemTest method setUpMockModuleEnvironment.

private void setUpMockModuleEnvironment() {
    ModuleManager moduleManager = mock(ModuleManager.class);
    ModuleRegistry moduleRegistry = new TableModuleRegistry();
    Module module = mock(Module.class);
    when(module.getId()).thenReturn(new Name(TEST_MODULE));
    when(module.getVersion()).thenReturn(new Version(0, 0, 1, true));
    when(module.getMetadata()).thenReturn(new ModuleMetadata());
    moduleRegistry.add(module);
    when(moduleManager.getRegistry()).thenReturn(moduleRegistry);
    ModuleEnvironment environment = mock(ModuleEnvironment.class);
    when(moduleManager.loadEnvironment(any(), anyBoolean())).thenReturn(environment);
    when(moduleManager.getEnvironment()).thenReturn(environment);
    registerBindButtonClasses = new ArrayList<>();
    when(environment.getTypesAnnotatedWith(eq(RegisterBindButton.class))).thenReturn(registerBindButtonClasses);
    when(environment.getTypesAnnotatedWith(eq(RegisterBindButton.class), any())).thenReturn(registerBindButtonClasses);
    registerRealBindAxisClasses = new ArrayList<>();
    when(environment.getTypesAnnotatedWith(eq(RegisterBindAxis.class))).thenReturn(registerRealBindAxisClasses);
    when(environment.getTypesAnnotatedWith(eq(RegisterBindAxis.class), any())).thenReturn(registerRealBindAxisClasses);
    when(environment.getModuleProviding(any())).thenReturn(new Name(TEST_MODULE));
    context.put(ModuleManager.class, moduleManager);
}
Also used : TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) Version(org.terasology.gestalt.naming.Version) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) RegisterBindAxis(org.terasology.engine.input.RegisterBindAxis) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

Aggregations

ModuleManager (org.terasology.engine.core.module.ModuleManager)35 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)15 Module (org.terasology.gestalt.module.Module)10 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ContextImpl (org.terasology.engine.context.internal.ContextImpl)7 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)7 ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)6 Name (org.terasology.gestalt.naming.Name)6 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)5 ModuleAwareAssetTypeManagerImpl (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl)5 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)5 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)5 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)5 GameEngine (org.terasology.engine.core.GameEngine)4 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)4 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)4 NetworkSystem (org.terasology.engine.network.NetworkSystem)4 TypeRegistry (org.terasology.reflection.TypeRegistry)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3