BundleClassesFinder { public Collection<Class<?>> getClasses(final Bundle bundle) { Collection<Class<?>> classes = new ArrayList<Class<?>>(); @SuppressWarnings("unchecked") Enumeration<URL> classEntries = bundle.findEntries(this.basePackage, RESOURCE_PATTERN, true); while ((classEntries != null) && classEntries.hasMoreElements()) { try { URL classURL = classEntries.nextElement(); ClassReader classReader = new ClassReader(classURL.openStream()); if (accepts(classReader)) { String className = classReader.getClassName().replace('/', '.'); if (LOG.isDebugEnabled()) { LOG.debug("Class: " + className + " has been found."); } Class<?> clazz = bundle.loadClass(className); classes.add(clazz); } } catch (ClassNotFoundException e) { LOG.error("Error loading class!", e); } catch (IOException e) { LOG.error("Error reading the class!", e); } } return classes; } BundleClassesFinder(String basePackage); Collection<Class<?>> getClasses(final Bundle bundle); Collection<Class<?>> getClasses(final Collection<Bundle> bundles); void addFilter(ClassFilter classFilter); Collection<Class<?>> traverseBundlesForOsgiServices(final Collection<Bundle> bundles);  }
@Test public void testGetClasses() throws ClassNotFoundException { bundleSetup(); Collection<Class<?>> classes = classFinder.getClasses(Lists.newArrayList(bundle)); Assert.assertEquals(classes.size(), 3); for (Class clazz : classes) { Assert.assertFalse(clazz.getSimpleName().equals("TestBundleClass4")); } }