Tuesday, November 4, 2008

Filtering resources in Eclipse

When you have a lot of files in an Eclipse 3.4 workspace things pretty much grind to a halt. I have a folder containing 200,000 images for a web project I'm working on and I need to include in the workspace. Starting Eclipse with this folder takes forever and Subversive hangs trying to to something with all the files.

I filed a bug report on this issue 3 years ago! https://bugs.eclipse.org/bugs/show_bug.cgi?id=84988. Eclipse development seems to move slowly.

I can exclude files from the Package Explore using a filter but the problem remains. Under the covers Eclipse is still monitoring these files at the resource level.

I found this plugin which claims to do what I want but I could not get it to work for me.

https://sourceforge.net/projects/eclipseresfltr/

Some people have posted about adding a "resource filter" to filter out files at a lower level
In the Resource Navigator (Window -> Show View -> Navigator) you can choose to filter resources that match .* or *.class but you cannot add your own filters. These default ones are added by plugins as extension points.

But you can add your own filters by messing with an existing Plugin and adding a filter definition to its plugin.xml. Just find a plugin that is not in a jar file - they are signed so you cannot alter their contents. I chose the jdt plugin org.eclipse.jdt.debug_3.4.0.v20080604 and added this to its plugin.xml

<extension point="org.eclipse.ui.ide.resourceFilters">
<filter selected="false" pattern="my-large-folder"></filter>
</extension>

However, this does NOT stop the resources from being scanned for updates for some reason. It just hides the folder from view but my machine was still pegged on close to 100% CPU.

Then I re-read one of the comments on my bug report above and finally solved the problem.
  1. Move the large folder outside your workspace.
  2. In the Package Explorer New -> File
  3. Enter the name of the large folder as the filename
  4. Click Advanced and check "Link to file in the filesystem"
  5. Enter /dev/null (on Mac OS X) and click finish
  6. Move the large folder back to your workspace.
Now the null file hides your folder. I also added a filter to the Package Exploer so the linked null file does not show. Now when I refresh the workspace or restart my machine no longer hangs. Nice one.

No comments: