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

Add directory monitor for Latex citations #11245

Merged
merged 11 commits into from Apr 29, 2024
Merged

Conversation

LoayGhreeb
Copy link
Contributor

Closes #10585.

  • Added directory monitor to automatically update LaTeX citations when a LaTeX file is created, removed, or modified.
  • Ignored parsing nested files (include or input commands). All .tex files in the selected directory and its subdirectories are parsed. This will be okay if there are no include commands referencing files outside the selected directory.
  • How can I set a listener for the citation key changes? This is needed to update the citation list without selecting another entry and coming back again if the cite key changes.
preview.mp4

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.

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.

Oh, wow! Did not expect that much changes to fix the code.

Very minor comments. Need to try out and to read the code inside IntelliJ.

I think, tests are hard for that one; thus it is OK not to have any test. -- However, maybe with @tempdir and some files.write things there could be tests?

Comment on lines 113 to 115
if (stateManager.getDirectoryMonitor() != null) {
stateManager.getDirectoryMonitor().shutdown();
}
Copy link
Member

Choose a reason for hiding this comment

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

@calixtus Can you check if the file DirectoryMonitor should reside in StateManager or if we should move it to Globals (similar to fileUpdateMonitor).

Copy link
Member

@calixtus calixtus Apr 25, 2024

Choose a reason for hiding this comment

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

Neither.

Globals is deprecated and is annoted as such. It shall not be used at all. We are working towards dissolving that class.

StateManager is not the new Globals.
The directory manager should be injected by constructor or in a view by the viewloader.

Copy link
Member

Choose a reason for hiding this comment

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

Can the File update monitor and the DirectoryMonitor be merged to a more generic class?

Copy link
Member

Choose a reason for hiding this comment

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

Note that Globals points to StateManager:

/**
 * @deprecated try to use {@link StateManager} and {@link org.jabref.preferences.PreferencesService}
 */

We need a "Global" DirectoryMonitor. Would you place it in org.jabref.gui.DefaultInjector and then add a shutdown method to it?

We need to have a full lifecycle of DirectoryMonitor. Creation, running, and shutdown. There currently is no migration guide at org.jabref.gui.Globals#shutdownThreadPools

To keep things going, I vote to move the currently directoryMonitor code into Globals and do a refactoring towards dependency injection afterwards.


Also the more generic ones migration away from FileUpdateMonitor to Apache Commons IO or other classes should be done later. Otherwise, IMHO the PR blows up only because of "clean code".


Side comment: Injector.registerExistingAndInject(this); is a neat thing. I wonder why we don't use that more often :p.

Copy link
Member

Choose a reason for hiding this comment

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

Lets go for Globals and then refactor it afterwards, so this PR keeps its focus,

src/main/java/org/jabref/model/util/DirectoryMonitor.java Outdated Show resolved Hide resolved
src/main/java/org/jabref/model/util/DirectoryMonitor.java Outdated Show resolved Hide resolved
@LoayGhreeb
Copy link
Contributor Author

I think, tests are hard for that one; thus it is OK not to have any test. -- However, maybe with @tempdir and some files.write things there could be tests?

Thinking about testing, what aspects we should cover?

  • Should we test that the listener works after a modification in a file? In my opinion, this is not necessary as it is already handled by Apache Commons IO.
  • Do we need to test the parser result after a modification in a file? This is already tested in the LaTeX parser.

What are your thoughts on this?

@koppor
Copy link
Member

koppor commented Apr 25, 2024

What are your thoughts on this?

I was thinking about more an "integration test" (or "system test" how JavaFX calls it; or "End-to-end test"). The separate parts are tested, but the combination you are doing in this PR is not tested.

@koppor
Copy link
Member

koppor commented Apr 25, 2024

Tried out, works great!

@koppor koppor added this pull request to the merge queue Apr 29, 2024
Merged via the queue into JabRef:main with commit 70b7748 Apr 29, 2024
26 of 27 checks passed
@LoayGhreeb LoayGhreeb deleted the DirectoryMonitor branch April 29, 2024 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add FileMonitor for LaTeX citations
3 participants