/*******************************************************************************
 * Copyright (c) 2012 Pivotal Software, Inc.
 * 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:
 * Pivotal Software, Inc. - initial API and implementation
 *******************************************************************************/
package org.springsource.ide.eclipse.gradle.core.modelmanager;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.springsource.ide.eclipse.gradle.core.GradleProject;

/**
 * Default implementation of ModelBuilder. Delegates to Gradle tooling API.
 * 
 * @author Kris De Volder
 */
public class DefaultModelBuilder extends AbstractModelBuilder {
	
	@Override
	public <T> T doBuild(GradleProject project, Class<T> type, IProgressMonitor mon) throws CoreException {
		return ToolinApiUtils.buildModel(project, type, mon);
	}
	
	public static <T> String jobName(GradleProject project, Class<T> requiredType) {
		return "Build '"+requiredType.getSimpleName()+"' model for '"+project.getDisplayName();
	}

}

@@ -702,58 +702,178 @@
 org.
-springsource.ide.eclipse.gradle.core.GradleProject
+eclipse.core.runtime.SubProgressMonitor;%0Aimport org.springsource.ide.eclipse.gradle.core.GradleProject;%0Aimport org.springsource.ide.eclipse.gradle.core.util.ExceptionUtil
 ;%0A%0A/
@@ -1173,61 +1173,557 @@
 %7B%0A%09%09
-return ToolinApiUtils.buildModel(project, type, mon);
+mon.beginTask(jobName(project, type), 10);%0A%09%09try %7B%0A%09%09%09return ToolinApiUtils.buildModel(project, type, new SubProgressMonitor(mon, 9));%0A%09%09%7D catch (CoreException e) %7B%0A%09%09%09if (ExceptionUtil.getDeepestCause(e).getClass().getName().equals(%22java.lang.InterruptedException%22)) %7B%0A%09%09%09%09//WTF: someone throws this spurriously aborting the build... don't want that, so try again and%0A%09%09%09%09// don't fail my tests because of this!%0A%09%09%09%09return ToolinApiUtils.buildModel(project, type, new SubProgressMonitor(mon, 1));%0A%09%09%09%7D%0A%09%09%09throw e;%0A%09%09%7D%0A%09%09finally %7B%0A%09%09%09mon.done();%0A%09%09%7D
 %0A%09%7D%0A

Handle spurious InterruptedException thrown by gradle.