how to detect android studio file modification events

458 views Asked by At

I need to visualize how a project develops over time.

I have used this: https://docs.oracle.com/javase/tutorial/essential/io/notification.html#overview as basis for detecting when any project file has been modified locally.

The current setup is Android Studio on windows 7. And my problem is that the java.nio.file.StandardWatchEventKinds from the example only gets fired when the programmer manually does a "ctrl-s". How do I detect Android Studios file modifications realtime?.

My fallback approach is to to set a timer an traverse all files. But i'd rather if I could just catch the appropriate file.

EDIT: solved with an IntelliJ plugin, took me 1/2 day.

first the tutorial from: https://confluence.jetbrains.com/display/IDEADEV/Getting+Started+with+Plugin+Development#GettingStartedwithPluginDevelopment-anchor3

and using the menuaction to start/stop a BulkFileListener:

public class Watcher implements BulkFileListener {

private final MessageBusConnection connection;

public Watcher() {
    connection = ApplicationManager.getApplication().getMessageBus().connect();
}

public void initComponent() {
    connection.subscribe(VirtualFileManager.VFS_CHANGES, this);
 }

public void disposeComponent() {
   connection.disconnect();
}

@Override
public void before(List<? extends VFileEvent> events) {
   //logging done
}

@Override
public void after(List<? extends VFileEvent> events) {
    //logging done
}
}

placed the . jar in ...\JetBrains\IntelliJ IDEA Community Edition 14.1.3\plugins and imported as instructed in the tutorial.

0

There are 0 answers