class ClasspathScanner {

    public List<Class<?>> getClassesWithAnnotation(final Class<? extends Annotation> desiredAnnotation,
                                                   final ClassLoader classLoader, final String[] cpElements) {

        final List<Class<?>> classList = new ArrayList<Class<?>>();

        final List<String> classNameList = new ArrayList<String>();

        for (final String cpElement : cpElements) {
            final File f = new File(cpElement);

            if (f.exists() && f.isDirectory()) {
                final List<File> files = getAllFiles(f, "class");

                for (final File classFile : files) {
                    classNameList.add(convertFileToClass(classFile, f));
                }

            } else {
                // jar file
                JarFile jarFile = null;
                try {
                    jarFile = new JarFile(f);

                    final Enumeration<JarEntry> entries = jarFile.entries();

                    while (entries.hasMoreElements()) {
                        final JarEntry nextElement = entries.nextElement();

                        if (!nextElement.isDirectory()) {
                            final String name = nextElement.getName();

                            if (name.endsWith(".class")) {
                                final String classname = name.replace(File.separatorChar, '.');
                                classNameList.add(classname.substring(0, classname.length() - 6));
                            }
                        }
                    }
                } catch (final IOException e) {
                    // don't care
                } finally {
                    if (jarFile != null) {
                        try {
                            jarFile.close();
                        } catch (IOException e) {
                            // don't care
                        }
                    }
                }

                // load up contents of jar

            }

        }

        for (final String className : classNameList) {
            try {
                if (!className.contains("$")) {
                    // no inner classes here thanks
                    final Class<?> clazz = classLoader.loadClass(className);

                    if (clazz.isAnnotationPresent(desiredAnnotation)) {
                        classList.add(clazz);
                    }
                }
            } catch (final NoClassDefFoundError e) {
                // don't care
            } catch (final ClassNotFoundException e) {
                // don't care about that either
            }

        }

        return classList;

    }

}