1 | private static List<String> getClasspathMatches(String[] strPathsOrJars) {
| | 1 | /**
|
2 | final String javaClassPath = System.getProperty("java.class.path"); // $NON-NLS-1$
| | 2 | * Find classes in the provided path(s)/jar(s) that extend the class(es).
|
3 | StringTokenizer stPaths =
| | 3 | * @param searchPathsOrJars - pathnames or jarfiles to search for classes
|
4 | new StringTokenizer(javaClassPath,
| | 4 | * @param classNames - required parent class(es) or annotations
|
5 | System.getProperty("path.separator")); // $NON-NLS-1$
| | 5 | * @param innerClasses - should we include inner classes?
|
6 | if (log.isDebugEnabled()) {
| | 6 | * @param contains - classname should contain this string
|
7 | log.debug("Classpath = " + javaClassPath);
| | 7 | * @param notContains - classname should not contain this string
|
8 | for (int i = 0; i < strPathsOrJars.length; i++) {
| | 8 | * @param annotations - true if classnames are annotations
|
9 | log.debug("strPathsOrJars[" + i + "] : " + strPathsOrJars[i]);
| | 9 | *
|
10 | }
| | 10 | * @return List containing discovered classes
|
11 | }
| | 11 | */
|
12 |
| | 12 | public static List<String> findClassesThatExtend(String[] searchPathsOrJars,
|
13 | // find all jar files or paths that end with strPathOrJar
| | 13 | final Class<?>[] classNames, final boolean innerClasses,
|
14 | ArrayList<String> listPaths = new ArrayList<String>();
| | 14 | String contains, String notContains, boolean annotations)
|
15 | String strPath = null;
| | 15 | throws IOException {
|
16 | while (stPaths.hasMoreTokens()) {
| | 16 | if (log.isDebugEnabled()) {
|
17 | strPath = fixPathEntry(stPaths.nextToken());
| | 17 | log.debug("searchPathsOrJars : " + Arrays.toString(searchPathsOrJars));
|
18 | if (strPathsOrJars == null) {
| | 18 | log.debug("superclass : " + Arrays.toString(classNames));
|
19 | log.debug("Adding: " + strPath);
| | 19 | log.debug("innerClasses : " + innerClasses + " annotations: " + annotations);
|
20 | listPaths.add(strPath);
| | 20 | log.debug("contains: " + contains + " notContains: " + notContains);
|
21 | } else {
| | 21 | }
|
22 | boolean found = false;
| | 22 |
|
23 | for (int i = 0; i < strPathsOrJars.length; i++) {
| | 23 | // Find all jars in the search path
|
24 | if (strPath.endsWith(strPathsOrJars[i])) {
| | 24 | String[] strPathsOrJars = addJarsInPath(searchPathsOrJars);
|
25 | found = true;
| | 25 | for (int k = 0; k < strPathsOrJars.length; k++) {
|
26 | log.debug("Adding " + strPath + " found at " + i);
| | 26 | strPathsOrJars[k] = fixPathEntry(strPathsOrJars[k]);
|
27 | listPaths.add(strPath);
| | 27 | }
|
28 | break;// no need to look further
| | 28 |
|
29 | }
| | 29 | // Now eliminate any classpath entries that do not "match" the search
|
30 | }
| | 30 | List<String> listPaths = getClasspathMatches(strPathsOrJars);
|
31 | if (!found) {
| | 31 | if (log.isDebugEnabled()) {
|
32 | log.debug("Did not find: " + strPath);
| | 32 | for (String path : listPaths) {
|
33 | }
| | 33 | log.debug("listPaths : " + path);
|
34 | }
| | 34 | }
|
35 | }
| | 35 | }
|
36 | return listPaths;
| | 36 |
|
37 | } | | 37 | @SuppressWarnings("unchecked") // Should only be called with classes that extend annotations
|
| | | 38 | final Class<? extends Annotation>[] annoclassNames = (Class<? extends Annotation>[]) classNames;
|
| | | 39 | Set<String> listClasses =
|
| | | 40 | annotations ?
|
| | | 41 | new AnnoFilterTreeSet(annoclassNames, innerClasses)
|
| | | 42 | :
|
| | | 43 | new FilterTreeSet(classNames, innerClasses, contains, notContains);
|
| | | 44 | // first get all the classes
|
| | | 45 | findClassesInPaths(listPaths, listClasses);
|
| | | 46 | if (log.isDebugEnabled()) {
|
| | | 47 | log.debug("listClasses.size()="+listClasses.size());
|
| | | 48 | for (String clazz : listClasses) {
|
| | | 49 | log.debug("listClasses : " + clazz);
|
| | | 50 | }
|
| | | 51 | }
|
| | | 52 |
|
| | | 53 | // // Now keep only the required classes
|
| | | 54 | // Set subClassList = findAllSubclasses(superClasses, listClasses, innerClasses);
|
| | | 55 | // if (log.isDebugEnabled()) {
|
| | | 56 | // log.debug("subClassList.size()="+subClassList.size());
|
| | | 57 | // Iterator tIter = subClassList.iterator();
|
| | | 58 | // while (tIter.hasNext()) {
|
| | | 59 | // log.debug("subClassList : " + tIter.next());
|
| | | 60 | // }
|
| | | 61 | // }
|
| | | 62 |
|
| | | 63 | return new ArrayList<String>(listClasses);//subClassList);
|
| | | 64 | } |