Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse workspaces sync settings - what to sync?

Tags:

eclipse

I know it has come up time and again but my specific question is : I have multiple workspaces using the wpt, cdt and jdt extensions (and others). I want to create hard links (I am on windows) from all my workspaces to a subset of settings files that govern things like shortcuts, workspace preferences etc. This way when I, for instance, change a shortcut in one workspace the change will propagate to all other workspaces. Problem is the .metadata/.plugins folder is a complete mess (I believe the settings are all there). For instance I know that I have to link the files :

<workspace>\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.core.prefs
<workspace>\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.ui.prefs

I believe I should not try to link the whole .metadata/.plugins folder as it contains workspace-specific data.

  • Would it be safe and enough to hardlink the \.metadata\.plugins\org.eclipse.core.runtime\.settings directory ?

  • Can someone point me to some documentation as to what are all those.index and .dat binary files inside \.metadata\.plugins\ ?

  • If this is not possible I would appreciate at least a reference for the various .prefs files inside \.metadata\.plugins\*\.settings directories, especially the .metadata\.plugins\org.eclipse.core.runtime\.settings one

Thanks

like image 825
Mr_and_Mrs_D Avatar asked Nov 11 '12 18:11

Mr_and_Mrs_D


2 Answers

Alright, what I did (eclipse juno on windows 7) was :

  • Created a new eclipse workspace, say test, run it and just shut it down

  • Made it into a git repo

  • Committed the files that were created by eclipse along with this .gitignore :

    # binary files
    *.dat
    *.tree
    *.index
    .metadata/.plugins/org.eclipse.jdt.core/invalidArchivesCache
    .metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache
    .metadata/.mylyn/repositories.xml.zip
    *.resources
    
    # logs
    *.log
    
    .metadata/.lock
    
    # later additions
    .metadata/.plugins/org.eclipse.pde.core/.cache/
    *.running
    
  • Switched to a new branch

    Fired up one of my workspaces, exported ALL the settings then fired up the test workspace and imported them. Compared the .metadata/ dirs of the workspaces with the help of Beyond Compare. The .metadata\.plugins\org.eclipse.core.runtime\.settings\ folders were identical apart from the org.eclipse.ui.workbench.prefs file - but the differences did not seem important (i.e. workspace specific). On shutting down the workspace the file org.eclipse.jdt.launching.prefs was also modified. Switched to master and repeated for the rest of my workspaces.


There were complications - so for instance :

  • the file org.eclipse.jdt.core.prefs was present in the test workspace while in the original workspace (from were I imported) there was the (binary identical) org.eclipse.jdt.core.prefs.bak.

  • The file org.eclipse.pde.core.prefs was not imported

  • The files org.eclipse.jdt.launching.prefs and org.eclipse.ui.workbench.prefs differ.

After the fifth workspace I was settled that the files

.metadata/.plugins/org.eclipse.jdt.launching/libraryInfos.xml 
.metadata/.plugins/org.eclipse.jdt.launching/.install.xml

are created when settings are imported (in a new workspace), that the file .metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.pde.core.prefs is not exported/imported, that the file .settings\org.eclipse.ui.workbench.prefs is merged on import (namely the *ENABLED_DECORATORS* var stays as is) and the org.eclipse.jdt.launching.prefs is edited on shutting eclipse down.

There are further complications like files containing project references :

  • For instance, the file org.eclipse.wst.sse.core.prefs contains project names from the workspace - I reported this as a bug (it was fixed really quick !).

  • CDT creates a bunch of files like :

    .settings/org.eclipse.cdt.core.prj-<projectName>.prefs
    .settings/org.eclipse.cdt.ui.prj-<projectName>.prefs
    

which are blindly synced on export/import. This actually is a much more complicated case than the previous one - reported it also.

In fact, whatever you have in the .settings dir will be copied along (I guess as long as it has a .prefs suffix). This warrants another bug report.

Similar situations are encountered in other files which contain workspace specific options - like in org.eclipse.ui.ide.prefs which contains references to the working sets - which are rather workspace specific - or in org.eclipse.ui.browser.prefs which contains the internalWebBrowserHistory - which is usually also workspace specific.


Anyway I decided to go for the hard links - so I normalized my preferences (it would be much much easier to start with a fresh workspace) and copied all the settings apart from org.eclipse.wst.sse.core.prefs, the cdt ones and the org.eclipse.pde.core.prefs (as for some reason it was not imported. The org.eclipse.ui.workbench.prefs which is rather special contains also the shortcuts). Then I run :

REM move_settings.bat
set SETTINGS_DIR=C:\path\to\tempalte\workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings
set WORKSPACE_SETTINGS_DIR=C:\path\to\actual\workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings
mkdir %WORKSPACE_SETTINGS_DIR%\zBackups
pause
FOR /F %%G IN ('DIR^ %%SETTINGS_DIR%%^ /b') DO (
    move %WORKSPACE_SETTINGS_DIR%\%%G %WORKSPACE_SETTINGS_DIR%\zBackups
    mklink /H %WORKSPACE_SETTINGS_DIR%\%%G %SETTINGS_DIR%\%%G
)
pause

for my workspaces.

And guess what : eclipse breaks hard links. I tried soft links (mklink %WORKSPACE_SETTINGS_DIR%\%%G %SETTINGS_DIR%\%%G) but no joy either.

Finally

I had to hard link (junction) the whole settings dir (along with all the problematic files I mentioned) - this is really not a solution. One of these days the situation must be addressed. Anyway here's the .bat I used :

:: Change to the directory that this batch file is in
:: NB: it must be invoked with a full path!
:: run the bat from the dir you want to backup your prefs to
for /f %%i in ("%0") do set curpath=%%~dpi
cd /d %curpath%

set WORKSPACES=javaEE\ javaSE\ c++\ python\ android\

set TEMPLATE_WORKSPACE=name_of_the_template_workspace\
set WORKSPACES_DIR=C:\Dropbox\eclipse_workspaces\
set SETTINGS_DIR=.metadata\.plugins\org.eclipse.core.runtime\.settings
REM set SETTINGS_DIR=.metadata\.plugins\org.eclipse.core.runtime\.settings\ WONT DO
set TEMPLATE_SETTINGS_DIR=%WORKSPACES_DIR%%TEMPLATE_WORKSPACE%%SETTINGS_DIR%

for %%G in (%WORKSPACES%) do (call :subroutine_needed %%G)
GOTO :eof

:subroutine_needed
    set WORKSPACE=%1
    set WORKSPACE_SETTINGS_DIR=%WORKSPACES_DIR%%WORKSPACE%%SETTINGS_DIR%
    set BACKUP_DIR=%CD%\zBackups\%WORKSPACE%
    mkdir %BACKUP_DIR%
    pause

    move %WORKSPACE_SETTINGS_DIR% %BACKUP_DIR%
    pause

    junction  %WORKSPACE_SETTINGS_DIR% %TEMPLATE_SETTINGS_DIR%
    pause

I'll update this post as needed

like image 193
Mr_and_Mrs_D Avatar answered Oct 19 '22 23:10

Mr_and_Mrs_D


You can also have a look to workspace mechanic, a small plugin developed by google : http://code.google.com/a/eclipselabs.org/p/workspacemechanic/

UPDATE 28/11/12

So as far I understand, you need to keep in sync some plugins preferences.

The wiki explains it quite well. The steps I recommend you are the following:

  • install workspace mechanic (only steps 1 and 2 of the following) : http://code.google.com/a/eclipselabs.org/p/workspacemechanic/wiki/GettingStarted
  • then start with a fresh workspace, and use the preference recorder and set your preferences as desired : http://code.google.com/a/eclipselabs.org/p/workspacemechanic/wiki/PreferenceRecorder (I recommend you to keep preferences in small seperated files, i.e. one .epf file for one plugin)
  • if the recording of your preferences doesn't cover the whole needs you can have a look on how to create your own preferences : http://code.google.com/a/eclipselabs.org/p/workspacemechanic/wiki/PreferenceTasks, also check some exemples here : http://code.google.com/a/eclipselabs.org/p/workspacemechanic/wiki/PreferenceExamples
  • if still not enough, then you can code you own Tasks : see here for an exemple http://code.google.com/a/eclipselabs.org/p/workspacemechanic/wiki/ClassTasks

With that you should be able to deal with syncing your workspace preferences.

Bonus: I like to put workspace mechanic preferences on dropbox to share it between team members and/or between my computers you can find a small how-to here : https://gist.github.com/3090900

Hope this helps.

Regards

like image 26
xavier.seignard Avatar answered Oct 19 '22 23:10

xavier.seignard