Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Baumgart2010-09-24 14:47:50 +0000
committerJens Baumgart2010-09-24 14:47:50 +0000
commit629fd55a1f3b1a00826777522b72fb2c91ad09b1 (patch)
treed4ccc807037b259d73d3c087a16f19eba32eac6a
parent4fb81b320fe1b3dc07df3e8bdc4b46a4bae78aac (diff)
downloadegit-629fd55a1f3b1a00826777522b72fb2c91ad09b1.tar.gz
egit-629fd55a1f3b1a00826777522b72fb2c91ad09b1.tar.xz
egit-629fd55a1f3b1a00826777522b72fb2c91ad09b1.zip
Cleanup repositories in LocalRepositoryTestCase
Repository instances are now closed in method afterClassBase. Deletion of files is retried if files are locked. File.deleteOnExit() is no longer used. This guarantees a proper shutdown of the test class. Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java25
1 files changed, 22 insertions, 3 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
index 65df972a39..28988afae0 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/common/LocalRepositoryTestCase.java
@@ -22,6 +22,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.core.RepositoryCache;
import org.eclipse.egit.core.op.CloneOperation;
import org.eclipse.egit.core.op.CommitOperation;
import org.eclipse.egit.core.op.ConnectProviderOperation;
@@ -135,19 +136,37 @@ public abstract class LocalRepositoryTestCase extends EGitTestCase {
new Eclipse().reset();
// cleanup
deleteAllProjects();
+ shutDownRepositories();
deleteRecursive(testDirectory);
Activator.getDefault().getRepositoryCache().clear();
}
- protected static void deleteRecursive(File dirOrFile) {
+ private static void shutDownRepositories() {
+ RepositoryCache cache = Activator.getDefault().getRepositoryCache();
+ for(Repository repository:cache.getAllRepositories())
+ repository.close();
+ cache.clear();
+ }
+
+ protected static void deleteRecursive(File dirOrFile) throws IOException {
if (dirOrFile.isDirectory()) {
for (File file : dirOrFile.listFiles()) {
deleteRecursive(file);
}
}
- boolean deleted = dirOrFile.delete();
+ boolean deleted = false;
+ for(int i=0; i<10; i++) {
+ deleted = dirOrFile.delete();
+ if (deleted)
+ break;
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
if (!deleted) {
- dirOrFile.deleteOnExit();
+ throw new IOException("could not delete " + dirOrFile.getPath());
}
}

Back to the top