Synchronously saving a document in a CheckinHandler
I've got a CheckinHandler which modifies files before check-in in its beforeCheckin method. Everything works fine if the files to check-in are not opened in IDEA. If a file is opened in an editor, the modifications I made are not serialized to the SCM, but only appear in the editor and the change list still shows a local change.
I tried to manually commit my changes with
FileDocumentManager.getInstance().saveDocument(aEditor.getDocument());
(call executes in a write action, wrapped in a CommandProcessor.executeCommand runnable).
Still no luck. The document is saved, but it seems that the call to saveDocument is not performed synchronously. I've verified the contents before and after the call and they are exactly the same.
Next thing I tried was
FileContentUtil.setFileText(project, aFile, getText());
but with the same result.
As a last resort, I've manually replaced the file contents via
OutputStream out = file.getOutputStream(ApplicationManager.getApplication());
Writer w = new BufferedWriter(new OutputStreamWriter(out, aFile.getEncoding()));
...
and that worked. But now I'm getting a dreaded dialog that informs me about a file cache conflict and asks whether I want to load the filesystem changes or keep the memory changes. I can accept the file change and the file is correctly commited, but a confirmation dialog for every file that will be checked-in is certainly a no-go.
The Javadoc of VirtuallFile#getOutputStream vaguely indicates that if a requestor is given, the change won't be considered external. I tried various objects as the requestor reference, but to no avail. Documentation is non-existent at this point and I'm running out of options.
I'm using IDEA 7.0.1 on Windows XP/Sun Java 6.0_03.
Can anybody shed some light here? I appreciate any comments. Thanks in advance.
Best regards,
Marco Hunsicker
Please sign in to leave a comment.