use of org.osgi.framework.BundleException in project aries by apache.
the class BundleFrameworkFactoryImpl method createBundleFramework.
public BundleFramework createBundleFramework(BundleContext bc, BundleFrameworkConfiguration config) throws BundleException {
BundleFramework framework = null;
ServiceReference sr = bc.getServiceReference(CompositeBundleFactory.class.getName());
if (sr != null) {
CompositeBundleFactory cbf = (CompositeBundleFactory) bc.getService(sr);
CompositeBundle compositeBundle = cbf.installCompositeBundle(config.getFrameworkProperties(), config.getFrameworkID(), config.getFrameworkManifest());
framework = new BundleFrameworkImpl(compositeBundle);
} else
throw new BundleException("Failed to obtain framework factory service");
return framework;
}
use of org.osgi.framework.BundleException in project aries by apache.
the class ApplicationContextManagerImpl method uninstall.
private void uninstall(ApplicationContextImpl app) {
Set<Bundle> bundles = app.getApplicationContent();
for (Bundle b : bundles) {
try {
b.uninstall();
} catch (BundleException be) {
// TODO ignoring this feels wrong, but I'm not sure how to communicate to the caller multiple failures.
}
}
app.setState(ApplicationState.UNINSTALLED);
}
use of org.osgi.framework.BundleException in project aries by apache.
the class AriesRepositoryGenerator method startFramework.
/**
* Start OSGi framework and install the necessary bundles
* @return
* @throws BundleException
*/
public BundleContext startFramework() throws BundleException {
ServiceLoader<FrameworkFactory> factoryLoader = ServiceLoader.load(FrameworkFactory.class, getClass().getClassLoader());
Iterator<FrameworkFactory> factoryIterator = factoryLoader.iterator();
//Map<String, String> osgiPropertyMap = new HashMap<String, String>();
if (!!!factoryIterator.hasNext()) {
System.out.println("Unable to locate the osgi jar");
}
try {
FrameworkFactory frameworkFactory = factoryIterator.next();
framework = frameworkFactory.newFramework(Collections.EMPTY_MAP);
} catch (ServiceConfigurationError sce) {
sce.printStackTrace();
}
framework.init();
framework.start();
// install the bundles in the current directory
Collection<Bundle> installedBundles = new ArrayList<Bundle>();
File bundleDir = new File(".");
File[] jars = bundleDir.listFiles();
try {
for (File jar : jars) {
if (jar.isFile() && (jar.getName().endsWith(".jar"))) {
String location = URLDecoder.decode(jar.toURI().toURL().toExternalForm(), "UTF-8");
if (shouldInstall(location, getIgnoreList())) {
installedBundles.add(framework.getBundleContext().installBundle("reference:" + location));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
ServiceReference paRef = framework.getBundleContext().getServiceReference(PackageAdmin.class.getCanonicalName());
if (paRef != null) {
try {
PackageAdmin admin = (PackageAdmin) framework.getBundleContext().getService(paRef);
admin.resolveBundles(installedBundles.toArray(new Bundle[installedBundles.size()]));
} finally {
framework.getBundleContext().ungetService(paRef);
}
} else {
System.out.println("Unable to find the service reference for package admin");
}
//loop through the list of installed bundles to start them
for (Bundle bundle : installedBundles) {
try {
if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
//start the bundle using its activiation policy
bundle.start(Bundle.START_ACTIVATION_POLICY);
} else {
//nothing to start, we have got a fragment
}
} catch (BundleException e) {
e.printStackTrace();
continue;
}
}
return framework.getBundleContext();
}
use of org.osgi.framework.BundleException in project aries by apache.
the class ApplicationContextManagerImpl method unbindBundleFrameworkManager.
public void unbindBundleFrameworkManager(BundleFrameworkManager bfm) {
LOGGER.debug(LOG_ENTRY, "unbindBundleFrameworkManager", bfm);
List<AriesApplicationContext> appContexts = new ArrayList<AriesApplicationContext>();
synchronized (_appToContextMap) {
appContexts.addAll(_appToContextMap.values());
}
for (AriesApplicationContext c : appContexts) {
try {
((ApplicationContextImpl) c).close();
} catch (BundleException e) {
LOGGER.debug(LOG_EXCEPTION, e);
}
}
LOGGER.debug(LOG_EXIT, "unbindBundleFrameworkManager");
}
use of org.osgi.framework.BundleException in project aries by apache.
the class ApplicationContextManagerImpl method update.
public AriesApplicationContext update(AriesApplication app, DeploymentMetadata oldMetadata) throws UpdateException {
ApplicationContextImpl oldCtx = _appToContextMap.get(app);
if (oldCtx == null) {
throw new IllegalArgumentException("AriesApplication " + app.getApplicationMetadata().getApplicationSymbolicName() + "/" + app.getApplicationMetadata().getApplicationVersion() + " cannot be updated because it is not installed");
}
uninstall(oldCtx);
try {
AriesApplicationContext newCtx = getApplicationContext(app);
if (oldCtx.getApplicationState() == ApplicationState.ACTIVE) {
newCtx.start();
}
return newCtx;
} catch (BundleException e) {
throw new UpdateException("Update failed: " + e.getMessage(), e, false, null);
} catch (ManagementException e) {
throw new UpdateException("Update failed: " + e.getMessage(), e, false, null);
}
}
Aggregations