use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class ModuleManager method ensureModulesDependOnEngine.
/**
* Ensure all modules declare a dependency on the engine module.
* <p>
* This is to ensure that the set of modules is a graph with a single root.
* We need this to ensure the engine is loaded <em>before</em> other modules
* when things iterate over the module list in dependency order.
* <p>
* See <a href="https://github.com/MovingBlocks/Terasology/issues/1450">#1450</a>.
*/
private void ensureModulesDependOnEngine() {
DependencyInfo engineDep = new DependencyInfo();
engineDep.setId(engineModule.getId());
engineDep.setMinVersion(engineModule.getVersion());
Set<Name> engineModules = Sets.newHashSet(engineModule.getId());
engineModules.addAll(engineModule.getMetadata().getDependencies().stream().map(DependencyInfo::getId).collect(Collectors.toList()));
registry.stream().filter(mod -> !engineModules.contains(mod.getId())).forEach(mod -> mod.getMetadata().getDependencies().add(engineDep));
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class ModuleManager method registerArchiveModule.
/**
* Load and register a new module for this file.
*/
@SuppressWarnings("UnusedReturnValue")
public Module registerArchiveModule(Path path) throws IOException {
Module module = moduleFactory.createArchiveModule(path.toFile());
registry.add(module);
ensureModulesDependOnEngine();
return module;
}
use of org.terasology.gestalt.module.Module 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;
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class ModuleListDownloader method call.
@Override
public ModuleRegistry call() throws IOException {
logger.info("Downloading modules ..");
TableModuleRegistry modules = new TableModuleRegistry();
URL url = new URL("http", serverAddress, "/modules/list/latest");
try (InputStreamReader reader = new InputStreamReader(url.openStream(), TerasologyConstants.CHARSET)) {
logger.info("Parsing content ..");
JsonArray jsonArray = gson.fromJson(reader, JsonArray.class);
for (JsonElement jObject : jsonArray) {
String json = gson.toJson(jObject);
ModuleMetadata meta = metaReader.read(new StringReader(json));
logger.debug("Read module {} - {}", meta.getId(), meta.getVersion());
modules.add(new Module(meta, new EmptyFileSource(), Collections.emptyList(), new Reflections(), (c) -> false));
}
int count = modules.size();
logger.info(String.format("Retrieved %d %s", count, (count == 1) ? "entry" : "entries"));
}
return modules;
}
use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.
the class ServerConnectionHandler method sendModules.
private void sendModules(List<NetData.ModuleRequest> moduleRequestList) {
for (NetData.ModuleRequest request : moduleRequestList) {
NetData.ModuleDataHeader.Builder result = NetData.ModuleDataHeader.newBuilder();
result.setId(request.getModuleId());
Module module = moduleManager.getEnvironment().get(new Name(request.getModuleId()));
if (!(module.getResources() instanceof ArchiveFileSource)) {
// TODO: gestaltv7 restore module downloading for maximum possibles
result.setError("Module not available for download");
} else {
FileReference fileReference = module.getResources().getFiles().iterator().next();
try (InputStream stream = fileReference.open()) {
ByteString byteString = ByteString.readFrom(stream, 1024);
channelHandlerContext.channel().write(NetData.NetMessage.newBuilder().setModuleData(NetData.ModuleData.newBuilder().setModule(byteString)).build());
result.setVersion(module.getVersion().toString());
result.setSize(byteString.size());
channelHandlerContext.channel().write(NetData.NetMessage.newBuilder().setModuleDataHeader(result).build());
} catch (IOException e) {
logger.error("Error sending module", e);
channelHandlerContext.channel().close();
break;
}
}
}
}
Aggregations