Bug 551237 - Add tracing option for build cycles

Logging the build cycle

Change-Id: I2259fdbf947b61d1d31cc300a83185ff3c2c7b08
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
diff --git a/bundles/org.eclipse.core.resources/.options b/bundles/org.eclipse.core.resources/.options
index d8a2ced..ceb6653 100644
--- a/bundles/org.eclipse.core.resources/.options
+++ b/bundles/org.eclipse.core.resources/.options
@@ -27,6 +27,9 @@
 # Reports the start and end of build delta calculations
 org.eclipse.core.resources/build/delta=false
 
+# Reports build cycles
+org.eclipse.core.resources/build/cycle=false
+
 # For incremental builds, displays which builder is being run
 # and because of changes in which project.
 org.eclipse.core.resources/build/needbuild=false
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java
index 13dac15..1aa80f9 100644
--- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java
+++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java
@@ -491,6 +491,12 @@
 				}
 				if (buildGraph != null) {
 					buildGraph.freeze();
+					if (Policy.DEBUG_BUILD_CYCLE && buildGraph.containsCycles()) {
+						List<IBuildConfiguration[]> nonTrivialComponents = buildGraph.nonTrivialComponents();
+						for (IBuildConfiguration[] iBuildConfigurations : nonTrivialComponents) {
+							Policy.debug("Cycle: " + Arrays.toString(iBuildConfigurations)); //$NON-NLS-1$
+						}
+					}
 					allConfigs = ComputeProjectOrder.computeVertexOrder(buildGraph, IBuildConfiguration.class).vertexes;
 				}
 
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/Policy.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/Policy.java
index 2d3eedd..88675f4 100644
--- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/Policy.java
+++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/utils/Policy.java
@@ -33,6 +33,7 @@
 			DEBUG_AUTO_REFRESH = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/refresh", false); //$NON-NLS-1$
 
 			DEBUG_BUILD_DELTA = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/delta", false); //$NON-NLS-1$
+			DEBUG_BUILD_CYCLE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/cycle", false); //$NON-NLS-1$
 			DEBUG_BUILD_FAILURE = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/failure", false); //$NON-NLS-1$
 			DEBUG_BUILD_INTERRUPT = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/interrupt", false); //$NON-NLS-1$
 			DEBUG_BUILD_INVOKING = DEBUG && options.getBooleanOption(ResourcesPlugin.PI_RESOURCES + "/build/invoking", false); //$NON-NLS-1$
@@ -74,6 +75,7 @@
 
 	//debug constants
 	public static boolean DEBUG_BUILD_DELTA = false;
+	public static boolean DEBUG_BUILD_CYCLE = false;
 	public static boolean DEBUG_BUILD_FAILURE = false;
 	public static boolean DEBUG_BUILD_INTERRUPT = false;
 	public static boolean DEBUG_BUILD_INVOKING = false;