public static String install(File f) throws IOException, BundleException { BundleFile bf; if (f.isDirectory()) { bf = new DirectoryBundleFile(f); } else { bf = new JarBundleFile(f); } BundleImpl bundle = new BundleImpl(osgi, bf, loader); if (bundle.getState() == 0) { // not a bundle (no Bundle-SymbolicName) return null; } osgi.install(bundle); return bundle.getSymbolicName(); }
@Override public void stop() throws BundleException { try { setStopping(); getActivator().stop(context); setStopped(); } catch (BundleException e) { throw new BundleException("Failed to stop activator: " + getActivatorClassName(), e); } catch (Exception e) { // stupid OSGi API throws Exception RuntimeException re = ExceptionUtils.runtimeException(e); throw new BundleException("Failed to stop activator: " + getActivatorClassName(), re); } }
protected void unregister(BundleRegistration reg) throws BundleException { if (getFragmentHost(reg) == null) { reg.bundle.stop(); } reg.bundle.setUnResolved(); bundles.remove(reg.bundle.getSymbolicName()); bundlesById.remove(reg.bundle.getBundleId()); reg.bundle.setUninstalled(); for (String depOnMe : reg.dependsOnMe) { BundleRegistration depReg = bundles.get(depOnMe); if (depReg != null) { // set to unresolved depReg.bundle.setUnResolved(); } } }
public synchronized void uninstall(BundleImpl bundle) throws BundleException { if (bundle.getState() != Bundle.UNINSTALLED) { BundleRegistration reg = bundles.get(bundle.getSymbolicName()); if (reg != null) { unregister(reg); } } }
public void shutdown() { BundleRegistration[] regs = bundles.values().toArray(new BundleRegistration[bundles.size()]); for (BundleRegistration reg : regs) { try { if (reg.bundle != null) { reg.bundle.shutdown(); } } catch (BundleException e) { log.error("Failed to stop bundle " + reg.bundle.getSymbolicName(), e); } catch (RuntimeException e) { log.error("Failed to stop bundle " + reg.bundle.getSymbolicName(), e); } } }
protected void doRegister(BundleRegistration reg) throws BundleException { String name = reg.bundle.getSymbolicName(); log.info("Registering resolved bundle: " + name); bundles.put(name, reg); bundlesById.put(reg.bundle.getBundleId(), reg); reg.bundle.setInstalled(); reg.bundle.setResolved(); String hostBundleId = getFragmentHost(reg); if (hostBundleId != null) { BundleRegistration host = bundles.get(hostBundleId); host.addFragment(reg.bundle.getSymbolicName()); } else { // TODO how to lazy start the bundle? reg.bundle.start(); } // check if there are objects waiting for me Set<BundleRegistration> regs = pendings.remove(name); if (regs != null) { for (BundleRegistration pendingReg : regs) { pendingReg.removeUnresolvedDependency(name); if (!pendingReg.hasUnresolvedDependencies()) { doRegister(pendingReg); } } } }
@Override public void start() throws BundleException { try { setStarting(); getActivator().start(context); setStarted(); } catch (BundleException e) { throw new BundleException("Failed to start bundle at: " + file + " with activator: " + getActivatorClassName(), e); } catch (Exception e) { // stupid OSGi API throws Exception RuntimeException re = ExceptionUtils.runtimeException(e); throw new BundleException("Failed to start bundle at: " + file + " with activator: " + getActivatorClassName(), re); } }
BundleFile file = nxBundle.getBundleFile(); File jarFile = null; if (file instanceof JarBundleFile) {
@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); }
@Override public Bundle installBundle(String location) throws BundleException { File file = new File(location); try { BundleFile bf = file.isDirectory() ? new DirectoryBundleFile(file) : new JarBundleFile(file); BundleImpl b = new BundleImpl(bundle.osgi, bf, bundle.loader); if (b.getSymbolicName() != null) { bundle.osgi.install(b); } return b; } catch (IOException e) { throw new BundleException("Failed to install bundle at " + location, e); } }
protected void doPostpone(BundleRegistration reg) { String name = reg.bundle.getSymbolicName(); log.info("Registering unresolved bundle: " + name); bundles.put(name, reg); bundlesById.put(reg.bundle.getBundleId(), reg); for (String dep : reg.waitingFor) { Set<BundleRegistration> regs = pendings.get(dep); if (regs == null) { regs = new HashSet<BundleRegistration>(); pendings.put(dep, regs); } regs.add(reg); } reg.bundle.setInstalled(); }
public void shutdown() throws BundleException { try { state = STOPPING; getActivator().stop(context); lastModified = System.currentTimeMillis(); state = UNINSTALLED; } catch (BundleException e) { throw new BundleException("Failed to stop activator: " + getActivatorClassName(), e); } catch (Exception e) { // stupid OSGi API throws Exception RuntimeException re = ExceptionUtils.runtimeException(e); throw new BundleException("Failed to stop activator: " + getActivatorClassName(), re); } }
public BundleActivator getActivator() throws BundleException { if (activator == null) { activator = NullActivator.INSTANCE; String className = getActivatorClassName(); if (className == null) { return activator; } try { activator = (BundleActivator) loadClass(className).newInstance(); } catch (ClassNotFoundException e) { throw new BundleException("Activator not found: " + className, e); } catch (InstantiationException e) { throw new BundleException("Activator not instantiable: " + className, e); } catch (IllegalAccessException e) { throw new BundleException("Activator not accessible: " + className, e); } } return activator; }
private String getFragmentHost(BundleRegistration reg) { String hostBundleId = reg.bundle.getHeaders().get(Constants.FRAGMENT_HOST); if (hostBundleId == null) { return null; } int p = hostBundleId.indexOf(';'); if (p > -1) { // remove version or other extra information if any hostBundleId = hostBundleId.substring(0, p); } return hostBundleId; }
public BundleImpl(OSGiAdapter osgi, BundleFile file, ClassLoader loader, boolean isSystemBundle) throws BundleException { this.osgi = osgi; this.loader = loader; this.file = file; this.location = file.getLocation(); Manifest mf = file.getManifest(); if (mf == null) { headers = null; symbolicName = null; id = -1; context = null; return; } try { headers = BundleManifestReader.getHeaders(mf); } catch (BundleException e) { throw new BundleException("Invalid OSGi Manifest in file " + file + " : " + e.getMessage(), e); } symbolicName = headers.get(Constants.BUNDLE_SYMBOLICNAME); allowHostOverride = Boolean.parseBoolean(headers.get(BundleManifestReader.ALLOW_HOST_OVERRIDE)); id = isSystemBundle ? 0 : osgi.getBundleId(symbolicName); context = createContext(); state = UNINSTALLED; }
BundleFile file = nxBundle.getBundleFile(); File jarFile = null; if (file instanceof JarBundleFile) {
public void installAll(List<BundleFile> bundles) throws BundleException { for (BundleFile bf : bundles) { install(new BundleImpl(this, bf, classLoader.getLoader())); } }
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); } }
public synchronized void install(BundleImpl bundle) throws BundleException { if (bundle.getState() == Bundle.UNINSTALLED) { BundleRegistration reg = bundles.get(bundle.getSymbolicName()); if (reg == null) { register(new BundleRegistration(bundle)); } else { register(reg); } } }
File jarFile = nxBundle.getBundleFile().getFile(); if (jarFile == null) { return binfo;