Search in sources :

Example 21 with Repository

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

the class MinimumImportsTest method testAppUsingAriesApplicationManager.

@Test
public void testAppUsingAriesApplicationManager() throws Exception {
    // Register a BlueprintListener to listen for the events from the BlueprintContainer for the bundle in the appmgrclienttest.eba
    AppMgrClientBlueprintListener acbl = new AppMgrClientBlueprintListener();
    ServiceRegistration sr = bundleContext.registerService("org.osgi.service.blueprint.container.BlueprintListener", acbl, null);
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("appmgrclienttest.eba")));
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
        repositoryAdmin.removeRepository(repo.getURI());
    }
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
    int sleepfor = 3000;
    while ((acbl.success == null || acbl.success == false) && sleepfor > 0) {
        Thread.sleep(100);
        sleepfor -= 100;
    }
    assertNotNull("Timed out - didn't receive Blueprint CREATED or FAILURE event", acbl.success);
    assertTrue("Received Blueprint FAILURE event", acbl.success);
    ctx.stop();
    manager.uninstall(ctx);
    sr.unregister();
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) File(java.io.File) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 22 with Repository

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

the class OBRAppManagerTest method testAppWithApplicationManifest.

@Test
public void testAppWithApplicationManifest() throws Exception {
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
        Resource[] resources = repo.getResources();
        for (Resource r : resources) {
            Capability[] cs = r.getCapabilities();
            for (Capability c : cs) {
                System.out.println(c.getName() + " : " + c.getProperties());
            }
        }
    }
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test.eba")));
    app = manager.resolve(app);
    //installing requires a valid url for the bundle in repository.xml.
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
    HelloWorld hw = context().getService(HelloWorld.class);
    String result = hw.getMessage();
    assertEquals(result, "hello world");
    ctx.stop();
    manager.uninstall(ctx);
}
Also used : RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Capability(org.apache.felix.bundlerepository.Capability) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) Resource(org.apache.felix.bundlerepository.Resource) AriesApplication(org.apache.aries.application.management.AriesApplication) HelloWorld(org.apache.aries.sample.HelloWorld) Repository(org.apache.felix.bundlerepository.Repository) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) File(java.io.File) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 23 with Repository

use of org.apache.felix.bundlerepository.Repository 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)

Example 24 with Repository

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

the class OBRAriesResolver method getLocalRepository.

private Repository getLocalRepository(RepositoryAdmin admin) {
    Repository localRepository = repositoryAdmin.getLocalRepository();
    Resource[] resources = localRepository.getResources();
    Resource[] newResources = new Resource[resources.length];
    for (int i = 0; i < resources.length; i++) {
        newResources[i] = new ResourceWrapper(resources[i]);
    }
    return repositoryAdmin.getHelper().repository(newResources);
}
Also used : ResourceWrapper(org.apache.aries.application.resolver.obr.impl.ResourceWrapper) PlatformRepository(org.apache.aries.application.management.spi.repository.PlatformRepository) Repository(org.apache.felix.bundlerepository.Repository) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Resource(org.apache.felix.bundlerepository.Resource) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint)

Aggregations

Repository (org.apache.felix.bundlerepository.Repository)24 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)13 File (java.io.File)12 Resource (org.apache.felix.bundlerepository.Resource)10 AriesApplication (org.apache.aries.application.management.AriesApplication)8 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)8 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)8 Test (org.junit.Test)8 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)5 DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)5 ArrayList (java.util.ArrayList)4 FileWriter (java.io.FileWriter)3 InputStreamReader (java.io.InputStreamReader)3 PlatformRepository (org.apache.aries.application.management.spi.repository.PlatformRepository)3 BundleContext (org.osgi.framework.BundleContext)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Content (org.apache.aries.application.Content)2 DeploymentContent (org.apache.aries.application.DeploymentContent)2 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)2