View | Details | Raw Unified | Return to bug 329657 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/events/AutoBuildJob.java (-2 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2010 IBM Corporation and others.
2
 * Copyright (c) 2003, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 159-165 Link Here
159
			monitor.done();
159
			monitor.done();
160
		}
160
		}
161
	}
161
	}
162
	
162
163
	/**
163
	/**
164
	 * Forces an autobuild to occur, even if nothing has changed since the last
164
	 * Forces an autobuild to occur, even if nothing has changed since the last
165
	 * build. This is used to force a build after a clean.
165
	 * build. This is used to force a build after a clean.
Lines 255-260 Link Here
255
	 */
255
	 */
256
	private synchronized void setInterrupted(boolean value) {
256
	private synchronized void setInterrupted(boolean value) {
257
		interrupted = value;
257
		interrupted = value;
258
		if (value)
259
			cancel();
258
	}
260
	}
259
261
260
	/**
262
	/**
(-)a/tests/org.eclipse.core.tests.resources/plugin.xml (+5 lines)
Lines 64-69 Link Here
64
      <run class="org.eclipse.core.tests.internal.builders.ClearMarkersBuilder"/>
64
      <run class="org.eclipse.core.tests.internal.builders.ClearMarkersBuilder"/>
65
    </builder>
65
    </builder>
66
  </extension>
66
  </extension>
67
  <extension point="org.eclipse.core.resources.builders" id="builderwithcallback" name="Builder With Callback">
68
    <builder>
69
      <run class="org.eclipse.core.tests.internal.builders.BuilderWithCallback"/>
70
    </builder>
71
  </extension>
67
  <extension point="org.eclipse.core.resources.builders" id="emptydeltabuilder" name="Empty Delta Builder">
72
  <extension point="org.eclipse.core.resources.builders" id="emptydeltabuilder" name="Empty Delta Builder">
68
    <builder callOnEmptyDelta="true">
73
    <builder callOnEmptyDelta="true">
69
      <run class="org.eclipse.core.tests.internal.builders.EmptyDeltaBuilder"/>
74
      <run class="org.eclipse.core.tests.internal.builders.EmptyDeltaBuilder"/>
(-)a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderTest.java (-1 / +65 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 *  Copyright (c) 2000, 2012 IBM Corporation and others.
2
 *  Copyright (c) 2000, 2014 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
5
 *  which accompanies this distribution, and is available at
Lines 21-26 Link Here
21
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.core.runtime.jobs.Job;
22
import org.eclipse.core.tests.harness.TestBarrier;
22
import org.eclipse.core.tests.harness.TestBarrier;
23
import org.eclipse.core.tests.harness.TestJob;
23
import org.eclipse.core.tests.harness.TestJob;
24
import org.eclipse.core.tests.internal.builders.BuilderWithCallback.IBuildCallback;
24
25
25
/**
26
/**
26
 * This class tests public API related to building and to build specifications.
27
 * This class tests public API related to building and to build specifications.
Lines 1117-1122 Link Here
1117
		}
1118
		}
1118
	}
1119
	}
1119
1120
1121
	public void testInterruptLongAutobuild() throws CoreException, InterruptedException {
1122
		setAutoBuilding(true);
1123
1124
		IProject project = getWorkspace().getRoot().getProject(getUniqueString());
1125
		final IFile file = project.getFile("file.txt");
1126
		ensureExistsInWorkspace(new IResource[] {project, file}, true);
1127
		addBuilder(project, BuilderWithCallback.BUILDER_NAME);
1128
1129
		waitForBuild();
1130
1131
		final int[] status = new int[] {0};
1132
		// use build callback to simulate user interaction with build
1133
		BuilderWithCallback.getInstance().setBuildCallback(new IBuildCallback() {
1134
			public IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) {
1135
				// let others know that build is running
1136
				status[0] = TestBarrier.STATUS_RUNNING;
1137
				// build will finish if monitor will be cancelled or the test already ended
1138
				while (!monitor.isCanceled() && status[0] != TestBarrier.STATUS_BLOCKED) {
1139
					try {
1140
						Thread.sleep(100);
1141
					} catch (InterruptedException e) {
1142
						// ignore
1143
					}
1144
				}
1145
				// let others know that build is finished
1146
				status[0] = TestBarrier.STATUS_DONE;
1147
				return null;
1148
			}
1149
		});
1150
1151
		// setContents will trigger a build
1152
		file.setContents(getRandomContents(), IResource.NONE, getMonitor());
1153
		// wait until build is running
1154
		TestBarrier.waitForStatus(status, TestBarrier.STATUS_RUNNING);
1155
		// setContents will trigger a build; do it in a separate job so that the main thread is not blocked
1156
		Job job = new Job("setContents") {
1157
			protected IStatus run(IProgressMonitor monitor) {
1158
				try {
1159
					file.setContents(getRandomContents(), IResource.NONE, getMonitor());
1160
				} catch (CoreException e) {
1161
					return e.getStatus();
1162
				}
1163
				return Status.OK_STATUS;
1164
			}
1165
		};
1166
		job.schedule();
1167
1168
		try {
1169
			// wait until build is finished; this should happen if build started after
1170
			// the first setContents call was cancelled by the second setContents call
1171
			TestBarrier.waitForStatus(status, TestBarrier.STATUS_DONE);
1172
		} finally {
1173
			BuilderWithCallback.getInstance().setBuildCallback(null);
1174
			// unblock the builder so that the job can finish before ending the test
1175
			status[0] = TestBarrier.STATUS_BLOCKED;
1176
			job.join();
1177
			assertTrue(job.getResult().isOK());
1178
		}
1179
1180
		waitForBuild();
1181
		ensureDoesNotExistInWorkspace(project);
1182
	}
1183
1120
	/**
1184
	/**
1121
	 * Tests the lifecycle of a builder.
1185
	 * Tests the lifecycle of a builder.
1122
	 */
1186
	 */
(-)a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuilderWithCallback.java (+49 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.tests.internal.builders;
12
13
import java.util.Map;
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IncrementalProjectBuilder;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
18
/**
19
 * Test builder that allows to override the build method using a callback interface.
20
 */
21
public class BuilderWithCallback extends IncrementalProjectBuilder {
22
	public interface IBuildCallback {
23
		IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor);
24
	}
25
26
	public static final String BUILDER_NAME = "org.eclipse.core.tests.resources.builderwithcallback";
27
28
	private static BuilderWithCallback instance;
29
30
	public static BuilderWithCallback getInstance() {
31
		return instance;
32
	}
33
34
	private IBuildCallback buildCallback;
35
36
	public BuilderWithCallback() {
37
		instance = this;
38
	}
39
40
	protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) {
41
		if (buildCallback != null)
42
			return buildCallback.build(kind, args, monitor);
43
		return null;
44
	}
45
46
	public void setBuildCallback(IBuildCallback buildCallback) {
47
		this.buildCallback = buildCallback;
48
	}
49
}

Return to bug 329657