private boolean isOnlineVersionNewer(Module localVersion, Module onlineVersion) { if (onlineVersion == null) { return false; } if (localVersion == null) { return true; } int versionCompare = onlineVersion.getVersion().compareTo(localVersion.getVersion()); if (versionCompare > 0) { return true; } else if (versionCompare == 0) { if (isSourceModule(localVersion)) { // In case the version of the local source module is the same as remote, don't download it again. return false; } else { /* * Multiple binaries get released as the same snapshot version, A version name match thus does not * guarantee that we have the newest version already if it is a snapshot version. * * Having the user redownload the same binary again is not ideal, but it is better then having the user * being stuck on an outdated snapshot binary. */ return onlineVersion.getVersion().isSnapshot(); } } else { return false; } } }
@Override public Map<String, ?> createTelemetryFieldToValue() { updateModules(); telemetryFieldToValue = new HashMap(); for (Module module : modules) { telemetryFieldToValue.put(module.getId().toString(), module.getVersion().toString()); } return telemetryFieldToValue; }
@Override public List<NameVersion> getModuleList() { List<NameVersion> result = Lists.newArrayList(); for (NetData.ModuleInfo moduleInfo : info.getModuleList()) { if (!moduleInfo.hasModuleId() || !moduleInfo.hasModuleVersion()) { logger.error("Received incomplete module info"); } else { Name id = new Name(moduleInfo.getModuleId()); Version version = new Version(moduleInfo.getModuleVersion()); result.add(new NameVersion(id, version)); } } return result; }
engineDep.setId(engineModule.getId()); engineDep.setMinVersion(engineModule.getVersion()); engineDep.setMaxVersion(engineModule.getVersion().getNextPatchVersion());
private void setUpMockModuleEnvironment() { ModuleManager moduleManager = mock(ModuleManager.class); ModuleRegistry moduleRegistry = new TableModuleRegistry(); Module module = mock(Module.class); when(module.isCodeModule()).thenReturn(true); 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); }
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 BaseModule(Collections.emptyList(), metadata) { @Override public ImmutableList<URL> getClasspaths() { return null; } @Override public boolean isOnClasspath() { return false; } @Override public boolean isCodeModule() { return false; } }; }
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; } }
/** * Gets the server information and passes it to the client, while also checking if all required modules have been downloaded. * @param channelHandlerContext * @param message Passes the server information message to the function. */ private void receivedServerInfo(ChannelHandlerContext channelHandlerContext, NetData.ServerInfoMessage message) { logger.info("Received server info"); ((EngineTime) CoreRegistry.get(Time.class)).setGameTime(message.getTime()); this.server = new ServerImpl(networkSystem, channelHandlerContext.getChannel()); server.setServerInfo(message); // Request missing modules for (NetData.ModuleInfo info : message.getModuleList()) { if (null == moduleManager.getRegistry().getModule(new Name(info.getModuleId()), new Version(info.getModuleVersion()))) { missingModules.add(info.getModuleId().toLowerCase(Locale.ENGLISH)); } } if (missingModules.isEmpty()) { joinStatus.setCurrentActivity("Finalizing join"); sendJoin(channelHandlerContext); } else { joinStatus.setCurrentActivity("Requesting missing modules"); NetData.NetMessage.Builder builder = NetData.NetMessage.newBuilder(); for (String module : missingModules) { builder.addModuleRequest(NetData.ModuleRequest.newBuilder().setModuleId(module)); } channelHandlerContext.getChannel().write(builder.build()); } }
@Override public String get() { ModuleSelectionInfo sel = moduleList.getSelection(); if (sel == null) { return ""; } return (sel.getOnlineVersion() != null) ? sel.getOnlineVersion().getVersion().toString() : "none"; } });
sb.append(translationSystem.translate("${engine:menu#game-details-version}")) .append(" ") .append(moduleMetadata.getVersion().toString()) .append('\n') .append('\n');
@Override public String get() { ModuleSelectionInfo sel = moduleList.getSelection(); if (sel == null) { return ""; } return sel.isPresent() ? sel.getMetadata().getVersion().toString() : translationSystem.translate("${engine:menu#module-version-installed-none}"); } });
private void loadGameModules() { final List<ModuleSelectionInfo> sortedGameModules = gameInfo.getManifest().getModules().stream() .sorted(Comparator.comparing(NameVersion::getName)) .map(nameVersion -> { Module module = moduleManager.getRegistry().getModule(nameVersion.getName(), nameVersion.getVersion()); if (module != null) { return ModuleSelectionInfo.strictVersion(module); } else { logger.warn("Can't find module in your classpath - {}:{}", nameVersion.getName(), nameVersion.getVersion()); module = moduleManager.getRegistry().getLatestModuleVersion(nameVersion.getName()); if (module != null) { logger.debug("Get the latest available version of module {} in your classpath", nameVersion.getName()); errors.add(String.format("Can't find module %s:%s in your classpath; loaded description for the latest available version.", nameVersion.getName(), nameVersion.getVersion())); return ModuleSelectionInfo.latestVersion(module); } logger.error("Can't find any versions of module {} in your classpath!", nameVersion.getName()); errors.add(String.format("Can't find any versions of module %s in your classpath!", nameVersion.getName())); return ModuleSelectionInfo.unavailableVersion(nameVersion.getName().toString(), nameVersion.getVersion().toString()); } }) .filter(Objects::nonNull) .collect(Collectors.toList()); gameModules.setList(sortedGameModules); gameModules.select(0); }
Path location = module.getLocations().get(0); try { result.setVersion(module.getVersion().toString()); result.setSize(Files.size(location)); channelHandlerContext.getChannel().write(NetData.NetMessage.newBuilder().setModuleDataHeader(result).build());
serverInfoMessageBuilder.addModule(NetData.ModuleInfo.newBuilder() .setModuleId(module.getId().toString()) .setModuleVersion(module.getVersion().toString()).build());