Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
StsTestCase cleanup should delete project contents
Browse files Browse the repository at this point in the history
  • Loading branch information
kdvolder committed Feb 2, 2015
1 parent 0413588 commit 21e2c65
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static String canocalizeXml(String originalServerXml) throws Exception {
return writer.toString().replace("\\s+\\n", "\\n");
}

public static void cleanUpProjects() throws CoreException {
public static void cleanUpProjects() throws Exception {
closeAllEditors();
deleteAllProjects();
}
Expand Down Expand Up @@ -235,16 +235,39 @@ public static File createTempDirectory(String prefix, String suffix) throws IOEx
return file;
}

public static void deleteAllProjects() throws CoreException {
public static void deleteAllProjects() throws Exception {
IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for (IProject project : allProjects) {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
project.close(null);
deleteResource(project, true);
deleteProject(project);
}
getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);
}

private static void deleteProject(IProject project) throws Exception {
int retryCount = 10; // wait 1 minute at most
Exception lastException = null;
while (project.exists() && --retryCount >= 0) {
waitForManualBuild();
waitForAutoBuild();
try {
project.delete(true, true, new NullProgressMonitor());
lastException = null;
} catch (Exception e) {
lastException = e;
try {
Thread.sleep(1000);
}
catch (InterruptedException e1) {
}
}
}
if (lastException!=null) {
throw lastException;
}
}

/**
* Delete this resource.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class StsUiTestCase extends SWTBotTestCase {
private final String defaultKbLayout = SWTBotPreferences.KEYBOARD_LAYOUT;

@After
public void after() throws CoreException {
public void after() throws Exception {
cleanUp();
}

Expand All @@ -47,7 +47,7 @@ public void before() throws Exception {
setUp();
}

protected void cleanUp() throws CoreException {
protected void cleanUp() throws Exception {
List<? extends SWTBotEditor> editors = bot.editors();
for (SWTBotEditor editor : editors) {
editor.close();
Expand Down

0 comments on commit 21e2c65

Please sign in to comment.