diff --git a/src/main/java/org/jabref/logic/bibtex/comparator/BibDatabaseDiff.java b/src/main/java/org/jabref/logic/bibtex/comparator/BibDatabaseDiff.java index 08d6e67899d..5ff9ce40d7d 100644 --- a/src/main/java/org/jabref/logic/bibtex/comparator/BibDatabaseDiff.java +++ b/src/main/java/org/jabref/logic/bibtex/comparator/BibDatabaseDiff.java @@ -30,7 +30,17 @@ private BibDatabaseDiff(BibDatabaseContext originalDatabase, BibDatabaseContext metaDataDiff = MetaDataDiff.compare(originalDatabase.getMetaData(), newDatabase.getMetaData()); preambleDiff = PreambleDiff.compare(originalDatabase, newDatabase); bibStringDiffs = BibStringDiff.compare(originalDatabase.getDatabase(), newDatabase.getDatabase()); + entryDiffs = getBibEntryDiffs(originalDatabase, newDatabase); + if (LOGGER.isDebugEnabled()) { + metaDataDiff.ifPresent(diff -> LOGGER.debug("Metadata differences: {}", diff)); + preambleDiff.ifPresent(diff -> LOGGER.debug("Premble differences: {}", diff)); + LOGGER.debug("BibString differences: {}", bibStringDiffs); + LOGGER.debug("Entry differences: {}", entryDiffs); + } + } + private List getBibEntryDiffs(BibDatabaseContext originalDatabase, BibDatabaseContext newDatabase) { + final List entryDiffs; // Sort both databases according to a common sort key. EntryComparator comparator = getEntryComparator(); List originalEntriesSorted = originalDatabase.getDatabase().getEntriesSorted(comparator); @@ -41,6 +51,7 @@ private BibDatabaseDiff(BibDatabaseContext originalDatabase, BibDatabaseContext newEntriesSorted.removeIf(BibEntry::isEmpty); entryDiffs = compareEntries(originalEntriesSorted, newEntriesSorted, originalDatabase.getMode()); + return entryDiffs; } private static EntryComparator getEntryComparator() { @@ -103,7 +114,6 @@ private static List compareEntries(List originalEntries, || duplicateCheck.isDuplicate(originalEntry, bestEntry, mode)) { matchedEntries.add(bestMatchIndex); differences.add(new BibEntryDiff(originalEntry, newEntries.get(bestMatchIndex))); - LOGGER.debug("Matched {} with {}", originalEntry, newEntries.get(bestMatchIndex)); } else { differences.add(new BibEntryDiff(originalEntry, null)); } diff --git a/src/main/java/org/jabref/logic/bibtex/comparator/BibEntryDiff.java b/src/main/java/org/jabref/logic/bibtex/comparator/BibEntryDiff.java index bcd098a3850..392c66b632f 100644 --- a/src/main/java/org/jabref/logic/bibtex/comparator/BibEntryDiff.java +++ b/src/main/java/org/jabref/logic/bibtex/comparator/BibEntryDiff.java @@ -1,5 +1,7 @@ package org.jabref.logic.bibtex.comparator; +import java.util.StringJoiner; + import org.jabref.model.entry.BibEntry; public class BibEntryDiff { @@ -18,4 +20,12 @@ public BibEntry getOriginalEntry() { public BibEntry getNewEntry() { return newEntry; } + + @Override + public String toString() { + return new StringJoiner(",\n", BibEntryDiff.class.getSimpleName() + "[", "]") + .add("originalEntry=" + originalEntry) + .add("newEntry=" + newEntry) + .toString(); + } } diff --git a/src/main/java/org/jabref/logic/bibtex/comparator/MetaDataDiff.java b/src/main/java/org/jabref/logic/bibtex/comparator/MetaDataDiff.java index 2748be2ec00..be9a0fd8c0d 100644 --- a/src/main/java/org/jabref/logic/bibtex/comparator/MetaDataDiff.java +++ b/src/main/java/org/jabref/logic/bibtex/comparator/MetaDataDiff.java @@ -75,8 +75,7 @@ private void addToListIfDiff(List changes, DifferenceType difference if (isDefaultContentSelectors(originalContentSelectors) && isDefaultContentSelectors(newContentSelectors)) { return; } - } - if (differenceType == DifferenceType.GROUPS) { + } else if (differenceType == DifferenceType.GROUPS) { Optional originalGroups = (Optional) originalObject; Optional newGroups = (Optional) newObject; if (isDefaultGroup(originalGroups) && isDefaultGroup(newGroups)) { @@ -137,6 +136,7 @@ public String toString() { "groupDiff=" + groupDiff + ", originalMetaData=" + originalMetaData + ", newMetaData=" + getNewMetaData() + + ", getDifferences()=" + getDifferences(new GlobalCitationKeyPatterns(CitationKeyPattern.NULL_CITATION_KEY_PATTERN)) + '}'; } } diff --git a/src/main/java/org/jabref/logic/bibtex/comparator/PreambleDiff.java b/src/main/java/org/jabref/logic/bibtex/comparator/PreambleDiff.java index 2308a8d80c6..a89ab3c88ef 100644 --- a/src/main/java/org/jabref/logic/bibtex/comparator/PreambleDiff.java +++ b/src/main/java/org/jabref/logic/bibtex/comparator/PreambleDiff.java @@ -50,4 +50,12 @@ public boolean equals(Object other) { public int hashCode() { return Objects.hash(originalPreamble, newPreamble); } + + @Override + public String toString() { + return "PreambleDiff{" + + "originalPreamble='" + originalPreamble + '\'' + + ", newPreamble='" + newPreamble + '\'' + + '}'; + } } diff --git a/src/main/resources/tinylog.properties b/src/main/resources/tinylog.properties index db3d8db17fb..ff04b1806ef 100644 --- a/src/main/resources/tinylog.properties +++ b/src/main/resources/tinylog.properties @@ -11,3 +11,5 @@ exception = strip: jdk.internal level@org.jabref.gui.maintable.PersistenceVisualStateTable = debug level@org.jabref.http.server.Server = debug + +level@org.jabref.logic.bibtex.comparator.BibDatabaseDiff = debug