Patches for FELIX-2181 - now runs workspace resolve task using a damped delay to ensure that event storm does not trigger multiple project builds.
Also filter refresh events in workspace repository to ensure that only sigil projects trigger a repository change event

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@920400 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/repository/eclipse/WorkspaceRepository.java b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/repository/eclipse/WorkspaceRepository.java
index 2e95b44..b47ca14 100644
--- a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/repository/eclipse/WorkspaceRepository.java
+++ b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/repository/eclipse/WorkspaceRepository.java
@@ -181,8 +181,14 @@
 
     private void handleRefresh(IResourceChangeEvent event)
     {
-        SigilCore.log("Refreshing workspace repository");
-        notifyChange();
+        if ( event.getResource() instanceof IProject ) {
+            IProject project = (IProject) event.getResource();
+            if ( isSigilProject(project) )
+            {
+                SigilCore.log("Refreshing workspace repository");
+                notifyChange();
+            }
+        }
     }
 
 
diff --git a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/job/ResolveProjectsJob.java b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/job/ResolveProjectsJob.java
index ee31d12..2bfff2b 100644
--- a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/job/ResolveProjectsJob.java
+++ b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/job/ResolveProjectsJob.java
@@ -35,7 +35,7 @@
 
 public class ResolveProjectsJob extends WorkspaceJob
 {
-    final Collection<ISigilProjectModel> sigilProjects;
+    private final Collection<ISigilProjectModel> sigilProjects;
     
     public ResolveProjectsJob( IWorkspace workspace )
     {
diff --git a/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/startup/SigilStartup.java b/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/startup/SigilStartup.java
index 7e0015a..b33e8fc 100644
--- a/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/startup/SigilStartup.java
+++ b/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/startup/SigilStartup.java
@@ -20,12 +20,18 @@
 package org.apache.felix.sigil.ui.eclipse.startup;
 
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.apache.felix.sigil.eclipse.SigilCore;
 import org.apache.felix.sigil.eclipse.job.ResolveProjectsJob;
 import org.apache.felix.sigil.repository.IRepositoryChangeListener;
 import org.apache.felix.sigil.repository.RepositoryChangeEvent;
 import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.ui.IStartup;
 
 
@@ -34,15 +40,31 @@
 
     public void earlyStartup()
     {
+        final AtomicInteger updateCounter = new AtomicInteger();
+        
         // Register a repository change listener to re-run the resolver when repository changes
         SigilCore.getGlobalRepositoryManager().addRepositoryChangeListener( new IRepositoryChangeListener()
         {
             public void repositoryChanged( RepositoryChangeEvent event )
             {
-                IWorkspace workspace = ResourcesPlugin.getWorkspace();
-                ResolveProjectsJob job = new ResolveProjectsJob( workspace );
-                job.setSystem( true );
-                job.schedule();
+                final int update = updateCounter.incrementAndGet();
+                
+                Job job = new Job("Pending repository update") {
+                    @Override
+                    protected IStatus run(IProgressMonitor monitor)
+                    {
+                        if ( update == updateCounter.get() ) {
+                            IWorkspace workspace = ResourcesPlugin.getWorkspace();
+                            ResolveProjectsJob job = new ResolveProjectsJob( workspace );
+                            job.setSystem( true );
+                            job.schedule();
+                        }
+                        return Status.OK_STATUS;
+                    }
+                    
+                };
+                job.setSystem(true);
+                job.schedule(100);
             }
         } );
     }