Search in sources :

Example 1 with ApplicationRepository

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;
}
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

IOException (java.io.IOException)1 JarURLConnection (java.net.JarURLConnection)1 URL (java.net.URL)1 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)1 BundleInfo (org.apache.aries.application.management.BundleInfo)1 ApplicationRepository (org.apache.aries.application.management.repository.ApplicationRepository)1 BundleRepository (org.apache.aries.application.management.spi.repository.BundleRepository)1 SimpleBundleInfo (org.apache.aries.application.utils.management.SimpleBundleInfo)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1