@Override public Bundle[] getFragments(Bundle bundle) { return osgi.getRegistry().getFragments(bundle.getSymbolicName()); }
public static synchronized void initialize(ClassLoader cl, File home, List<File> bundleFiles, Map<String, Object> hostEnv) { if (isInitialized) { return; } FrameworkLoader.home = home; FrameworkLoader.bundleFiles = bundleFiles == null ? new ArrayList<>() : bundleFiles; Collections.sort(FrameworkLoader.bundleFiles); loader = cl; doInitialize(hostEnv); osgi = new OSGiAdapter(home); isInitialized = true; }
public void fireFrameworkStarted() throws BundleException { if (osgi.getSystemBundle() == null) { SystemBundleFile file; try { file = new SystemBundleFile(osgi.getWorkingDir()); } catch (IOException e) { throw new BundleException("Cannot create system bundle file", e); } osgi.setSystemBundle(new SystemBundle(osgi, file, loader)); } osgi.fireFrameworkEvent(new FrameworkEvent(FrameworkEvent.STARTED, osgi.getSystemBundle(), null)); }
@Override @Deprecated public RuntimeContext deployTestContrib(String bundle, URL contrib) throws Exception { Bundle b = bundleLoader.getOSGi().getRegistry().getBundle(bundle); if (b == null) { b = osgi.getSystemBundle(); } OSGiRuntimeContext ctx = new OSGiRuntimeContext(runtime, b); ctx.deploy(contrib); return ctx; }
@Override @Deprecated public void deployFolder(File folder, ClassLoader loader) throws Exception { DirectoryBundleFile bf = new DirectoryBundleFile(folder); BundleImpl bundle = new BundleImpl(osgi, bf, loader); osgi.install(bundle); }
throw e; osgi = new OSGiAdapter(workingDir); BundleFile bf = new SystemBundleFile(workingDir); bundleLoader = new StandaloneBundleLoader(osgi, RuntimeHarnessImpl.class.getClassLoader()); SystemBundle systemBundle = new SystemBundle(osgi, bf, bundleLoader.getSharedClassLoader().getLoader()); osgi.setSystemBundle(systemBundle); Thread.currentThread().setContextClassLoader(bundleLoader.getSharedClassLoader().getLoader());
private static void doStart() throws BundleException { printStartMessage(); // install system bundle first BundleFile bf; try { bf = new SystemBundleFile(home); } catch (IOException e) { throw new BundleException("Cannot create system bundle for " + home, e); } SystemBundle systemBundle = new SystemBundle(osgi, bf, loader); osgi.setSystemBundle(systemBundle); printDeploymentOrderInfo(bundleFiles); for (File f : bundleFiles) { if (!isBundle(f)) { continue; } try { install(f); } catch (IOException | BundleException | RuntimeException e) { log.error("Failed to install bundle: " + f, e); } } osgi.fireFrameworkEvent(new FrameworkEvent(FrameworkEvent.STARTED, systemBundle, null)); // osgi.fireFrameworkEvent(new // FrameworkEvent(FrameworkEvent.AFTER_START, systemBundle, null)); }
@Override public Bundle[] getBundles(String symbolicName, String versionRange) { return new Bundle[] { osgi.getBundle(symbolicName) }; }
public static void main(String[] args) throws Exception { File home = new File("/tmp/test_osgi_loader"); OSGiAdapter osgi = new OSGiAdapter(home); System.out.println("Starting ..."); StandaloneBundleLoader loader = new StandaloneBundleLoader(osgi); Thread.currentThread().setContextClassLoader(loader.loader.getLoader()); double s = System.currentTimeMillis(); try { loader.setExtractNestedJARs(true); loader.setScanForNestedJARs(true); List<BundleFile> bundles = new ArrayList<BundleFile>(); List<BundleFile> jars = new ArrayList<BundleFile>(); loader.load(new File("/opt/jboss/server/default/deploy/nuxeo.ear"), bundles, jars); loader.installAll(bundles); System.out.println(">>>> Loading done!!!!"); } finally { System.out.println("Shutting down"); osgi.shutdown(); } double e = System.currentTimeMillis(); System.out.println("Total time: " + ((e - s) / 1000) + " sec."); System.exit(0); }
@Override public void fireFrameworkStarted() { if (frameworkStarted) { throw new IllegalStateException("fireFrameworkStarted must not be called more than once"); } frameworkStarted = true; boolean txStarted = !TransactionHelper.isTransactionActiveOrMarkedRollback() && TransactionHelper.startTransaction(); boolean txFinished = false; try { osgi.fireFrameworkEvent(new FrameworkEvent(FrameworkEvent.STARTED, runtimeBundle, null)); txFinished = true; } finally { if (!txFinished) { TransactionHelper.setTransactionRollbackOnly(); } if (txStarted) { TransactionHelper.commitOrRollbackTransaction(); } } }
@Override public void addBundleListener(BundleListener listener) { bundle.osgi.addBundleListener(listener); }
@Override public void addFrameworkListener(FrameworkListener listener) { bundle.osgi.addFrameworkListener(listener); }
@Override public void installBundle(BundleFile bundleFile) throws BundleException { osgi.install(new BundleImpl(osgi, bundleFile, loader.getLoader())); }
public static void uninstall(String symbolicName) throws BundleException { BundleImpl bundle = osgi.getBundle(symbolicName); if (bundle != null) { bundle.uninstall(); } }
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; }
public void setSystemBundle(SystemBundle systemBundle) throws BundleException { if (this.systemBundle != null) { throw new IllegalStateException("Cannot set system bundle"); } install(systemBundle); registry.addBundleAlias("system.bundle", systemBundle.getSymbolicName()); this.systemBundle = systemBundle; systemBundle.getBundleContext().registerService(PackageAdmin.class.getName(), new PackageAdminImpl(this), null); }
OSGiRuntimeService runtime = (OSGiRuntimeService) harness.getContext().getRuntime(); for (String name : bundles) { Bundle bundle = harness.getOSGiAdapter().getBundle(name); if (bundle == null) { try { harness.deployBundle(name); bundle = harness.getOSGiAdapter().getBundle(name); if (bundle == null) { throw new UnsupportedOperationException("Should not occur");
public synchronized void start() { if (osgi != null) { throw new IllegalStateException("Nuxeo Runtime already started"); } osgi = new OSGiAdapter(env.getHome(), env.getData(), env.getProperties()); }
@Override public void deployBundle(String name) throws Exception { // install only if not yet installed Bundle bundle = bundleLoader.getOSGi().getRegistry().getBundle(name); if (bundle == null) { BundleFile bundleFile = lookupBundle(name); bundleLoader.loadBundle(bundleFile); bundleLoader.installBundle(bundleFile); bundle = bundleLoader.getOSGi().getRegistry().getBundle(name); } else { log.info("A bundle with name {} has been found. Deploy is ignored.", name); } if (runtime.getContext(bundle) == null) { runtime.createContext(bundle); } }
public synchronized void deployBundle(File file) throws BundleException, IOException { if (!isStarted()) { throw new IllegalStateException("Framework not started"); } if (!file.getPath().endsWith(".jar")) { return; // not a valid bundle } BundleFile bf = file.isDirectory() ? new DirectoryBundleFile(file) : new JarBundleFile(file); try { BundleImpl bundle = new BundleImpl(osgi, bf, loader); if (bundle.getSymbolicName() != null) { osgi.install(bundle); } } catch (NullPointerException t) { // do nothing: may happen with non OSGi manifests // System.out.println("Ignore: "+file); } }