@Override public String deployBundle(File file, boolean reloadResourceClasspath) throws BundleException { String name = getOSGIBundleName(file); if (name == null) { log.error( String.format( "No Bundle-SymbolicName found in MANIFEST for jar at '%s'", file.getAbsolutePath())); return null; } String path = file.getAbsolutePath(); log.info( String.format("Before deploy bundle for file at '%s'\n" + "%s", path, getRuntimeStatus())); if (reloadResourceClasspath) { URL url; try { url = new File(path).toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } Framework.reloadResourceLoader(Arrays.asList(url), null); } // check if this is a bundle first Bundle newBundle = getBundleContext().installBundle(path); if (newBundle == null) { throw new IllegalArgumentException("Could not find a valid bundle at path: " + path); } Transaction tx = TransactionHelper.suspendTransaction(); try { newBundle.start(); } finally { TransactionHelper.resumeTransaction(tx); } log.info( String.format( "Deploy done for bundle with name '%s'.\n" + "%s", newBundle.getSymbolicName(), getRuntimeStatus())); return newBundle.getSymbolicName(); }
@Override public void undeployBundle(File file, boolean reloadResources) throws BundleException { String name = getOSGIBundleName(file); String path = file.getAbsolutePath(); if (name == null) { log.error(String.format("No Bundle-SymbolicName found in MANIFEST for jar at '%s'", path)); return; } undeployBundle(name); if (reloadResources) { URL url; try { url = new File(path).toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } Framework.reloadResourceLoader(null, Arrays.asList(url)); } }