/** * Lookup resource by given name. If OSGi runtime is detected and the originClass parameter is not null, * an attempt will be made to get the resource input stream via OSGi API from the bundle where originClass is included. * Otherwise (non OSGi environment) or if OSGi fails to provide the input stream, the return value * will be taken from the provided loader getResourceAsStream method. * * @param loader class loader where to lookup the resource in non-OSGi environment or if OSGi means fail. * @param originClass if not null, and OSGi environment is detected, the resource will be taken from the bundle including * the originClass type. * @param name filename of the desired resource. * @return an input stream corresponding to the required resource or null if the resource could not be found. */ public static InputStream getResourceAsStream(final ClassLoader loader, final Class<?> originClass, final String name) { try { if (bundleReferenceClass != null && originClass != null && bundleReferenceClass.isInstance(ReflectionHelper.class.getClassLoader())) { final Bundle bundle = FrameworkUtil.getBundle(originClass); final URL resourceUrl = (bundle != null) ? bundle.getEntry(name) : null; if (resourceUrl != null) { return resourceUrl.openStream(); } } } catch (final IOException ex) { // ignore } return loader.getResourceAsStream(name); }
/** * Lookup resource by given name. If OSGi runtime is detected and the originClass parameter is not null, * an attempt will be made to get the resource input stream via OSGi API from the bundle where originClass is included. * Otherwise (non OSGi environment) or if OSGi fails to provide the input stream, the return value * will be taken from the provided loader getResourceAsStream method. * * @param loader class loader where to lookup the resource in non-OSGi environment or if OSGi means fail. * @param originClass if not null, and OSGi environment is detected, the resource will be taken from the bundle including * the originClass type. * @param name filename of the desired resource. * @return an input stream corresponding to the required resource or null if the resource could not be found. */ public static InputStream getResourceAsStream(final ClassLoader loader, final Class<?> originClass, final String name) { try { if (bundleReferenceClass != null && originClass != null && bundleReferenceClass.isInstance(ReflectionHelper.class.getClassLoader())) { final Bundle bundle = FrameworkUtil.getBundle(originClass); final URL resourceUrl = (bundle != null) ? bundle.getEntry(name) : null; if (resourceUrl != null) { return resourceUrl.openStream(); } } } catch (final IOException ex) { // ignore } return loader.getResourceAsStream(name); }
public void execute(final Bundle bundle) { try { final URL url = bundle.getEntry(resourceName); if (url != null) { results.add(url); } } catch (final IllegalStateException e) { // The bundle has been uninstalled - ignore it } } }, context);
public void execute(final Bundle bundle) { try { final URL url = bundle.getEntry(path); if (url != null) { final URI uri = url.toURI(); if (!uris.contains(uri)) { // We haven't seen this URL before; add it urls.add(url); uris.add(uri); } } } catch (final IllegalStateException e) { // The bundle has been uninstalled - ignore it } catch (final URISyntaxException e) { // The URL can't be converted to a URI - ignore it } } }, context);
/** * Locates the first bundle that contains the presented type name and return * its bundle symbolic name. * * @param context that can be used to obtain bundles to search (required) * @param typeNameInExternalForm a type name (eg com.foo.Bar) * @return the bundle symbolic name, if found (or null if not found) */ public static String findFirstBundleForTypeName(final BundleContext context, final String typeNameInExternalForm) { Validate.notNull(context, "Bundle context required to perform the search"); Validate.notBlank(typeNameInExternalForm, "Resource name to locate is required"); final String resourceName = "/" + typeNameInExternalForm.replace('.', '/') + ".class"; final Bundle[] bundles = context.getBundles(); if (bundles == null) { return null; } for (final Bundle bundle : bundles) { try { final URL url = bundle.getEntry(resourceName); if (url != null) { return bundle.getSymbolicName(); } } catch (final RuntimeException e) { return null; } } return null; }
final URL url = bundle.getEntry(resourceName); if (url != null) { return bundle.loadClass(typeNameInExternalForm);
@Override public URL getEntry(String path) { return bundle.getEntry(path); }
private static URL findInPlugin(Bundle b, IPath filePath, ArrayList multiple) { URL result = b.getEntry(filePath.toString()); if (result != null && multiple != null) multiple.add(result); return result; }
private static URL findInPlugin(Bundle b, IPath filePath, ArrayList<URL> multiple) { URL result = b.getEntry(filePath.toString()); if (result != null && multiple != null) multiple.add(result); return result; }
public URI getURI() { try { return b.getEntry(distanceFromTop).toURI(); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
private String getSwaggerUiRoot(Bundle b, String swaggerUiVersion) { if (swaggerUiVersion == null) { swaggerUiVersion = b.getVersion().toString(); } URL entry = b.getEntry(SwaggerUiResolver.UI_RESOURCES_ROOT_START + swaggerUiVersion); if (entry != null) { return entry.toString() + "/"; } return null; } }
public boolean foundInJar(Bundle bundle, String jarName, ZipEntry entry, InputStream in) throws Exception { URL jarURL = bundle.getEntry(jarName); URL url = new URL("jar:" + jarURL.toString() + "!/" + entry.getName()); resources.add(url); return true; }
public static URL resolveResourceFromBundle(Bundle bundle, String name) throws ViewNotFoundException { URL url = bundle.getEntry(name); if (url == null) { throw new ViewNotFoundException(null, bundle, name); } return url; }
public boolean foundInJar(Bundle bundle, String jarName, ZipEntry entry, InputStream in) throws Exception { URL jarURL = bundle.getEntry(jarName); URL beansUrl = new URL("jar:" + jarURL.toString() + "!/" + entry.getName()); logger.info("adding the following beans.xml URL: " + beansUrl); beanXMLs.add(beansUrl); beanArchiveJarNames.add(jarName); return true; }
private static void addDevEntries(Bundle b, ArrayList classpath) { if (!DevClassPathHelper.inDevelopmentMode()) return; String[] binaryPaths = DevClassPathHelper.getDevClassPath(b.getSymbolicName()); for (int i = 0; i < binaryPaths.length; i++) { URL classpathEntry = b.getEntry(binaryPaths[i]); if (classpathEntry != null) classpath.add(classpathEntry); } } }
public BundleJarEntry getBundleJarEntry(String name) { URL url = bundle.getEntry(name); if (url == null) { return null; } return new BundleJarEntry(name, url, getManifestSafe()); }
private void processIconAttr() { String iconAttr = mElement.getAttribute(ATTR_ICON); if (iconAttr != null && iconAttr.trim().length() > 0) { URL url = Platform.getBundle( mElement.getContributor().getName()).getEntry( iconAttr); mIcon = ImageDescriptor.createFromURL(url); } else { mIcon = ImageDescriptor.getMissingImageDescriptor(); } }
@Test public void testStringsForResourcesInBundleWhenNoResources() throws Exception { Bundle bundle = createMock(Bundle.class); expect(bundle.getEntry("/META-INF/services/org.jclouds.apis.ApiMetadata")).andReturn(null); replay(bundle); assertEquals(Bundles.stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle), ImmutableSet.of()); verify(bundle); }
public URL getBlobManagerContrib(FeaturesRunner runner) { String bundleName = "org.nuxeo.ecm.core.test"; String contribPath = "OSGI-INF/test-storage-blob-contrib.xml"; RuntimeHarness harness = runner.getFeature(RuntimeFeature.class).getHarness(); Bundle bundle = harness.getOSGiAdapter().getRegistry().getBundle(bundleName); URL contribURL = bundle.getEntry(contribPath); assertNotNull("deployment contrib " + contribPath + " not found", contribURL); return contribURL; }