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

Preserve user comments in bib file #1471

Merged
merged 38 commits into from
Jul 14, 2016
Merged

Preserve user comments in bib file #1471

merged 38 commits into from
Jul 14, 2016

Conversation

lenhard
Copy link
Member

@lenhard lenhard commented Jun 3, 2016

So I am finally having my take at #1026. The current solution was surprisingly easy so far (despite what I had written before). It looks explicitly for our encoding prefix in the file ("Encoding: ") and kills lines that contain it (but only lines preceding an entry, it will not delete something that is inside an entry). Other user comments are left untouched and are always written out again, even if the entry is reformatted.

User comments that are above meta data, bibtex strings, or the preamble will still be removed, though. Changing that would require large scale changes to these items in our model, since we would also need to store the parsed serialization for them, which we do not do so far.

This should receive significant automated, but also manual, testing, since it modifies a quite critical part and has the potential to destroy bib files. I will add a few more tests for this PR.

  • Change in CHANGELOG.md described
  • Tests created for changes

@lenhard lenhard force-pushed the preserve-comments branch from e00aeae to 14db4bf Compare June 8, 2016 14:05
@lenhard
Copy link
Member Author

lenhard commented Jun 8, 2016

Ok, I'd like to put this up for discussion.

User comments are now kept under the following circumstances:

  • Above any BibEntry
  • Above any BibtexString
  • Comments at the end of the file

This is independent of whether an entry is changed/reformatted, but not if it is deleted. If it is reformated, user comment text is located exactly one blank line above the reformated entry.

User comments are still not kept when:

  • Above meta data comments
  • Above the Preamble
  • Contains JabRef's ENCODING_PREFIX
  • Above an entry that has been deleted

Is this good enough? It should be sufficient in most scenarios and work if someone opens his non-JabRef bib file with JabRef. If someone starts adding arbitrary text between JabRef's Metadata, though... The latter is hard to achieve since we do not store the serialization of MetaData. If we want to, I'd have to make some additions to our MetaData objects. I could also store the comments between meta data and add them as a bunch at the end of the file, but then the relative position gets lost. Before I do more work, I'd like to clarify the following points:

  • Does the storage of arbitrary text above MetaData really matter?
  • Is it ok to delete comments if the entry below them is deleted?

@lenhard lenhard added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jun 8, 2016
@@ -12,6 +12,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- JabRef does no longer delete user comments outside of BibTeX entries [#1026]
Copy link
Member

Choose a reason for hiding this comment

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

Change format of changelog entry to match the other ones.

@simonharrer
Copy link
Contributor

LGTM. I think integration tests are more valuable. So this would suffice for me.

@lenhard
Copy link
Member Author

lenhard commented Jul 11, 2016

Great! Let us talk briefly about this during the next devcall and decide if we take it into 3.5 or 3.6.

@tobiasdiez
Copy link
Member

For 3.6

@tobiasdiez tobiasdiez added this to the v3.6 milestone Jul 13, 2016
@@ -369,7 +369,7 @@ return true;</string>
</serializedBean>
<condition>context.getBooleanVariable("addToDockAction")</condition>
</action>
<group name="Registry" id="239" customizedId="" beanClass="com.install4j.runtime.beans.groups.ActionGroup" enabled="true" commentSet="false" comment="" actionElevationType="inherit">
<group name="Registry" id="239" customizedId="" beanClass="com.install4j.runtime.beans.groups.ActionGroup" enabled="true" commentSet="false" comment="" actionElevationType="elevated">
Copy link
Member

Choose a reason for hiding this comment

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

Why is an install4j change part of this PR?

Copy link
Member

Choose a reason for hiding this comment

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

I revert it later, sorry...

stefan-kolb and others added 5 commits July 13, 2016 14:21
This reverts commit 67a4885.
# Conflicts:
#	CHANGELOG.md
#	src/main/java/net/sf/jabref/model/entry/BibEntry.java
/*
* Returns user comments (arbitrary text before the string) if there are any. If not returns the empty string
*/
public String getUserComments() {
Copy link
Member

Choose a reason for hiding this comment

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

This is now an exact copy of BibEntry.getUserComments right? Maybe add a superclass BibItem containing this method and then BibEntry and BibString derive from this superclass (maybe there is even more common code which could be extracted to the super class)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to always slip into the role of your antagonist, but I am against creating a class hierarchy. In most cases, it makes the code harder to understand, and the code duplication savings are just not worth the effort. In addition, one has to adhere to the liskov substitution principle to create a good class hierarchy, but this is hard to do right.

Copy link
Member

Choose a reason for hiding this comment

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

No problem, having an experienced antagonist is probably the best way to learn something 😄

So now ignoring everything about the actual implementation and only speaking about "business objects": There are different items which can be contained in a bib file. For example @Comments, @Strings and normal bib entries. They all have a similar structure (e.g begin with @, followed by some identifier and then braces which surround the actual content) and all of them could have some text comments in front of them. Thus there is also a common behavior when it comes to parsing and writing.
So how would my deer antagonist reflect this common structure and behavior in java code?

My idea would be: BibString, BibEntry, BibComment all derive from BibItem. BibItem has methods to parse and write at least the form @something { abstract method to parse / write value }. Then the writer just gets a list of BibItems and invokes the write method on them. Similarly the parser returns a list of BibItems while the parsing of every item was done in the subclass. But again...this idea somehow corresponds from a service implementation to a full-blown domain model....so yeah, maybe we should discuss this in the next dev call ;-)

@stefan-kolb
Copy link
Member

@lenhard Please squash the commits via Github when merging this 😄


BibEntry entry = entries.iterator().next();
assertEquals("test", entry.getCiteKey());
Copy link
Member

Choose a reason for hiding this comment

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

Why did you removed this (suboptimal) assertions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you being serious? In this very same PR you asked me to reduce the number asserts as far as possible, aiming for one assertion per test. This is the reason.

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 type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants