diff --git a/jabgui/src/main/java/org/jabref/gui/JabRefGUI.java b/jabgui/src/main/java/org/jabref/gui/JabRefGUI.java index dd5f3f4be1b..93c404b35fe 100644 --- a/jabgui/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/jabgui/src/main/java/org/jabref/gui/JabRefGUI.java @@ -116,13 +116,13 @@ public void start(Stage stage) { dialogService, fileUpdateMonitor, preferences, + gitHandlerRegistry, aiService, stateManager, countingUndoManager, Injector.instantiateModelOrService(BibEntryTypesManager.class), clipBoardManager, - taskExecutor, - gitHandlerRegistry); + taskExecutor); openWindow(); @@ -164,6 +164,7 @@ public void initialize() { Injector.setModelOrService(GitHandlerRegistry.class, gitHandlerRegistry); BibEntryTypesManager entryTypesManager = preferences.getCustomEntryTypesRepository(); + JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences()); Injector.setModelOrService(BibEntryTypesManager.class, entryTypesManager); Injector.setModelOrService(JournalAbbreviationRepository.class, journalAbbreviationRepository); diff --git a/jabgui/src/main/java/org/jabref/gui/consistency/ConsistencyCheckAction.java b/jabgui/src/main/java/org/jabref/gui/consistency/ConsistencyCheckAction.java index 3cb1d9adaab..42a24bf315e 100644 --- a/jabgui/src/main/java/org/jabref/gui/consistency/ConsistencyCheckAction.java +++ b/jabgui/src/main/java/org/jabref/gui/consistency/ConsistencyCheckAction.java @@ -62,7 +62,7 @@ public BibliographyConsistencyCheck.Result call() { BibDatabaseContext bibContext = databaseContext.get(); - BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(); + BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(preferences, entryTypesManager); return consistencyCheck.check(bibContext, (count, total) -> UiTaskExecutor.runInJavaFXThread(() -> { updateProgress(count, total); diff --git a/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java b/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java index 94c372811cf..fe8e98aa043 100644 --- a/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java +++ b/jabgui/src/main/java/org/jabref/gui/frame/JabRefFrame.java @@ -58,6 +58,7 @@ import org.jabref.logic.ai.AiService; import org.jabref.logic.git.util.GitHandlerRegistry; import org.jabref.logic.journals.JournalAbbreviationRepository; +import org.jabref.logic.preferences.CliPreferences; import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.TaskExecutor; import org.jabref.model.database.BibDatabaseContext; @@ -100,11 +101,11 @@ private enum PanelMode { MAIN_TABLE, MAIN_TABLE_AND_ENTRY_EDITOR } private final StateManager stateManager; private final CountingUndoManager undoManager; private final DialogService dialogService; + private final GitHandlerRegistry gitHandlerRegistry; private final FileUpdateMonitor fileUpdateMonitor; private final BibEntryTypesManager entryTypesManager; private final ClipBoardManager clipBoardManager; private final TaskExecutor taskExecutor; - private final GitHandlerRegistry gitHandlerRegistry; private final JabRefFrameViewModel viewModel; private final GuiPushToApplicationCommand pushToApplicationCommand; @@ -123,24 +124,24 @@ public JabRefFrame(Stage mainStage, DialogService dialogService, FileUpdateMonitor fileUpdateMonitor, GuiPreferences preferences, + GitHandlerRegistry gitHandlerRegistry, AiService aiService, StateManager stateManager, CountingUndoManager undoManager, BibEntryTypesManager entryTypesManager, ClipBoardManager clipBoardManager, - TaskExecutor taskExecutor, - GitHandlerRegistry gitHandlerRegistry) { + TaskExecutor taskExecutor) { this.mainStage = mainStage; this.dialogService = dialogService; this.fileUpdateMonitor = fileUpdateMonitor; this.preferences = preferences; + this.gitHandlerRegistry = gitHandlerRegistry; this.aiService = aiService; this.stateManager = stateManager; this.undoManager = undoManager; this.entryTypesManager = entryTypesManager; this.clipBoardManager = clipBoardManager; this.taskExecutor = taskExecutor; - this.gitHandlerRegistry = gitHandlerRegistry; setId("frame"); diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java b/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java index 9ffc9f0a9a3..e7e0e01f14f 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java @@ -17,6 +17,7 @@ import org.jabref.gui.util.ControlHelper; import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.logic.l10n.Localization; +import org.jabref.model.entry.BibEntryTypesManager; import com.airhacks.afterburner.views.ViewLoader; import com.tobiasdiez.easybind.EasyBind; @@ -39,6 +40,7 @@ public class PreferencesDialogView extends BaseDialog preferencesTabToSelectClass; @@ -67,7 +69,7 @@ public PreferencesDialogViewModel getViewModel() { @FXML private void initialize() { - viewModel = new PreferencesDialogViewModel(dialogService, preferences); + viewModel = new PreferencesDialogViewModel(dialogService, preferences, bibEntryTypesManager); preferenceTabList.itemsProperty().setValue(viewModel.getPreferenceTabs()); diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java b/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java index 5836422f225..c0e1adf5108 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java @@ -54,10 +54,12 @@ public class PreferencesDialogViewModel extends AbstractViewModel { private final DialogService dialogService; private final GuiPreferences preferences; private final ObservableList preferenceTabs; + private final BibEntryTypesManager bibEntryTypesManager; - public PreferencesDialogViewModel(DialogService dialogService, GuiPreferences preferences) { + public PreferencesDialogViewModel(DialogService dialogService, GuiPreferences preferences, BibEntryTypesManager bibEntryTypesManager) { this.dialogService = dialogService; this.preferences = preferences; + this.bibEntryTypesManager = bibEntryTypesManager; // This enables passing unsaved preference values from the AI tab to the "web search" tab. AiTab aiTab = new AiTab(); @@ -190,9 +192,9 @@ public void storeAllSettings() { + Localization.lang("You must restart JabRef for this to come into effect.")); } - Injector.setModelOrService(BibEntryTypesManager.class, preferences.getCustomEntryTypesRepository()); + Injector.setModelOrService(BibEntryTypesManager.class, preferences.getCustomEntryTypesRepository(bibEntryTypesManager)); dialogService.notify(Localization.lang("Preferences recorded.")); - } + }; /** * Inserts the preference values into the Properties of the ViewModel diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTab.java b/jabgui/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTab.java index 832cde6eb81..51d95428c6f 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTab.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTab.java @@ -57,6 +57,7 @@ public class CustomEntryTypesTab extends AbstractPreferenceTabView { private static final Logger LOGGER = LoggerFactory.getLogger(CheckConsistency.class); + private static final BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); @ParentCommand private ArgumentProcessor argumentProcessor; @@ -64,7 +66,7 @@ public Integer call() { BibDatabaseContext databaseContext = parserResult.get().getDatabaseContext(); - BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(); + BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(argumentProcessor.cliPreferences, bibEntryTypesManager); BibliographyConsistencyCheck.Result result = consistencyCheck.check(databaseContext, (count, total) -> { if (!sharedOptions.porcelain) { System.out.println(Localization.lang("Checking consistency for entry type %0 of %1", count + 1, total)); diff --git a/jabkit/src/main/java/org/jabref/cli/PdfUpdate.java b/jabkit/src/main/java/org/jabref/cli/PdfUpdate.java index 08ebb73d135..5d84dea3c67 100644 --- a/jabkit/src/main/java/org/jabref/cli/PdfUpdate.java +++ b/jabkit/src/main/java/org/jabref/cli/PdfUpdate.java @@ -37,6 +37,7 @@ @Command(name = "update", description = "Update linked PDFs with XMP and/or embedded BibTeX.") class PdfUpdate implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(PdfUpdate.class); + private static final BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); @ParentCommand protected Pdf pdf; @@ -93,7 +94,7 @@ public void run() { pdf.argumentProcessor.cliPreferences.getXmpPreferences(), pdf.argumentProcessor.cliPreferences.getFilePreferences(), pdf.argumentProcessor.cliPreferences.getLibraryPreferences().getDefaultBibDatabaseMode(), - pdf.argumentProcessor.cliPreferences.getCustomEntryTypesRepository(), + pdf.argumentProcessor.cliPreferences.getCustomEntryTypesRepository(bibEntryTypesManager), pdf.argumentProcessor.cliPreferences.getFieldPreferences(), Injector.instantiateModelOrService(JournalAbbreviationRepository.class), formats.contains("xmp"), diff --git a/jablib/src/main/java/org/jabref/logic/exporter/ExporterFactory.java b/jablib/src/main/java/org/jabref/logic/exporter/ExporterFactory.java index bcd6de20bef..7adec166096 100644 --- a/jablib/src/main/java/org/jabref/logic/exporter/ExporterFactory.java +++ b/jablib/src/main/java/org/jabref/logic/exporter/ExporterFactory.java @@ -13,6 +13,7 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.metadata.SelfContainedSaveOrder; public class ExporterFactory { @@ -30,6 +31,7 @@ public static ExporterFactory create(CliPreferences preferences) { XmpPreferences xmpPreferences = preferences.getXmpPreferences(); FieldPreferences fieldPreferences = preferences.getFieldPreferences(); BibDatabaseMode bibDatabaseMode = preferences.getLibraryPreferences().getDefaultBibDatabaseMode(); + BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); List exporters = new ArrayList<>(); @@ -59,7 +61,7 @@ public static ExporterFactory create(CliPreferences preferences) { exporters.add(new ModsExporter()); exporters.add(new XmpExporter(xmpPreferences)); exporters.add(new XmpPdfExporter(xmpPreferences)); - exporters.add(new EmbeddedBibFilePdfExporter(bibDatabaseMode, preferences.getCustomEntryTypesRepository(), fieldPreferences)); + exporters.add(new EmbeddedBibFilePdfExporter(bibDatabaseMode, preferences.getCustomEntryTypesRepository(bibEntryTypesManager), fieldPreferences)); exporters.add(new CffExporter()); exporters.add(new EndnoteXmlExporter(preferences.getBibEntryPreferences())); diff --git a/jablib/src/main/java/org/jabref/logic/preferences/CliPreferences.java b/jablib/src/main/java/org/jabref/logic/preferences/CliPreferences.java index f1a40419522..954bd0040bd 100644 --- a/jablib/src/main/java/org/jabref/logic/preferences/CliPreferences.java +++ b/jablib/src/main/java/org/jabref/logic/preferences/CliPreferences.java @@ -69,6 +69,8 @@ public interface CliPreferences { */ SelfContainedSaveConfiguration getSelfContainedExportConfiguration(); + BibEntryTypesManager getCustomEntryTypesRepository(BibEntryTypesManager bibEntryTypesManager); + BibEntryTypesManager getCustomEntryTypesRepository(); void storeCustomEntryTypesRepository(BibEntryTypesManager entryTypesManager); diff --git a/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java b/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java index c0f87ed2ddb..eb6a9742d33 100644 --- a/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java +++ b/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java @@ -1219,8 +1219,6 @@ public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { //************************************************************************************************************* // CustomEntryTypes //************************************************************************************************************* - - @Override public BibEntryTypesManager getCustomEntryTypesRepository() { BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); EnumSet.allOf(BibDatabaseMode.class).forEach(mode -> @@ -1228,6 +1226,13 @@ public BibEntryTypesManager getCustomEntryTypesRepository() { return bibEntryTypesManager; } + @Override + public BibEntryTypesManager getCustomEntryTypesRepository(BibEntryTypesManager bibEntryTypesManager) { + EnumSet.allOf(BibDatabaseMode.class).forEach(mode -> + bibEntryTypesManager.addCustomOrModifiedTypes(getBibEntryTypes(mode), mode)); + return bibEntryTypesManager; + } + private List getBibEntryTypes(BibDatabaseMode bibDatabaseMode) { List storedEntryTypes = new ArrayList<>(); Preferences prefsNode = getPrefsNodeForCustomizedEntryTypes(bibDatabaseMode); diff --git a/jablib/src/main/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheck.java b/jablib/src/main/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheck.java index 64915003c35..11532d32484 100644 --- a/jablib/src/main/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheck.java +++ b/jablib/src/main/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheck.java @@ -1,7 +1,6 @@ package org.jabref.logic.quality.consistency; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -17,16 +16,14 @@ import org.jabref.logic.bibtex.comparator.BibEntryByFieldsComparator; import org.jabref.logic.bibtex.comparator.FieldComparatorStack; import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryType; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.InternalField; import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UserSpecificCommentField; -import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; -import org.jabref.model.entry.types.BibtexEntryTypeDefinitions; import org.jabref.model.entry.types.EntryType; import com.google.common.annotations.VisibleForTesting; @@ -55,6 +52,12 @@ public class BibliographyConsistencyCheck { StandardField.MODIFICATIONDATE ); + private final BibEntryTypesManager bibEntryTypesManager; + + public BibliographyConsistencyCheck(org.jabref.logic.preferences.CliPreferences cliPreferences, BibEntryTypesManager bibEntryTypesManager) { + this.bibEntryTypesManager = cliPreferences.getCustomEntryTypesRepository(bibEntryTypesManager); + } + private static Set filterExcludedFields(Collection fields) { return fields.stream() .filter(field -> !EXPLICITLY_EXCLUDED_FIELDS.contains(field)) @@ -73,11 +76,17 @@ private static Set filterExcludedFields(Collection fields) { @VisibleForTesting List filterAndSortEntriesWithFieldDifferences(Set entries, Set differingFields, Set requiredFields) { return entries.stream() - .filter(entry -> - // This removes entries that have all differing fields set (could be confusing to the user) - !Collections.disjoint(entry.getFields(), differingFields) - // This ensures that all entries with missing required fields are included - || !entry.getFields().containsAll(requiredFields)) + .filter(entry -> { + // Include entries that are missing any required fields + boolean missingRequiredField = requiredFields.stream().anyMatch(field -> !entry.hasField(field)); + + // Include entries that have any of the differing fields + boolean hasDifferingField = differingFields.stream().anyMatch(entry::hasField); + + // Include all entries when there are differing fields (to show inconsistencies) + // OR when missing required fields + return !differingFields.isEmpty() || missingRequiredField; + }) .sorted(new FieldComparatorStack<>(List.of( new BibEntryByCitationKeyComparator(), new BibEntryByFieldsComparator() @@ -112,12 +121,10 @@ public Result check(BibDatabaseContext bibContext, BiConsumer collectEntriesIntoMaps(bibContext, entryTypeToFieldsInAnyEntryMap, entryTypeToFieldsInAllEntriesMap, entryTypeToEntriesMap); - List entryTypeDefinitions; - if (bibContext.getMode() == BibDatabaseMode.BIBLATEX) { - entryTypeDefinitions = BiblatexEntryTypeDefinitions.ALL; - } else { - entryTypeDefinitions = BibtexEntryTypeDefinitions.ALL; - } + List entryTypeDefinitions = bibEntryTypesManager + .getAllTypes(bibContext.getMode()) + .stream() + .toList(); // Use LinkedHashMap to preserve the order of Bib(tex|latex)EntryTypeDefinitions.ALL Map resultMap = new LinkedHashMap<>(); @@ -161,7 +168,6 @@ public Result check(BibDatabaseContext bibContext, BiConsumer } private static void collectEntriesIntoMaps(BibDatabaseContext bibContext, Map> entryTypeToFieldsInAnyEntryMap, Map> entryTypeToFieldsInAllEntriesMap, Map> entryTypeToEntriesMap) { - BibDatabaseMode mode = bibContext.getMode(); List entries = bibContext.getEntries(); for (BibEntry entry : entries) { diff --git a/jablib/src/test/java/org/jabref/logic/exporter/ExporterTest.java b/jablib/src/test/java/org/jabref/logic/exporter/ExporterTest.java index 970cefe8f74..a3e16e2081e 100644 --- a/jablib/src/test/java/org/jabref/logic/exporter/ExporterTest.java +++ b/jablib/src/test/java/org/jabref/logic/exporter/ExporterTest.java @@ -32,9 +32,10 @@ public class ExporterTest { private static Stream exportFormats() { CliPreferences preferences = mock(CliPreferences.class, Answers.RETURNS_DEEP_STUBS); + BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); when(preferences.getExportPreferences().getExportSaveOrder()).thenReturn(SaveOrder.getDefaultSaveOrder()); when(preferences.getExportPreferences().getCustomExporters()).thenReturn(FXCollections.emptyObservableList()); - when(preferences.getCustomEntryTypesRepository()).thenReturn(mock(BibEntryTypesManager.class)); + when(preferences.getCustomEntryTypesRepository(bibEntryTypesManager)).thenReturn(mock(BibEntryTypesManager.class)); ExporterFactory exporterFactory = ExporterFactory.create(preferences); diff --git a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultCsvWriterTest.java b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultCsvWriterTest.java index 6bcb7ba90a6..bcc43afc880 100644 --- a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultCsvWriterTest.java +++ b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultCsvWriterTest.java @@ -8,10 +8,12 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.fileformat.BibtexImporter; +import org.jabref.logic.preferences.CliPreferences; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; import org.jabref.model.entry.types.StandardEntryType; @@ -27,7 +29,9 @@ class BibliographyConsistencyCheckResultCsvWriterTest { + private final BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); private final BibtexImporter importer = new BibtexImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS), new DummyFileUpdateMonitor()); + private final CliPreferences cliPreferences = mock(CliPreferences.class, Answers.RETURNS_DEEP_STUBS); @Test void checkSimpleLibrary(@TempDir Path tempDir) throws IOException { @@ -42,8 +46,8 @@ void checkSimpleLibrary(@TempDir Path tempDir) throws IOException { database.insertEntry(second); BibDatabaseContext bibContext = new BibDatabaseContext(database); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (count, total) -> { }); Path csvFile = tempDir.resolve("checkSimpleLibrary-result.csv"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(csvFile)); @@ -73,8 +77,8 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) throws IOException { BibDatabaseContext bibContext = new BibDatabaseContext(database); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (count, total) -> { }); Path csvFile = tempDir.resolve("checkDifferentOutputSymbols-result.csv"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(csvFile)); @@ -119,8 +123,8 @@ void checkComplexLibrary(@TempDir Path tempDir) throws IOException { database.insertEntry(fifth); BibDatabaseContext bibContext = new BibDatabaseContext(database); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (count, total) -> { }); Path csvFile = tempDir.resolve("checkSimpleLibrary-result.csv"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(csvFile)); @@ -151,8 +155,8 @@ void checkLibraryWithoutIssues(@TempDir Path tempDir) throws IOException { BibDatabaseContext bibContext = new BibDatabaseContext(database); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (count, total) -> { }); Path csvFile = tempDir.resolve("checkLibraryWithoutIssues-result.csv"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(csvFile)); @@ -170,8 +174,9 @@ void checkManualInput() throws IOException { Path file = Path.of("C:\\TEMP\\JabRef\\biblio-anon.bib"); Path csvFile = file.resolveSibling("biblio-cited.csv"); BibDatabaseContext databaseContext = importer.importDatabase(file).getDatabaseContext(); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, (_, _) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(databaseContext, (_, _) -> { }); + try (Writer writer = new OutputStreamWriter(Files.newOutputStream(csvFile)); BibliographyConsistencyCheckResultCsvWriter paperConsistencyCheckResultCsvWriter = new BibliographyConsistencyCheckResultCsvWriter(result, writer, true)) { paperConsistencyCheckResultCsvWriter.writeFindings(); diff --git a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultTxtWriterTest.java b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultTxtWriterTest.java index 176ee0fc7c3..bad5c35c764 100644 --- a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultTxtWriterTest.java +++ b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultTxtWriterTest.java @@ -9,6 +9,7 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.fileformat.BibtexImporter; +import org.jabref.logic.preferences.CliPreferences; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; @@ -29,6 +30,8 @@ class BibliographyConsistencyCheckResultTxtWriterTest { private final BibtexImporter importer = new BibtexImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS), new DummyFileUpdateMonitor()); + private final BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); + private final CliPreferences cliPreferences = mock(CliPreferences.class, Answers.RETURNS_DEEP_STUBS); @Test void checkSimpleLibrary(@TempDir Path tempDir) throws IOException { @@ -44,8 +47,8 @@ void checkSimpleLibrary(@TempDir Path tempDir) throws IOException { BibDatabaseContext bibContext = new BibDatabaseContext(database); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (count, total) -> { }); Path txtFile = tempDir.resolve("checkSimpleLibrary-result.txt"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile)); @@ -88,7 +91,7 @@ void entriesMissingRequiredFieldsAreReported(@TempDir Path tempDir) throws Excep BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); bibContext.setMode(BibDatabaseMode.BIBLATEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager) .check(bibContext, (_, _) -> { }); @@ -131,8 +134,7 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) throws IOException { BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { - }); + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); Path txtFile = tempDir.resolve("checkDifferentOutputSymbols-result.txt"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile)); @@ -171,8 +173,8 @@ void checkVeryLongCitationKey(@TempDir Path tempDir) throws IOException { bibDatabase.insertEntries(bibEntriesList); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); Path txtFile = tempDir.resolve("checkDifferentOutputSymbols-result.txt"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile)); @@ -228,8 +230,7 @@ void checkComplexLibrary(@TempDir Path tempDir) throws IOException { bibDatabase.insertEntries(bibEntriesList); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { - }); + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); Path txtFile = tempDir.resolve("checkSimpleLibrary-result.txt"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile)); @@ -270,8 +271,7 @@ void checkLibraryWithoutIssuesWithOutPorcelain(@TempDir Path tempDir) throws IOE bibDatabase.insertEntries(bibEntriesList); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { - }); + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); Path txtFile = tempDir.resolve("checkLibraryWithoutIssues-result.txt"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile)); @@ -298,8 +298,7 @@ void checkLibraryWithoutIssuesWithPorcelain(@TempDir Path tempDir) throws IOExce bibDatabase.insertEntries(bibEntriesList); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { - }); + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); Path txtFile = tempDir.resolve("checkLibraryWithoutIssues-result.txt"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile)); @@ -315,8 +314,9 @@ void checkManualInput() throws IOException { Path file = Path.of("C:\\TEMP\\JabRef\\biblio-anon.bib"); Path txtFile = file.resolveSibling("biblio-cited.txt"); BibDatabaseContext databaseContext = importer.importDatabase(file).getDatabaseContext(); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, (_, _) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); + try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile)); BibliographyConsistencyCheckResultTxtWriter txtWriter = new BibliographyConsistencyCheckResultTxtWriter(result, writer, true)) { txtWriter.writeFindings(); diff --git a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckTest.java b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckTest.java index 12987b2cf40..0da1eaeba6d 100644 --- a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckTest.java +++ b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckTest.java @@ -4,11 +4,47 @@ import java.util.List; import java.util.Map; import java.util.Set; - +import java.util.prefs.BackingStoreException; + +import org.jabref.logic.FilePreferences; +import org.jabref.logic.InternalPreferences; +import org.jabref.logic.JabRefException; +import org.jabref.logic.LibraryPreferences; +import org.jabref.logic.ai.AiPreferences; +import org.jabref.logic.bibtex.FieldPreferences; +import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences; +import org.jabref.logic.cleanup.CleanupPreferences; +import org.jabref.logic.exporter.ExportPreferences; +import org.jabref.logic.exporter.SelfContainedSaveConfiguration; +import org.jabref.logic.git.preferences.GitPreferences; +import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.ImporterPreferences; +import org.jabref.logic.importer.fetcher.MrDlibPreferences; +import org.jabref.logic.importer.util.GrobidPreferences; +import org.jabref.logic.journals.JournalAbbreviationPreferences; +import org.jabref.logic.journals.JournalAbbreviationRepository; +import org.jabref.logic.layout.LayoutFormatterPreferences; +import org.jabref.logic.layout.format.NameFormatterPreferences; +import org.jabref.logic.net.ProxyPreferences; +import org.jabref.logic.net.ssl.SSLPreferences; +import org.jabref.logic.openoffice.OpenOfficePreferences; +import org.jabref.logic.preferences.CliPreferences; +import org.jabref.logic.preferences.DOIPreferences; +import org.jabref.logic.preferences.LastFilesOpenedPreferences; +import org.jabref.logic.preferences.OwnerPreferences; +import org.jabref.logic.preferences.TimestampPreferences; +import org.jabref.logic.protectedterms.ProtectedTermsPreferences; +import org.jabref.logic.push.PushToApplicationPreferences; +import org.jabref.logic.remote.RemotePreferences; +import org.jabref.logic.search.SearchPreferences; +import org.jabref.logic.util.io.AutoLinkPreferences; +import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryPreferences; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.field.StandardField; @@ -22,6 +58,218 @@ import static org.junit.jupiter.api.Assertions.assertEquals; class BibliographyConsistencyCheckTest { + private final BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); + CliPreferences cliPreferences = new CliPreferences() { + @Override + public void clear() throws BackingStoreException { + + } + + @Override + public void deleteKey(String key) throws IllegalArgumentException { + + } + + @Override + public BibEntryTypesManager getCustomEntryTypesRepository() { + return bibEntryTypesManager; + } + + @Override + public BibEntryTypesManager getCustomEntryTypesRepository(BibEntryTypesManager bibEntryTypesManager) { + return bibEntryTypesManager; + } + + @Override + public void flush() { + + } + + @Override + public void exportPreferences(Path file) throws JabRefException { + + } + + @Override + public void importPreferences(Path file) throws JabRefException { + + } + + @Override + public InternalPreferences getInternalPreferences() { + return null; + } + + @Override + public BibEntryPreferences getBibEntryPreferences() { + return null; + } + + @Override + public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { + return null; + } + + @Override + public FilePreferences getFilePreferences() { + return null; + } + + @Override + public FieldPreferences getFieldPreferences() { + return null; + } + + @Override + public Map getPreferences() { + return Map.of(); + } + + @Override + public Map getDefaults() { + return Map.of(); + } + + @Override + public LayoutFormatterPreferences getLayoutFormatterPreferences() { + return null; + } + + @Override + public ImportFormatPreferences getImportFormatPreferences() { + return null; + } + + @Override + public SelfContainedSaveConfiguration getSelfContainedExportConfiguration() { + return null; + } + + @Override + public void storeCustomEntryTypesRepository(BibEntryTypesManager entryTypesManager) { + + } + + @Override + public CleanupPreferences getCleanupPreferences() { + return null; + } + + @Override + public CleanupPreferences getDefaultCleanupPreset() { + return null; + } + + @Override + public LibraryPreferences getLibraryPreferences() { + return null; + } + + @Override + public DOIPreferences getDOIPreferences() { + return null; + } + + @Override + public OwnerPreferences getOwnerPreferences() { + return null; + } + + @Override + public TimestampPreferences getTimestampPreferences() { + return null; + } + + @Override + public RemotePreferences getRemotePreferences() { + return null; + } + + @Override + public ProxyPreferences getProxyPreferences() { + return null; + } + + @Override + public SSLPreferences getSSLPreferences() { + return null; + } + + @Override + public CitationKeyPatternPreferences getCitationKeyPatternPreferences() { + return null; + } + + @Override + public AutoLinkPreferences getAutoLinkPreferences() { + return null; + } + + @Override + public ExportPreferences getExportPreferences() { + return null; + } + + @Override + public ImporterPreferences getImporterPreferences() { + return null; + } + + @Override + public GrobidPreferences getGrobidPreferences() { + return null; + } + + @Override + public XmpPreferences getXmpPreferences() { + return null; + } + + @Override + public NameFormatterPreferences getNameFormatterPreferences() { + return null; + } + + @Override + public SearchPreferences getSearchPreferences() { + return null; + } + + @Override + public MrDlibPreferences getMrDlibPreferences() { + return null; + } + + @Override + public ProtectedTermsPreferences getProtectedTermsPreferences() { + return null; + } + + @Override + public AiPreferences getAiPreferences() { + return null; + } + + @Override + public LastFilesOpenedPreferences getLastFilesOpenedPreferences() { + return null; + } + + @Override + public OpenOfficePreferences getOpenOfficePreferences(JournalAbbreviationRepository journalAbbreviationRepository) { + return null; + } + + @Override + public PushToApplicationPreferences getPushToApplicationPreferences() { + return null; + } + + @Override + public GitPreferences getGitPreferences() { + return null; + } + }; @Test void checkSimpleLibrary(@TempDir Path tempDir) { @@ -34,8 +282,8 @@ void checkSimpleLibrary(@TempDir Path tempDir) { BibDatabase database = new BibDatabase(List.of(first, second)); BibDatabaseContext bibContext = new BibDatabaseContext(database); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult entryTypeResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); BibliographyConsistencyCheck.Result expected = new BibliographyConsistencyCheck.Result(Map.of(StandardEntryType.Article, entryTypeResult)); @@ -55,8 +303,8 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) { BibDatabase bibDatabase = new BibDatabase(List.of(first, second)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult entryTypeResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.TITLE, customField), List.of(first, second)); BibliographyConsistencyCheck.Result expected = new BibliographyConsistencyCheck.Result(Map.of(StandardEntryType.Article, entryTypeResult)); @@ -88,8 +336,7 @@ void checkComplexLibrary(@TempDir Path tempDir) { BibDatabase bibDatabase = new BibDatabase(List.of(first, second, third, fourth, fifth)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { - }); + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult articleResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); BibliographyConsistencyCheck.EntryTypeResult inProceedingsResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER, StandardField.LOCATION), List.of(fifth, fourth, third)); @@ -111,8 +358,7 @@ void checkLibraryWithoutIssues(@TempDir Path tempDir) { BibDatabase bibDatabase = new BibDatabase(List.of(first, second)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { - }); + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); BibliographyConsistencyCheck.Result expected = new BibliographyConsistencyCheck.Result(Map.of()); assertEquals(expected, result); @@ -132,9 +378,7 @@ void filteredFieldsAreIgnored() { BibDatabase bibDatabase = new BibDatabase(List.of(a, b)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() - .check(bibContext, (_, _) -> { - }); + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); assertEquals(Map.of(), result.entryTypeToResultMap(), "Differences only in filtered fields must be ignored"); @@ -149,9 +393,7 @@ void nonFilteredFieldDifferenceIsReported() { BibDatabase bibDatabase = new BibDatabase(List.of(withAuthor, withoutAuthor)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() - .check(bibContext, (_, _) -> { - }); + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult typeResult = result.entryTypeToResultMap().get(StandardEntryType.Misc); @@ -173,9 +415,7 @@ void unsetRequriedFieldsReported() { BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); bibContext.setMode(BibDatabaseMode.BIBLATEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() - .check(bibContext, (_, _) -> { - }); + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult typeResult = result.entryTypeToResultMap().get(StandardEntryType.Online); @@ -197,9 +437,9 @@ void unsetFieldsReportedInBibtexMode() { BibDatabase bibDatabase = new BibDatabase(List.of(withDate, withoutDate)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() - .check(bibContext, (_, _) -> { - }); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); + BibliographyConsistencyCheck.EntryTypeResult typeResult = result.entryTypeToResultMap().get(StandardEntryType.Online); @@ -234,7 +474,7 @@ void checkFieldEntriesWithFieldDifferences() { new UnknownField("customField"), StandardField.PUBLISHER ); - List result = new BibliographyConsistencyCheck().filterAndSortEntriesWithFieldDifferences( + List result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).filterAndSortEntriesWithFieldDifferences( Set.of(entry1, entry2, entry3, entry4, entry5), differingFields, Set.of(StandardField.AUTHOR, StandardField.TITLE, StandardField.PAGES, StandardField.PDF)); @@ -268,8 +508,7 @@ void checkComplexLibraryWithAdditionalEntry(@TempDir Path tempDir) { BibDatabase bibDatabase = new BibDatabase(List.of(first, second, third, fourth, fifth, sixth)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result actualResult = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { - }); + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager).check(bibContext, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult articleResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); BibliographyConsistencyCheck.EntryTypeResult expectedInProceedings = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER, StandardField.LOCATION, StandardField.YEAR), List.of(fifth, fourth, sixth, third)); diff --git a/jabls/src/main/java/org/jabref/languageserver/util/LspConsistencyCheck.java b/jabls/src/main/java/org/jabref/languageserver/util/LspConsistencyCheck.java index 12609191704..a941a6b5c4f 100644 --- a/jabls/src/main/java/org/jabref/languageserver/util/LspConsistencyCheck.java +++ b/jabls/src/main/java/org/jabref/languageserver/util/LspConsistencyCheck.java @@ -9,6 +9,7 @@ import org.jabref.logic.importer.ParserResult; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.preferences.CliPreferences; import org.jabref.logic.quality.consistency.BibliographyConsistencyCheck; import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.BibEntryTypesManager; @@ -21,10 +22,11 @@ public class LspConsistencyCheck { - public List check(ParserResult parserResult) { + public List check(BibDatabaseContext bibDatabaseContext, String content, CliPreferences cliPreferences) { List diagnostics = new ArrayList<>(); - BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(); - BibliographyConsistencyCheck.Result result = consistencyCheck.check(parserResult.getDatabaseContext(), (_, _) -> { + BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); + BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(cliPreferences, bibEntryTypesManager); + BibliographyConsistencyCheck.Result result = consistencyCheck.check(bibDatabaseContext, (_, _) -> { }); Set allReportedFields = result.entryTypeToResultMap().values().stream() diff --git a/jabls/src/main/java/org/jabref/languageserver/util/LspDiagnosticHandler.java b/jabls/src/main/java/org/jabref/languageserver/util/LspDiagnosticHandler.java index ca5c31d53c8..ef52cd7a059 100644 --- a/jabls/src/main/java/org/jabref/languageserver/util/LspDiagnosticHandler.java +++ b/jabls/src/main/java/org/jabref/languageserver/util/LspDiagnosticHandler.java @@ -32,7 +32,7 @@ public class LspDiagnosticHandler { private static final Logger LOGGER = LoggerFactory.getLogger(LspDiagnosticHandler.class); private static final int NO_VERSION = -1; - private final CliPreferences jabRefCliPreferences; + private final CliPreferences cliPreferences; private final LspIntegrityCheck lspIntegrityCheck; private final LspConsistencyCheck lspConsistencyCheck; private final LspClientHandler clientHandler; @@ -43,7 +43,7 @@ public class LspDiagnosticHandler { public LspDiagnosticHandler(LspClientHandler clientHandler, CliPreferences cliPreferences, JournalAbbreviationRepository abbreviationRepository) { this.clientHandler = clientHandler; - this.jabRefCliPreferences = cliPreferences; + this.cliPreferences = cliPreferences; this.lspIntegrityCheck = new LspIntegrityCheck(cliPreferences, abbreviationRepository); this.lspConsistencyCheck = new LspConsistencyCheck(); this.integrityDiagnosticsCache = new ConcurrentHashMap<>(); @@ -71,8 +71,8 @@ private List computeDiagnostics(String content, String uri) { List diagnostics = new ArrayList<>(); ParserResult parserResult; try { - parserResult = parserResultFromString(content, jabRefCliPreferences.getImportFormatPreferences()); - } catch (JabRefException | IOException e) { + bibDatabaseContext = BibDatabaseContext.of(content, cliPreferences.getImportFormatPreferences()); + } catch (JabRefException e) { Diagnostic parseDiagnostic = LspDiagnosticBuilder.create(Localization.lang( "Failed to parse entries.\nThe following error was encountered:\n%0", e.getMessage())).setSeverity(DiagnosticSeverity.Error).build(); @@ -90,7 +90,7 @@ private List computeDiagnostics(String content, String uri) { } if (clientHandler.getSettings().isConsistencyCheck()) { - consistencyDiagnosticsCache.put(uri, lspConsistencyCheck.check(parserResult)); + consistencyDiagnosticsCache.put(uri, lspConsistencyCheck.check(bibDatabaseContext, content, cliPreferences)); LOGGER.debug("Cached consistency diagnostics for {}", uri); }