Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/gradle/de.undercouch.download-…
Browse files Browse the repository at this point in the history
…5.4.0
  • Loading branch information
Sheikah45 committed Mar 25, 2023
2 parents 1ddf982 + 769458a commit f0f26a7
Show file tree
Hide file tree
Showing 24 changed files with 163 additions and 173 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.faforever.client.config;

import com.faforever.client.mod.ModService;
import com.faforever.client.patch.GameBinariesUpdateTask;
import com.faforever.client.patch.GameUpdater;
import com.faforever.client.patch.GameUpdaterImpl;
import com.faforever.client.patch.SimpleHttpFeaturedModUpdater;
import com.faforever.client.preferences.DataPrefs;
import com.faforever.client.preferences.ForgedAlliancePrefs;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.task.TaskService;
import lombok.AllArgsConstructor;
import org.springframework.context.ApplicationContext;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -18,16 +18,15 @@
public class FeaturedModUpdaterConfig {

private final ModService modService;
private final ApplicationContext applicationContext;
private final ObjectFactory<GameBinariesUpdateTask> gameBinariesUpdateTaskFactory;
private final TaskService taskService;
private final SimpleHttpFeaturedModUpdater httpFeaturedModUpdater;
private final PreferencesService preferencesService;
private final DataPrefs dataPrefs;
private final ForgedAlliancePrefs forgedAlliancePrefs;

@Bean
GameUpdater gameUpdater() {
return new GameUpdaterImpl(modService, applicationContext, taskService, preferencesService, dataPrefs, forgedAlliancePrefs)
return new GameUpdaterImpl(modService, taskService, dataPrefs, forgedAlliancePrefs, gameBinariesUpdateTaskFactory)
.addFeaturedModUpdater(httpFeaturedModUpdater);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -65,13 +65,13 @@ public class IceAdapterImpl implements IceAdapter, InitializingBean, DisposableB
private static final Logger advancedLogger = LoggerFactory.getLogger("faf-ice-adapter-advanced");

private final OperatingSystem operatingSystem;
private final ApplicationContext applicationContext;
private final PlayerService playerService;
private final EventBus eventBus;
private final FafServerAccessor fafServerAccessor;
private final IceServerMapper iceServerMapper;
private final Preferences preferences;
private final ForgedAlliancePrefs forgedAlliancePrefs;
private final ObjectFactory<IceAdapterCallbacks> iceAdapterCallbacksFactory;

private final IceAdapterApi iceAdapterProxy = newIceAdapterProxy();
private GameType gameType;
Expand Down Expand Up @@ -134,7 +134,7 @@ public CompletableFuture<Integer> start(int gameId) {
throw new CompletionException(e);
}

IceAdapterCallbacks iceAdapterCallbacks = applicationContext.getBean(IceAdapterCallbacks.class);
IceAdapterCallbacks iceAdapterCallbacks = iceAdapterCallbacksFactory.getObject();
initializeIceAdapterConnection(adapterPort, iceAdapterCallbacks);

return gpgPort;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/faforever/client/fx/WebViewConfigurer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.faforever.client.fx;

import com.faforever.client.config.ClientProperties;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.theme.UiService;
import javafx.concurrent.Worker.State;
import javafx.event.EventHandler;
Expand All @@ -12,8 +11,8 @@
import javafx.scene.web.WebView;
import lombok.RequiredArgsConstructor;
import netscape.javascript.JSObject;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
Expand All @@ -32,8 +31,8 @@ public class WebViewConfigurer {
private static final double ZOOM_STEP = 0.2d;

private final UiService uiService;
private final ApplicationContext applicationContext;
private final ClientProperties clientProperties;
private final ObjectFactory<BrowserCallback> browserCallbackFactory;

public void configureWebView(WebView webView) {
WebEngine engine = webView.getEngine();
Expand All @@ -50,7 +49,7 @@ public void configureWebView(WebView webView) {
}
});

BrowserCallback browserCallback = applicationContext.getBean(BrowserCallback.class);
BrowserCallback browserCallback = browserCallbackFactory.getObject();
EventHandler<MouseEvent> moveHandler = event -> {
browserCallback.setLastMouseX(event.getScreenX());
browserCallback.setLastMouseY(event.getScreenY());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/faforever/client/game/VaultPathHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import javafx.scene.control.CheckBox;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.stereotype.Component;

import java.nio.file.Path;
Expand All @@ -29,11 +29,11 @@ public class VaultPathHandler {

private final PlatformService platformService;
private final TaskService taskService;
private final ApplicationContext applicationContext;
private final PreferencesService preferencesService;
private final NotificationService notificationService;
private final I18n i18n;
private final ForgedAlliancePrefs forgedAlliancePrefs;
private final ObjectFactory<MoveDirectoryTask> moveDirectoryTaskFactory;

public void verifyVaultPathAndShowWarning() {
if (preferencesService.isVaultBasePathInvalidForAscii()) {
Expand Down Expand Up @@ -61,7 +61,7 @@ private void showWarning() {
public void onVaultPathUpdated(Path newPath) {
log.info("User changed vault directory to: `{}`", newPath);

MoveDirectoryTask moveDirectoryTask = applicationContext.getBean(MoveDirectoryTask.class);
MoveDirectoryTask moveDirectoryTask = moveDirectoryTaskFactory.getObject();
moveDirectoryTask.setOldDirectory(forgedAlliancePrefs.getVaultBaseDirectory());
moveDirectoryTask.setNewDirectory(newPath);
moveDirectoryTask.setAfterCopyAction(() -> forgedAlliancePrefs.setVaultBaseDirectory(newPath));
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/faforever/client/map/MapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
import org.luaj.vm2.LuaValue;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -113,7 +113,6 @@ public class MapService implements InitializingBean, DisposableBean {

private final NotificationService notificationService;
private final TaskService taskService;
private final ApplicationContext applicationContext;
private final FafApiAccessor fafApiAccessor;
private final AssetService assetService;
private final I18n i18n;
Expand All @@ -126,6 +125,9 @@ public class MapService implements InitializingBean, DisposableBean {
private final ClientProperties clientProperties;
private final ForgedAlliancePrefs forgedAlliancePrefs;
private final Preferences preferences;
private final ObjectFactory<MapUploadTask> mapUploadTaskFactory;
private final ObjectFactory<DownloadMapTask> downloadMapTaskFactory;
private final ObjectFactory<UninstallMapTask> uninstallMapTaskFactory;

private final ObservableMap<String, MapVersionBean> mapsByFolderName = FXCollections.observableHashMap();
@Getter
Expand Down Expand Up @@ -420,7 +422,7 @@ public CompletableFuture<Void> uninstallMap(MapVersionBean mapVersion) {
if (isOfficialMap(mapVersion.getFolderName())) {
throw new IllegalArgumentException("Attempt to uninstall an official map");
}
UninstallMapTask task = applicationContext.getBean(UninstallMapTask.class);
UninstallMapTask task = uninstallMapTaskFactory.getObject();
task.setMap(mapVersion);
return taskService.submitTask(task).getFuture();
}
Expand Down Expand Up @@ -451,7 +453,7 @@ public Path getPathForMapCaseInsensitive(String approxName) {
}

public CompletableTask<Void> uploadMap(Path mapPath, boolean ranked) {
MapUploadTask mapUploadTask = applicationContext.getBean(MapUploadTask.class);
MapUploadTask mapUploadTask = mapUploadTaskFactory.getObject();
mapUploadTask.setMapPath(mapPath);
mapUploadTask.setRanked(ranked);

Expand Down Expand Up @@ -507,7 +509,7 @@ private CompletableFuture<Void> downloadAndInstallMap(String folderName, URL dow
return CompletableFuture.completedFuture(null);
}

DownloadMapTask task = applicationContext.getBean(DownloadMapTask.class);
DownloadMapTask task = downloadMapTaskFactory.getObject();
task.setMapUrl(downloadUrl);
task.setFolderName(folderName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -50,22 +50,29 @@ public class MapGeneratorService implements DisposableBean {
private static final Pattern VERSION_PATTERN = Pattern.compile("\\d\\d?\\d?\\.\\d\\d?\\d?\\.\\d\\d?\\d?");
protected static final Pattern GENERATED_MAP_PATTERN = Pattern.compile("neroxis_map_generator_(" + VERSION_PATTERN + ")_(.*)");

private final ApplicationContext applicationContext;
private final TaskService taskService;
private final ClientProperties clientProperties;
private final ForgedAlliancePrefs forgedAlliancePrefs;
private final DataPrefs dataPrefs;
private final WebClient webClient;
private final ObjectFactory<GenerateMapTask> generateMapTaskFactory;
private final ObjectFactory<DownloadMapGeneratorTask> downloadMapGeneratorTaskFactory;
private final ObjectFactory<GeneratorOptionsTask> generatorOptionsTaskFactory;

private ComparableVersion defaultGeneratorVersion;

public MapGeneratorService(ApplicationContext applicationContext, TaskService taskService, ClientProperties clientProperties, ForgedAlliancePrefs forgedAlliancePrefs, DataPrefs dataPrefs, Builder webClientBuilder) {
this.applicationContext = applicationContext;
public MapGeneratorService(TaskService taskService, ClientProperties clientProperties, ForgedAlliancePrefs forgedAlliancePrefs, DataPrefs dataPrefs, Builder webClientBuilder,
ObjectFactory<GenerateMapTask> generateMapTaskFactory,
ObjectFactory<DownloadMapGeneratorTask> downloadMapGeneratorTaskFactory,
ObjectFactory<GeneratorOptionsTask> generatorOptionsTaskFactory) {
this.taskService = taskService;
this.clientProperties = clientProperties;
this.forgedAlliancePrefs = forgedAlliancePrefs;
this.dataPrefs = dataPrefs;
webClient = webClientBuilder.build();
this.webClient = webClientBuilder.build();
this.generateMapTaskFactory = generateMapTaskFactory;
this.downloadMapGeneratorTaskFactory = downloadMapGeneratorTaskFactory;
this.generatorOptionsTaskFactory = generatorOptionsTaskFactory;
}

@Override
Expand Down Expand Up @@ -128,7 +135,7 @@ public CompletableFuture<String> generateMap(String mapName) {

CompletableFuture<Void> downloadGeneratorFuture = downloadGeneratorIfNecessary(version);

GenerateMapTask generateMapTask = applicationContext.getBean(GenerateMapTask.class);
GenerateMapTask generateMapTask = generateMapTaskFactory.getObject();
generateMapTask.setVersion(version);
generateMapTask.setSeed(seed);
generateMapTask.setMapName(mapName);
Expand All @@ -142,7 +149,7 @@ public CompletableFuture<String> generateMap(GeneratorOptions generatorOptions)

CompletableFuture<Void> downloadGeneratorFuture = downloadGeneratorIfNecessary(defaultGeneratorVersion);

GenerateMapTask generateMapTask = applicationContext.getBean(GenerateMapTask.class);
GenerateMapTask generateMapTask = generateMapTaskFactory.getObject();
generateMapTask.setVersion(defaultGeneratorVersion);
generateMapTask.setGeneratorExecutableFile(generatorExecutablePath);
generateMapTask.setGeneratorOptions(generatorOptions);
Expand Down Expand Up @@ -170,7 +177,7 @@ public CompletableFuture<Void> downloadGeneratorIfNecessary(ComparableVersion ve
}

log.info("Downloading MapGenerator version: {}", version);
DownloadMapGeneratorTask downloadMapGeneratorTask = applicationContext.getBean(DownloadMapGeneratorTask.class);
DownloadMapGeneratorTask downloadMapGeneratorTask = downloadMapGeneratorTaskFactory.getObject();
downloadMapGeneratorTask.setVersion(version);
return taskService.submitTask(downloadMapGeneratorTask).getFuture();
} else {
Expand All @@ -187,7 +194,7 @@ public CompletableFuture<Void> getNewestGenerator() {

public CompletableFuture<List<String>> getGeneratorStyles() {
Assert.checkNullIllegalState(defaultGeneratorVersion, "Generator version not set");
GeneratorOptionsTask generatorOptionsTask = applicationContext.getBean(GeneratorOptionsTask.class);
GeneratorOptionsTask generatorOptionsTask = generatorOptionsTaskFactory.getObject();
Path generatorExecutablePath = getGeneratorExecutablePath(defaultGeneratorVersion);
generatorOptionsTask.setVersion(defaultGeneratorVersion);
generatorOptionsTask.setQuery("--styles");
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/faforever/client/mod/ModService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -105,7 +105,6 @@ public class ModService implements InitializingBean, DisposableBean {

private final FafApiAccessor fafApiAccessor;
private final TaskService taskService;
private final ApplicationContext applicationContext;
private final NotificationService notificationService;
private final I18n i18n;
private final PlatformService platformService;
Expand All @@ -115,6 +114,9 @@ public class ModService implements InitializingBean, DisposableBean {
private final ModMapper modMapper;
private final ForgedAlliancePrefs forgedAlliancePrefs;
private final Preferences preferences;
private final ObjectFactory<ModUploadTask> modUploadTaskFactory;
private final ObjectFactory<DownloadModTask> downloadModTaskFactory;
private final ObjectFactory<UninstallModTask> uninstallModTaskFactory;

private final ModReader modReader = new ModReader();

Expand Down Expand Up @@ -234,7 +236,7 @@ public CompletableFuture<Void> downloadAndInstallMod(URL url) {

public CompletableFuture<Void> downloadAndInstallMod(URL url, @Nullable DoubleProperty progressProperty,
@Nullable StringProperty titleProperty) {
DownloadModTask task = applicationContext.getBean(DownloadModTask.class);
DownloadModTask task = downloadModTaskFactory.getObject();
task.setUrl(url);
if (progressProperty != null) {
progressProperty.bind(task.progressProperty());
Expand Down Expand Up @@ -273,7 +275,7 @@ public boolean isInstalled(String uid) {
}

public CompletableFuture<Void> uninstallMod(ModVersionBean modVersion) {
UninstallModTask task = applicationContext.getBean(UninstallModTask.class);
UninstallModTask task = uninstallModTaskFactory.getObject();
task.setMod(modVersion);
return taskService.submitTask(task).getFuture();
}
Expand Down Expand Up @@ -306,7 +308,7 @@ public ModVersionBean extractModInfo(InputStream inputStream, Path basePath) {
}

public CompletableTask<Void> uploadMod(Path modPath) {
ModUploadTask modUploadTask = applicationContext.getBean(ModUploadTask.class);
ModUploadTask modUploadTask = modUploadTaskFactory.getObject();
modUploadTask.setModPath(modPath);

return taskService.submitTask(modUploadTask);
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/faforever/client/patch/GameUpdaterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import com.faforever.client.mod.ModService;
import com.faforever.client.preferences.DataPrefs;
import com.faforever.client.preferences.ForgedAlliancePrefs;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.client.task.TaskService;
import com.faforever.client.update.Version;
import com.faforever.client.util.ConcurrentUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.jetbrains.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.beans.factory.ObjectFactory;

import java.io.IOException;
import java.nio.file.AccessDeniedException;
Expand Down Expand Up @@ -47,11 +46,10 @@ public class GameUpdaterImpl implements GameUpdater {

private final List<FeaturedModUpdater> featuredModUpdaters = new ArrayList<>();
private final ModService modService;
private final ApplicationContext applicationContext;
private final TaskService taskService;
private final PreferencesService preferencesService;
private final DataPrefs dataPrefs;
private final ForgedAlliancePrefs forgedAlliancePrefs;
private final ObjectFactory<GameBinariesUpdateTask> gameBinariesUpdateTaskFactory;

private ComparableVersion gameVersion;
private String gameType;
Expand Down Expand Up @@ -155,7 +153,7 @@ private CompletableFuture<PatchResult> updateFeaturedMod(FeaturedModBean feature
}

private CompletableFuture<Void> updateGameBinaries(ComparableVersion version) {
GameBinariesUpdateTask binariesUpdateTask = applicationContext.getBean(GameBinariesUpdateTaskImpl.class);
GameBinariesUpdateTask binariesUpdateTask = gameBinariesUpdateTaskFactory.getObject();
binariesUpdateTask.setVersion(version);
gameVersion = version;
return taskService.submitTask(binariesUpdateTask).getFuture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.faforever.client.task.TaskService;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.Nullable;
import org.springframework.context.ApplicationContext;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

Expand All @@ -17,11 +17,11 @@
public class SimpleHttpFeaturedModUpdater implements FeaturedModUpdater {

private final TaskService taskService;
private final ApplicationContext applicationContext;
private final ObjectFactory<SimpleHttpFeaturedModUpdaterTask> simpleHttpFeaturedModUpdaterTaskFactory;

@Override
public CompletableFuture<PatchResult> updateMod(FeaturedModBean featuredMod, @Nullable Integer version) {
SimpleHttpFeaturedModUpdaterTask task = applicationContext.getBean(SimpleHttpFeaturedModUpdaterTask.class);
SimpleHttpFeaturedModUpdaterTask task = simpleHttpFeaturedModUpdaterTaskFactory.getObject();
task.setVersion(version);
task.setFeaturedMod(featuredMod);

Expand Down

0 comments on commit f0f26a7

Please sign in to comment.