use of org.apache.aries.application.management.repository.ApplicationRepository in project aries by apache.
the class AriesApplicationManagerImpl method install.
public AriesApplicationContext install(AriesApplication app) throws BundleException, ManagementException, ResolverException {
if (!app.isResolved()) {
app = resolve(app);
}
// Register an Application Repository for this application if none exists
String appScope = app.getApplicationMetadata().getApplicationScope();
ServiceReference[] ref = null;
try {
String filter = "(" + BundleRepository.REPOSITORY_SCOPE + "=" + appScope + ")";
ref = _bundleContext.getServiceReferences(BundleRepository.class.getName(), filter);
} catch (InvalidSyntaxException e) {
// Something went wrong attempting to find a service so we will act as if
// there is no existing service.
}
if (ref == null || ref.length == 0) {
Dictionary dict = new Hashtable();
dict.put(BundleRepository.REPOSITORY_SCOPE, appScope);
ServiceRegistration serviceReg = _bundleContext.registerService(BundleRepository.class.getName(), new ApplicationRepository(app), dict);
serviceRegistrations.put(app, serviceReg);
}
AriesApplicationContext result = _applicationContextManager.getApplicationContext(app);
// When installing bundles in the .eba file we use the jar url scheme. This results in a
// JarFile being held open, which is bad as on windows we cannot delete the .eba file
// so as a work around we open a url connection to one of the bundles in the eba and
// if it is a jar url we close the associated JarFile.
Iterator<BundleInfo> bi = app.getBundleInfo().iterator();
if (bi.hasNext()) {
String location = bi.next().getLocation();
if (location.startsWith("jar")) {
try {
URL url = new URL(location);
JarURLConnection urlc = (JarURLConnection) url.openConnection();
// Make sure that we pick up the cached version rather than creating a new one
urlc.setUseCaches(true);
urlc.getJarFile().close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return result;
}
Aggregations