git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 2/4] Add shutdown hooks to try to clean up after unit tests anyway

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Nov 27, 2008, 21:15 UTC
Message-ID
<1227820535-9785-3-git-send-email-robin.rosenberg@dewire.com>
In-Reply-To
<1227820535-9785-2-git-send-email-robin.rosenberg@dewire.com>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../org/spearce/jgit/lib/RepositoryTestCase.java   |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
index 9c272f6..ef4fd1b 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
@@ -66,8 +66,8 @@
 		jcommitter = new PersonIdent("J. Committer", "jcommitter@example.com");
 	}
 
-	protected static boolean recursiveDelete(final File dir) {
-		return recursiveDelete(dir, false, null);
+	protected boolean recursiveDelete(final File dir) {
+		return recursiveDelete(dir, false, getClass().getName() + "." + getName());
 	}
 
 	protected static boolean recursiveDelete(final File dir, boolean silent,
@@ -161,6 +161,12 @@ public void run() {
 			};
 			Runtime.getRuntime().addShutdownHook(shutdownhook);
 		}
+		Runtime.getRuntime().addShutdownHook(new Thread() {
+			@Override
+			public void run() {
+				recursiveDelete(trash);
+			}
+		});
 		db = new Repository(trash_git);
 		db.create();
 
@@ -197,12 +203,18 @@ protected void tearDown() throws Exception {
 	 * @throws IOException
 	 */
 	protected Repository createNewEmptyRepo() throws IOException {
-		File newTestRepo = new File(trashParent, "new"+System.currentTimeMillis()+"/.git");
+		final File newTestRepo = new File(trashParent, "new"+System.currentTimeMillis()+"/.git");
 		assertFalse(newTestRepo.exists());
 		File unusedDir = new File(trashParent, "tmp"+System.currentTimeMillis());
 		assertTrue(unusedDir.mkdirs());
 		final Repository newRepo = new Repository(newTestRepo);
 		newRepo.create();
+		Runtime.getRuntime().addShutdownHook(new Thread() {
+			@Override
+			public void run() {
+				recursiveDelete(newTestRepo);
+			}
+		});
 		return newRepo;
 	}
 
-- 
1.6.0.3.640.g6331a
Previous: Robin RosenbergNext: Robin Rosenberg
Message 3 of 5 in “RepositoryTestCase cleanups”
  1. 0/4 RepositoryTestCase cleanupsRobin Rosenberg, Nov 27, 2008
  2. 1/4 Make the cleanup less verbose when it fails to delete temporary stuff.Robin Rosenberg, Nov 27, 2008
  3. 2/4 Add shutdown hooks to try to clean up after unit tests anywayRobin Rosenberg, Nov 27, 2008
  4. 3/4 Cleanup malformed test casesRobin Rosenberg, Nov 27, 2008
  5. 4/4 Automatically clean up any repositories created by the test casesRobin Rosenberg, Nov 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.