@Override public void visitArchive(ArchiveContext context) { final Collection<String> resources = bundleWiring.listResources( "/", "*", BundleWiring.LISTRESOURCES_RECURSE ); for ( final String resource : resources ) {
final Collection<String> cfgResources = bundleWiring.listResources( "/", "hibernate.cfg.xml",
public static void ensureAllClassesLoaded(Bundle bundle) throws ClassNotFoundException { BundleWiring wiring = bundle.adapt(BundleWiring.class); if (wiring != null) { for (String path : wiring.listResources("/", "*.class", BundleWiring.LISTRESOURCES_RECURSE)) { String className = path.substring(0, path.length() - ".class".length()); className = className.replace('/', '.'); bundle.loadClass(className); } } }
public static Collection<String> getClassEntriesInBundleClassPath(Bundle bundle, Set<String> packagesToScan) { BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); if (packagesToScan.isEmpty()) { return bundleWiring.listResources("/", "*" + CLASS_FILE_TYPE_SUFFIX, BundleWiring.LISTRESOURCES_LOCAL | BundleWiring.LISTRESOURCES_RECURSE); } else { List<String> ret = new ArrayList<>(); for (String pkg : packagesToScan) { ret.addAll(bundleWiring.listResources(packageToPath(pkg), "*" + CLASS_FILE_TYPE_SUFFIX, BundleWiring.LISTRESOURCES_LOCAL)); } return ret; } }
private <T> List<Class<? extends T>> findSubTypesOf(Bundle bundle, Collection<Class<T>> superclasses) { BundleWiring wiring = bundle.adapt(BundleWiring.class); Collection<String> names = wiring .listResources("/", "*", BundleWiring.LISTRESOURCES_RECURSE); return names.stream().map(new Function<String, Class<?>>() { @Override @SneakyThrows public Class<?> apply(String name) { String n = name.replaceAll("\\.class$", "").replace('/', '.'); try { return bundle.loadClass(n); } catch (ClassNotFoundException | NoClassDefFoundError e) { return null; } } }).filter(c -> c != null).filter(c -> superclasses.stream().anyMatch(sc -> sc.isAssignableFrom(c))) .filter(c -> !c.isInterface() && !Modifier.isAbstract(c.getModifiers())) .map((Function<Class<?>, Class<? extends T>>) aClass -> (Class<? extends T>) aClass) .collect(Collectors.toList()); }
protected void printResources(Bundle bundle) { BundleWiring wiring = (BundleWiring) bundle.adapt(BundleWiring.class); if (wiring != null) { Collection<String> resources = null; if (displayAllFiles) { resources = wiring.listResources("/", null, BundleWiring.LISTRESOURCES_RECURSE); } else { resources = wiring.listResources("/", "*class", BundleWiring.LISTRESOURCES_RECURSE); } if (resources.size() > 0) { System.out.println("\n" + Util.getBundleName(bundle)); } for (String resource : resources) { System.out.println(resource); } } else { System.out.println("Bundle " + bundle.getBundleId() + " is not resolved"); } }
public static List<URL> findResources(Iterable<Bundle> bundles, String path, String pattern, boolean recurse) { List<URL> resources = new ArrayList<>(); for (Bundle bundle : bundles) { Collection<String> names = bundle .adapt(BundleWiring.class) .listResources( path, pattern, BundleWiring.LISTRESOURCES_LOCAL | (recurse ? BundleWiring.LISTRESOURCES_RECURSE : 0)); for (String name : names) { resources.add(bundle.getResource(name)); } } return resources; }
public static List<URL> findResources(Iterable<Bundle> bundles, String path, String pattern, boolean recurse) { List<URL> resources = new ArrayList<>(); for (Bundle bundle : bundles) { Collection<String> names = bundle .adapt(BundleWiring.class) .listResources( path, pattern, BundleWiring.LISTRESOURCES_LOCAL | (recurse ? BundleWiring.LISTRESOURCES_RECURSE : 0)); for (String name : names) { resources.add(bundle.getResource(name)); } } return resources; }
private void scanClasses(Bundle bundle, Map<Long, Collection<Class<?>>> map, BiConsumer<String, Throwable> throwableHandler) { BundleWiring wiring = bundle.adapt(BundleWiring.class); // get all .class resources of this bundle Collection<String> classes = wiring.listResources("/", "*.class", BundleWiring.LISTRESOURCES_RECURSE); Collection<Class<?>> bundleClasses = new ArrayList<>(); for (String clazz : classes) { String className = clazz.replaceAll("\\.class$", "").replace('/', '.'); if (bundle.equals(flowServerBundle) && !className.startsWith("com.vaadin")) { continue; } if ("module-info".equals(className)) { // New modular Java info class which we are not intrested in continue; } try { bundleClasses.add(bundle.loadClass(className)); } catch (ClassNotFoundException | NoClassDefFoundError exception) { throwableHandler.accept(className, exception); } } map.put(bundle.getBundleId(), bundleClasses); }
private void loadImplementationsInBundle(final Test test, final String packageName) { final BundleWiring wiring = FrameworkUtil.getBundle(ResolverUtil.class).adapt(BundleWiring.class); final Collection<String> list = wiring.listResources(packageName, "*.class", BundleWiring.LISTRESOURCES_RECURSE); for (final String name : list) { addIfMatching(test, name); } }
protected void findResource() { Bundle[] bundles = bundleContext.getBundles(); String filter = "*" + className + "*"; for (Bundle bundle : bundles) { BundleWiring wiring = (BundleWiring) bundle.adapt(BundleWiring.class); if (wiring != null) { Collection<String> resources = wiring.listResources("/", filter, BundleWiring.LISTRESOURCES_RECURSE); if (resources.size() > 0) { System.out.println("\n" + Util.getBundleName(bundle)); } for (String resource:resources) { System.out.println(resource); } } else { System.out.println("Bundle " + bundle.getBundleId() + " is not resolved."); } } }
List<String> exports = getExports(bundle); if (displayAllFiles){ resources = wiring.listResources("/", null, BundleWiring.LISTRESOURCES_RECURSE); } else { resources = wiring.listResources("/", "*class", BundleWiring.LISTRESOURCES_RECURSE); localResources = wiring.listResources("/", null, BundleWiring.LISTRESOURCES_RECURSE | BundleWiring.LISTRESOURCES_LOCAL); } else { localResources = wiring.listResources("/", "/*.class", BundleWiring.LISTRESOURCES_RECURSE | BundleWiring.LISTRESOURCES_LOCAL);
BundleWiring wiring = bundle.adapt(BundleWiring.class); if (wiring != null){ Collection<String> resources = wiring.listResources(path, filter, BundleWiring.LISTRESOURCES_RECURSE); if (resources.size() > 0){ String title = ShellUtil.getBundleName(bundle);
@Override protected void find(PackageScanFilter test, String packageName, Set<Class<?>> classes) { packageName = packageName.replace('.', '/'); Collection<String> names = bundleWiring.listResources(packageName, "*.class", BundleWiring.LISTRESOURCES_RECURSE); if (names == null) { return; } ClassLoader bundleClassLoader = bundleWiring.getClassLoader(); for (String name : names) { String fixedName = name.substring(0, name.indexOf('.')).replace('/', '.'); try { Class<?> klass = bundleClassLoader.loadClass(fixedName); if (test.matches(klass)) { classes.add(klass); } } catch (ClassNotFoundException e) { log.debug("Cant load class: " + e.getMessage()); } } } }
BundleWiring wiring = bundle.adapt(BundleWiring.class); if (wiring != null){ Collection<String> resources = wiring.listResources(path, filter, BundleWiring.LISTRESOURCES_RECURSE); if (resources.size() > 0){ String title = ShellUtil.getBundleName(bundle);
public static Collection<String> findJPAAnnotatedClasses(Bundle b) { BundleWiring bw = b.adapt(BundleWiring.class); Collection<String> resources = bw.listResources("/", "*.class", BundleWiring.LISTRESOURCES_LOCAL | BundleWiring.LISTRESOURCES_RECURSE); Collection<String> classes = new ArrayList<String>(); ClassLoader cl = new TempBundleDelegatingClassLoader(b, JPAAnnotationScanner.class.getClassLoader()); for(String s : resources) { s = s.replace('/', '.').substring(0, s.length() - 6); try { Class<?> clazz = Class.forName(s, false, cl); if(clazz.isAnnotationPresent(Entity.class) || clazz.isAnnotationPresent(MappedSuperclass.class) || clazz.isAnnotationPresent(Embeddable.class)) { classes.add(s); } } catch (ClassNotFoundException e) { logEx(e); } catch (NoClassDefFoundError e) { logEx(e); } } return classes; }
@Override public Iterator<Entry> iterator() { entries = new HashMap<>(); for (String name : bundle.adapt(BundleWiring.class).listResources( "/", "*.class", BundleWiring.LISTRESOURCES_LOCAL | BundleWiring.LISTRESOURCES_RECURSE)) { String klass = toClassName("", name); if (filter.accept(bundle, klass)) { URL url = bundle.getResource(name); BundleArchiveEntry archiveEntry = new BundleArchiveEntry(bundle, url, klass); entries.put(klass, archiveEntry); } } return entries.values().iterator(); }
private boolean checkClassResource(String classPackageName, String classFileName, BundleWiring wiring) { if (wiring == null) { return false; } if ((wiring.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) { // fragment case; need to get the host wiring wiring = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE).get(0).getProviderWiring(); } Collection<String> classResourcePaths = wiring.listResources(classPackageName, classFileName, 0); return classResourcePaths != null && !classResourcePaths.isEmpty(); } }
Collection<String> resources = wiring.listResources("/", "*.class", BundleWiring.FINDENTRIES_RECURSE + BundleWiring.LISTRESOURCES_LOCAL); if (resources == null) {
Collection<String> resources = wiring.listResources("/", "*.class", BundleWiring.FINDENTRIES_RECURSE + BundleWiring.LISTRESOURCES_LOCAL); if (resources == null) {