File Watcher
Been trying to find a way to make a file watcher to checks a file for changes, and runs of method. But every approach i tried sofar results in the UI of intellij just hanging.
This is what i tried last time
https://gist.github.com/cmcpasserby/1e4699ab2f580d13eb03
Im working with a toolwindow and a consoleView and am instantianting this FileWatcher object in my ToolWindow's activate field by passing in a Runnable that creates my object.
Im guessing there must be some native way to watch for file changes in intellij but not sure how to approach it.
Please sign in to leave a comment.
There are multiple ways to watch for file changes, which work in different ways. What exactly are you trying to accomplish?
What I'm trying to do is watch a log file from a other application for changes, than print those changes to a console view in a new tool window.
Look at the LogConsoleImpl class in the IntelliJ IDEA Community Edition sources. Most likely it already does exactly what you need.
What would be the usage on this, im assuming there is some method i have to override with my own logic, but cant figure it out. Also when using this it seems to mark the file i want it to read from as Read-Only.
edit:
nvm i just forgot to run .activate() on it.
I havent been able to find any samples of how people are using the LogContentProprocessor, it's one method parseLogLine looks pretty simple to implement but i got no clue how to get the proper ConsoleViewContentType as a key to use with LogFragment.
The possible values of ConsoleViewContentType are defined as public static final fields in the ConsoleViewContentType class. You can simply use ConsoleViewContentType.NORMAL_OUTPUT if you don't need any special processing.
I was refering to the a Key type needed in the constructor of
https://github.com/JetBrains/intellij-community/blob/ff16ce78a1e0ddb6e67fd1dbc6e6a597e20d483a/platform/lang-api/src/com/intellij/diagnostic/logging/LogFragment.java
Since I need to return a list of LogFragments in my parseLine method of LogContentPreprocessor.
Or Should I just be overriding the AddMessage method instead of trying to feed it a custom LogContentPreprocessor.
Also thanks you have been a big help with me getting my life head this api.
Ah. Just use ProcessOutputTypes.STDOUT.