Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write customized types in alphabetical order #5663

Merged
merged 2 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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