[SOLVED] How to synchronize a copy project in the background using JavaElementDeltas? [message #648109] |
Tue, 11 January 2011 09:20 |
Kivanc Muslu Messages: 153 Registered: November 2010 |
Senior Member |
|
|
For people who are interested with a better sync (without needing to save), please see this post: http://www.eclipse.org/forums/index.php?t=msg&th=203265& amp;S=b5d5c7bdcea0b480fec5983a64c3aa1c
Note: I had posted a very similar message to Eclipse JDT Forums and someone recommended me to post here also.
Hi all,
Let's say that I have created a copy of a project (IProject) using IProject.copy(). I want this copy to be in sync with the original project as the user changes the original project.
Looking at the Eclipse API I have seen
JavaCore.addElementChangedListener(IElementChangedListener listener);
This is pretty interesting and works fine for getting all the changes done to the project as ElementChangedEvents. I can event get JavaElementDeltas (and I presume that Deltas represent the exact change between two versions of the project), however my problem is that I cannot find a way to apply these deltas to the project.
So my question(s):
1-) Is there a way to apply a JavaElementDelta to a project (IProject)? (I assume that if I apply all the deltas I got from the original project to the copy project, they will always be in sync)
2-) If yes to 1, is it possible to apply a JavaElementDelta generated by an IProject (let's say project1) to another IProject (project2, in my case the copy project)?
3-) Is there another way to do what I want to do (i.e., keep 2 projects in sync textually)? (as long as it is doable and uses Eclipse API, it doesn't matter if it is hard, easy, hacky or etc.)?
Thanks a lot in advance, regards,
[Updated on: Thu, 27 January 2011 13:18] Report message to a moderator
|
|
|
Re: How to synchronize a copy project in the background using JavaElementDeltas? [message #648179 is a reply to message #648109] |
Tue, 11 January 2011 16:18 |
Konstantin Komissarchik Messages: 1077 Registered: July 2009 |
Senior Member |
|
|
Two answers for you...
1. You may be able to use linked folders instead of actually copying files. With linked folders you can have two projects include the same physical folder on disk. Create the projects. The in the new folder wizard, hit the advanced button and go from there. I have used this feature before to x-compile the same code against different versions of a library (N separate projects).
2. If you do need actual physical copying, take a look at IResourceChangeListener and IWorkspace.addResourceChangeListener() API instead. This API deals with changes at file level, so it sounds more appropriate for your problem. You will still get a delta in your listener.
I have never seen any way to apply a delta, but writing apply logic should be pretty trivial. After all, you are being told exactly what has changed. Several things to keep in mind:
A. Make sure that your plugin is configured to auto-start. You want to get your listener added as quickly as possible; before any changes are made and events could be missed. Even with auto-start, there is a risk that you will miss changes, so I would recommend performing a diff of projects on plugin startup and reconciling changes before going into the listening mode. Make sure to do the initial diff/reconcile in a Job. Don't block plugin startup.
B. You will likely want to filter out certain directories from your synchronization, such as the Java output directory where the class files are written. Filter out project metadata files as well.
C. Make sure that you are using Eclipse resources API (IFile and IFolder) instead of Java IO for all of your operations. Make sure that you understand resource stale state and the refresh operation. When a resource is stale in workspace (has been modified external), reading or writing it will throw an exception. Will need a strategy for dealing with stale resources. May want to just skip them. When user hits refresh, your listener will get a delta with changes.
- Konstantin
[Updated on: Tue, 11 January 2011 16:21] Report message to a moderator
|
|
|
Re: How to synchronize a copy project in the background using JavaElementDeltas? [message #648221 is a reply to message #648179] |
Tue, 11 January 2011 21:01 |
Kivanc Muslu Messages: 153 Registered: November 2010 |
Senior Member |
|
|
Hi Konstantin,
Thank you very much for your response. Just a quick question: when you say
Quote: | I have never seen any way to apply a delta, but writing apply logic should be pretty trivial. After all, you are being told exactly what has changed.
|
and with the remaining of your suggestions, do you mean that I get the actual change in the deltas (i.e., what exactly changed from two consecutive project points), however, there is no API to apply a delta itself (i.e., calling Eclipse's internal methods) and I have to implement my own apply method.
Moreover, as far as I understand you are suggesting me to apply the change at IFile or IResource level (i.e., recopy the change file or resource). Am I correct? Is there no way to just apply the change? It might not really give me that much overhead to copy the whole file, however if there were a way to apply only the diff that would be great.
Thanks again!
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03731 seconds