Lines 10-22
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.core.tests.internal.builders; |
11 |
package org.eclipse.core.tests.internal.builders; |
12 |
|
12 |
|
13 |
import java.util.Map; |
13 |
import java.util.*; |
14 |
import junit.framework.Test; |
14 |
import junit.framework.Test; |
15 |
import junit.framework.TestSuite; |
15 |
import junit.framework.TestSuite; |
16 |
import org.eclipse.core.resources.*; |
16 |
import org.eclipse.core.resources.*; |
17 |
import org.eclipse.core.runtime.*; |
17 |
import org.eclipse.core.runtime.*; |
18 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
18 |
import org.eclipse.core.runtime.jobs.*; |
19 |
import org.eclipse.core.runtime.jobs.Job; |
|
|
20 |
import org.eclipse.core.tests.harness.TestBarrier; |
19 |
import org.eclipse.core.tests.harness.TestBarrier; |
21 |
import org.eclipse.core.tests.internal.builders.TestBuilder.BuilderRuleCallback; |
20 |
import org.eclipse.core.tests.internal.builders.TestBuilder.BuilderRuleCallback; |
22 |
|
21 |
|
Lines 205-208
Link Here
|
205 |
tb2.waitForStatus(TestBarrier.STATUS_DONE); |
204 |
tb2.waitForStatus(TestBarrier.STATUS_DONE); |
206 |
} |
205 |
} |
207 |
|
206 |
|
|
|
207 |
private HashSet<ISchedulingRule> getRulesAsSet(ISchedulingRule rule) { |
208 |
HashSet<ISchedulingRule> rules = new HashSet<ISchedulingRule>(); |
209 |
if (rule == null) |
210 |
return rules; |
211 |
if (rule instanceof MultiRule) |
212 |
rules.addAll(Arrays.asList(((MultiRule) rule).getChildren())); |
213 |
else |
214 |
rules.add(rule); |
215 |
return rules; |
216 |
} |
217 |
|
218 |
/** |
219 |
* Tests for regression in running the build with reduced scheduling rules. |
220 |
* @throws Exception |
221 |
*/ |
222 |
public void testBug343256() throws Exception { |
223 |
String name = "testBug343256"; |
224 |
setAutoBuilding(false); |
225 |
final IProject project = getWorkspace().getRoot().getProject(name); |
226 |
create(project, false); |
227 |
|
228 |
IProjectDescription desc = project.getDescription(); |
229 |
desc.setBuildSpec(new ICommand[] {createCommand(desc, EmptyDeltaBuilder.BUILDER_NAME, "Project1Build1"), createCommand(desc, EmptyDeltaBuilder2.BUILDER_NAME, "Project1Build2")}); |
230 |
project.setDescription(desc, getMonitor()); |
231 |
|
232 |
// Ensure the builder is instantiated |
233 |
project.build(IncrementalProjectBuilder.CLEAN_BUILD, getMonitor()); |
234 |
|
235 |
final TestBarrier tb1 = new TestBarrier(TestBarrier.STATUS_WAIT_FOR_START); |
236 |
final TestBarrier tb2 = new TestBarrier(TestBarrier.STATUS_WAIT_FOR_START); |
237 |
|
238 |
// Scheduling rules to returng from #getRule |
239 |
final ISchedulingRule[] getRules = new ISchedulingRule[2]; |
240 |
final ISchedulingRule[] buildRules = new ISchedulingRule[2]; |
241 |
|
242 |
// Create a builder set a null scheduling rule |
243 |
EmptyDeltaBuilder builder = EmptyDeltaBuilder.getInstance(); |
244 |
EmptyDeltaBuilder2 builder2 = EmptyDeltaBuilder2.getInstance(); |
245 |
|
246 |
// Set the rule call-back |
247 |
builder.setRuleCallback(new BuilderRuleCallback() { |
248 |
public ISchedulingRule getRule(String name, IncrementalProjectBuilder builder, int trigger, Map args) { |
249 |
tb1.waitForStatus(TestBarrier.STATUS_START); |
250 |
return getRules[0]; |
251 |
} |
252 |
|
253 |
public IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException { |
254 |
HashSet<ISchedulingRule> h1 = getRulesAsSet(Job.getJobManager().currentRule()); |
255 |
HashSet<ISchedulingRule> h2 = getRulesAsSet(buildRules[0]); |
256 |
// shared scheduling rule |
257 |
assertTrue(h1.equals(h2)); |
258 |
tb1.setStatus(TestBarrier.STATUS_DONE); |
259 |
return super.build(kind, args, monitor); |
260 |
} |
261 |
}); |
262 |
// Set the rule call-back |
263 |
builder2.setRuleCallback(new BuilderRuleCallback() { |
264 |
public ISchedulingRule getRule(String name, IncrementalProjectBuilder builder, int trigger, Map<String, String> args) { |
265 |
tb2.waitForStatus(TestBarrier.STATUS_START); |
266 |
return getRules[1]; |
267 |
} |
268 |
|
269 |
public IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException { |
270 |
HashSet<ISchedulingRule> h1 = getRulesAsSet(Job.getJobManager().currentRule()); |
271 |
HashSet<ISchedulingRule> h2 = getRulesAsSet(buildRules[1]); |
272 |
assertTrue(h1.equals(h2)); |
273 |
tb2.setStatus(TestBarrier.STATUS_DONE); |
274 |
return super.build(kind, args, monitor); |
275 |
} |
276 |
}); |
277 |
|
278 |
// IProject.build() |
279 |
Job j = new Job("IProject.build()") { |
280 |
protected IStatus run(IProgressMonitor monitor) { |
281 |
try { |
282 |
project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); |
283 |
} catch (CoreException e) { |
284 |
fail(e.toString()); |
285 |
} |
286 |
return Status.OK_STATUS; |
287 |
} |
288 |
}; |
289 |
invokeTestBug343256(project, getRules, buildRules, tb1, tb2, j); |
290 |
|
291 |
// IWorkspace.build() |
292 |
j = new Job("IWorkspace.build()") { |
293 |
protected IStatus run(IProgressMonitor monitor) { |
294 |
try { |
295 |
getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, monitor); |
296 |
} catch (CoreException e) { |
297 |
fail(e.toString()); |
298 |
} |
299 |
return Status.OK_STATUS; |
300 |
} |
301 |
}; |
302 |
invokeTestBug343256(project, getRules, buildRules, tb1, tb2, j); |
303 |
|
304 |
// IWorkspace.build(IBuildConfiguration[],...) |
305 |
j = new Job("IWorkspace.build(IBuildConfiguration[],...)") { |
306 |
protected IStatus run(IProgressMonitor monitor) { |
307 |
try { |
308 |
getWorkspace().build(new IBuildConfiguration[] {project.getActiveBuildConfig()}, IncrementalProjectBuilder.FULL_BUILD, true, monitor); |
309 |
} catch (CoreException e) { |
310 |
fail(e.toString()); |
311 |
} |
312 |
return Status.OK_STATUS; |
313 |
} |
314 |
}; |
315 |
invokeTestBug343256(project, getRules, buildRules, tb1, tb2, j); |
316 |
|
317 |
} |
318 |
|
319 |
/** |
320 |
* Helper method do invoke a set of tests on Bug343256 using the different sets of builder API |
321 |
*/ |
322 |
private void invokeTestBug343256(IProject project, ISchedulingRule[] getRules, ISchedulingRule[] buildRules, TestBarrier tb1, TestBarrier tb2, Job j) { |
323 |
// Test 1 - IProject#build project sched rule |
324 |
getRules[0] = getRules[1] = project; |
325 |
buildRules[0] = buildRules[1] = new MultiRule(new ISchedulingRule[] {getRules[0]}); |
326 |
tb1.setStatus(TestBarrier.STATUS_START); |
327 |
tb2.setStatus(TestBarrier.STATUS_START); |
328 |
j.schedule(); |
329 |
tb1.waitForStatus(TestBarrier.STATUS_DONE); |
330 |
tb2.waitForStatus(TestBarrier.STATUS_DONE); |
331 |
|
332 |
// Test 2 - IProject#build null rule |
333 |
getRules[0] = getRules[1] = null; |
334 |
buildRules[0] = buildRules[1] = null; |
335 |
tb1.setStatus(TestBarrier.STATUS_START); |
336 |
tb2.setStatus(TestBarrier.STATUS_START); |
337 |
j.schedule(); |
338 |
tb1.waitForStatus(TestBarrier.STATUS_DONE); |
339 |
tb2.waitForStatus(TestBarrier.STATUS_DONE); |
340 |
|
341 |
// Test 3 - IProject#build mixed projects |
342 |
getRules[0] = project; |
343 |
getRules[1] = getWorkspace().getRoot().getProject("other"); |
344 |
buildRules[0] = buildRules[1] = new MultiRule(new ISchedulingRule[] {getRules[0], getRules[1]}); |
345 |
// TODO it should be: |
346 |
// buildRules[0] = getRules[0] |
347 |
// buildRules[1] = getRules[1] |
348 |
tb1.setStatus(TestBarrier.STATUS_START); |
349 |
tb2.setStatus(TestBarrier.STATUS_START); |
350 |
j.schedule(); |
351 |
tb1.waitForStatus(TestBarrier.STATUS_DONE); |
352 |
tb2.waitForStatus(TestBarrier.STATUS_DONE); |
353 |
|
354 |
// Test 4 - IProject#build project + null |
355 |
getRules[0] = project; |
356 |
getRules[1] = null; |
357 |
buildRules[0] = buildRules[1] = getWorkspace().getRoot(); |
358 |
// TODO it should be: |
359 |
// buildRules[0] = getRules[0] |
360 |
// buildRules[1] = null |
361 |
tb1.setStatus(TestBarrier.STATUS_START); |
362 |
tb2.setStatus(TestBarrier.STATUS_START); |
363 |
j.schedule(); |
364 |
tb1.waitForStatus(TestBarrier.STATUS_DONE); |
365 |
tb2.waitForStatus(TestBarrier.STATUS_DONE); |
366 |
} |
208 |
} |
367 |
} |