Search in sources :

Example 36 with Resource

use of org.apache.felix.bundlerepository.Resource 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 37 with Resource

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

the class Aries1523Test method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    BundleContext context = context();
    ServiceReference<RepositoryAdmin> ref = context.getServiceReference(RepositoryAdmin.class);
    assertNotNull("The RepositoryAdmin service does not exist", ref);
    try {
        repositoryAdmin = (RepositoryAdmin) context.getService(ref);
        DataModelHelper helper = repositoryAdmin.getHelper();
        url = createRepositoryXml(helper);
        Repository repository = repositoryAdmin.addRepository(url);
        Resource resource = repository.getResources()[0];
        System.out.println(resource.getURI());
    } finally {
        context.ungetService(ref);
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Resource(org.apache.felix.bundlerepository.Resource) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) BundleContext(org.osgi.framework.BundleContext)

Example 38 with Resource

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

the class Aries1608Test method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    BundleContext context = context();
    ServiceReference<RepositoryAdmin> ref = context.getServiceReference(RepositoryAdmin.class);
    assertNotNull("The RepositoryAdmin service does not exist", ref);
    try {
        repositoryAdmin = (RepositoryAdmin) context.getService(ref);
        DataModelHelper helper = repositoryAdmin.getHelper();
        url = createRepositoryXml(helper);
        Repository repository = repositoryAdmin.addRepository(url);
        Resource resource = repository.getResources()[0];
        System.out.println(resource.getURI());
    } finally {
        context.ungetService(ref);
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Resource(org.apache.felix.bundlerepository.Resource) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) BundleContext(org.osgi.framework.BundleContext)

Example 39 with Resource

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

the class RepositoryAdminRepository method findProviders.

public Collection<Capability> findProviders(Requirement requirement) {
    logger.debug(LOG_ENTRY, "findProviders", requirement);
    Collection<Capability> result = Collections.emptyList();
    if (IdentityNamespace.IDENTITY_NAMESPACE.equals(requirement.getNamespace())) {
        result = new ArrayList<Capability>();
        for (org.apache.felix.bundlerepository.Repository r : repositoryAdmin.listRepositories()) {
            FelixRepositoryAdapter repository = new FelixRepositoryAdapter(r);
            Map<Requirement, Collection<Capability>> map = repository.findProviders(Arrays.asList(requirement));
            Collection<Capability> capabilities = map.get(requirement);
            if (capabilities != null)
                result.addAll(capabilities);
        }
        return result;
    } else {
        Resource[] resources = repositoryAdmin.discoverResources(new org.apache.felix.bundlerepository.Requirement[] { new OsgiRequirementAdapter(requirement) });
        logger.debug("Found {} resources with capabilities satisfying {}", resources == null ? 0 : resources.length, requirement);
        if (resources != null && resources.length != 0) {
            result = new ArrayList<Capability>(result.size());
            OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(requirement);
            for (Resource resource : resources) {
                logger.debug("Evaluating resource {}", resource);
                for (org.apache.felix.bundlerepository.Capability capability : resource.getCapabilities()) {
                    logger.debug("Evaluating capability {}", capability);
                    if (adapter.isSatisfied(capability)) {
                        logger.debug("Adding capability {}", capability);
                        result.add(new FelixCapabilityAdapter(capability, new FelixResourceAdapter(resource)));
                    }
                }
            }
        }
    }
    logger.debug(LOG_EXIT, "findProviders", result);
    return result;
}
Also used : Capability(org.osgi.resource.Capability) Resource(org.apache.felix.bundlerepository.Resource) OsgiRequirementAdapter(org.apache.aries.subsystem.util.felix.OsgiRequirementAdapter) FelixResourceAdapter(org.apache.aries.subsystem.util.felix.FelixResourceAdapter) Requirement(org.osgi.resource.Requirement) FelixCapabilityAdapter(org.apache.aries.subsystem.util.felix.FelixCapabilityAdapter) FelixRepositoryAdapter(org.apache.aries.subsystem.util.felix.FelixRepositoryAdapter) Collection(java.util.Collection)

Example 40 with Resource

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

the class Aries1522Test method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    BundleContext context = context();
    ServiceReference<RepositoryAdmin> ref = context.getServiceReference(RepositoryAdmin.class);
    assertNotNull("The RepositoryAdmin service does not exist", ref);
    try {
        repositoryAdmin = (RepositoryAdmin) context.getService(ref);
        DataModelHelper helper = repositoryAdmin.getHelper();
        url = createRepositoryXml(helper);
        Repository repository = repositoryAdmin.addRepository(url);
        Resource resource = repository.getResources()[0];
        System.out.println(resource.getURI());
    } finally {
        context.ungetService(ref);
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Resource(org.apache.felix.bundlerepository.Resource) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Resource (org.apache.felix.bundlerepository.Resource)45 Repository (org.apache.felix.bundlerepository.Repository)19 Capability (org.apache.felix.bundlerepository.Capability)9 Resolver (org.apache.felix.bundlerepository.Resolver)9 ArrayList (java.util.ArrayList)8 ModelledResource (org.apache.aries.application.modelling.ModelledResource)8 ModelledBundleResource (org.apache.aries.application.resolver.obr.ext.ModelledBundleResource)8 Reason (org.apache.felix.bundlerepository.Reason)7 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)7 HashMap (java.util.HashMap)6 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)6 URL (java.net.URL)5 File (java.io.File)4 DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)4 FileWriter (java.io.FileWriter)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Requirement (org.apache.felix.bundlerepository.Requirement)3 BundleContext (org.osgi.framework.BundleContext)3