public BundleClassFinder(PackageAdmin packageAdmin, Bundle bundle, ClassDiscoveryFilter discoveryFilter) { this.packageAdmin = packageAdmin; this.bundle = BundleUtils.unwrapBundle(bundle); this.discoveryFilter = discoveryFilter; }
private Bundle getBundle() { Bundle bundle = BundleUtils.getContextBundle(false); if (bundle == null) { throw new IllegalStateException("Unable to get Bundle object associated with the context classloader"); } return bundle; }
private static URL getPersistenceUnitRoot(Bundle bundle, String persistenceUnitRoot) throws MalformedURLException { if (persistenceUnitRoot == null || persistenceUnitRoot.equals(".")) { return BundleUtils.getEntry(bundle, "/"); } else { // according to EJB3.0 Persistence Specification section 6.2 // 1. the root of a persistence unit could be the WEB-INF/classes directory of a WAR file // 2. the root of a persistence unit could be EJB-JAR, APPCLIENT-JAR // 3. the persistence unit can be a jar in the following 3 places: WEB-INF/lib directory of a war; root of a EAR; lib directory of a EAR return BundleUtils.getEntry(bundle, persistenceUnitRoot); } }
private static List<Class<?>> getServiceClasses(String providerid) { Bundle bundle = BundleUtils.getContextBundle(true); if (bundle == null || bundle.getBundleContext() == null) { bundle = BundleUtils.getBundle(SAAJFactoryFinder.class.getClassLoader(), true); } if (bundle == null || bundle.getBundleContext() == null) { return Collections.<Class<?>>emptyList(); } BundleContext bundleContext = bundle.getBundleContext(); ServiceReference serviceReference = null; try { serviceReference = bundleContext.getServiceReference("org.apache.geronimo.osgi.registry.api.ProviderRegistry"); if (serviceReference != null) { ProviderRegistry registry = (ProviderRegistry) bundleContext.getService(serviceReference); return registry.getServiceClasses(providerid); } return Collections.<Class<?>>emptyList(); } finally { if (serviceReference != null) { try { bundleContext.ungetService(serviceReference); } catch (Exception e) { } } } }
/** * Returns bundle (if any) associated with current thread's context classloader. * Invoking this method is equivalent to getBundle(Thread.currentThread().getContextClassLoader(), unwrap) */ public static Bundle getContextBundle(boolean unwrap) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); return classLoader == null ? null : getBundle(classLoader, unwrap); }
private Configuration createTempConfiguration() throws DeploymentException { LinkedHashSet<Artifact> resolvedParentIds = null; try { ConfigurationData configurationData = new ConfigurationData(moduleType, null, childConfigurationDatas, environment, baseDir, inPlaceConfigurationDir, naming); createTempManifest(); createPluginMetadata(); String location = BundleUtils.toReferenceFileLocation(getConfigurationDir()); tempBundle = bundleContext.installBundle(location); if (BundleUtils.canStart(tempBundle)) { tempBundle.start(Bundle.START_TRANSIENT); } configurationData.setBundleContext(tempBundle.getBundleContext()); configurationManager.loadConfiguration(configurationData); return configurationManager.getConfiguration(environment.getConfigId()); } catch (Exception e) { throw new DeploymentException("Unable to create configuration for deployment: dependencies: " + resolvedParentIds, e); } }
private static LinkedHashSet<Bundle> getWiredBundles42(Bundle bundle) { ServiceReference reference = bundle.getBundleContext().getServiceReference(PackageAdmin.class.getName()); PackageAdmin packageAdmin = (PackageAdmin) bundle.getBundleContext().getService(reference); try { return getWiredBundles(packageAdmin, bundle); } finally { bundle.getBundleContext().ungetService(reference); } }
private void startBundle(Bundle bundle) { if (BundleUtils.canStart(bundle)) { try { bundle.start(Bundle.START_TRANSIENT); } catch (BundleException e) { log.error("Bundle " + bundle.getBundleId() + " failed to start: " + e.getMessage()); } } }
/** * The new delegating bundle classloader will make sure the resources in the wink-server bundle could be found even if * wired bundles are not searched * @return */ protected ClassLoader getContextClassLoader() { ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); List<Bundle> bundles = new ArrayList<Bundle>(2); bundles.add(BundleUtils.getBundle(contextCL, false)); bundles.add(BundleUtils.getBundle(RestServlet.class.getClassLoader(), true)); return new BundleClassLoader(new DelegatingBundle(bundles)); }
private synchronized LinkedHashSet<Bundle> getWiredBundles() { if (wiredBundles == null) { wiredBundles = BundleUtils.getWiredBundles((bundle instanceof DelegatingBundle) ? ((DelegatingBundle) bundle).getMainBundle() : bundle); } return wiredBundles; }
public TransformerWrapper(ClassTransformer classTransformer, Bundle bundle) { this.classTransformer = classTransformer; this.bundle = BundleUtils.unwrapBundle(bundle); }
public URL getResource(String name) { try { return BundleUtils.getEntry(bundle, name); } catch (MalformedURLException e) { logger.warn("MalformedURLException when getting entry:" + name + " from bundle " + bundle.getSymbolicName(), e); return null; } }
IOUtils.close(is); Bundle bundle = BundleUtils.getContextBundle(true); if (bundle != null) { URL url = bundle.getEntry(ALTERNATIVE_SHORTCUTS);
private Set<Bundle> getDependentBundles(Long bundleId) { BundleContext bundleContext = activator.getBundleContext(); Set<Bundle> dependentBundles = new HashSet<Bundle>(); // add in bundles from dependency manager ServiceReference serviceReference = bundleContext.getServiceReference(DependencyManager.class.getName()); if (serviceReference != null) { DependencyManager dependencyManager = (DependencyManager) bundleContext.getService(serviceReference); try { dependentBundles.addAll(dependencyManager.getFullDependentBundles(bundleId)); } finally { bundleContext.ungetService(serviceReference); } } // add in wired bundles if WAB Bundle bundle = bundleContext.getBundle(bundleId); String contextPath = (String) bundle.getHeaders().get("Web-ContextPath"); if (contextPath != null) { Set<Bundle> wiredBundles = BundleUtils.getWiredBundles(bundle); dependentBundles.addAll(wiredBundles); } return dependentBundles; }
public TransformerWrapper(ClassTransformer classTransformer, Bundle bundle) { this.classTransformer = classTransformer; this.bundle = BundleUtils.unwrapBundle(bundle); }
public boolean foundInJar(Bundle bundle, String jarName, ZipEntry entry, InputStream inputStream) throws Exception { URL jarURL = BundleUtils.getEntry(bundle, jarName); URL url = new URL("jar:" + jarURL.toString() + "!/" + entry.getName()); resources.add(url); return continueScanning; } });
@Override public void scan() throws WebBeansDeploymentException { logger.info("Using OsgiMetaDataScannerService!"); Bundle mainBundle = BundleUtils.getContextBundle(true); if (mainBundle != null) { ServiceReference reference = mainBundle.getBundleContext().getServiceReference(PackageAdmin.class.getName()); try { PackageAdmin packageAdmin = (PackageAdmin) mainBundle.getBundleContext().getService(reference); // search for all META-INF/beans.xml files findBeansXml(mainBundle, packageAdmin); // search for all classes if (!beanXMLs.isEmpty()) { findBeanClasses(mainBundle, packageAdmin); } } catch(Exception e) { throw new WebBeansDeploymentException("problem while scanning OSGi bundle", e); } finally { mainBundle.getBundleContext().ungetService(reference); } } }
/** * Set up a BundleResourceFinder * The suffix may contain a path fragment, unlike the bundle.findEntries method. * * @param packageAdmin package admin for finding fragments * @param bundle bundle to search * @param prefix search only paths and zip files starting with this prefix * @param suffix return only entries ending in this suffix. * @param discoveryFilter filter for matching directories and zip files. */ public BundleResourceFinder(PackageAdmin packageAdmin, Bundle bundle, String prefix, String suffix, ResourceDiscoveryFilter discoveryFilter) { this.packageAdmin = packageAdmin; this.bundle = BundleUtils.unwrapBundle(bundle); this.prefix = addSlash(prefix.trim()); this.suffix = suffix.trim(); int pos = this.suffix.lastIndexOf("/"); if (pos > -1) { osgiSuffix = this.suffix.substring(pos + 1, this.suffix.length()); extendedMatching = true; } else { osgiSuffix = "*" + this.suffix; extendedMatching = false; } this.discoveryFilter = discoveryFilter; }
protected URL getWsdlURL(Bundle bundle, String wsdlFile) { if (wsdlFile == null || wsdlFile.trim().length() == 0) { return null; } URL wsdlURL = null; wsdlFile = wsdlFile.trim(); try { wsdlURL = new URL(wsdlFile); } catch (MalformedURLException e) { // Not a URL, try as a resource wsdlURL = bundle.getResource("/" + wsdlFile); if (wsdlURL == null) { try { wsdlURL = BundleUtils.getEntry(bundle, wsdlFile); } catch (MalformedURLException e1) { log.warn("MalformedURLException when getting entry:" + wsdlFile + " from bundle " + bundle.getSymbolicName(), e); } } } return wsdlURL; }
public BundleAnnotationFinder(PackageAdmin packageAdmin, Bundle bundle, ResourceDiscoveryFilter discoveryFilter, Set<String> paths) throws Exception { this.bundle = BundleUtils.unwrapBundle(bundle); BundleResourceFinder bundleResourceFinder = new BundleResourceFinder(packageAdmin, this.bundle, "", ".class", discoveryFilter); bundleResourceFinder.find(new AnnotationFindingCallback()); this.paths = paths; }