mirror of https://github.com/apache/lucene.git
rename LTC.registerTempFile to registerTempDir, clarified javadocs. Also fixed _TestUtil.rmDir() to not throw NPE if a 'file' is given
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1200403 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
edb422e30b
commit
969afcf642
|
@ -1179,8 +1179,13 @@ public abstract class LuceneTestCase extends Assert {
|
|||
return d;
|
||||
}
|
||||
|
||||
/** Registers a temp file that will be deleted when tests are done. */
|
||||
public static void registerTempFile(File tmpFile) {
|
||||
/**
|
||||
* Registers a temp directory that will be deleted when tests are done. This
|
||||
* is used by {@link _TestUtil#getTempDir(String)} and
|
||||
* {@link _TestUtil#unzip(File, File)}, so you should call these methods when
|
||||
* possible.
|
||||
*/
|
||||
static void registerTempDir(File tmpFile) {
|
||||
tempDirs.put(tmpFile.getAbsoluteFile(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
|
||||
|
@ -1193,11 +1198,9 @@ public abstract class LuceneTestCase extends Assert {
|
|||
final Class<? extends Directory> clazz = Class.forName(clazzName).asSubclass(Directory.class);
|
||||
// If it is a FSDirectory type, try its ctor(File)
|
||||
if (FSDirectory.class.isAssignableFrom(clazz)) {
|
||||
final File tmpFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
|
||||
tmpFile.delete();
|
||||
tmpFile.mkdir();
|
||||
registerTempFile(tmpFile);
|
||||
return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), tmpFile);
|
||||
final File dir = _TestUtil.getTempDir("index");
|
||||
dir.mkdirs(); // ensure it's created so we 'have' it.
|
||||
return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), dir);
|
||||
}
|
||||
|
||||
// try empty ctor
|
||||
|
|
|
@ -62,7 +62,7 @@ public class _TestUtil {
|
|||
try {
|
||||
File f = createTempFile(desc, "tmp", LuceneTestCase.TEMP_DIR);
|
||||
f.delete();
|
||||
LuceneTestCase.registerTempFile(f);
|
||||
LuceneTestCase.registerTempDir(f);
|
||||
return f;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -74,6 +74,9 @@ public class _TestUtil {
|
|||
*/
|
||||
public static void rmDir(File dir) throws IOException {
|
||||
if (dir.exists()) {
|
||||
if (dir.isFile() && !dir.delete()) {
|
||||
throw new IOException("could not delete " + dir);
|
||||
}
|
||||
for (File f : dir.listFiles()) {
|
||||
if (f.isDirectory()) {
|
||||
rmDir(f);
|
||||
|
@ -101,7 +104,7 @@ public class _TestUtil {
|
|||
rmDir(destDir);
|
||||
|
||||
destDir.mkdir();
|
||||
LuceneTestCase.registerTempFile(destDir);
|
||||
LuceneTestCase.registerTempDir(destDir);
|
||||
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
|
|
Loading…
Reference in New Issue