01: package org.objectweb.celtix.testutil.common;
02:
03: import java.io.File;
04: import java.net.URL;
05: import java.net.URLClassLoader;
06:
07: public final class TestUtil {
08:
09: private TestUtil() {
10: //Complete
11: }
12:
13: // Deletes all files and subdirectories under dir.
14: // Returns true if all deletions were successful.
15: // If a deletion fails, the method stops attempting to delete and returns false.
16: public static boolean deleteDir(File dir) {
17: if (dir.isDirectory()) {
18: String[] children = dir.list();
19: for (int i = 0; i < children.length; i++) {
20: boolean success = deleteDir(new File(dir, children[i]));
21: if (!success) {
22: return false;
23: }
24: }
25: }
26:
27: // The directory is now empty so delete it
28: return dir.delete();
29: }
30:
31: public static String getClassPath(ClassLoader loader) {
32: StringBuffer classPath = new StringBuffer();
33: if (loader instanceof URLClassLoader) {
34: URLClassLoader urlLoader = (URLClassLoader) loader;
35: for (URL url : urlLoader.getURLs()) {
36: String file = url.getFile();
37: if (file.indexOf("junit") == -1) {
38: classPath.append(url.getFile());
39: classPath.append(System
40: .getProperty("path.separator"));
41: }
42: }
43: }
44: return classPath.toString();
45: }
46: }
|