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