]> source.dussan.org Git - jgit.git/commitdiff
Cleanup directories leftover by test. 15/3815/5
authorAdrian Goerler <adrian.goerler@sap.com>
Thu, 7 Jul 2011 21:16:40 +0000 (23:16 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 7 Jul 2011 21:16:40 +0000 (23:16 +0200)
Use the temporary file management from superclass.

Change-Id: I3042951dc21860b4b85dd72a6bf41ee7cfe2aba4
Signed-off-by: Adrian Goerler <adrian.goerler@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/InitCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java

index 6e74a04563affff6ebc47aaeea4baf90707e718b..0c7ae7de72085fef8c48b5897f0a810957178af3 100644 (file)
@@ -307,6 +307,26 @@ public abstract class LocalDiskRepositoryTestCase {
                toClose.add(r);
        }
 
+       private String createUniqueTestFolderPrefix() {
+               return "test" + (System.currentTimeMillis() + "_" + (testCount++));
+       }
+
+       /**
+        * Creates a unique directory for a test
+        *
+        * @param name
+        *            a subdirectory
+        * @return a unique directory for a test
+        * @throws IOException
+        */
+       protected File createTempDirectory(String name) throws IOException {
+               String gitdirName = createUniqueTestFolderPrefix();
+               File parent = new File(trash, gitdirName);
+               File directory = new File(parent, name);
+               FileUtils.mkdirs(directory);
+               return directory.getCanonicalFile();
+       }
+
        /**
         * Creates a new unique directory for a test repository
         *
@@ -317,11 +337,12 @@ public abstract class LocalDiskRepositoryTestCase {
         * @throws IOException
         */
        protected File createUniqueTestGitDir(boolean bare) throws IOException {
-               String uniqueId = System.currentTimeMillis() + "_" + (testCount++);
-               String gitdirName = "test" + uniqueId + (bare ? "" : "/")
-                               + Constants.DOT_GIT;
-               File gitdir = new File(trash, gitdirName).getCanonicalFile();
-               return gitdir;
+               String gitdirName = createUniqueTestFolderPrefix();
+               if (!bare)
+                       gitdirName += "/";
+               gitdirName += Constants.DOT_GIT;
+               File gitdir = new File(trash, gitdirName);
+               return gitdir.getCanonicalFile();
        }
 
        protected File createTempFile() throws IOException {
@@ -453,4 +474,5 @@ public abstract class LocalDiskRepositoryTestCase {
        private String testId() {
                return getClass().getName() + "." + testCount;
        }
+
 }
index e43ce3431f8c0e24ddf5996612aa61802fd3316e..76aed91b6d9342765cd21c8459b5444d37cd18d2 100644 (file)
@@ -235,21 +235,4 @@ public class CloneCommandTest extends RepositoryTestCase {
                        assertTrue(e.getMessage().contains(dirName));
                }
        }
-
-       public static File createTempDirectory(String name) throws IOException {
-               final File temp;
-               temp = File.createTempFile(name, Long.toString(System.nanoTime()));
-
-               if (!(temp.delete())) {
-                       throw new IOException("Could not delete temp file: "
-                                       + temp.getAbsolutePath());
-               }
-
-               if (!(temp.mkdir())) {
-                       throw new IOException("Could not create temp directory: "
-                                       + temp.getAbsolutePath());
-               }
-               return temp;
-       }
-
 }
index 797aad4efb037eeb740c55847c9025758ceb57f7..28236369e484fac513c81f7010b7cda8ee998a11 100644 (file)
@@ -50,7 +50,6 @@ import java.io.IOException;
 
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.lib.RepositoryTestCase;
-import org.eclipse.jgit.util.FileUtils;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -97,13 +96,4 @@ public class InitCommandTest extends RepositoryTestCase {
                assertNotNull(repository);
                assertTrue(repository.isBare());
        }
-
-       public static File createTempDirectory(String name) throws IOException {
-               final File temp;
-               temp = File.createTempFile(name, Long.toString(System.nanoTime()));
-               FileUtils.delete(temp);
-               FileUtils.mkdir(temp);
-               return temp;
-       }
-
 }
index a4a5a2671b1b5f38916e5112f1c874af1fda2e8e..7d3a55e2afccede2dfdde1ffc726716a9dad1f46 100644 (file)
@@ -47,7 +47,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
 import java.io.File;
-import java.io.IOException;
 import java.util.Collection;
 
 import org.eclipse.jgit.lib.Constants;
@@ -145,20 +144,4 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
                }
        }
 
-       public static File createTempDirectory(String name) throws IOException {
-               final File temp;
-               temp = File.createTempFile(name, Long.toString(System.nanoTime()));
-
-               if (!(temp.delete())) {
-                       throw new IOException("Could not delete temp file: "
-                                       + temp.getAbsolutePath());
-               }
-
-               if (!(temp.mkdir())) {
-                       throw new IOException("Could not create temp directory: "
-                                       + temp.getAbsolutePath());
-               }
-               return temp;
-       }
-
 }