Search in sources :

Example 1 with BundleReference

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();
}
Also used : BundleReference(org.osgi.framework.BundleReference) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with BundleReference

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);
        }
    }
}
Also used : Preference(org.apache.felix.ipojo.extender.internal.queue.pref.Preference) Bundle(org.osgi.framework.Bundle) BundleReference(org.osgi.framework.BundleReference)

Example 3 with BundleReference

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);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) Bundle(org.osgi.framework.Bundle) InputStream(java.io.InputStream) FunctionInfo(org.eclipse.linuxtools.cdt.libhover.FunctionInfo) BundleReference(org.osgi.framework.BundleReference) LibHoverInfo(org.eclipse.linuxtools.cdt.libhover.LibHoverInfo) ParseDevHelp(org.eclipse.linuxtools.internal.cdt.libhover.devhelp.ParseDevHelp) IWorkspace(org.eclipse.core.resources.IWorkspace) File(java.io.File) Test(org.junit.Test)

Example 4 with BundleReference

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());
}
Also used : Bundle(org.osgi.framework.Bundle) ModuleClassLoader(org.eclipse.osgi.internal.loader.ModuleClassLoader) URLClassLoader(java.net.URLClassLoader) WovenClass(org.osgi.framework.hooks.weaving.WovenClass) BundleReference(org.osgi.framework.BundleReference)

Example 5 with BundleReference

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);
            }
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleReference(org.osgi.framework.BundleReference) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Aggregations

BundleReference (org.osgi.framework.BundleReference)11 Bundle (org.osgi.framework.Bundle)6 File (java.io.File)2 InputStream (java.io.InputStream)2 ServiceLoader (java.util.ServiceLoader)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 IWorkspace (org.eclipse.core.resources.IWorkspace)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 Test (org.junit.Test)2 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Preference (org.apache.felix.ipojo.extender.internal.queue.pref.Preference)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 ITopic (org.eclipse.help.ITopic)1 IUAElement (org.eclipse.help.IUAElement)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 FunctionInfo (org.eclipse.linuxtools.cdt.libhover.FunctionInfo)1 LibHoverInfo (org.eclipse.linuxtools.cdt.libhover.LibHoverInfo)1