Search in sources :

Example 1 with PlatformRepository

use of org.apache.aries.application.management.spi.repository.PlatformRepository in project aries by apache.

the class OBRAriesResolver method getConfiguredObrResolver.

private Resolver getConfiguredObrResolver(String appName, String appVersion, Collection<ModelledResource> byValueBundles, boolean noExtraRepositories) throws ResolverException {
    log.debug(LOG_ENTRY, "getConfiguredObrResolver", new Object[] { appName, appVersion, byValueBundles });
    DataModelHelper helper = repositoryAdmin.getHelper();
    Repository appRepo;
    try {
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        RepositoryGeneratorImpl.generateRepository(repositoryAdmin, appName + "_" + appVersion, byValueBundles, bytesOut);
        appRepo = helper.readRepository(new InputStreamReader(new ByteArrayInputStream(bytesOut.toByteArray())));
    } catch (Exception e) {
        throw new ResolverException(e);
    }
    List<Repository> resolveRepos = new ArrayList<Repository>();
    // add system repository
    resolveRepos.add(repositoryAdmin.getSystemRepository());
    // add application repository
    resolveRepos.add(appRepo);
    if (!!!noExtraRepositories) {
        // add local repository if configured
        if (!(excludeLocalRuntime())) {
            resolveRepos.add(getLocalRepository(repositoryAdmin));
        }
        // Need to refresh the repositories added to repository admin
        // add user-defined repositories
        Repository[] repos = repositoryAdmin.listRepositories();
        for (Repository r : repos) {
            resolveRepos.add(r);
        }
    }
    Resolver obrResolver = repositoryAdmin.resolver(resolveRepos.toArray(new Repository[resolveRepos.size()]));
    addPlatformRepositories(obrResolver, appName, platformRepository);
    log.debug(LOG_EXIT, "getConfiguredObrResolver", obrResolver);
    return obrResolver;
}
Also used : PlatformRepository(org.apache.aries.application.management.spi.repository.PlatformRepository) Repository(org.apache.felix.bundlerepository.Repository) ResolverException(org.apache.aries.application.management.ResolverException) InputStreamReader(java.io.InputStreamReader) Resolver(org.apache.felix.bundlerepository.Resolver) AriesApplicationResolver(org.apache.aries.application.management.spi.resolve.AriesApplicationResolver) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResolverException(org.apache.aries.application.management.ResolverException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException)

Example 2 with PlatformRepository

use of org.apache.aries.application.management.spi.repository.PlatformRepository 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

ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStreamReader (java.io.InputStreamReader)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 DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)2 Repository (org.apache.felix.bundlerepository.Repository)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 ArrayList (java.util.ArrayList)1 AriesApplicationResolver (org.apache.aries.application.management.spi.resolve.AriesApplicationResolver)1 ModelledResource (org.apache.aries.application.modelling.ModelledResource)1 ModelledBundleResource (org.apache.aries.application.resolver.obr.ext.ModelledBundleResource)1 Capability (org.apache.felix.bundlerepository.Capability)1 Resolver (org.apache.felix.bundlerepository.Resolver)1 Resource (org.apache.felix.bundlerepository.Resource)1