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());
}
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());
}
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());
}
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;
}
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.");
}
}
}
}
Aggregations