Search in sources :

Example 6 with DataModelHelper

use of org.apache.felix.bundlerepository.DataModelHelper in project aries by apache.

the class OBRAriesResolver method addPlatformRepositories.

/* A 'platform repository' describes capabilities of the target runtime environment
   * These should be added to the resolver without being listed as coming from a particular 
   * repository or bundle.  
   */
private void addPlatformRepositories(Resolver obrResolver, String appName, PlatformRepository platformRepository) {
    log.debug(LOG_ENTRY, "addPlatformRepositories", new Object[] { obrResolver, appName });
    DataModelHelper helper = repositoryAdmin.getHelper();
    if (platformRepository != null) {
        Collection<URI> uris = platformRepository.getPlatformRepositoryURLs();
        if ((uris != null) && (!uris.isEmpty())) {
            for (URI uri : uris) {
                InputStream is = null;
                try {
                    is = uri.toURL().openStream();
                    Reader repoReader = new InputStreamReader(is);
                    Repository aPlatformRepo = helper.readRepository(repoReader);
                    Resource[] resources = aPlatformRepo.getResources();
                    for (Resource r : resources) {
                        Capability[] caps = r.getCapabilities();
                        for (Capability c : caps) {
                            obrResolver.addGlobalCapability(c);
                        }
                    }
                } catch (Exception e) {
                    // not a big problem
                    log.error(MessageUtil.getMessage("RESOLVER_UNABLE_TO_READ_REPOSITORY_EXCEPTION", new Object[] { appName, uri }));
                } finally {
                    IOUtils.close(is);
                }
            }
        }
    }
    log.debug(LOG_EXIT, "addPlatformRepositories");
}
Also used : PlatformRepository(org.apache.aries.application.management.spi.repository.PlatformRepository) Repository(org.apache.felix.bundlerepository.Repository) InputStreamReader(java.io.InputStreamReader) Capability(org.apache.felix.bundlerepository.Capability) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Resource(org.apache.felix.bundlerepository.Resource) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) URI(java.net.URI) ResolverException(org.apache.aries.application.management.ResolverException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException)

Aggregations

DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)6 Repository (org.apache.felix.bundlerepository.Repository)5 Resource (org.apache.felix.bundlerepository.Resource)4 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)3 BundleContext (org.osgi.framework.BundleContext)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)2 ResolverException (org.apache.aries.application.management.ResolverException)2 PlatformRepository (org.apache.aries.application.management.spi.repository.PlatformRepository)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 URI (java.net.URI)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AriesApplicationResolver (org.apache.aries.application.management.spi.resolve.AriesApplicationResolver)1