Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java')
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java620
1 files changed, 310 insertions, 310 deletions
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
index 4e9a3bf89..89a823af7 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
@@ -107,9 +107,9 @@ import org.eclipse.ui.internal.decorators.DecoratorManager;
public class EclipseTest extends ResourceTest {
private static final int LOCK_WAIT_TIME = 1000;
- private static final String CVS_TEST_LOCK_FILE = ".lock";
- private static final String CVS_TEST_LOCK_PROJECT = "cvsTestLock";
- protected static IProgressMonitor DEFAULT_MONITOR = new NullProgressMonitor();
+ private static final String CVS_TEST_LOCK_FILE = ".lock";
+ private static final String CVS_TEST_LOCK_PROJECT = "cvsTestLock";
+ protected static IProgressMonitor DEFAULT_MONITOR = new NullProgressMonitor();
protected static final int RANDOM_CONTENT_SIZE = 3876;
protected static String eol = System.getProperty("line.separator");
private static boolean modelSync = true;
@@ -220,12 +220,12 @@ public class EclipseTest extends ResourceTest {
protected void addResources(IResource[] newResources) throws CoreException {
if (newResources.length == 0) return;
ResourceMapping[] mappings = asResourceMappers(newResources, IResource.DEPTH_INFINITE);
- add(mappings);
+ add(mappings);
}
- protected void add(ResourceMapping[] mappings) throws CVSException {
- executeHeadless(new AddOperation(null, mappings));
- }
+ protected void add(ResourceMapping[] mappings) throws CVSException {
+ executeHeadless(new AddOperation(null, mappings));
+ }
/**
* Perform a CVS edit of the given resources
@@ -346,49 +346,49 @@ public class EclipseTest extends ResourceTest {
/**
* Update the resources from an existing container with the changes from the CVS repository
*/
- protected IResource[] updateResources(IResource[] resources, boolean ignoreLocalChanges) throws CVSException {
- LocalOption[] options = Command.NO_LOCAL_OPTIONS;
+ protected IResource[] updateResources(IResource[] resources, boolean ignoreLocalChanges) throws CVSException {
+ LocalOption[] options = Command.NO_LOCAL_OPTIONS;
if(ignoreLocalChanges) {
options = new LocalOption[] {Update.IGNORE_LOCAL_CHANGES};
}
- ResourceMapping[] mappers = asResourceMappers(resources, IResource.DEPTH_INFINITE);
+ ResourceMapping[] mappers = asResourceMappers(resources, IResource.DEPTH_INFINITE);
update(mappers, options);
return resources;
- }
+ }
- /**
- * Update the resources contained in the given mappers.
- */
- protected void update(ResourceMapping[] mappings, LocalOption[] options) throws CVSException {
- if (options == null)
- options = Command.NO_LOCAL_OPTIONS;
- if (isModelSyncEnabled() && options == Command.NO_LOCAL_OPTIONS) {
- executeHeadless(new ModelUpdateOperation(null, mappings, false) {
- @Override
+ /**
+ * Update the resources contained in the given mappers.
+ */
+ protected void update(ResourceMapping[] mappings, LocalOption[] options) throws CVSException {
+ if (options == null)
+ options = Command.NO_LOCAL_OPTIONS;
+ if (isModelSyncEnabled() && options == Command.NO_LOCAL_OPTIONS) {
+ executeHeadless(new ModelUpdateOperation(null, mappings, false) {
+ @Override
protected boolean isAttemptHeadlessMerge() {
- return true;
- }
- @Override
+ return true;
+ }
+ @Override
protected void handlePreviewRequest() {
- // Don't preview anything
- }
- @Override
+ // Don't preview anything
+ }
+ @Override
protected void handleNoChanges() {
- // Do nothing
- }
- @Override
+ // Do nothing
+ }
+ @Override
protected void handleValidationFailure(IStatus status) {
- // Do nothing
- }
- @Override
+ // Do nothing
+ }
+ @Override
protected void handleMergeFailure(IStatus status) {
- // Do nothing
- }
- });
- } else {
- executeHeadless(new UpdateOperation(null, mappings, options, null));
- }
- }
+ // Do nothing
+ }
+ });
+ } else {
+ executeHeadless(new UpdateOperation(null, mappings, options, null));
+ }
+ }
protected void replace(IContainer container, String[] hierarchy, CVSTag tag, boolean recurse) throws CoreException {
IResource[] resources = getResources(container, hierarchy);
@@ -400,31 +400,31 @@ public class EclipseTest extends ResourceTest {
executeHeadless(op);
}
- protected void replace(ResourceMapping[] mappings) throws CVSException {
- if (isModelSyncEnabled()) {
- executeHeadless(new ModelReplaceOperation(null, mappings, false) {
- @Override
+ protected void replace(ResourceMapping[] mappings) throws CVSException {
+ if (isModelSyncEnabled()) {
+ executeHeadless(new ModelReplaceOperation(null, mappings, false) {
+ @Override
protected boolean promptForOverwrite() {
- return true;
- }
- @Override
+ return true;
+ }
+ @Override
protected void handlePreviewRequest() {
- // Don't prompt
- }
- @Override
+ // Don't prompt
+ }
+ @Override
protected void handleMergeFailure(IStatus status) {
- // Don't prompt
- }
- @Override
+ // Don't prompt
+ }
+ @Override
protected void handleValidationFailure(IStatus status) {
- // Don't prompt
- }
- });
- } else {
- executeHeadless(new ReplaceOperation(null, mappings, null));
- }
- }
-
+ // Don't prompt
+ }
+ });
+ } else {
+ executeHeadless(new ReplaceOperation(null, mappings, null));
+ }
+ }
+
public void updateProject(IProject project, CVSTag tag, boolean ignoreLocalChanges) throws TeamException {
if (tag == null) {
ResourceMapping[] mappings = asResourceMappers(new IResource[] { project }, IResource.DEPTH_INFINITE);
@@ -468,51 +468,51 @@ public class EclipseTest extends ResourceTest {
protected void commitResources(IResource[] resources, int depth, String message) throws TeamException, CoreException {
if (resources.length == 0) return;
ResourceMapping[] resourceMappers = asResourceMappers(resources, depth);
- commit(resourceMappers, message);
+ commit(resourceMappers, message);
}
- /**
- * Commit the resources contained by the mappers.
- */
- protected void commit(ResourceMapping[] mappers, String message) throws CVSException {
- executeHeadless(new CommitOperation(null, mappers, new Command.LocalOption[0], message));
- }
+ /**
+ * Commit the resources contained by the mappers.
+ */
+ protected void commit(ResourceMapping[] mappers, String message) throws CVSException {
+ executeHeadless(new CommitOperation(null, mappers, new Command.LocalOption[0], message));
+ }
- /**
- * Convert the resources to a resource mapper that traverses the resources
- * to the specified depth.
- * @param resources the resource
- * @return a resource mapper for traversing the resources to the depth specified
- */
- protected ResourceMapping[] asResourceMappers(IResource[] resources, int depth) {
- return WorkspaceResourceMapper.asResourceMappers(resources, depth);
- }
-
- protected ICVSResource asCVSResource(IResource resource) {
- return CVSWorkspaceRoot.getCVSResourceFor(resource);
- }
-
+ /**
+ * Convert the resources to a resource mapper that traverses the resources
+ * to the specified depth.
+ * @param resources the resource
+ * @return a resource mapper for traversing the resources to the depth specified
+ */
+ protected ResourceMapping[] asResourceMappers(IResource[] resources, int depth) {
+ return WorkspaceResourceMapper.asResourceMappers(resources, depth);
+ }
+
+ protected ICVSResource asCVSResource(IResource resource) {
+ return CVSWorkspaceRoot.getCVSResourceFor(resource);
+ }
+
/**
* Commit the resources from an existing container to the CVS repository
*/
public void tagProject(IProject project, CVSTag tag, boolean force) throws TeamException {
ResourceMapping[] mappings = RepositoryProviderOperation.asResourceMappers(new IResource[] {project});
- tag(mappings, tag, force);
+ tag(mappings, tag, force);
}
- /**
- * Tag the resources contained in the given mappings
- */
- protected void tag(ResourceMapping[] mappings, CVSTag tag, boolean force) throws TeamException {
- ITagOperation op = new TagOperation((IWorkbenchPart)null, mappings);
- runTag(op, tag, force);
- }
+ /**
+ * Tag the resources contained in the given mappings
+ */
+ protected void tag(ResourceMapping[] mappings, CVSTag tag, boolean force) throws TeamException {
+ ITagOperation op = new TagOperation((IWorkbenchPart)null, mappings);
+ runTag(op, tag, force);
+ }
public void tagRemoteResource(ICVSRemoteResource resource, CVSTag tag, boolean force) throws TeamException {
ITagOperation op = new TagInRepositoryOperation(null, new ICVSRemoteResource[] {resource});
runTag(op, tag, force);
}
-
+
protected void runTag(ITagOperation op, CVSTag tag, boolean force) throws TeamException {
op.setTag(tag);
if (force) op.moveTag();
@@ -531,15 +531,15 @@ public class EclipseTest extends ResourceTest {
}
public void makeBranch(IResource[] resources, CVSTag version, CVSTag branch, boolean update) throws CVSException {
ResourceMapping[] mappings = asResourceMappers(resources, IResource.DEPTH_INFINITE);
- branch(mappings, version, branch, update);
+ branch(mappings, version, branch, update);
}
- protected void branch(ResourceMapping[] mappings, CVSTag version, CVSTag branch, boolean update) throws CVSException {
- BranchOperation op = new BranchOperation(null, mappings);
- op.setTags(version, branch, update);
- executeHeadless(op);
- }
-
+ protected void branch(ResourceMapping[] mappings, CVSTag version, CVSTag branch, boolean update) throws CVSException {
+ BranchOperation op = new BranchOperation(null, mappings);
+ op.setTags(version, branch, update);
+ executeHeadless(op);
+ }
+
/**
* Return a collection of resources defined by hierarchy. The resources
* are added to the workspace and to the file system. If the manage flag is true, the
@@ -555,7 +555,7 @@ public class EclipseTest extends ResourceTest {
for (int i = 0; i < result.length; i++) {
if (result[i].getType() == IResource.FILE)
// 3786 bytes is the average size of Eclipse Java files!
- ((IFile) result[i]).setContents(getRandomContents(RANDOM_CONTENT_SIZE), true, false, null);
+ ((IFile) result[i]).setContents(getRandomContents(RANDOM_CONTENT_SIZE), true, false, null);
}
return result;
}
@@ -596,8 +596,8 @@ public class EclipseTest extends ResourceTest {
}
protected IProject checkoutProject(IProject project, String moduleName, CVSTag tag) throws TeamException {
- if (project == null)
- project = getWorkspace().getRoot().getProject(new Path(moduleName).lastSegment());
+ if (project == null)
+ project = getWorkspace().getRoot().getProject(new Path(moduleName).lastSegment());
checkout(getRepository(), project, moduleName, tag, DEFAULT_MONITOR);
return project;
}
@@ -670,16 +670,16 @@ public class EclipseTest extends ResourceTest {
* Compare resources by casting them to their prpoer type
*/
protected void assertEquals(IPath parent, ICVSResource resource1, ICVSResource resource2, boolean includeTimestamps, boolean includeTags) throws CoreException, CVSException, IOException {
- if ((resource1 == null && resource2 == null)
- || (resource1 == null && ! resource2.exists())
- || (resource2 == null && ! resource1.exists()))
- return;
- if (resource1 == null && resource2 != null) {
- fail("Expected no resource for " + resource2.getRepositoryRelativePath() + " but there was one");
- }
- if (resource2 == null && resource1 != null) {
- fail("Expected resource " + resource1.getRepositoryRelativePath() + " was missing");
- }
+ if ((resource1 == null && resource2 == null)
+ || (resource1 == null && ! resource2.exists())
+ || (resource2 == null && ! resource1.exists()))
+ return;
+ if (resource1 == null && resource2 != null) {
+ fail("Expected no resource for " + resource2.getRepositoryRelativePath() + " but there was one");
+ }
+ if (resource2 == null && resource1 != null) {
+ fail("Expected resource " + resource1.getRepositoryRelativePath() + " was missing");
+ }
assertEquals("Resource types do not match for " + parent.append(resource1.getName()), resource1.isFolder(), resource2.isFolder());
if (!resource1.isFolder())
assertEquals(parent, (ICVSFile)resource1, (ICVSFile)resource2, includeTimestamps, includeTags);
@@ -1076,17 +1076,17 @@ public class EclipseTest extends ResourceTest {
public static void waitForIgnoreFileHandling() {
waitForJobCompletion(SyncFileChangeListener.getDeferredHandler().getEventHandlerJob());
- waitForDecorator();
+ waitForDecorator();
}
- protected static void waitForDecorator() {
- // Wait for the decorator job
- Job[] decorators = Job.getJobManager().find(DecoratorManager.FAMILY_DECORATE);
- for (int i = 0; i < decorators.length; i++) {
- Job job = decorators[i];
- waitForJobCompletion(job);
- }
- }
+ protected static void waitForDecorator() {
+ // Wait for the decorator job
+ Job[] decorators = Job.getJobManager().find(DecoratorManager.FAMILY_DECORATE);
+ for (int i = 0; i < decorators.length; i++) {
+ Job job = decorators[i];
+ waitForJobCompletion(job);
+ }
+ }
public static void waitForSubscriberInputHandling(SubscriberSyncInfoCollector input) {
input.waitForCollector(new IProgressMonitor() {
@@ -1136,14 +1136,14 @@ public class EclipseTest extends ResourceTest {
if (ex instanceof InvocationTargetException)
throw CVSException.wrapException(ex);
}
-
- @Override
+
+ @Override
protected void setUp() throws Exception {
- RepositoryProviderOperation.consultModelsWhenBuildingScope = false;
- if (CVSTestSetup.ENSURE_SEQUENTIAL_ACCESS)
- obtainCVSServerLock();
- super.setUp();
- }
+ RepositoryProviderOperation.consultModelsWhenBuildingScope = false;
+ if (CVSTestSetup.ENSURE_SEQUENTIAL_ACCESS)
+ obtainCVSServerLock();
+ super.setUp();
+ }
@Override
protected void tearDown() throws Exception {
@@ -1165,153 +1165,153 @@ public class EclipseTest extends ResourceTest {
}
TestUtil.cleanUp();
}
-
- private void obtainCVSServerLock() {
- IProject project = null;
- boolean firstTry = true;
- while (project == null) {
- try {
- project = checkoutProject(null, CVS_TEST_LOCK_PROJECT , null);
- } catch (TeamException e) {
- // The checkout of the lock project failed so lets create it if it doesn't exist
- if (firstTry) {
- try {
- createTestLockProject(DEFAULT_MONITOR);
- } catch (TeamException e1) {
- // We couldn't check out the project or create it
- // It's possible someone beat us to it so we'll try the checkout again.
- }
- } else {
- // We tried twice to check out the project and failed.
- // Lets just go ahead and run but we'll log the fact that we couldn't get the lock
- write(new CVSStatus(IStatus.ERROR, "Could not obtain the CVS server lock. The test will containue but any performance timings may be affected", e), 0);
- return;
- }
- firstTry = false;
- }
- }
- if (project != null) {
- IFile lockFile = project.getFile(CVS_TEST_LOCK_FILE);
- boolean obtained = false;
- int attempts = 0;
- while (!obtained) {
- attempts++;
- if (lockFile.exists()) {
- // If the file exists, check if the lock has expired
- if (hasExpired(lockFile)) {
- try {
- overwriteLock(lockFile);
- return;
- } catch (CoreException e) {
- // Ignore the error and continue
- }
- }
- } else {
- try {
- writeLock(lockFile);
- return;
- } catch (CoreException e) {
- // Ignore the error, since it probably means someone beat us to it.
- }
- }
- // Wait for a while before testing the lock again
- try {
- Thread.sleep(LOCK_WAIT_TIME);
- } catch (InterruptedException e) {
- // Ignore
- }
- try {
- // Update the lockfile in case someone else got to it first
- replace(new IResource[] { lockFile }, null, true);
- } catch (CoreException e) {
- // An error updated is not recoverable so just continue
- write(new CVSStatus(IStatus.ERROR, "Could not obtain the CVS server lock. The test will continue but any performance timings may be affected", e), 0);
- return;
- }
- if (attempts > MAX_LOCK_ATTEMPTS) {
- write(new CVSStatus(IStatus.ERROR, "Could not obtain the CVS server lock. The test will continue but any performance timings may be affected", new Exception()), 0);
- return;
- }
- }
- }
- }
-
- private boolean hasExpired(IFile lockFile) {
- long timestamp = lockFile.getLocalTimeStamp();
- return System.currentTimeMillis() - timestamp > LOCK_EXPIRATION_THRESHOLD;
- }
+
+ private void obtainCVSServerLock() {
+ IProject project = null;
+ boolean firstTry = true;
+ while (project == null) {
+ try {
+ project = checkoutProject(null, CVS_TEST_LOCK_PROJECT , null);
+ } catch (TeamException e) {
+ // The checkout of the lock project failed so lets create it if it doesn't exist
+ if (firstTry) {
+ try {
+ createTestLockProject(DEFAULT_MONITOR);
+ } catch (TeamException e1) {
+ // We couldn't check out the project or create it
+ // It's possible someone beat us to it so we'll try the checkout again.
+ }
+ } else {
+ // We tried twice to check out the project and failed.
+ // Lets just go ahead and run but we'll log the fact that we couldn't get the lock
+ write(new CVSStatus(IStatus.ERROR, "Could not obtain the CVS server lock. The test will containue but any performance timings may be affected", e), 0);
+ return;
+ }
+ firstTry = false;
+ }
+ }
+ if (project != null) {
+ IFile lockFile = project.getFile(CVS_TEST_LOCK_FILE);
+ boolean obtained = false;
+ int attempts = 0;
+ while (!obtained) {
+ attempts++;
+ if (lockFile.exists()) {
+ // If the file exists, check if the lock has expired
+ if (hasExpired(lockFile)) {
+ try {
+ overwriteLock(lockFile);
+ return;
+ } catch (CoreException e) {
+ // Ignore the error and continue
+ }
+ }
+ } else {
+ try {
+ writeLock(lockFile);
+ return;
+ } catch (CoreException e) {
+ // Ignore the error, since it probably means someone beat us to it.
+ }
+ }
+ // Wait for a while before testing the lock again
+ try {
+ Thread.sleep(LOCK_WAIT_TIME);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ try {
+ // Update the lockfile in case someone else got to it first
+ replace(new IResource[] { lockFile }, null, true);
+ } catch (CoreException e) {
+ // An error updated is not recoverable so just continue
+ write(new CVSStatus(IStatus.ERROR, "Could not obtain the CVS server lock. The test will continue but any performance timings may be affected", e), 0);
+ return;
+ }
+ if (attempts > MAX_LOCK_ATTEMPTS) {
+ write(new CVSStatus(IStatus.ERROR, "Could not obtain the CVS server lock. The test will continue but any performance timings may be affected", new Exception()), 0);
+ return;
+ }
+ }
+ }
+ }
+
+ private boolean hasExpired(IFile lockFile) {
+ long timestamp = lockFile.getLocalTimeStamp();
+ return System.currentTimeMillis() - timestamp > LOCK_EXPIRATION_THRESHOLD;
+ }
- private void overwriteLock(IFile lockFile) throws CoreException {
- lockFile.setContents(getLockContents(), true, true, null);
- commitResources(new IResource[] { lockFile }, IResource.DEPTH_ZERO);
- }
+ private void overwriteLock(IFile lockFile) throws CoreException {
+ lockFile.setContents(getLockContents(), true, true, null);
+ commitResources(new IResource[] { lockFile }, IResource.DEPTH_ZERO);
+ }
- private void writeLock(IFile lockFile) throws CoreException {
- lockFile.create(getLockContents(), false, null);
- addResources(new IResource[] { lockFile });
- commitResources(new IResource[] { lockFile }, IResource.DEPTH_ZERO);
- }
+ private void writeLock(IFile lockFile) throws CoreException {
+ lockFile.create(getLockContents(), false, null);
+ addResources(new IResource[] { lockFile });
+ commitResources(new IResource[] { lockFile }, IResource.DEPTH_ZERO);
+ }
- private InputStream getLockContents() {
- lockId = Long.toString(System.currentTimeMillis());
- return new ByteArrayInputStream(lockId.getBytes());
- }
+ private InputStream getLockContents() {
+ lockId = Long.toString(System.currentTimeMillis());
+ return new ByteArrayInputStream(lockId.getBytes());
+ }
- private void createTestLockProject(IProgressMonitor monitor) throws TeamException {
- CVSRepositoryLocation repository = getRepository();
- RemoteFolderTree root = new RemoteFolderTree(null, repository, Path.EMPTY.toString(), null);
- RemoteFolderTree child = new RemoteFolderTree(root, CVS_TEST_LOCK_PROJECT, repository, new Path(null, root.getRepositoryRelativePath()).append(CVS_TEST_LOCK_PROJECT).toString(), null);
- root.setChildren(new ICVSRemoteResource[] { child });
- Session s = new Session(repository, root);
- s.open(monitor, true /* open for modification */);
- try {
- IStatus status = Command.ADD.execute(s,
- Command.NO_GLOBAL_OPTIONS,
- Command.NO_LOCAL_OPTIONS,
- new String[] { CVS_TEST_LOCK_PROJECT },
- null,
- monitor);
- // If we get a warning, the operation most likely failed so check that the status is OK
- if (status.getCode() == CVSStatus.SERVER_ERROR || ! status.isOK()) {
- throw new CVSServerException(status);
- }
- } finally {
- s.close();
- }
- }
-
+ private void createTestLockProject(IProgressMonitor monitor) throws TeamException {
+ CVSRepositoryLocation repository = getRepository();
+ RemoteFolderTree root = new RemoteFolderTree(null, repository, Path.EMPTY.toString(), null);
+ RemoteFolderTree child = new RemoteFolderTree(root, CVS_TEST_LOCK_PROJECT, repository, new Path(null, root.getRepositoryRelativePath()).append(CVS_TEST_LOCK_PROJECT).toString(), null);
+ root.setChildren(new ICVSRemoteResource[] { child });
+ Session s = new Session(repository, root);
+ s.open(monitor, true /* open for modification */);
+ try {
+ IStatus status = Command.ADD.execute(s,
+ Command.NO_GLOBAL_OPTIONS,
+ Command.NO_LOCAL_OPTIONS,
+ new String[] { CVS_TEST_LOCK_PROJECT },
+ null,
+ monitor);
+ // If we get a warning, the operation most likely failed so check that the status is OK
+ if (status.getCode() == CVSStatus.SERVER_ERROR || ! status.isOK()) {
+ throw new CVSServerException(status);
+ }
+ } finally {
+ s.close();
+ }
+ }
+
private void releaseCVSServerLock() {
- if (lockId != null) {
- try {
- IProject project = getWorkspace().getRoot().getProject(CVS_TEST_LOCK_PROJECT);
- // Update the project and verify we still have the lock
- IFile file = project.getFile(CVS_TEST_LOCK_FILE);
- String id = getFileContents(file);
- if (id.equals(lockId)) {
- // We have the lock so let's free it (but first check if someone preempted us)
- ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor(file);
- byte[] bytes = cvsFile.getSyncBytes();
- if (bytes != null) {
- String revision = ResourceSyncInfo.getRevision(bytes);
- updateResources(new IResource[] { file }, true);
- bytes = cvsFile.getSyncBytes();
- if (bytes == null || !ResourceSyncInfo.getRevision(bytes).equals(revision)) {
- write(new CVSStatus(IStatus.ERROR, "The CVS server lock expired while this test was running. Any performance timings may be affected", new Exception()), 0);
- return;
- }
- }
- // Delete the lock file and commit
- deleteResources(project, new String[] { CVS_TEST_LOCK_FILE }, true);
- }
- } catch (CoreException e) {
- write(e.getStatus(), 0);
- } catch (IOException e) {
- write(new CVSStatus(IStatus.ERROR, "An error occurred while reading the lock file", e), 0);
- }
- }
- }
+ if (lockId != null) {
+ try {
+ IProject project = getWorkspace().getRoot().getProject(CVS_TEST_LOCK_PROJECT);
+ // Update the project and verify we still have the lock
+ IFile file = project.getFile(CVS_TEST_LOCK_FILE);
+ String id = getFileContents(file);
+ if (id.equals(lockId)) {
+ // We have the lock so let's free it (but first check if someone preempted us)
+ ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor(file);
+ byte[] bytes = cvsFile.getSyncBytes();
+ if (bytes != null) {
+ String revision = ResourceSyncInfo.getRevision(bytes);
+ updateResources(new IResource[] { file }, true);
+ bytes = cvsFile.getSyncBytes();
+ if (bytes == null || !ResourceSyncInfo.getRevision(bytes).equals(revision)) {
+ write(new CVSStatus(IStatus.ERROR, "The CVS server lock expired while this test was running. Any performance timings may be affected", new Exception()), 0);
+ return;
+ }
+ }
+ // Delete the lock file and commit
+ deleteResources(project, new String[] { CVS_TEST_LOCK_FILE }, true);
+ }
+ } catch (CoreException e) {
+ write(e.getStatus(), 0);
+ } catch (IOException e) {
+ write(new CVSStatus(IStatus.ERROR, "An error occurred while reading the lock file", e), 0);
+ }
+ }
+ }
- protected void write(IStatus status, int indent) {
+ protected void write(IStatus status, int indent) {
PrintStream output = System.out;
indent(output, indent);
output.println("Severity: " + status.getSeverity());
@@ -1471,54 +1471,54 @@ public class EclipseTest extends ResourceTest {
}
}
- protected void assertStatusContainsCode(IStatus status, int code) {
- if (status.isMultiStatus()) {
- IStatus[] children = status.getChildren();
- for (int i = 0; i < children.length; i++) {
- IStatus child = children[i];
- if (child.getCode() == code)
- return;
- }
- fail("Expected status code was not present");
- } else {
- assertEquals("Status code is not what is expected", status.getCode(), code);
- }
- }
+ protected void assertStatusContainsCode(IStatus status, int code) {
+ if (status.isMultiStatus()) {
+ IStatus[] children = status.getChildren();
+ for (int i = 0; i < children.length; i++) {
+ IStatus child = children[i];
+ if (child.getCode() == code)
+ return;
+ }
+ fail("Expected status code was not present");
+ } else {
+ assertEquals("Status code is not what is expected", status.getCode(), code);
+ }
+ }
- @Override
+ @Override
protected void runTest() throws Throwable {
- if (!CVSTestSetup.RECORD_PROTOCOL_TRAFFIC) {
- super.runTest();
- return;
- }
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- Policy.recorder = new PrintStream(os);
- try {
- try {
- // Override the runTest method in order to print the entire trace of a
- // test that failed due to a CoreException including nested exceptions
- super.runTest();
- } catch (CoreException e) {
- e.printStackTrace();
- write(e.getStatus(), 0);
- throw e;
- }
- } catch (Throwable e) {
- // Transfer the recorded debug info to stdout
- Policy.recorder.close();
- System.out.println(new String(os.toByteArray()));
- throw e;
- } finally {
- Policy.recorder.close();
- Policy.recorder = null;
- }
- }
-
- @Override
+ if (!CVSTestSetup.RECORD_PROTOCOL_TRAFFIC) {
+ super.runTest();
+ return;
+ }
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ Policy.recorder = new PrintStream(os);
+ try {
+ try {
+ // Override the runTest method in order to print the entire trace of a
+ // test that failed due to a CoreException including nested exceptions
+ super.runTest();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ write(e.getStatus(), 0);
+ throw e;
+ }
+ } catch (Throwable e) {
+ // Transfer the recorded debug info to stdout
+ Policy.recorder.close();
+ System.out.println(new String(os.toByteArray()));
+ throw e;
+ } finally {
+ Policy.recorder.close();
+ Policy.recorder = null;
+ }
+ }
+
+ @Override
protected void cleanup() throws CoreException {
ensureDoesNotExistInWorkspace(getWorkspace().getRoot());
getWorkspace().save(true, null);
//don't leak builder jobs, since they may affect subsequent tests
waitForBuild();
- }
+ }
}

Back to the top