Backport Bug 520269 to WTP 3.6.3

Signed-off-by: John Collier <John.J.Collier@ibm.com>
diff --git a/plugins/org.eclipse.wst.common.modulecore/META-INF/MANIFEST.MF b/plugins/org.eclipse.wst.common.modulecore/META-INF/MANIFEST.MF
index e7896d6..446df7a 100644
--- a/plugins/org.eclipse.wst.common.modulecore/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.wst.common.modulecore/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@
 Bundle-Name: %Bundle-Name.0
 Bundle-Vendor: %provider
 Bundle-SymbolicName: org.eclipse.wst.common.modulecore; singleton:=true
-Bundle-Version: 1.2.401.qualifier
+Bundle-Version: 1.2.402.qualifier
 Bundle-Activator: org.eclipse.wst.common.componentcore.internal.ModulecorePlugin
 Bundle-Localization: plugin
 Export-Package: org.eclipse.wst.common.componentcore,
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplManager.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplManager.java
index 58f80d4..e85e904 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplManager.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/util/ComponentImplManager.java
@@ -25,6 +25,7 @@
 import org.eclipse.core.runtime.ISafeRunnable;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.core.runtime.jobs.ILock;
 import org.eclipse.jem.util.RegistryReader;
 import org.eclipse.jem.util.emf.workbench.ISynchronizerExtender;
 import org.eclipse.jem.util.emf.workbench.ProjectResourceSet;
@@ -37,6 +38,7 @@
 import org.eclipse.wst.common.componentcore.internal.resources.VirtualFolder;
 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
 import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.internal.emfworkbench.edit.EMFWorkbenchEditContextFactory;
 import org.eclipse.wst.common.project.facet.core.IFacetedProject;
 import org.eclipse.wst.common.project.facet.core.IProjectFacet;
 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
@@ -203,7 +205,22 @@
 		return createComponent(project, true);
 	}
 
-	public synchronized IVirtualComponent createComponent(IProject project, boolean checkSettings) {
+	public IVirtualComponent createComponent(IProject project, boolean checkSettings) {
+		// acquire the lock that StructureEdit will need already, to prevent others from locking that before calling createComponent() - see bug 508685 and bug 511793
+		ILock lock = EMFWorkbenchEditContextFactory.getProjectLockObject(project);
+		try{
+			if(null != lock){
+				lock.acquire();
+			}
+			return createComponentSynchronously(project, checkSettings);
+		} finally{
+			if(null != lock){
+				lock.release();
+			}
+		}
+	}
+
+	private synchronized IVirtualComponent createComponentSynchronously(IProject project, boolean checkSettings) {
 		try {
 			IVirtualComponent component = ComponentCacheManager.instance().getComponent(project);
 			if(component != null) {
diff --git a/plugins/org.eclipse.wst.common.modulecore/pom.xml b/plugins/org.eclipse.wst.common.modulecore/pom.xml
index b6291f8..a0dccc7 100644
--- a/plugins/org.eclipse.wst.common.modulecore/pom.xml
+++ b/plugins/org.eclipse.wst.common.modulecore/pom.xml
@@ -22,6 +22,6 @@
 

   <groupId>org.eclipse.webtools.common</groupId>

   <artifactId>org.eclipse.wst.common.modulecore</artifactId>

-  <version>1.2.401-SNAPSHOT</version>

+  <version>1.2.402-SNAPSHOT</version>

   <packaging>eclipse-plugin</packaging>

 </project>