Skip to content

Commit

Permalink
Write customized types in alphabetical order (#5663)
Browse files Browse the repository at this point in the history
* Write customized types in alphabetical order

* Update CHANGELOG.md
  • Loading branch information
tobiasdiez authored Nov 27, 2019
1 parent 917defc commit 783b3bb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -157,7 +157,7 @@ public void savePartOfDatabase(BibDatabaseContext bibDatabaseContext, List<BibEn
}

// Map to collect entry type definitions that we must save along with entries using them.
Set<BibEntryType> typesToWrite = new HashSet<>();
Set<BibEntryType> typesToWrite = new TreeSet<>();

// Some file formats write something at the start of the file (like the encoding)
if (preferences.getSaveType() != SavePreferences.DatabaseSaveType.PLAIN_BIBTEX) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 783b3bb

Please sign in to comment.