Search in sources :

Example 1 with ModuleMetadata

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

the class ClasspathCompromisingModuleFactoryTest method directoryModuleContainsClass.

@Test
public void directoryModuleContainsClass() {
    // This test assumes that the unittest module is under the current working directory (`engine-test/`)
    File engineTestDirectory = new File(System.getProperty("user.dir", "."));
    ModuleMetadata metadata = new ModuleMetadata(new Name("unittest"), new Version("1.0.0"));
    Module module = factory.createDirectoryModule(metadata, engineTestDirectory);
    // and that ExampleClass is inside that directory
    assertTrue(module.getClassPredicate().test(ExampleClass.class));
    // and that this other class (in engine, not engine-test) is outside that directory.
    assertFalse(module.getClassPredicate().test(someClassOutsideTheModule));
// These assumptions could break if things get moved around enough.
}
Also used : ExampleClass(org.terasology.unittest.ExampleClass) Version(org.terasology.gestalt.naming.Version) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) Module(org.terasology.gestalt.module.Module) File(java.io.File) Name(org.terasology.gestalt.naming.Name) Test(org.junit.jupiter.api.Test)

Example 2 with ModuleMetadata

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

Example 3 with ModuleMetadata

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

the class GameDetailsScreen method getModuleDescription.

private String getModuleDescription(final ModuleSelectionInfo moduleSelectionInfo) {
    final StringBuilder sb = new StringBuilder();
    final ModuleMetadata moduleMetadata = moduleSelectionInfo.getMetadata();
    if (moduleMetadata != null) {
        sb.append(translationSystem.translate("${engine:menu#game-details-game-title} ")).append(moduleMetadata.getDisplayName()).append('\n').append('\n');
        if (moduleSelectionInfo.isLatestVersion()) {
            sb.append(translationSystem.translate("${engine:menu#game-details-invalid-module-version-warning}")).append('\n').append('\n');
        }
        if (moduleMetadata.getVersion() != null) {
            sb.append(translationSystem.translate("${engine:menu#game-details-version}")).append(" ").append(moduleMetadata.getVersion().toString()).append('\n').append('\n');
        }
        String moduleDescription = moduleMetadata.getDescription().toString();
        if (StringUtils.isBlank(moduleDescription)) {
            moduleDescription = translationSystem.translate("${engine:menu#game-details-no-description}");
        }
        sb.append(translationSystem.translate("${engine:menu#game-details-description}")).append(moduleDescription).append('\n').append('\n');
        StringBuilder dependenciesNames;
        final List<DependencyInfo> dependencies = moduleMetadata.getDependencies();
        if (dependencies != null && !dependencies.isEmpty()) {
            dependenciesNames = new StringBuilder(translationSystem.translate("${engine:menu#module-dependencies-exist}") + ":" + '\n');
            for (DependencyInfo dependency : dependencies) {
                dependenciesNames.append("   ").append(dependency.getId().toString()).append('\n');
            }
        } else {
            dependenciesNames = new StringBuilder(translationSystem.translate("${engine:menu#module-dependencies-empty}") + ".");
        }
        return sb.append(dependenciesNames).toString();
    }
    if (moduleSelectionInfo.isUnavailableVersion()) {
        return sb.append(translationSystem.translate("${engine:menu#game-details-invalid-module-error}")).append("\n").append('\n').append(translationSystem.translate("${engine:menu#game-details-version}")).append(" ").append(moduleSelectionInfo.getUnavailableModuleVersion()).toString();
    }
    return translationSystem.translate("${engine:menu#game-details-invalid-module-error}");
}
Also used : ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo)

Example 4 with ModuleMetadata

use of org.terasology.gestalt.module.ModuleMetadata 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 5 with ModuleMetadata

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

Aggregations

ModuleMetadata (org.terasology.gestalt.module.ModuleMetadata)7 Module (org.terasology.gestalt.module.Module)6 Name (org.terasology.gestalt.naming.Name)4 Reflections (org.reflections.Reflections)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 TerasologyConstants (org.terasology.engine.core.TerasologyConstants)2 EmptyFileSource (org.terasology.gestalt.module.resources.EmptyFileSource)2 Version (org.terasology.gestalt.naming.Version)2 TargetLengthBasedClassNameAbbreviator (ch.qos.logback.classic.pattern.TargetLengthBasedClassNameAbbreviator)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1