KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > testutil > common > TestUtil


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