[331719] Deadlock in DependencyGraphImpl call to yieldRule from the AutoBuildJob
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/DependencyGraphImpl.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/DependencyGraphImpl.java
index 06f569f..2f0c1bb 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/DependencyGraphImpl.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/DependencyGraphImpl.java
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
 package org.eclipse.wst.common.componentcore.internal.builder;
 
 import java.io.BufferedInputStream;
@@ -93,17 +104,31 @@
 			modStamp++;
 		}
 	}
+
+	
 	/**
 	 * Returns the set of projects whose components reference the specified
 	 * target project's component. For example if projects A and B both
 	 * reference C. Passing C as the targetProject will return {A, B}
 	 */
 	public Set<IProject> getReferencingComponents(IProject targetProject) {
-		waitForAllUpdates(null);
+		IDependencyGraphReferences refs = getReferencingComponents(targetProject, true);
+		return refs.getReferencingComponents();
+	}
+
+	public IDependencyGraphReferences getReferencingComponents(IProject targetProject, boolean waitForAllUpdates) {
+		DependencyGraphReferences refs = new DependencyGraphReferences();
+		refs.targetProject = targetProject;
+		if(waitForAllUpdates){
+			refs.stale = false;
+			waitForAllUpdates(null);
+		} else if(isUpdateNecessary()){
+			refs.stale = true;
+		}
 		synchronized (graphLock) {
 			Set<IProject> set = graph.get(targetProject);
 			if (set == null) {
-				return Collections.EMPTY_SET;
+				refs.referencingProjects = Collections.EMPTY_SET;
 			} else {
 				DependencyGraphEvent event = null;
 				for (Iterator<IProject> iterator = set.iterator(); iterator.hasNext();) {
@@ -123,11 +148,16 @@
 				}
 				Set<IProject> copy = new HashSet<IProject>();
 				copy.addAll(set);
-				return copy;
+				refs.referencingProjects = copy;
 			}
 		}
-	}
+		return refs;
+	} 
 
+	public boolean isStale() {
+		return isUpdateNecessary();
+	}
+	
 	private class DependencyGraphResourceChangedListener implements IResourceChangeListener, IResourceDeltaVisitor {
 		// only registered for post change events
 		public void resourceChanged(IResourceChangeEvent event) {
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/DependencyGraphReferences.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/DependencyGraphReferences.java
new file mode 100644
index 0000000..115195a
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/DependencyGraphReferences.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.common.componentcore.internal.builder;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+
+class DependencyGraphReferences implements IDependencyGraphReferences {
+
+	IProject targetProject = null;
+
+	Set<IProject> referencingProjects = null;
+
+	boolean stale;
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.wst.common.componentcore.internal.builder.IDependencyGraphReferences#getTargetProject()
+	 */
+	public IProject getTargetProject() {
+		return targetProject;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.wst.common.componentcore.internal.builder.IDependencyGraphReferences#getReferencingComponents()
+	 */
+	public Set<IProject> getReferencingComponents() {
+		return referencingProjects;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.wst.common.componentcore.internal.builder.IDependencyGraphReferences#isStale()
+	 */
+	public boolean isStale() {
+		return stale;
+	}
+}
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/IDependencyGraph.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/IDependencyGraph.java
index 07442a1..aea957a 100644
--- a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/IDependencyGraph.java
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/IDependencyGraph.java
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
 package org.eclipse.wst.common.componentcore.internal.builder;
 
 import java.util.Set;
@@ -68,6 +79,30 @@
 	public Set<IProject> getReferencingComponents(IProject targetProject);
 
 	/**
+	 * If <code>waitForAllUpdates</code> is <code>true</code> this method is
+	 * equivalent to {@link #getReferencingComponents(IProject)}. Otherwise this
+	 * method will return immediately without waiting for all updates to occur
+	 * and potentially returning stale data. This a safer way to call
+	 * getReferences to avoid deadlocks. If stale data is returned, then a
+	 * subsequent on the same thread can be made, but there may be deadlock risk
+	 * depending on what ISchedulingRule is currently held.  A safer reaction
+	 * to stale data would be to schedule another job to run in future to try again.
+	 * 
+	 * @param targetProject
+	 * @param waitForAllUpdates
+	 * @return
+	 */
+	public IDependencyGraphReferences getReferencingComponents(
+			IProject targetProject, boolean waitForAllUpdates);
+	
+	
+	/**
+	 * Returns <code>true</code> if there are any pending updates.
+	 * @return
+	 */
+	public boolean isStale();
+	
+	/**
 	 * Returns a modification stamp. This modification stamp will be different
 	 * if the project dependencies ever change.
 	 */
diff --git a/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/IDependencyGraphReferences.java b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/IDependencyGraphReferences.java
new file mode 100644
index 0000000..315a693
--- /dev/null
+++ b/plugins/org.eclipse.wst.common.modulecore/modulecore-src/org/eclipse/wst/common/componentcore/internal/builder/IDependencyGraphReferences.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.common.componentcore.internal.builder;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+
+public interface IDependencyGraphReferences {
+
+	public abstract IProject getTargetProject();
+
+	/**
+	 * Returns the set of referencing projects; see
+	 * {@link IDependencyGraph#getReferencingComponents(IProject)}
+	 * 
+	 * @return
+	 */
+	public abstract Set<IProject> getReferencingComponents();
+
+	/**
+	 * If this is value is <code>true</code>, then it is possible that this data
+	 * is stale. It is also possible this data is accurate.
+	 * 
+	 * @return
+	 */
+	public abstract boolean isStale();
+
+}
\ No newline at end of file