Search in sources :

Example 6 with BundleInfo

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();
    }
}
Also used : BundleInfo(org.apache.aries.application.management.BundleInfo) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) Bundle(org.osgi.framework.Bundle) ExportedService(org.apache.aries.application.modelling.ExportedService) ImportedService(org.apache.aries.application.modelling.ImportedService)

Example 7 with BundleInfo

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;
}
Also used : BundleInfo(org.apache.aries.application.management.BundleInfo) Bundle(org.osgi.framework.Bundle) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with BundleInfo

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;
}
Also used : BundleInfo(org.apache.aries.application.management.BundleInfo) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL) URLConnection(java.net.URLConnection) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 9 with BundleInfo

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();
}
Also used : BundleInfo(org.apache.aries.application.management.BundleInfo) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo)

Example 10 with BundleInfo

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;
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) JarURLConnection(java.net.JarURLConnection) ApplicationRepository(org.apache.aries.application.management.repository.ApplicationRepository) IOException(java.io.IOException) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) URL(java.net.URL) ServiceReference(org.osgi.framework.ServiceReference) BundleInfo(org.apache.aries.application.management.BundleInfo) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

BundleInfo (org.apache.aries.application.management.BundleInfo)13 SimpleBundleInfo (org.apache.aries.application.utils.management.SimpleBundleInfo)5 HashSet (java.util.HashSet)4 Version (org.osgi.framework.Version)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 URL (java.net.URL)3 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)3 Content (org.apache.aries.application.Content)3 AriesApplication (org.apache.aries.application.management.AriesApplication)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)2 DeploymentContentImpl (org.apache.aries.application.impl.DeploymentContentImpl)2 ResolveConstraint (org.apache.aries.application.management.ResolveConstraint)2 BundleConversion (org.apache.aries.application.management.spi.convert.BundleConversion)2