test/tools/jar/ChangeDir.java
Print this page
@@ -38,14 +38,17 @@
/** Remove dirs & files needed for test. */
private static void cleanup(File dir) throws Throwable {
if (dir != null && dir.exists()) {
for (File ff : dir.listFiles()) {
+ if (ff.isDirectory()) {
+ cleanup(ff);
+ } else {
check(ff.delete());
}
+ }
check(dir.delete());
- check(new File(jarName).delete());
}
}
public static void realMain(String[] args) throws Throwable {
doTest("/");
@@ -60,18 +63,21 @@
doTest("\\/");
}
}
static void doTest(String sep) throws Throwable {
- File testDir = null;
+ File topDir = null;
+ File jarFile = new File(jarName);
JarFile jf = null;
try {
// Create a subdirectory "a/b"
- File f = File.createTempFile("delete", ".me");
- String dirName = f.getParent();
- testDir = new File(dirName + sep + "a" + sep + "b");
+ topDir = File.createTempFile("delete", ".me");
+ check(topDir.delete());
+
+ File testDir = new File(topDir.getPath() + sep + "a" + sep + "b");
cleanup(testDir);
+ jarFile.delete();
check(testDir.mkdirs());
// Create file in that subdirectory
File testFile = new File(testDir, fileName);
check(testFile.createNewFile());
@@ -80,11 +86,11 @@
// path name.
List<String> argList = new ArrayList<String>();
argList.add("cf");
argList.add(jarName);
argList.add("-C");
- argList.add(dirName + sep + "a" + sep + sep + "b"); // Note double 'sep' is intentional
+ argList.add(topDir.getPath() + sep + "a" + sep + sep + "b"); // Note double 'sep' is intentional
argList.add(fileName);
String jarArgs[] = new String[argList.size()];
jarArgs = argList.toArray(jarArgs);
Main jarTool = new Main(System.out, System.err, "jar");
@@ -106,11 +112,12 @@
}
} finally {
if (jf != null) {
jf.close();
}
- cleanup(testDir);
+ cleanup(topDir);
+ jarFile.delete();
}
}
//--------------------- Infrastructure ---------------------------
static volatile int passed = 0, failed = 0;