Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DI-1 #687

Closed
wants to merge 32 commits into from
Closed

DI-1 #687

Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
418abad
Migrate BibEntryTypesManager
calixtus May 22, 2024
a72a5ab
Fix deprecation
calixtus May 23, 2024
fcc1b86
Migrate UndoManager
calixtus May 23, 2024
da9b991
Remove BibEntryTypesManager from Globals
calixtus May 23, 2024
f174227
Migrate PreferencesService
calixtus May 23, 2024
e358d17
Migrate DialogService
calixtus May 23, 2024
7bae500
Migrate ThemeManager
calixtus May 23, 2024
6d34bae
Migrate StateManager
calixtus May 23, 2024
3d58c7f
Migrate TaskExecutor
calixtus May 23, 2024
513d577
Migrate KeyBindingRepository WIP
calixtus May 23, 2024
b1a7a68
Fix StringToList conversion
calixtus May 23, 2024
f11d97c
Migrate KeyBindingRepository
calixtus May 23, 2024
5530353
Fix some tests
calixtus May 23, 2024
37fa15b
Checkstyle
calixtus May 23, 2024
a5674f4
Rewrite
calixtus May 23, 2024
1a572c9
Checkstyle
calixtus May 23, 2024
7ec1dbc
Fix tests
calixtus May 24, 2024
4b5b72e
Migrate ProtectedTermsLoader
calixtus May 24, 2024
7d93569
Refactor Launcher and extract logging initialization
calixtus May 24, 2024
555824c
Migrate JournalAbbreviationsRepository
calixtus May 24, 2024
fd17b7a
Move initialization to initialize
calixtus May 26, 2024
efc6767
Migrate ClipBoardManager
calixtus May 26, 2024
103a718
Migrate RemoteListenerServerManager
calixtus May 26, 2024
8bac78a
Migrate BuildInfo
calixtus May 26, 2024
55a1345
Merge remote-tracking branch 'refs/remotes/upstream/main' into di
calixtus May 27, 2024
9aa8cc4
Fix merge errors
calixtus May 27, 2024
5a085e1
Add some text on DI
koppor May 27, 2024
5d55857
Migrate FileUpdateMonitor and DirectoryMonitor, Remove Globals
calixtus May 27, 2024
7154f80
Remove DefaultInjector
calixtus May 27, 2024
3f0a318
Merge remote-tracking branch 'koppor/di' into di
calixtus May 27, 2024
56bc88a
Fix JavaDoc error
calixtus May 27, 2024
1c72950
Fix JavaDoc comment
calixtus May 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Migrate BibEntryTypesManager
calixtus committed May 22, 2024
commit 418abad06a2406bc54fbf45da57594bb9c6b85ca
7 changes: 4 additions & 3 deletions src/main/java/org/jabref/Launcher.java
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -64,8 +65,8 @@ public static void main(String[] args) {

addLogToDisk();
try {
BibEntryTypesManager entryTypesManager = new BibEntryTypesManager();
Globals.entryTypesManager = entryTypesManager;
Injector.setModelOrService(BibEntryTypesManager.class, new BibEntryTypesManager());
BibEntryTypesManager entryTypesManager = Injector.instantiateModelOrService(BibEntryTypesManager.class);

// Initialize preferences
final JabRefPreferences preferences = JabRefPreferences.getInstance();
@@ -187,7 +188,7 @@ private static void initGlobals(PreferencesService preferences) {
// Read list(s) of journal names and abbreviations
Globals.journalAbbreviationRepository = JournalAbbreviationLoader
.loadRepository(preferences.getJournalAbbreviationPreferences());
Globals.entryTypesManager = preferences.getCustomEntryTypesRepository();
Injector.setModelOrService(BibEntryTypesManager.class, preferences.getCustomEntryTypesRepository());
Globals.protectedTermsLoader = new ProtectedTermsLoader(preferences.getProtectedTermsPreferences());
}

9 changes: 5 additions & 4 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
@@ -59,6 +59,7 @@
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.SearchPreferences;

import com.airhacks.afterburner.injection.Injector;
import com.google.common.base.Throwables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -250,7 +251,7 @@ public void processArguments() {
preferencesService.getXmpPreferences(),
preferencesService.getFilePreferences(),
preferencesService.getLibraryPreferences().getDefaultBibDatabaseMode(),
Globals.entryTypesManager,
Injector.instantiateModelOrService(BibEntryTypesManager.class),
preferencesService.getFieldPreferences(),
Globals.journalAbbreviationRepository,
cli.isWriteXMPtoPdf() || cli.isWriteMetadatatoPdf(),
@@ -486,7 +487,7 @@ private boolean exportMatches(List<ParserResult> loaded) {
// export new database
ExporterFactory exporterFactory = ExporterFactory.create(
preferencesService,
Globals.entryTypesManager);
Injector.instantiateModelOrService(BibEntryTypesManager.class));
Optional<Exporter> exporter = exporterFactory.getExporterByName(formatName);
if (exporter.isEmpty()) {
System.err.println(Localization.lang("Unknown export format %0", formatName));
@@ -661,7 +662,7 @@ private void exportFile(List<ParserResult> loaded, String[] data) {
System.out.println(Localization.lang("Exporting %0", data[0]));
ExporterFactory exporterFactory = ExporterFactory.create(
preferencesService,
Globals.entryTypesManager);
Injector.instantiateModelOrService(BibEntryTypesManager.class));
Optional<Exporter> exporter = exporterFactory.getExporterByName(data[1]);
if (exporter.isEmpty()) {
System.err.println(Localization.lang("Unknown export format %0", data[1]));
@@ -684,7 +685,7 @@ private void exportFile(List<ParserResult> loaded, String[] data) {
private void importPreferences() {
try {
preferencesService.importPreferences(Path.of(cli.getPreferencesImport()));
Globals.entryTypesManager = preferencesService.getCustomEntryTypesRepository();
Injector.setModelOrService(BibEntryTypesManager.class, preferencesService.getCustomEntryTypesRepository());
} catch (JabRefException ex) {
LOGGER.error("Cannot import preferences", ex);
}
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/cli/JabRefCLI.java
Original file line number Diff line number Diff line change
@@ -10,10 +10,12 @@
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
@@ -326,7 +328,7 @@ public static void printUsage(PreferencesService preferencesService) {

ExporterFactory exporterFactory = ExporterFactory.create(
preferencesService,
Globals.entryTypesManager);
Injector.instantiateModelOrService(BibEntryTypesManager.class));
List<Pair<String, String>> exportFormats = exporterFactory
.getExporters().stream()
.map(format -> new Pair<>(format.getName(), format.getId()))
3 changes: 0 additions & 3 deletions src/main/java/org/jabref/gui/DefaultInjector.java
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

@@ -50,8 +49,6 @@ private static Object createDependency(Class<?> clazz) {
return Globals.getClipboardManager();
} else if (clazz == UndoManager.class) {
return Globals.undoManager;
} else if (clazz == BibEntryTypesManager.class) {
return Globals.entryTypesManager;
} else {
try {
return clazz.newInstance();
22 changes: 0 additions & 22 deletions src/main/java/org/jabref/gui/Globals.java
Original file line number Diff line number Diff line change
@@ -2,25 +2,20 @@

import org.jabref.architecture.AllowedToUseAwt;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.remote.CLIMessageHandler;
import org.jabref.gui.telemetry.Telemetry;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.util.DefaultDirectoryMonitor;
import org.jabref.gui.util.DefaultFileUpdateMonitor;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.remote.server.RemoteListenerServerManager;
import org.jabref.logic.util.BuildInfo;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.util.DirectoryMonitor;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

import kong.unirest.Unirest;

/**
* @deprecated try to use {@link StateManager} and {@link org.jabref.preferences.PreferencesService}
*/
@@ -102,18 +97,6 @@ public static DirectoryMonitor getDirectoryMonitor() {
return directoryMonitor;
}

// Background tasks
public static void startBackgroundTasks() {
// TODO Currently deactivated due to incompatibilities in XML
/* if (Globals.prefs.getTelemetryPreferences().shouldCollectTelemetry() && !GraphicsEnvironment.isHeadless()) {
Telemetry.start(prefs.getTelemetryPreferences());
} */
RemotePreferences remotePreferences = prefs.getRemotePreferences();
if (remotePreferences.useRemoteServer()) {
Globals.REMOTE_LISTENER.openAndStart(new CLIMessageHandler(prefs, fileUpdateMonitor, entryTypesManager), remotePreferences.getPort());
}
}

public static void shutdownThreadPools() {
TASK_EXECUTOR.shutdown();
if (fileUpdateMonitor != null) {
@@ -126,9 +109,4 @@ public static void shutdownThreadPools() {

JabRefExecutorService.INSTANCE.shutdownEverything();
}

public static void stopBackgroundTasks() {
Telemetry.shutdown();
Unirest.shutDown();
}
}
33 changes: 30 additions & 3 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
@@ -16,18 +16,23 @@
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.keyboard.TextInputKeyBindings;
import org.jabref.gui.openoffice.OOBibBaseConnect;
import org.jabref.gui.remote.CLIMessageHandler;
import org.jabref.gui.telemetry.Telemetry;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.logic.UiCommand;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.ProxyRegisterer;
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.util.WebViewStore;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.GuiPreferences;
import org.jabref.preferences.JabRefPreferences;

import com.airhacks.afterburner.injection.Injector;
import com.tobiasdiez.easybind.EasyBind;
import kong.unirest.Unirest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -61,7 +66,7 @@ public void start(Stage stage) {
this.mainStage = stage;

FallbackExceptionHandler.installExceptionHandler();
Globals.startBackgroundTasks();
startBackgroundTasks();

WebViewStore.init();

@@ -77,7 +82,7 @@ public void start(Stage stage) {
preferencesService,
Globals.stateManager,
Globals.undoManager,
Globals.entryTypesManager,
Injector.instantiateModelOrService(BibEntryTypesManager.class),
Globals.TASK_EXECUTOR);

openWindow();
@@ -105,7 +110,7 @@ public void start(Stage stage) {
@Override
public void stop() {
OOBibBaseConnect.closeOfficeConnection();
Globals.stopBackgroundTasks();
stopBackgroundTasks();
Globals.shutdownThreadPools();
}

@@ -257,4 +262,26 @@ public static DialogService getDialogService() {
public static ThemeManager getThemeManager() {
return themeManager;
}

// Background tasks
public static void startBackgroundTasks() {
// TODO Currently deactivated due to incompatibilities in XML
/* if (Globals.prefs.getTelemetryPreferences().shouldCollectTelemetry() && !GraphicsEnvironment.isHeadless()) {
Telemetry.start(prefs.getTelemetryPreferences());
} */
RemotePreferences remotePreferences = Globals.prefs.getRemotePreferences();
if (remotePreferences.useRemoteServer()) {
Globals.REMOTE_LISTENER.openAndStart(
new CLIMessageHandler(
Globals.prefs,
Globals.getFileUpdateMonitor(),
Injector.instantiateModelOrService(BibEntryTypesManager.class)),
remotePreferences.getPort());
}
}

public static void stopBackgroundTasks() {
Telemetry.shutdown();
Unirest.shutDown();
}
}
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
@@ -88,6 +88,7 @@
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;
import com.google.common.eventbus.Subscribe;
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.Subscription;
@@ -334,7 +335,7 @@ public void installAutosaveManagerAndBackupManager() {
autosaveManager.registerListener(new AutosaveUiManager(this, dialogService, preferencesService, entryTypesManager));
}
if (isDatabaseReadyForBackup(bibDatabaseContext) && preferencesService.getFilePreferences().shouldCreateBackup()) {
BackupManager.start(this, bibDatabaseContext, Globals.entryTypesManager, preferencesService);
BackupManager.start(this, bibDatabaseContext, Injector.instantiateModelOrService(BibEntryTypesManager.class), preferencesService);
}
}

@@ -795,7 +796,7 @@ private boolean confirmClose() {

if (buttonType.equals(saveChanges)) {
try {
SaveDatabaseAction saveAction = new SaveDatabaseAction(this, dialogService, preferencesService, Globals.entryTypesManager);
SaveDatabaseAction saveAction = new SaveDatabaseAction(this, dialogService, preferencesService, Injector.instantiateModelOrService(BibEntryTypesManager.class));
if (saveAction.save()) {
return true;
}
6 changes: 4 additions & 2 deletions src/main/java/org/jabref/gui/entrytype/EntryTypeView.java
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
import javafx.stage.Screen;

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.util.BaseDialog;
@@ -31,6 +30,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.types.BiblatexAPAEntryTypeDefinitions;
import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions;
import org.jabref.model.entry.types.BiblatexSoftwareEntryTypeDefinitions;
@@ -42,6 +42,7 @@
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;
import com.airhacks.afterburner.views.ViewLoader;
import com.tobiasdiez.easybind.EasyBind;
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;
@@ -186,7 +187,8 @@ public void initialize() {
addEntriesToPane(otherEntriesPane, otherEntries);

BibDatabaseMode customTypeDatabaseMode = isBiblatexMode ? BibDatabaseMode.BIBLATEX : BibDatabaseMode.BIBTEX;
List<BibEntryType> customTypes = Globals.entryTypesManager.getAllCustomTypes(customTypeDatabaseMode);
BibEntryTypesManager entryTypesManager = Injector.instantiateModelOrService(BibEntryTypesManager.class);
List<BibEntryType> customTypes = entryTypesManager.getAllCustomTypes(customTypeDatabaseMode);
if (customTypes.isEmpty()) {
customTitlePane.setVisible(false);
} else {
Original file line number Diff line number Diff line change
@@ -26,8 +26,10 @@
import org.jabref.logic.util.FileType;
import org.jabref.logic.util.StandardFileType;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -75,7 +77,7 @@ public void execute() {

ExporterFactory exporterFactory = ExporterFactory.create(
preferences,
Globals.entryTypesManager);
Injector.instantiateModelOrService(BibEntryTypesManager.class));
List<Exporter> exporters = exporterFactory.getExporters().stream()
.sorted(Comparator.comparing(Exporter::getName))
.filter(exporter -> SUPPORTED_FILETYPES.contains(exporter.getFileType()))
6 changes: 4 additions & 2 deletions src/main/java/org/jabref/gui/exporter/SaveAction.java
Original file line number Diff line number Diff line change
@@ -3,13 +3,15 @@
import java.util.function.Supplier;

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionHelper;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;

/**
* This class is just a simple wrapper for the soon to be refactored SaveDatabaseAction.
*/
@@ -46,7 +48,7 @@ public void execute() {
tabSupplier.get(),
dialogService,
preferencesService,
Globals.entryTypesManager);
Injector.instantiateModelOrService(BibEntryTypesManager.class));

switch (saveMethod) {
case SAVE -> saveDatabaseAction.save();
6 changes: 4 additions & 2 deletions src/main/java/org/jabref/gui/exporter/SaveAllAction.java
Original file line number Diff line number Diff line change
@@ -4,12 +4,14 @@
import java.util.function.Supplier;

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.injection.Injector;

public class SaveAllAction extends SimpleCommand {

private final Supplier<List<LibraryTab>> tabsSupplier;
@@ -27,7 +29,7 @@ public void execute() {
dialogService.notify(Localization.lang("Saving all libraries..."));

for (LibraryTab libraryTab : tabsSupplier.get()) {
SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction(libraryTab, dialogService, preferencesService, Globals.entryTypesManager);
SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction(libraryTab, dialogService, preferencesService, Injector.instantiateModelOrService(BibEntryTypesManager.class));
boolean saveResult = saveDatabaseAction.save();
if (!saveResult) {
dialogService.notify(Localization.lang("Could not save file."));
Loading