-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
394aa80
Add directory monitor
LoayGhreeb f0ef69a
Ignore parsing nested files
LoayGhreeb 87b6393
Add listener for LaTex directory, update LatexCitationsTab
LoayGhreeb ec86de5
Update CHANGELOG.md
LoayGhreeb d4f405c
Decision record
LoayGhreeb a5974d2
Refine ADR-030
koppor 3e40c0e
Update module-info.java
koppor 6fdb044
handle non-existing directories
LoayGhreeb 1da2890
Java Doc
LoayGhreeb a5e1605
Java Doc
LoayGhreeb bf073d2
Move directoryMonitor to Globals
LoayGhreeb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
docs/decisions/0030-use-apache-commons-io-for-directory-monitoring.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
nav_order: 30 | ||
parent: Decision Records | ||
--- | ||
# Use Apache Commons IO for directory monitoring | ||
|
||
## Context and Problem Statement | ||
|
||
In JabRef, there is a need to add a directory monitor that will listen for changes in a specified directory. | ||
|
||
Currently, the monitor is used to automatically update the [LaTeX Citations](https://docs.jabref.org/advanced/entryeditor/latex-citations) when a LaTeX file in the LaTeX directory is created, removed, or modified ([#10585](https://github.com/JabRef/jabref/issues/10585)). | ||
Additionally, this monitor will be used to create a dynamic group that mirrors the file system structure ([#10930](https://github.com/JabRef/jabref/issues/10930)). | ||
|
||
## Considered Options | ||
|
||
* Use [java.nio.file.WatchService](https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/WatchService.html) | ||
* Use [io.methvin.watcher.DirectoryWatcher](https://github.com/gmethvin/directory-watcher) | ||
* Use [org.apache.commons.io.monitor](https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/monitor/package-summary.html) | ||
|
||
## Decision Outcome | ||
|
||
Chosen option: "Use [org.apache.commons.io.monitor](https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/monitor/package-summary.html)", because comes out best (see below). | ||
|
||
## Pros and Cons of the Options | ||
|
||
### java.nio.file.WatchService | ||
|
||
* Good, because it is a standard Java API for watching directories. | ||
* Good, because it does not need polling, it is event-based for most operating systems. | ||
* Bad, because: | ||
1. Does not detect files coming together with a new folder (JDK issue: [JDK-8162948](https://bugs.openjdk.org/browse/JDK-8162948)). | ||
2. Deleting a subdirectory does not detect deleted files in that directory. | ||
3. Access denied when trying to delete the recursively watched directory on Windows (JDK issue: [JDK-6972833](https://bugs.openjdk.org/browse/JDK-6972833)). | ||
4. Implemented on macOS by the generic `PollingWatchService`. (JDK issue: [JDK-8293067](https://bugs.openjdk.org/browse/JDK-8293067)) | ||
|
||
### io.methvin.watcher.DirectoryWatcher | ||
|
||
* Good, because it implemented on top of the `java.nio.file.WatchService`, which is a standard Java API for watching directories. | ||
* Good, because it resolves some of the issues of the `java.nio.file.WatchService`. | ||
* Uses`ExtendedWatchEventModifier.FILE_TREE` on Windows, which resolves issues (1, 3) of the `java.nio.file.WatchService`. | ||
* On macOS have native implementation based on the Carbon File System Events API, this resolves issue (4) of the `java.nio.file.WatchService`. | ||
* Bad, because issue (2) of the `java.nio.file.WatchService` is not resolved. | ||
|
||
### org.apache.commons.io.monitor | ||
|
||
* Good, because there are no observed issues. | ||
* Good, because can handle huge amount of files without overflowing. | ||
* Bad, because it uses a polling mechanism at fixed intervals, which can waste CPU cycles if no change occurs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 inStateManager
or if we should move it toGlobals
(similar tofileUpdateMonitor
).There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
:We need a "Global" DirectoryMonitor. Would you place it in
org.jabref.gui.DefaultInjector
and then add ashutdown
method to it?We need to have a full lifecycle of
DirectoryMonitor
. Creation, running, and shutdown. There currently is no migration guide atorg.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.There was a problem hiding this comment.
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,