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.
}
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);
}
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}");
}
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);
}
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;
}
Aggregations