01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.testutil.common;
19:
20: import java.io.File;
21: import java.lang.reflect.Method;
22: import java.net.URISyntaxException;
23: import java.net.URL;
24: import java.net.URLClassLoader;
25:
26: public final class TestUtil {
27:
28: private TestUtil() {
29: //Complete
30: }
31:
32: // Deletes all files and subdirectories under dir.
33: // Returns true if all deletions were successful.
34: // If a deletion fails, the method stops attempting to delete and returns false.
35: public static boolean deleteDir(File dir) {
36: if (dir.isDirectory()) {
37: String[] children = dir.list();
38: for (int i = 0; i < children.length; i++) {
39: boolean success = deleteDir(new File(dir, children[i]));
40: if (!success) {
41: return false;
42: }
43: }
44: }
45:
46: // The directory is now empty so delete it
47: return dir.delete();
48: }
49:
50: public static String getClassPath(ClassLoader loader)
51: throws URISyntaxException {
52: StringBuffer classPath = new StringBuffer();
53: if (loader instanceof URLClassLoader) {
54: URLClassLoader urlLoader = (URLClassLoader) loader;
55: for (URL url : urlLoader.getURLs()) {
56: String file = url.getFile();
57: if (file.indexOf("junit") == -1) {
58: classPath.append(url.toURI().getPort());
59: classPath.append(System
60: .getProperty("path.separator"));
61: }
62: }
63: }
64: return classPath.toString();
65: }
66:
67: public static Method getMethod(Class<?> clazz, String methodName) {
68: Method[] declMethods = clazz.getDeclaredMethods();
69: for (Method method : declMethods) {
70: if (method.getName().equals(methodName)) {
71: return method;
72: }
73: }
74: return null;
75: }
76: }
|