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 |
*/ |