diff --git a/CHANGELOG.md b/CHANGELOG.md index 9da117cf0bc..9318eeeb021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We added an option to show the preview as an extra tab in the entry editor (instead of in a split view). [#5244](https://github.com/JabRef/jabref/issues/5244) - A custom Open/LibreOffice jstyle file now requires a layout line for the entry type `default` [#5452](https://github.com/JabRef/jabref/issues/5452) - The entry editor is now open by default when JabRef starts up. [#5460](https://github.com/JabRef/jabref/issues/5460) +- Customized entry types are now serialized in alphabetical order in the bib file. - We added a new ADS fetcher to use the new ADS API [#4949](https://github.com/JabRef/jabref/issues/4949) - We added support of the [X11 primary selection](https://unix.stackexchange.com/a/139193/18033) [#2389](https://github.com/JabRef/jabref/issues/2389) - We added support to switch between biblatex and bibtex library types. [#5550](https://github.com/JabRef/jabref/issues/5550) diff --git a/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java b/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java index ee643f1ced7..94a8beb41c1 100644 --- a/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java +++ b/src/main/java/org/jabref/logic/exporter/BibDatabaseWriter.java @@ -7,13 +7,13 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -157,7 +157,7 @@ public void savePartOfDatabase(BibDatabaseContext bibDatabaseContext, List typesToWrite = new HashSet<>(); + Set typesToWrite = new TreeSet<>(); // Some file formats write something at the start of the file (like the encoding) if (preferences.getSaveType() != SavePreferences.DatabaseSaveType.PLAIN_BIBTEX) { diff --git a/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java b/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java index 0ec73d0ceac..f6ee7f5c92b 100644 --- a/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java +++ b/src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java @@ -287,6 +287,38 @@ void writeEntryWithCustomizedTypeAlsoWritesTypeDeclaration() throws Exception { + "@Comment{jabref-entrytype: customizedtype: req[author;date;title] opt[month;publisher;year]}" + OS.NEWLINE, stringWriter.toString()); } + + @Test + void writeCustomizedTypesInAlphabeticalOrder() throws Exception { + EntryType customizedType = new UnknownEntryType("customizedType"); + EntryType otherCustomizedType = new UnknownEntryType("otherCustomizedType"); + BibEntryType customizedBibType = new BibEntryType( + customizedType, + Collections.singletonList(new BibField(StandardField.TITLE, FieldPriority.IMPORTANT)), + Collections.singletonList(new OrFields(StandardField.TITLE))); + BibEntryType otherCustomizedBibType = new BibEntryType( + otherCustomizedType, + Collections.singletonList(new BibField(StandardField.TITLE, FieldPriority.IMPORTANT)), + Collections.singletonList(new OrFields(StandardField.TITLE))); + entryTypesManager.addCustomOrModifiedType(otherCustomizedBibType, BibDatabaseMode.BIBTEX); + entryTypesManager.addCustomOrModifiedType(customizedBibType, BibDatabaseMode.BIBTEX); + BibEntry entry = new BibEntry(customizedType); + BibEntry otherEntry = new BibEntry(otherCustomizedType); + database.insertEntry(otherEntry); + database.insertEntry(entry); + + databaseWriter.savePartOfDatabase(bibtexContext, Arrays.asList(entry, otherEntry)); + + assertEquals( + OS.NEWLINE + + "@Customizedtype{," + OS.NEWLINE + "}" + OS.NEWLINE + OS.NEWLINE + + "@Othercustomizedtype{," + OS.NEWLINE + "}" + OS.NEWLINE + OS.NEWLINE + + "@Comment{jabref-meta: databaseType:bibtex;}" + + OS.NEWLINE + OS.NEWLINE + + "@Comment{jabref-entrytype: customizedtype: req[title] opt[]}" + OS.NEWLINE + OS.NEWLINE + + "@Comment{jabref-entrytype: othercustomizedtype: req[title] opt[]}" + OS.NEWLINE, + stringWriter.toString()); + } @Test void roundtripWithArticleMonths() throws Exception {