Search in sources :

Example 6 with Resource

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

the class RepositoryImplTest method testReferral1.

public void testReferral1() throws Exception {
    URL url = getClass().getResource("/referral1_repository.xml");
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
    RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
    Referral[] refs = repo.getReferrals();
    assertNotNull("Expect referrals", refs);
    assertTrue("Expect one referral", refs.length == 1);
    // <referral depth="1" url="referred.xml" />
    assertEquals(1, refs[0].getDepth());
    assertEquals("referred.xml", refs[0].getUrl());
    // expect two resources
    Resource[] res = repoAdmin.discoverResources((String) null);
    assertNotNull("Expect Resource", res);
    assertEquals("Expect two resources", 2, res.length);
    // first resource is from the referral1_repository.xml
    assertEquals("6", res[0].getId());
    // assertEquals("referral1_repository", res[0].getRepository().getName());
    // second resource is from the referred.xml
    assertEquals("99", res[1].getId());
// assertEquals("referred", res[1].getRepository().getName());
}
Also used : Resource(org.apache.felix.bundlerepository.Resource) URL(java.net.URL)

Example 7 with Resource

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

the class StaxParserTest method testPullParser.

public void testPullParser() throws Exception {
    URL url = getClass().getResource("/repo_for_resolvertest.xml");
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin(PullParser.class);
    RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
    Resolver resolver = repoAdmin.resolver();
    Resource[] discoverResources = repoAdmin.discoverResources("(symbolicname=org.apache.felix.test*)");
    assertNotNull(discoverResources);
    assertEquals(1, discoverResources.length);
    resolver.add(discoverResources[0]);
    assertTrue(resolver.resolve());
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) Resource(org.apache.felix.bundlerepository.Resource) URL(java.net.URL)

Example 8 with Resource

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

the class StaxParserTest method testStaxParser.

public void testStaxParser() throws Exception {
    URL url = getClass().getResource("/repo_for_resolvertest.xml");
    RepositoryAdminImpl repoAdmin = createRepositoryAdmin(StaxParser.class);
    RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
    Resolver resolver = repoAdmin.resolver();
    Resource[] discoverResources = repoAdmin.discoverResources("(symbolicname=org.apache.felix.test*)");
    assertNotNull(discoverResources);
    assertEquals(1, discoverResources.length);
    resolver.add(discoverResources[0]);
    assertTrue(resolver.resolve());
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) Resource(org.apache.felix.bundlerepository.Resource) URL(java.net.URL)

Example 9 with Resource

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

the class OSGiRepositoryImpl method findProviders.

private Collection<Capability> findProviders(Requirement req) {
    List<Capability> caps = new ArrayList<Capability>();
    if (IdentityNamespace.IDENTITY_NAMESPACE.equals(req.getNamespace())) {
        for (org.apache.felix.bundlerepository.Repository repo : repository.listRepositories()) {
            for (org.apache.felix.bundlerepository.Resource res : repo.getResources()) {
                String f = req.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
                try {
                    addResourceForIdentity(res, f == null ? null : FrameworkUtil.createFilter(f), caps);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    } else {
        org.apache.felix.bundlerepository.Resource[] resources = repository.discoverResources(new org.apache.felix.bundlerepository.Requirement[] { new OSGiRequirementAdapter(req) });
        OSGiRequirementAdapter adapter = new OSGiRequirementAdapter(req);
        for (org.apache.felix.bundlerepository.Resource resource : resources) {
            for (org.apache.felix.bundlerepository.Capability cap : resource.getCapabilities()) {
                if (adapter.isSatisfied(cap))
                    caps.add(new FelixCapabilityAdapter(cap, new FelixResourceAdapter(resource)));
            }
        }
    }
    return caps;
}
Also used : Resource(org.apache.felix.bundlerepository.Resource) Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList) Resource(org.apache.felix.bundlerepository.Resource) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 10 with Resource

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

the class ObrCommandImpl method _deploy.

private void _deploy(ParsedCommand pc, String command, PrintStream out, PrintStream err) throws IOException, InvalidSyntaxException {
    org.apache.felix.bundlerepository.Resolver resolver = m_repoAdmin.resolver();
    for (int i = 0; (pc != null) && (i < pc.getTargetCount()); i++) {
        // Find the target's bundle resource.
        Resource resource = selectNewestVersion(searchRepository(pc.getTargetId(i), pc.getTargetVersion(i)));
        if (resource != null) {
            resolver.add(resource);
        } else {
            err.println("Unknown bundle - " + pc.getTargetId(i));
        }
    }
    if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
        if (resolver.resolve()) {
            out.println("Target resource(s):");
            printUnderline(out, 19);
            Resource[] resources = resolver.getAddedResources();
            for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
                out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
            }
            resources = resolver.getRequiredResources();
            if ((resources != null) && (resources.length > 0)) {
                out.println("\nRequired resource(s):");
                printUnderline(out, 21);
                for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                    out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
                }
            }
            resources = resolver.getOptionalResources();
            if ((resources != null) && (resources.length > 0)) {
                out.println("\nOptional resource(s):");
                printUnderline(out, 21);
                for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                    out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
                }
            }
            try {
                out.print("\nDeploying...");
                resolver.deploy(command.equals(START_CMD) ? Resolver.START : 0);
                out.println("done.");
            } catch (IllegalStateException ex) {
                err.println(ex);
            }
        } else {
            Reason[] reqs = resolver.getUnsatisfiedRequirements();
            if ((reqs != null) && (reqs.length > 0)) {
                out.println("Unsatisfied requirement(s):");
                printUnderline(out, 27);
                for (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
                    out.println("   " + reqs[reqIdx].getRequirement().getFilter());
                    out.println("      " + reqs[reqIdx].getResource().getPresentationName());
                }
            } else {
                out.println("Could not resolve targets.");
            }
        }
    }
}
Also used : Resolver(org.apache.felix.bundlerepository.Resolver) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason)

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