Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/upstream/main' into di
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
#	src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java
#	src/main/java/org/jabref/gui/fieldeditors/ISSNEditor.java
#	src/main/java/org/jabref/gui/fieldeditors/JournalEditor.java
#	src/main/java/org/jabref/gui/fieldeditors/OwnerEditor.java
#	src/main/java/org/jabref/gui/fieldeditors/PersonsEditor.java
#	src/main/java/org/jabref/gui/fieldeditors/SimpleEditor.java
  • Loading branch information
calixtus committed Jun 17, 2024
2 parents c39b382 + d51b52b commit bdefb7d
Show file tree
Hide file tree
Showing 79 changed files with 1,021 additions and 734 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where drag and dropping entries from one library to another was not always working. [#11254](https://github.com/JabRef/jabref/issues/11254)
- We fixed an issue where drag and dropping entries created a shallow copy. [#11160](https://github.com/JabRef/jabref/issues/11160)
- We fixed an issue where imports to a custom group would only work for the first entry [#11085](https://github.com/JabRef/jabref/issues/11085), [#11269](https://github.com/JabRef/jabref/issues/11269)
- We fixed an issue when cursor jumped to the beginning of the line. [#5904](https://github.com/JabRef/jabref/issues/5904)
- We fixed an issue where a new entry was not added to the selected group [#8933](https://github.com/JabRef/jabref/issues/8933)
- We fixed an issue where the horizontal position of the Entry Preview inside the entry editor was not remembered across restarts [#11281](https://github.com/JabRef/jabref/issues/11281)
- We fixed an issue where the search index was not updated after linking PDF files. [#11317](https://github.com/JabRef/jabref/pull/11317)
- We fixed rendering of (first) author with a single letter surname. [forum#4330](https://discourse.jabref.org/t/correct-rendering-of-first-author-with-a-single-letter-surname/4330)
- We fixed that the import of the related articles tab sometimes used the wrong library mode. [#11282](https://github.com/JabRef/jabref/pull/11282)
- We fixed an issue where the entry editor context menu was not shown correctly when JabRef is opened on a second, extended screen [#11323](https://github.com/JabRef/jabref/issues/11323), [#11174](https://github.com/JabRef/jabref/issues/11174)
- We fixe an issue where the value of "Override default font settings" was not applied on startup [#11344](https://github.com/JabRef/jabref/issues/11344)
- We fixed an issue where the value of "Override default font settings" was not applied on startup [#11344](https://github.com/JabRef/jabref/issues/11344)
- We fixed an issue when "Library changed on disk" appeared after a save by JabRef. [#4877](https://github.com/JabRef/jabref/issues/4877)

### Removed

Expand Down
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,11 @@ testlogger {

tasks.withType(Test) {
reports.html.outputLocation.set(file("${reporting.baseDir}/${name}"))
// Enable parallel tests. See https://docs.gradle.org/8.1/userguide/performance.html#execute_tests_in_parallel for details.
maxParallelForks = Runtime.runtime.availableProcessors() - 1
ignoreFailures = true
// Enable parallel tests (on desktop).
// See https://docs.gradle.org/8.1/userguide/performance.html#execute_tests_in_parallel for details.
if (!providers.environmentVariable("CI").isPresent()) {
maxParallelForks = Math.max(Runtime.runtime.availableProcessors() - 1, 1)
}
}

tasks.register('databaseTest', Test) {
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
org.gradle.vs.watch=true

# hint by https://docs.gradle.org/current/userguide/performance.html#increase_the_heap_size
org.gradle.jvmargs=-Xmx4096M
# Hint by https://docs.gradle.org/current/userguide/performance.html#increase_the_heap_size
# Otherwise, one gets "Java heap space" errors.
org.gradle.jvmargs=-Xmx6096M

# hint by https://docs.gradle.org/current/userguide/performance.html#enable_configuration_cache
# Does not work:
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/org/jabref/gui/autosaveandbackup/BackupManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import org.jabref.logic.util.BackupFileType;
import org.jabref.logic.util.CoarseChangeFilter;
import org.jabref.logic.util.io.BackupFileUtil;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.event.BibDatabaseContextChangedEvent;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.metadata.SaveOrder;
import org.jabref.model.metadata.SelfContainedSaveOrder;
Expand Down Expand Up @@ -67,7 +69,7 @@ public class BackupManager {
private final LibraryTab libraryTab;

// Contains a list of all backup paths
// During a write, the less recent backup file is deleted
// During writing, the less recent backup file is deleted
private final Queue<Path> backupFilesQueue = new LinkedBlockingQueue<>();
private boolean needsBackup = false;

Expand Down Expand Up @@ -259,10 +261,19 @@ void performBackup(Path backupPath) {
.withSaveOrder(saveOrder)
.withReformatOnSave(preferences.getLibraryPreferences().shouldAlwaysReformatOnSave());

// "Clone" the database context
// We "know" that "only" the BibEntries might be changed during writing (see [org.jabref.logic.exporter.BibDatabaseWriter.savePartOfDatabase])
List<BibEntry> list = bibDatabaseContext.getDatabase().getEntries().stream()
.map(BibEntry::clone)
.map(BibEntry.class::cast)
.toList();
BibDatabase bibDatabaseClone = new BibDatabase(list);
BibDatabaseContext bibDatabaseContextClone = new BibDatabaseContext(bibDatabaseClone, bibDatabaseContext.getMetaData());

Charset encoding = bibDatabaseContext.getMetaData().getEncoding().orElse(StandardCharsets.UTF_8);
// We want to have successful backups only
// Thus, we do not use a plain "FileWriter", but the "AtomicFileWriter"
// Example: What happens if one hard powers off the machine (or kills the jabref process) during the write of the backup?
// Example: What happens if one hard powers off the machine (or kills the jabref process) during writing of the backup?
// This MUST NOT create a broken backup file that then jabref wants to "restore" from?
try (Writer writer = new AtomicFileWriter(backupPath, encoding, false)) {
BibWriter bibWriter = new BibWriter(writer, bibDatabaseContext.getDatabase().getNewLineSeparator());
Expand All @@ -272,7 +283,8 @@ void performBackup(Path backupPath) {
preferences.getFieldPreferences(),
preferences.getCitationKeyPatternPreferences(),
entryTypesManager)
.saveDatabase(bibDatabaseContext);
// we save the clone to prevent the original database (and thus the UI) from being changed
.saveDatabase(bibDatabaseContextClone);
backupFilesQueue.add(backupPath);

// We wrote the file successfully
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private List<EntryEditorTab> createTabs() {
tabs.add(new SciteTab(preferencesService, taskExecutor, dialogService));
tabs.add(new CitationRelationsTab(dialogService, databaseContext,
undoManager, stateManager, fileMonitor, preferencesService, libraryTab, taskExecutor));
tabs.add(new RelatedArticlesTab(buildInfo, preferencesService, dialogService, taskExecutor));
tabs.add(new RelatedArticlesTab(buildInfo, databaseContext, preferencesService, dialogService, taskExecutor));
sourceTab = new SourceTab(
databaseContext,
undoManager,
Expand Down Expand Up @@ -362,9 +362,6 @@ private void adaptVisibleTabs() {
}
}

/**
* @return the currently edited entry
*/
public BibEntry getCurrentlyEditedEntry() {
return currentlyEditedEntry;
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
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.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.preferences.MrDlibPreferences;
Expand All @@ -48,12 +47,17 @@ public class RelatedArticlesTab extends EntryEditorTab {
private final BuildInfo buildInfo;
private final TaskExecutor taskExecutor;

private final BibDatabaseContext databaseContext;

private final PreferencesService preferencesService;

public RelatedArticlesTab(BuildInfo buildInfo,
BibDatabaseContext databaseContext,
PreferencesService preferencesService,
DialogService dialogService,
TaskExecutor taskExecutor) {
this.databaseContext = databaseContext;

this.dialogService = dialogService;
this.buildInfo = buildInfo;
this.taskExecutor = taskExecutor;
Expand Down Expand Up @@ -84,7 +88,7 @@ private StackPane getRelatedArticlesPane(BibEntry entry) {
.wrap(() -> fetcher.performSearch(entry))
.onRunning(() -> progress.setVisible(true))
.onSuccess(relatedArticles -> {
ImportCleanup cleanup = ImportCleanup.targeting(BibDatabaseModeDetection.inferMode(new BibDatabase(List.of(entry))));
ImportCleanup cleanup = ImportCleanup.targeting(databaseContext.getMode(), preferencesService.getFieldPreferences());
cleanup.doPostCleanup(relatedArticles);
progress.setVisible(false);
root.getChildren().add(getRelatedArticleInfo(relatedArticles, fetcher));
Expand Down
54 changes: 27 additions & 27 deletions src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class ImportHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(ImportHandler.class);
private final BibDatabaseContext bibDatabaseContext;
private final PreferencesService preferencesService;
private final PreferencesService preferences;
private final FileUpdateMonitor fileUpdateMonitor;
private final ExternalFilesEntryLinker linker;
private final ExternalFilesContentImporter contentImporter;
Expand All @@ -76,22 +76,22 @@ public class ImportHandler {
private final TaskExecutor taskExecutor;

public ImportHandler(BibDatabaseContext database,
PreferencesService preferencesService,
PreferencesService preferences,
FileUpdateMonitor fileupdateMonitor,
UndoManager undoManager,
StateManager stateManager,
DialogService dialogService,
TaskExecutor taskExecutor) {

this.bibDatabaseContext = database;
this.preferencesService = preferencesService;
this.preferences = preferences;
this.fileUpdateMonitor = fileupdateMonitor;
this.stateManager = stateManager;
this.dialogService = dialogService;
this.taskExecutor = taskExecutor;

this.linker = new ExternalFilesEntryLinker(preferencesService.getFilePreferences(), database, dialogService);
this.contentImporter = new ExternalFilesContentImporter(preferencesService.getImportFormatPreferences());
this.linker = new ExternalFilesEntryLinker(preferences.getFilePreferences(), database, dialogService);
this.contentImporter = new ExternalFilesContentImporter(preferences.getImportFormatPreferences());
this.undoManager = undoManager;
}

Expand Down Expand Up @@ -186,7 +186,7 @@ private BibEntry createEmptyEntryWithLink(Path file) {
* There is no automatic download done.
*/
public void importEntries(List<BibEntry> entries) {
ImportCleanup cleanup = ImportCleanup.targeting(bibDatabaseContext.getMode());
ImportCleanup cleanup = ImportCleanup.targeting(bibDatabaseContext.getMode(), preferences.getFieldPreferences());
cleanup.doPostCleanup(entries);
importCleanedEntries(entries);
}
Expand Down Expand Up @@ -218,7 +218,7 @@ private void importEntryWithDuplicateCheck(BibDatabaseContext bibDatabaseContext

@VisibleForTesting
BibEntry cleanUpEntry(BibDatabaseContext bibDatabaseContext, BibEntry entry) {
ImportCleanup cleanup = ImportCleanup.targeting(bibDatabaseContext.getMode());
ImportCleanup cleanup = ImportCleanup.targeting(bibDatabaseContext.getMode(), preferences.getFieldPreferences());
return cleanup.doPostCleanup(entry);
}

Expand Down Expand Up @@ -248,26 +248,26 @@ public Optional<BibEntry> handleDuplicates(BibDatabaseContext bibDatabaseContext
}

public DuplicateDecisionResult getDuplicateDecision(BibEntry originalEntry, BibEntry duplicateEntry, BibDatabaseContext bibDatabaseContext, DuplicateResolverDialog.DuplicateResolverResult decision) {
DuplicateResolverDialog dialog = new DuplicateResolverDialog(duplicateEntry, originalEntry, DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, bibDatabaseContext, stateManager, dialogService, preferencesService);
DuplicateResolverDialog dialog = new DuplicateResolverDialog(duplicateEntry, originalEntry, DuplicateResolverDialog.DuplicateResolverType.IMPORT_CHECK, bibDatabaseContext, stateManager, dialogService, preferences);
if (decision == BREAK) {
decision = dialogService.showCustomDialogAndWait(dialog).orElse(BREAK);
}
if (preferencesService.getMergeDialogPreferences().shouldMergeApplyToAllEntries()) {
preferencesService.getMergeDialogPreferences().setAllEntriesDuplicateResolverDecision(decision);
if (preferences.getMergeDialogPreferences().shouldMergeApplyToAllEntries()) {
preferences.getMergeDialogPreferences().setAllEntriesDuplicateResolverDecision(decision);
}
return new DuplicateDecisionResult(decision, dialog.getMergedEntry());
}

public void setAutomaticFields(List<BibEntry> entries) {
UpdateField.setAutomaticFields(
entries,
preferencesService.getOwnerPreferences(),
preferencesService.getTimestampPreferences()
preferences.getOwnerPreferences(),
preferences.getTimestampPreferences()
);
}

public void downloadLinkedFiles(BibEntry entry) {
if (preferencesService.getFilePreferences().shouldDownloadLinkedFiles()) {
if (preferences.getFilePreferences().shouldDownloadLinkedFiles()) {
entry.getFiles().stream()
.filter(LinkedFile::isOnlineLink)
.forEach(linkedFile ->
Expand All @@ -277,7 +277,7 @@ public void downloadLinkedFiles(BibEntry entry) {
bibDatabaseContext,
taskExecutor,
dialogService,
preferencesService
preferences
).download(false)
);
}
Expand All @@ -302,19 +302,19 @@ private void addToGroups(List<BibEntry> entries, Collection<GroupTreeNode> group
* @param entries entries to generate keys for
*/
private void generateKeys(List<BibEntry> entries) {
if (!preferencesService.getImporterPreferences().isGenerateNewKeyOnImport()) {
if (!preferences.getImporterPreferences().isGenerateNewKeyOnImport()) {
return;
}
CitationKeyGenerator keyGenerator = new CitationKeyGenerator(
bibDatabaseContext.getMetaData().getCiteKeyPatterns(preferencesService.getCitationKeyPatternPreferences()
.getKeyPatterns()),
bibDatabaseContext.getMetaData().getCiteKeyPatterns(preferences.getCitationKeyPatternPreferences()
.getKeyPatterns()),
bibDatabaseContext.getDatabase(),
preferencesService.getCitationKeyPatternPreferences());
preferences.getCitationKeyPatternPreferences());
entries.forEach(keyGenerator::generateAndSetKey);
}

public List<BibEntry> handleBibTeXData(String entries) {
BibtexParser parser = new BibtexParser(preferencesService.getImportFormatPreferences(), fileUpdateMonitor);
BibtexParser parser = new BibtexParser(preferences.getImportFormatPreferences(), fileUpdateMonitor);
try {
List<BibEntry> result = parser.parseEntries(new ByteArrayInputStream(entries.getBytes(StandardCharsets.UTF_8)));
Collection<BibtexString> stringConstants = parser.getStringValues();
Expand Down Expand Up @@ -372,9 +372,9 @@ public List<BibEntry> handleStringData(String data) throws FetcherException {
private List<BibEntry> tryImportFormats(String data) {
try {
ImportFormatReader importFormatReader = new ImportFormatReader(
preferencesService.getImporterPreferences(),
preferencesService.getImportFormatPreferences(),
preferencesService.getCitationKeyPatternPreferences(),
preferences.getImporterPreferences(),
preferences.getImportFormatPreferences(),
preferences.getCitationKeyPatternPreferences(),
fileUpdateMonitor
);
UnknownFormatImport unknownFormatImport = importFormatReader.importUnknownFormat(data);
Expand All @@ -387,19 +387,19 @@ private List<BibEntry> tryImportFormats(String data) {

private List<BibEntry> fetchByDOI(DOI doi) throws FetcherException {
LOGGER.info("Found DOI identifier in clipboard");
Optional<BibEntry> entry = new DoiFetcher(preferencesService.getImportFormatPreferences()).performSearchById(doi.getDOI());
Optional<BibEntry> entry = new DoiFetcher(preferences.getImportFormatPreferences()).performSearchById(doi.getDOI());
return OptionalUtil.toList(entry);
}

private List<BibEntry> fetchByArXiv(ArXivIdentifier arXivIdentifier) throws FetcherException {
LOGGER.info("Found arxiv identifier in clipboard");
Optional<BibEntry> entry = new ArXivFetcher(preferencesService.getImportFormatPreferences()).performSearchById(arXivIdentifier.getNormalizedWithoutVersion());
Optional<BibEntry> entry = new ArXivFetcher(preferences.getImportFormatPreferences()).performSearchById(arXivIdentifier.getNormalizedWithoutVersion());
return OptionalUtil.toList(entry);
}

private List<BibEntry> fetchByISBN(ISBN isbn) throws FetcherException {
LOGGER.info("Found ISBN identifier in clipboard");
Optional<BibEntry> entry = new IsbnFetcher(preferencesService.getImportFormatPreferences()).performSearchById(isbn.getNormalized());
Optional<BibEntry> entry = new IsbnFetcher(preferences.getImportFormatPreferences()).performSearchById(isbn.getNormalized());
return OptionalUtil.toList(entry);
}

Expand All @@ -412,8 +412,8 @@ public void importEntriesWithDuplicateCheck(BibDatabaseContext database, List<Bi
firstEntry = false;
continue;
}
if (preferencesService.getMergeDialogPreferences().shouldMergeApplyToAllEntries()) {
DuplicateResolverDialog.DuplicateResolverResult decision = preferencesService.getMergeDialogPreferences().getAllEntriesDuplicateResolverDecision();
if (preferences.getMergeDialogPreferences().shouldMergeApplyToAllEntries()) {
DuplicateResolverDialog.DuplicateResolverResult decision = preferences.getMergeDialogPreferences().getAllEntriesDuplicateResolverDecision();
LOGGER.debug("Not first entry, pref flag is true, we use {}", decision);
importEntryWithDuplicateCheck(database, entry, decision);
} else {
Expand Down
Loading

0 comments on commit bdefb7d

Please sign in to comment.