From b4c48efa769b6ec92dfeb8dd4cd1a9288fb1ede8 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 5 Feb 2025 22:52:52 +0100 Subject: [PATCH] Fix BibTexStrings not included in backup file (#12464) * Fix BibTexStrings not included in backup file Fixes https://github.com/JabRef/jabref/issues/12462 * fix checkstyle --- CHANGELOG.md | 1 + .../gui/autosaveandbackup/BackupManager.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9ecede44ef..bccf8db02be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where removing the sort from the table did not restore the original order. [#12371](https://github.com/JabRef/jabref/pull/12371) - We fixed an issue where JabRef icon merges with dark background [#7771](https://github.com/JabRef/jabref/issues/7771) - We fixed an issue where an entry's group was no longer highlighted on selection [#12413](https://github.com/JabRef/jabref/issues/12413) +- We fixed an issue where BibTeX Strings were not included in the backup file [#12462](https://github.com/JabRef/jabref/issues/12462) ### Removed diff --git a/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java b/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java index acae02c01c8..6ef3e41970c 100644 --- a/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java +++ b/src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java @@ -38,6 +38,7 @@ import org.jabref.model.database.event.BibDatabaseContextChangedEvent; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryTypesManager; +import org.jabref.model.entry.BibtexString; import org.jabref.model.metadata.SaveOrder; import org.jabref.model.metadata.SelfContainedSaveOrder; @@ -59,7 +60,7 @@ public class BackupManager { private static final int DELAY_BETWEEN_BACKUP_ATTEMPTS_IN_SECONDS = 19; - private static Set runningInstances = new HashSet<>(); + private static final Set RUNNING_INSTANCES = new HashSet<>(); private final BibDatabaseContext bibDatabaseContext; private final CliPreferences preferences; @@ -109,7 +110,7 @@ static Optional getLatestBackupPath(Path originalPath, Path backupDir) { public static BackupManager start(LibraryTab libraryTab, BibDatabaseContext bibDatabaseContext, BibEntryTypesManager entryTypesManager, CliPreferences preferences) { BackupManager backupManager = new BackupManager(libraryTab, bibDatabaseContext, entryTypesManager, preferences); backupManager.startBackupTask(preferences.getFilePreferences().getBackupDirectory()); - runningInstances.add(backupManager); + RUNNING_INSTANCES.add(backupManager); return backupManager; } @@ -119,7 +120,7 @@ public static BackupManager start(LibraryTab libraryTab, BibDatabaseContext bibD * @param bibDatabaseContext Associated {@link BibDatabaseContext} */ public static void discardBackup(BibDatabaseContext bibDatabaseContext, Path backupDir) { - runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.discardBackup(backupDir)); + RUNNING_INSTANCES.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.discardBackup(backupDir)); } /** @@ -130,8 +131,8 @@ public static void discardBackup(BibDatabaseContext bibDatabaseContext, Path bac * @param backupDir The path to the backup directory */ public static void shutdown(BibDatabaseContext bibDatabaseContext, Path backupDir, boolean createBackup) { - runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.shutdown(backupDir, createBackup)); - runningInstances.removeIf(instance -> instance.bibDatabaseContext == bibDatabaseContext); + RUNNING_INSTANCES.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.shutdown(backupDir, createBackup)); + RUNNING_INSTANCES.removeIf(instance -> instance.bibDatabaseContext == bibDatabaseContext); } /** @@ -268,6 +269,9 @@ void performBackup(Path backupPath) { .map(BibEntry.class::cast) .toList(); BibDatabase bibDatabaseClone = new BibDatabase(list); + bibDatabaseContext.getDatabase().getStringValues().stream().map(BibtexString::clone) + .map(BibtexString.class::cast) + .forEach(bibDatabaseClone::addString); BibDatabaseContext bibDatabaseContextClone = new BibDatabaseContext(bibDatabaseClone, bibDatabaseContext.getMetaData()); Charset encoding = bibDatabaseContext.getMetaData().getEncoding().orElse(StandardCharsets.UTF_8);