PackageAdmin packageAdmin = (PackageAdmin) bundle.getBundleContext().getService(reference);
//1. Generated the jar file list, which contains META-INF/beans.xml file
final Set<String> annotationScanRequiredJarFiles = new HashSet<String>();
String moduleNamePrefix = webModule.isStandAlone() ? "" : webModule.getTargetPath() + "/";
BundleResourceFinder resourceFinder = new BundleResourceFinder(packageAdmin, bundle, "META-INF/", "beans.xml", new ResourceDiscoveryFilter() {
@Override
public boolean directoryDiscoveryRequired(String directoryName) {
return false;
}
@Override
public boolean rangeDiscoveryRequired(DiscoveryRange discoveryRange) {
return discoveryRange == DiscoveryRange.BUNDLE_CLASSPATH;
}
@Override
public boolean zipFileDiscoveryRequired(String zipFileName) {
return zipFileName.endsWith(".jar");
}
});
resourceFinder.find(new ResourceFinderCallback() {
@Override
public boolean foundInDirectory(Bundle arg0, String arg1, URL arg2) throws Exception {
return false;
}
@Override
public boolean foundInJar(Bundle bundle, String zipFileName, ZipEntry zipEntry, InputStream in) throws Exception {
String zipEntryName = zipEntry.getName();
if (zipEntryName.equals("META-INF/beans.xml")) {
annotationScanRequiredJarFiles.add(zipFileName);
}
return true;
}
});
final String webInfClassesFolder = moduleNamePrefix + "WEB-INF/classes/";
final boolean webInfClassesScanRequired = bundle.getEntry(moduleNamePrefix + "WEB-INF/beans.xml") != null;
//2. Scan annotations
BundleAnnotationFinder bundleAnnotationFinder = new BundleAnnotationFinder(packageAdmin, bundle, new ResourceDiscoveryFilter() {
@Override
public boolean directoryDiscoveryRequired(String directory) {
return directory.equals(webInfClassesFolder) && webInfClassesScanRequired;
}