Skip to content

Commit

Permalink
Migrate BuildInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
calixtus committed May 26, 2024
1 parent 103a718 commit 8bac78a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/main/java/org/jabref/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<String, String> configuration = Map.of(
Expand All @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/cli/JabRefCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> getLeftOver() {
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/jabref/gui/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -307,7 +309,7 @@ private List<EntryEditorTab> 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,
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")));
Expand All @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/frame/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())),
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/help/SearchForUpdateAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down

0 comments on commit 8bac78a

Please sign in to comment.