Bug 577530 - scale build iterations depending on affected projects

Scale maximum allowed build iterations count depending on affected
projects - allow at least two build cycles per project.

Change-Id: I6ab1d88faf0909ad5caee2918944fb1d6f75118a
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.resources/+/188398
Tested-by: Platform Bot <platform-bot@eclipse.org>
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/events/BuildManager.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/events/BuildManager.java
index ff81887..cd378a6 100644
--- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/events/BuildManager.java
+++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/events/BuildManager.java
@@ -377,6 +377,9 @@
 	private void basicBuildLoop(IBuildConfiguration[] configs, IBuildConfiguration[] requestedConfigs, int trigger, MultiStatus status, IProgressMonitor monitor) {
 		int projectWork = configs.length > 0 ? TOTAL_BUILD_WORK / configs.length : 0;
 		int maxIterations = workspace.getDescription().getMaxBuildIterations();
+		// Scale allowed iterations count depending on affected projects -
+		// allow at least two build cycles per project
+		maxIterations = Math.max(configs.length * 2, maxIterations);
 		if (maxIterations <= 0)
 			maxIterations = 1;
 		rebuildRequested = true;