问题
I have a plugin that adds arbitary information to resources of projects through the persistent property mechanism of eclipse. Now these projects are stored in version control systems like SVN and GIT.
The persistent properties will not get checked in because they are stored in the metadata of the workspace and not inside the project itsself.
%workspace%\.metadata\.plugins\org.eclipse.core.resources\.projects\%projectname%\.indexes
- Is there a way to save these properties to the project and manage them via version control?
- If not, does anyone have tried a custom solution for this?
There has been a question alike here:
Eclipse: Storing info in .project file
and the answer is useful if you want to store project scope information that does not refer to single resources. But i need to connect information to folders and files and store that information inside the projects filesystem location.
回答1:
You could include the path of the resource in the 'key' part of the project scope preference value. So:
preferences.putString("/path/to/file/keyword", value);
回答2:
I know this is a rather old question but it pops up as one of the top matches when searching for "Eclipse project scoped resource properties". (Having searched for this, it's obvious that I was looking for a solution myself.)
Eclipse provides project scoped preferences with the
ProjectScope. These preferences are stored in files in /<project>/.settings
and can thus be added to version control easily. If you have e.g. set the encoding for a file in your project, you'll find org.eclipse.core.resources.prefs
in this directory, and you can see how the resources plugin (which maintains this file) uses a specific scheme to combine a property name and a resource name in a preferences key.
Using this as a basis, I have implemented a custom solution for storing "persistent resource properties in Version Control" (a.k.a. "project scoped resource properties"). You can have a look at the solution here. Generating a key and storing the properties as preferences is straightforward and easy. In addition, my custom solution tracks deletions of files and removes properties to avoid having them "pop up" if you later create a file with the same name again. It also tracks moves/renames and keeps the properties associated with the moved/renamed file. Note that it deliberately doesn't copy the associated properties if a file is copied, because this is not the intended behavior for my use case.
It works, but as is usual with such a complex environment as the Eclipse platform, I have probably not considered every issue. When I have time, I'll dig in the source code of the resources plugin and have a look how to do it properly. Meanwhile, it works well enough for me.
来源:https://stackoverflow.com/questions/26649569/storing-persistent-resource-properties-in-version-control