use of org.apache.aries.application.management.BundleInfo in project aries by apache.
the class SharedFrameworkPreResolveHook method collectFakeResources.
@Override
public void collectFakeResources(Collection<ModelledResource> resources) {
Bundle b = fwMgr.getSharedBundleFramework().getIsolatedBundleContext().getBundle(1);
BundleInfo info = new BundleInfoImpl(b);
Collection<ImportedService> serviceImports = Collections.emptySet();
Collection<ExportedService> serviceExports = Collections.emptySet();
try {
resources.add(mgr.getModelledResource(info.getLocation(), info, serviceImports, serviceExports));
} catch (InvalidAttributeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.aries.application.management.BundleInfo in project aries by apache.
the class ApplicationContextImpl method stop.
public void stop() throws BundleException {
for (Map.Entry<BundleInfo, Bundle> entry : _bundles.entrySet()) {
Bundle b = entry.getValue();
b.stop();
}
_state = ApplicationState.RESOLVED;
}
use of org.apache.aries.application.management.BundleInfo in project aries by apache.
the class DeploymentManifestManagerImpl method getByValueBundles.
/**
* Get a list of bundles included by value in this application.
* @param app The Aries Application
* @return a list of by value bundles
* @throws IOException
* @throws InvalidAttributeException
* @throws ModellerException
*/
private Collection<ModelledResource> getByValueBundles(AriesApplication app) throws IOException, InvalidAttributeException, ModellerException {
_logger.debug(LOG_ENTRY, "getByValueBundles", new Object[] { app });
Collection<BundleInfo> bundles = app.getBundleInfo();
Collection<ModelledResource> result = new ArrayList<ModelledResource>();
for (BundleInfo bundleInfo : bundles) {
// find out the eba directory
String bundleLocation = bundleInfo.getLocation();
String bundleFileName = bundleLocation.substring(bundleLocation.lastIndexOf('/') + 1);
// just the portion of root directory excluding !
URL jarUrl = new URL(bundleLocation);
URLConnection jarCon = jarUrl.openConnection();
jarCon.connect();
InputStream in = jarCon.getInputStream();
File dir = getLocalPlatform().getTemporaryDirectory();
File temp = new File(dir, bundleFileName);
OutputStream out = new FileOutputStream(temp);
IOUtils.copy(in, out);
IOUtils.close(out);
result.add(modelledResourceManager.getModelledResource(null, FileSystem.getFSRoot(temp)));
// delete the temp file
temp.delete();
IOUtils.deleteRecursive(dir);
}
_logger.debug(LOG_EXIT, "getByValueBundles", new Object[] { result });
return result;
}
use of org.apache.aries.application.management.BundleInfo in project aries by apache.
the class AriesApplicationManagerImpl method buildAppContent.
private String buildAppContent(Set<BundleInfo> bundleInfos) {
StringBuilder builder = new StringBuilder();
Iterator<BundleInfo> iterator = bundleInfos.iterator();
while (iterator.hasNext()) {
BundleInfo info = iterator.next();
builder.append(info.getSymbolicName());
// bundle version is not a required manifest header
if (info.getVersion() != null) {
String version = info.getVersion().toString();
builder.append(";version=\"[");
builder.append(version);
builder.append(',');
builder.append(version);
builder.append("]\"");
}
if (iterator.hasNext()) {
builder.append(",");
}
}
return builder.toString();
}
use of org.apache.aries.application.management.BundleInfo 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