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

Support for exporting to YAML format #7007

Merged
merged 16 commits into from
Oct 22, 2020
Merged

Support for exporting to YAML format #7007

merged 16 commits into from
Oct 22, 2020

Conversation

joethei
Copy link
Contributor

@joethei joethei commented Oct 12, 2020

@joethei joethei marked this pull request as draft October 12, 2020 17:08
@joethei joethei marked this pull request as ready for review October 12, 2020 17:24
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Some nitpicks remaining. The empty line fix should have gone in a separate PR as discussions on regular expressions typically take more time. Let's see if it goes well, here.

Could you also add a test case for the example at #6974? I think, there could be issues at the date export. - Maybe good for a follow-jup PR?

@@ -278,8 +269,12 @@ public void export(final BibDatabaseContext databaseContext, final Path file,
// Write the entry
if (layout != null) {
if (deleteBlankLines) {
String withoutBlankLines = BLANK_LINE_MATCHER.matcher(layout.doLayout(entry, databaseContext.getDatabase())).replaceAll("");
ps.write(withoutBlankLines);
String[] lines = layout.doLayout(entry, databaseContext.getDatabase()).split("\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double check: Does this work on Windows and Linux equally well? Mayybe OS.NEW_LINE should be used?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative implementation could have been to update the regular expression. I am really not sure why it stopped working.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly enough when using OS.NEW_LINE on Windows its breaks.
need to do an test on linux though, currently having problems running my vm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should check both? We don't know which line endings the user has in the template files (if modified)

@koppor
Copy link
Member

koppor commented Oct 14, 2020

I see the unit tests failing:

  Test exportCorrectContent(Path) FAILED

  org.opentest4j.AssertionFailedError: expected: <[---, references:, - id: test,   author:,   - literal: "Test Author",   title: "Test Title",   issued: 2020,   url: http://example.com, ---]> but was: <[---, references:, - id: test  author:  - literal: "Test Author"  title: "Test Title"  issued: 2020  url: http://example.com---]>
      at org.jabref.logic.exporter.YamlExporterTest.exportCorrectContent(YamlExporterTest.java:77)

Could you please check what's going wrong there?

@joethei
Copy link
Contributor Author

joethei commented Oct 14, 2020

I see the unit tests failing:

  Test exportCorrectContent(Path) FAILED

  org.opentest4j.AssertionFailedError: expected: <[---, references:, - id: test,   author:,   - literal: "Test Author",   title: "Test Title",   issued: 2020,   url: http://example.com, ---]> but was: <[---, references:, - id: test  author:  - literal: "Test Author"  title: "Test Title"  issued: 2020  url: http://example.com---]>
      at org.jabref.logic.exporter.YamlExporterTest.exportCorrectContent(YamlExporterTest.java:77)

Could you please check what's going wrong there?

I already fixed that issue in my local branch, currently testing the blank line deletion.

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Oct 17, 2020
Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got three nitpicks.
Thanks for the good work so far.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for delay. Hope, you are still in the context. I have some micro comments...

package org.jabref.logic.exporter;

/**
this enum represents the behaviour for blank lines in {@link TemplateExporter}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full JavaDoc 😇

Suggested change
this enum represents the behaviour for blank lines in {@link TemplateExporter}
* This enum represents the behaviour for blank lines in {@link TemplateExporter}

private static final String LAYOUT_EXTENSION = ".layout";
private static final String FORMATTERS_EXTENSION = ".formatters";
private static final String BEGIN_INFIX = ".begin";
private static final String END_INFIX = ".end";


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not add two empty lines - I wonder why checkstyle did not complain

@Override
public String format(String value) {
Map<String, String> map = Map.of(StandardEntryType.Article.getDisplayName(), "article",
StandardEntryType.Book.getDisplayName(), "book",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple switch was not possible

  return switch(value) {
     case StandardEntryType.Article.getDisplayName() -> "article",
     ...
     case StandardEntryType.Conference.getDisplayName() -> "paper-conference",
     ...
     default -> "no-type";
  }

@koppor koppor changed the title support for exporting to YAML format. Support for exporting to YAML format Oct 22, 2020
@koppor koppor merged commit 7f4c36c into JabRef:master Oct 22, 2020
@koppor
Copy link
Member

koppor commented Oct 22, 2020

Thank you for the patience @joethei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alternative serialization format as core data file (e.g. YAML in addition to BibTeX)
4 participants