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

Test case for ioob (and some code cleanup) #10399

Merged
merged 18 commits into from
Sep 19, 2023
Merged

Test case for ioob (and some code cleanup) #10399

merged 18 commits into from
Sep 19, 2023

Conversation

koppor
Copy link
Member

@koppor koppor commented Sep 18, 2023

This adds src/test/java/org/jabref/gui/maintable/MainTableDataModelTest for checking that in a "controlled" environment, all listeners are installed correctly. - It is a copy of the UI code. However, in JabRef, the UI does not behave the same.

While I was on it, some minor code improvements were made.

Follow up to #10389

More things added

  • Comparators fixed: null is smaller than something in
  • CRLF handling on non-Windows machines

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@koppor koppor added the dev: code-quality Issues related to code or architecture decisions label Sep 18, 2023
package org.jabref.gui.maintable;

import java.util.List;
import java.util.stream.Collectors;
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck> reported by reviewdog 🐶
Unused import - java.util.stream.Collectors.

import java.util.stream.Collectors;

import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck> reported by reviewdog 🐶
Unused import - javafx.beans.Observable.

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck> reported by reviewdog 🐶
Unused import - javafx.beans.value.ObservableValue.

import com.tobiasdiez.easybind.EasyBind;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck> reported by reviewdog 🐶
Using the '.' form of import should be avoided - org.junit.jupiter.api.Assertions..

@github-actions
Copy link
Contributor

Your code currently does not meet JabRef's code guidelines. The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR. Please carefully follow the setup guide for the codestyle. Afterwards, please run checkstyle locally and fix the issues.

More information on code quality in JabRef is available at https://devdocs.jabref.org/getting-into-the-code/development-strategy.html.

@@ -65,8 +65,7 @@ public void bindToEntry(BibEntry entry) {
fieldBinding,
newValue -> {
if (newValue != null) {
// Controlsfx uses hardcoded \n for multiline fields, but JabRef stores them in OS Newlines format
String oldValue = entry.getField(field).map(value -> value.replace(OS.NEWLINE, "\n").trim()).orElse(null);
String oldValue = entry.getField(field).map(String::trim).orElse("");
Copy link
Member

Choose a reason for hiding this comment

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

The source field always uses \n as separator internally. We need this check to prevent the change detection

Copy link
Member Author

Choose a reason for hiding this comment

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

The source field always uses \n as separator internally.

I saw it in the debugger.

Therefore

value.replace(OS.NEWLINE, "\n")

is a no-op.

Reason:

Let's split up the cases.

  • OS.NEWLINE is \r\n. Since "**always uses \n **" is true, \r\n is never matched. So no replacement is made
  • OS.NEWLINE is \n. Since "**always uses \n **" is true, \n is replaced by \n. It is replaced by the same character. The identity. Thus, no change.

Did I miss something?

Side note: During the file write, the newlines are now normalized. The whole file does have the same newline separator. It came in with #8238.

Copy link
Member

@Siedlerchr Siedlerchr Sep 19, 2023

Choose a reason for hiding this comment

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

Yes, we have to compare old entry and new Entry.
New entry is what controlsfx uses.
Old Entry however is what comes from the stored bib file, might have had OS.Newline -> Replaced with \n and compare with new entry from source tab so that we don't create a diff "database changed"

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that I kept the trim.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but that does not unify OS.newline

  1. If I have a bib file with OS.newline chars e.-g \r\n and now I change the bibtex source -> This will trigger a change

Copy link
Member Author

Choose a reason for hiding this comment

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

OMG. Thus, if you open the attached file (CRLF terminators), go into the comment field, the cursor will jump?

crlf.bib.txt

I now hard-coded CRLF in the code (instead of relying on OS.Newline)

Copy link
Member

Choose a reason for hiding this comment

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

That's why we replace the chars.

// A file may be loaded using CRLF. ControlsFX uses hardcoded \n for multiline fields.
// Normalizing is done during writing of the .bib file (see org.jabref.logic.exporter.BibWriter.BibWriter).
// Thus, we need to normalize the line endings.
String oldValue = entry.getField(field).map(value -> value.replace("\r\n", "\n").trim()).orElse(null);
Copy link
Member

Choose a reason for hiding this comment

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

OS.Newline please as mac only uses \r

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought, that was Mac OS 9 and earlier: Source https://stackoverflow.com/a/13295575/873282. Mac OS 9 was EOL in 2001.

More sources: https://de.wikipedia.org/wiki/Zeilenvorschub#Computer links to https://de.wikipedia.org/wiki/Mac_OS_(Classic) for \r as line separator.

Please double check if we really need to support \r. I would really consider it being outdated!


My case illustrated by crlf.bib is as follows:

  • A Windows user edits a file using their favourit editor.
  • The editor stores CRLF
  • The file is sent to a Linux user
  • The Linux user opens the file and positions the cursor in the comment field
  • Autosave triggers
  • Cursor moves (this is described in the comments why we need these checks)

If I do not overlook something: OS.Newline does not help: OS.Newline is \n on Linux. The file uses \r\n (because it was created on Windows). - In other words: OS.Newline is dependent on the current operating system and not on the operating system the .bib file was created.

I could route through org.jabref.model.database.BibDatabase#getNewLineSeparator to org.jabref.gui.fieldeditors.AbstractEditorViewModel#bindToEntry. This seems to be too much effort for the gain that \r\n is supported.

Copy link
Member

@Siedlerchr Siedlerchr Sep 19, 2023

Choose a reason for hiding this comment

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

Yes, but Excel export to CSV still uses CR. :-P

W.T.F...

Copy link
Member Author

Choose a reason for hiding this comment

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

@Siedlerchr
Copy link
Member

Error: eckstyle] [ERROR] /home/runner/work/jabref/jabref/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java:16:8: Unused import - org.jabref.logic.util.OS. [UnusedImports]

Siedlerchr
Siedlerchr previously approved these changes Sep 19, 2023
@koppor koppor enabled auto-merge September 19, 2023 12:07
@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 2023

The build for this PR is no longer available. Please visit https://builds.jabref.org/main/ for the latest build.

@koppor koppor disabled auto-merge September 19, 2023 12:39
@koppor koppor merged commit aad9618 into main Sep 19, 2023
@koppor koppor deleted the work-in-ioob branch September 19, 2023 12:39
lbenicio pushed a commit to lbenicio/jabref that referenced this pull request Sep 26, 2023
Co-authored-by: Christoph <siedlerkiller@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev: code-quality Issues related to code or architecture decisions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants