Ensure internal cache is flushed on project delete (fix for FELIX-2168)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@919000 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/SigilCore.java b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/SigilCore.java
index d5cadfa..95a2d40 100644
--- a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/SigilCore.java
+++ b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/SigilCore.java
@@ -42,6 +42,7 @@
 import org.apache.felix.sigil.eclipse.internal.repository.eclipse.GlobalRepositoryManager;
 import org.apache.felix.sigil.eclipse.internal.repository.eclipse.SigilRepositoryManager;
 import org.apache.felix.sigil.eclipse.internal.resources.ProjectResourceListener;
+import org.apache.felix.sigil.eclipse.internal.resources.SigilProjectManager;
 import org.apache.felix.sigil.eclipse.model.project.ISigilModelRoot;
 import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
 import org.apache.felix.sigil.eclipse.model.repository.IRepositoryConfiguration;
@@ -133,6 +134,7 @@
     private ServiceTracker serializerTracker;
 
     private static IRepositoryConfiguration repositoryConfig;
+    private static SigilProjectManager projectManager;
     private static OSGiInstallManager installs;
     private static ISigilModelRoot modelRoot;
     private static HashMap<Object, SigilRepositoryManager> repositoryManagers = new HashMap<Object, SigilRepositoryManager>();
@@ -238,26 +240,9 @@
     }
 
 
-    private static HashMap<IProject, SigilProject> projects = new HashMap<IProject, SigilProject>();
-    
     public static ISigilProjectModel create( IProject project ) throws CoreException
     {
-        if ( project.hasNature( NATURE_ID ) )
-        {
-            SigilProject p = null;
-            synchronized( projects ) {
-                p = projects.get(project);
-                if ( p == null ) {
-                   p = new SigilProject( project );
-                   projects.put(project, p);
-                }
-            }
-            return p; 
-        }
-        else
-        {
-            throw newCoreException( "Project " + project.getName() + " is not a sigil project", null );
-        }
+        return projectManager.getSigilProject(project);
     }
 
 
@@ -293,6 +278,8 @@
         installs = new OSGiInstallManager();
 
         globalRepositoryManager = new GlobalRepositoryManager();
+        
+        projectManager = new SigilProjectManager();
 
         registerModelElements( context );
         registerResourceListeners();
@@ -416,7 +403,7 @@
             @Override
             protected IStatus run( IProgressMonitor monitor )
             {
-                ResourcesPlugin.getWorkspace().addResourceChangeListener( new ProjectResourceListener(),
+                ResourcesPlugin.getWorkspace().addResourceChangeListener( new ProjectResourceListener(projectManager),
                     ProjectResourceListener.EVENT_MASKS );
                 return Status.OK_STATUS;
             }
diff --git a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/resources/ProjectResourceListener.java b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/resources/ProjectResourceListener.java
index 8a51e6a..d833e48 100644
--- a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/resources/ProjectResourceListener.java
+++ b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/resources/ProjectResourceListener.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.felix.sigil.eclipse.internal.resources;
 
 import java.util.LinkedList;
@@ -23,6 +41,12 @@
 public class ProjectResourceListener implements IResourceChangeListener
 {
     public static final int EVENT_MASKS = IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.POST_CHANGE;
+    private final SigilProjectManager projectManager;
+
+    public ProjectResourceListener(SigilProjectManager projectManager)
+    {
+        this.projectManager = projectManager;
+    }
 
     public void resourceChanged( IResourceChangeEvent event )
     {
@@ -104,6 +128,7 @@
             if ( SigilCore.isSigilProject( project ) )
             {
                 readCapabilities(project);
+                projectManager.flushSigilProject(project);
             }
         }
     }
diff --git a/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/resources/SigilProjectManager.java b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/resources/SigilProjectManager.java
new file mode 100644
index 0000000..7b734f7
--- /dev/null
+++ b/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/resources/SigilProjectManager.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.sigil.eclipse.internal.resources;
+
+import java.util.HashMap;
+
+import org.apache.felix.sigil.eclipse.SigilCore;
+import org.apache.felix.sigil.eclipse.internal.model.project.SigilProject;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+
+public class SigilProjectManager
+{
+    private static HashMap<IProject, SigilProject> projects = new HashMap<IProject, SigilProject>();
+    
+    public SigilProject getSigilProject(IProject project) throws CoreException {
+        if ( project.hasNature( SigilCore.NATURE_ID ) )
+        {
+            SigilProject p = null;
+            synchronized( projects ) {
+                p = projects.get(project);
+                if ( p == null ) {
+                   p = new SigilProject( project );
+                   projects.put(project, p);
+                }
+            }
+            return p; 
+        }
+        else
+        {
+            throw SigilCore.newCoreException( "Project " + project.getName() + " is not a sigil project", null );
+        }
+    }
+    
+    public void flushSigilProject(IProject project) {
+        synchronized(project) {
+            projects.remove(project);
+        }
+    }
+}