use of org.osgi.framework.BundleReference in project hibernate-orm by hibernate.
the class OsgiPersistenceProvider method createContainerEntityManagerFactory.
@Override
@SuppressWarnings("unchecked")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
final Map settings = generateSettings(properties);
// OSGi ClassLoaders must implement BundleReference
settings.put(org.hibernate.cfg.AvailableSettings.SCANNER, new OsgiScanner(((BundleReference) info.getClassLoader()).getBundle()));
osgiClassLoader.addClassLoader(info.getClassLoader());
return Bootstrap.getEntityManagerFactoryBuilder(info, settings, new OSGiClassLoaderServiceImpl(osgiClassLoader, osgiServiceUtil)).build();
}
use of org.osgi.framework.BundleReference in project felix by apache.
the class EnforcedQueueService method checkBundlePreference.
/**
* Checks the bundle processing preference and compare with the enforced preference.
*
* @param callable the callable
*/
private void checkBundlePreference(Callable<?> callable) {
if (callable instanceof BundleReference) {
Bundle bundle = ((BundleReference) callable).getBundle();
Preference preference = m_strategy.select(bundle);
if (!isCompatible(preference)) {
// Log a warning, Bundle asked for a synchronous processing,
// but we will enforce parametrised processing
String message = String.format("Enforcing %s mode for Bundle %s/%s [%d] (asking for %s)", m_enforced.name(), bundle.getSymbolicName(), bundle.getVersion(), bundle.getBundleId(), preference);
m_logger.log(Logger.WARNING, message);
}
}
}
use of org.osgi.framework.BundleReference in project linuxtools by eclipse.
the class CheckDevhelp method testParseMyApp.
@Test
public void testParseMyApp() throws IOException {
// We need to have a devhelp directory with contents to test.
// Copy over the needed devhelp/html2 contents in this test plug-in
// to the workspace. This test verifies: bug 433507 and also
// tests non-breaking spaces used in latest gtk-doc devhelp generation.
ClassLoader cl = getClass().getClassLoader();
Bundle bundle = null;
if (cl instanceof BundleReference) {
bundle = ((BundleReference) cl).getBundle();
}
IWorkspace ws = ResourcesPlugin.getWorkspace();
IPath wslocpath = ws.getRoot().getLocation();
// $NON-NLS-1$
IPath outfilepath = wslocpath.append("devhelp/html2/myapp");
File outfiledir = outfilepath.toFile();
assertTrue(outfiledir.mkdirs());
// $NON-NLS-1$
outfilepath = outfilepath.append("myapp.devhelp2");
File outfile = outfilepath.toFile();
// $NON-NLS-1$
IPath outfilepath2 = wslocpath.append("devhelp/html2/myapp/myapp.html");
File outfile2 = outfilepath2.toFile();
// $NON-NLS-1$
IPath outfilepath3 = wslocpath.append("devhelp/html2/myapp/myapp2.html");
File outfile3 = outfilepath3.toFile();
// $NON-NLS-1$
IPath outfilepath4 = wslocpath.append("devhelp/html2/myapp/style.css");
File outfile4 = outfilepath4.toFile();
outfile.createNewFile();
outfile2.createNewFile();
outfile3.createNewFile();
outfile4.createNewFile();
try (InputStream in = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp.devhelp2"), false)) {
// $NON-NLS-1$
Files.copy(in, Paths.get(outfile.toURI()), StandardCopyOption.REPLACE_EXISTING);
}
try (InputStream in2 = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp.html"), false)) {
// $NON-NLS-1$
Files.copy(in2, Paths.get(outfile2.toURI()), StandardCopyOption.REPLACE_EXISTING);
}
try (InputStream in3 = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp2.html"), false)) {
// $NON-NLS-1$
Files.copy(in3, Paths.get(outfile3.toURI()), StandardCopyOption.REPLACE_EXISTING);
}
try (InputStream in4 = FileLocator.openStream(bundle, new Path("devhelp/html2/myapp/myapp2.html"), false)) {
// $NON-NLS-1$
Files.copy(in4, Paths.get(outfile4.toURI()), StandardCopyOption.REPLACE_EXISTING);
}
// $NON-NLS-1$
IPath x = wslocpath.append("devhelp/html2");
ParseDevHelp.DevHelpParser p = new ParseDevHelp.DevHelpParser(x.toOSString());
LibHoverInfo hover = p.parse(new NullProgressMonitor());
assertNotNull(hover);
Map<String, FunctionInfo> functions = hover.functions;
assertNotNull(functions);
assertFalse(functions.isEmpty());
// $NON-NLS-1$
FunctionInfo f = functions.get("myapp_init");
assertNotNull(f);
String desc = f.getDescription();
assertFalse(desc.isEmpty());
String endOfDesc = desc.substring(desc.length() - 50);
// $NON-NLS-1$
assertEquals("pointer to application's argv. </p></dd>\n\n\n</dl>\n\n", endOfDesc);
// $NON-NLS-1$
FunctionInfo g = functions.get("myapp_init_check");
assertNotNull(g);
}
use of org.osgi.framework.BundleReference in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testBundleReference02.
public void testBundleReference02() throws Exception {
// $NON-NLS-1$
Bundle test = installer.installBundle("test");
// $NON-NLS-1$
Class clazz = test.loadClass("test1.Activator");
ClassLoader cl = clazz.getClassLoader();
if (!(cl instanceof BundleReference))
// $NON-NLS-1$
fail("ClassLoader is not of type BundleReference");
// $NON-NLS-1$
assertEquals("Wrong bundle", test, ((BundleReference) cl).getBundle());
}
use of org.osgi.framework.BundleReference in project logging-log4j2 by apache.
the class BundleContextSelector method shutdown.
@Override
public void shutdown(final String fqcn, final ClassLoader loader, final boolean currentContext, final boolean allContexts) {
LoggerContext ctx = null;
Bundle bundle = null;
if (currentContext) {
ctx = ContextAnchor.THREAD_CONTEXT.get();
ContextAnchor.THREAD_CONTEXT.remove();
}
if (ctx == null && loader instanceof BundleReference) {
bundle = ((BundleReference) loader).getBundle();
ctx = getLoggerContext(bundle);
removeLoggerContext(ctx);
}
if (ctx == null) {
final Class<?> callerClass = StackLocatorUtil.getCallerClass(fqcn);
if (callerClass != null) {
bundle = FrameworkUtil.getBundle(callerClass);
ctx = getLoggerContext(FrameworkUtil.getBundle(callerClass));
removeLoggerContext(ctx);
}
}
if (ctx == null) {
ctx = ContextAnchor.THREAD_CONTEXT.get();
ContextAnchor.THREAD_CONTEXT.remove();
}
if (ctx != null) {
ctx.stop(DEFAULT_STOP_TIMEOUT, TimeUnit.MILLISECONDS);
}
if (bundle != null && allContexts) {
final Bundle[] bundles = bundle.getBundleContext().getBundles();
for (final Bundle bdl : bundles) {
ctx = getLoggerContext(bdl);
if (ctx != null) {
ctx.stop(DEFAULT_STOP_TIMEOUT, TimeUnit.MILLISECONDS);
}
}
}
}
Aggregations