test/tools/jar/ChangeDir.java
Print this page
*** 38,51 ****
/** Remove dirs & files needed for test. */
private static void cleanup(File dir) throws Throwable {
if (dir != null && dir.exists()) {
for (File ff : dir.listFiles()) {
check(ff.delete());
}
check(dir.delete());
- check(new File(jarName).delete());
}
}
public static void realMain(String[] args) throws Throwable {
doTest("/");
--- 38,54 ----
/** 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());
}
}
public static void realMain(String[] args) throws Throwable {
doTest("/");
*** 60,77 ****
doTest("\\/");
}
}
static void doTest(String sep) throws Throwable {
! File testDir = null;
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");
cleanup(testDir);
check(testDir.mkdirs());
// Create file in that subdirectory
File testFile = new File(testDir, fileName);
check(testFile.createNewFile());
--- 63,83 ----
doTest("\\/");
}
}
static void doTest(String sep) throws Throwable {
! File topDir = null;
! File jarFile = new File(jarName);
JarFile jf = null;
try {
// Create a subdirectory "a/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,90 ****
// 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(fileName);
String jarArgs[] = new String[argList.size()];
jarArgs = argList.toArray(jarArgs);
Main jarTool = new Main(System.out, System.err, "jar");
--- 86,96 ----
// path name.
List<String> argList = new ArrayList<String>();
argList.add("cf");
argList.add(jarName);
argList.add("-C");
! 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,116 ****
}
} finally {
if (jf != null) {
jf.close();
}
! cleanup(testDir);
}
}
//--------------------- Infrastructure ---------------------------
static volatile int passed = 0, failed = 0;
--- 112,123 ----
}
} finally {
if (jf != null) {
jf.close();
}
! cleanup(topDir);
! jarFile.delete();
}
}
//--------------------- Infrastructure ---------------------------
static volatile int passed = 0, failed = 0;