diff --git a/src/main/java/org/jabref/Launcher.java b/src/main/java/org/jabref/Launcher.java index 8fbbf6f2157..db187b6c2ed 100644 --- a/src/main/java/org/jabref/Launcher.java +++ b/src/main/java/org/jabref/Launcher.java @@ -26,6 +26,7 @@ import org.jabref.logic.protectedterms.ProtectedTermsLoader; import org.jabref.logic.remote.RemotePreferences; import org.jabref.logic.remote.client.RemoteClient; +import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.OS; import org.jabref.migrations.PreferencesMigrations; import org.jabref.model.entry.BibEntryTypesManager; @@ -54,6 +55,8 @@ public static void main(String[] args) { initLogging(args); try { + Injector.setModelOrService(BuildInfo.class, new BuildInfo()); + // Initialize preferences final JabRefPreferences preferences = JabRefPreferences.getInstance(); Injector.setModelOrService(PreferencesService.class, preferences); @@ -130,10 +133,11 @@ private static void initLogging(String[] args) { try { Files.createDirectories(directory); } catch (IOException e) { - initializeLogger(); + LOGGER = LoggerFactory.getLogger(Launcher.class); LOGGER.error("Could not create log directory {}", directory, e); return; } + // The "Shared File Writer" is explained at // https://tinylog.org/v2/configuration/#shared-file-writer Map configuration = Map.of( @@ -145,12 +149,8 @@ private static void initLogging(String[] args) { "writerFile.charset", "UTF-8", "writerFile.policies", "startup", "writerFile.backups", "30"); - configuration.forEach(Configuration::set); - initializeLogger(); - } - private static void initializeLogger() { LOGGER = LoggerFactory.getLogger(Launcher.class); } diff --git a/src/main/java/org/jabref/cli/JabRefCLI.java b/src/main/java/org/jabref/cli/JabRefCLI.java index ebe3261610f..6e8c76b54b9 100644 --- a/src/main/java/org/jabref/cli/JabRefCLI.java +++ b/src/main/java/org/jabref/cli/JabRefCLI.java @@ -5,10 +5,10 @@ import javafx.util.Pair; -import org.jabref.gui.Globals; import org.jabref.logic.exporter.ExporterFactory; import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.strings.StringUtil; @@ -343,7 +343,8 @@ public static void printUsage(PreferencesService preferencesService) { } private String getVersionInfo() { - return "JabRef %s".formatted(Globals.BUILD_INFO.version); + BuildInfo buildInfo = Injector.instantiateModelOrService(BuildInfo.class); + return "JabRef %s".formatted(buildInfo.version); } public List getLeftOver() { diff --git a/src/main/java/org/jabref/gui/Globals.java b/src/main/java/org/jabref/gui/Globals.java index 9af5a77ef8b..b5cdea98035 100644 --- a/src/main/java/org/jabref/gui/Globals.java +++ b/src/main/java/org/jabref/gui/Globals.java @@ -3,7 +3,6 @@ import org.jabref.architecture.AllowedToUseAwt; import org.jabref.gui.util.DefaultDirectoryMonitor; import org.jabref.gui.util.DefaultFileUpdateMonitor; -import org.jabref.logic.util.BuildInfo; import org.jabref.model.util.DirectoryMonitor; import org.jabref.model.util.FileUpdateMonitor; @@ -13,12 +12,6 @@ @Deprecated @AllowedToUseAwt("Requires AWT for headless check") public class Globals { - - /** - * JabRef version info - */ - public static final BuildInfo BUILD_INFO = new BuildInfo(); - private static DefaultFileUpdateMonitor fileUpdateMonitor; private static DefaultDirectoryMonitor directoryMonitor; diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index cbd4736e30c..c1642203787 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -30,6 +30,7 @@ import org.jabref.logic.net.ProxyRegisterer; import org.jabref.logic.remote.RemotePreferences; import org.jabref.logic.remote.server.RemoteListenerServerManager; +import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.WebViewStore; import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.strings.StringUtil; @@ -105,9 +106,10 @@ public void start(Stage stage) { "with this session.")); } + BuildInfo buildInfo = Injector.instantiateModelOrService(BuildInfo.class); EasyBind.subscribe(preferencesService.getInternalPreferences().versionCheckEnabledProperty(), enabled -> { if (enabled) { - new VersionWorker(Globals.BUILD_INFO.version, + new VersionWorker(buildInfo.version, dialogService, taskExecutor, preferencesService) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index ee11a9d6236..f8ee4bc186f 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -51,6 +51,7 @@ import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter; import org.jabref.logic.journals.JournalAbbreviationRepository; +import org.jabref.logic.util.BuildInfo; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryTypesManager; @@ -109,6 +110,7 @@ public class EntryEditor extends BorderPane { @FXML private Button typeChangeButton; @FXML private Button fetcherButton; @FXML private Label typeLabel; + @Inject private BuildInfo buildInfo; @Inject private DialogService dialogService; @Inject private TaskExecutor taskExecutor; @Inject private PreferencesService preferencesService; @@ -307,7 +309,7 @@ private List createTabs() { preferencesService, libraryTab, taskExecutor)); - entryEditorTabs.add(new RelatedArticlesTab(entryEditorPreferences, preferencesService, dialogService, taskExecutor)); + entryEditorTabs.add(new RelatedArticlesTab(buildInfo, entryEditorPreferences, preferencesService, dialogService, taskExecutor)); sourceTab = new SourceTab( databaseContext, undoManager, diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index 1cf3ad74e5b..3dc16596746 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -19,13 +19,13 @@ import javafx.scene.text.Text; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.importer.fetcher.MrDLibFetcher; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.BuildInfo; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseModeDetection; import org.jabref.model.entry.BibEntry; @@ -46,12 +46,15 @@ public class RelatedArticlesTab extends EntryEditorTab { private final EntryEditorPreferences preferences; private final DialogService dialogService; private final PreferencesService preferencesService; + private final BuildInfo buildInfo; private final TaskExecutor taskExecutor; - public RelatedArticlesTab(EntryEditorPreferences preferences, + public RelatedArticlesTab(BuildInfo buildInfo, + EntryEditorPreferences preferences, PreferencesService preferencesService, DialogService dialogService, TaskExecutor taskExecutor) { + this.buildInfo = buildInfo; this.taskExecutor = taskExecutor; setText(Localization.lang("Related articles")); setTooltip(new Tooltip(Localization.lang("Related articles"))); @@ -72,8 +75,10 @@ private StackPane getRelatedArticlesPane(BibEntry entry) { ProgressIndicator progress = new ProgressIndicator(); progress.setMaxSize(100, 100); - MrDLibFetcher fetcher = new MrDLibFetcher(preferencesService.getWorkspacePreferences().getLanguage().name(), - Globals.BUILD_INFO.version, preferencesService.getMrDlibPreferences()); + MrDLibFetcher fetcher = new MrDLibFetcher( + preferencesService.getWorkspacePreferences().getLanguage().name(), + buildInfo.version, + preferencesService.getMrDlibPreferences()); BackgroundTask .wrap(() -> fetcher.performSearch(entry)) .onRunning(() -> progress.setVisible(true)) diff --git a/src/main/java/org/jabref/gui/frame/MainMenu.java b/src/main/java/org/jabref/gui/frame/MainMenu.java index 1bace124387..3a5884af9cf 100644 --- a/src/main/java/org/jabref/gui/frame/MainMenu.java +++ b/src/main/java/org/jabref/gui/frame/MainMenu.java @@ -12,7 +12,6 @@ import org.jabref.gui.ClipBoardManager; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; import org.jabref.gui.StateManager; import org.jabref.gui.actions.ActionFactory; import org.jabref.gui.actions.StandardActions; @@ -334,7 +333,7 @@ private void createMenu() { new SeparatorMenuItem(), factory.createMenuItem(StandardActions.DONATE, new OpenBrowserAction("https://donations.jabref.org", dialogService, preferencesService.getFilePreferences())), - factory.createMenuItem(StandardActions.SEARCH_FOR_UPDATES, new SearchForUpdateAction(Globals.BUILD_INFO, preferencesService, dialogService, taskExecutor)), + factory.createMenuItem(StandardActions.SEARCH_FOR_UPDATES, new SearchForUpdateAction(preferencesService, dialogService, taskExecutor)), factory.createSubMenu(StandardActions.WEB_MENU, factory.createMenuItem(StandardActions.OPEN_WEBPAGE, new OpenBrowserAction("https://jabref.org/", dialogService, preferencesService.getFilePreferences())), factory.createMenuItem(StandardActions.OPEN_BLOG, new OpenBrowserAction("https://blog.jabref.org/", dialogService, preferencesService.getFilePreferences())), diff --git a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java index 9d0f12ea503..94110fddf4f 100644 --- a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java +++ b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java @@ -6,18 +6,17 @@ import org.jabref.logic.util.BuildInfo; import org.jabref.preferences.PreferencesService; +import com.airhacks.afterburner.injection.Injector; + public class SearchForUpdateAction extends SimpleCommand { - private final BuildInfo buildInfo; private final PreferencesService preferencesService; private final DialogService dialogService; private final TaskExecutor taskExecutor; - public SearchForUpdateAction(BuildInfo buildInfo, - PreferencesService preferencesService, + public SearchForUpdateAction(PreferencesService preferencesService, DialogService dialogService, TaskExecutor taskExecutor) { - this.buildInfo = buildInfo; this.preferencesService = preferencesService; this.dialogService = dialogService; this.taskExecutor = taskExecutor; @@ -27,6 +26,7 @@ public SearchForUpdateAction(BuildInfo buildInfo, @Override public void execute() { + BuildInfo buildInfo = Injector.instantiateModelOrService(BuildInfo.class); new VersionWorker(buildInfo.version, dialogService, taskExecutor, preferencesService) .checkForNewVersionAsync(); }