use of org.osgi.resource.Resource in project karaf by apache.
the class RepositoryTest method testLoadRepoWithCapabilitiesAndRequirement.
public void testLoadRepoWithCapabilitiesAndRequirement() throws Exception {
RepositoryImpl r = new RepositoryImpl(getClass().getResource("repo3.xml").toURI());
// Check features
Feature[] features = r.getFeatures();
assertNotNull(features);
assertEquals(1, features.length);
assertNotNull(features[0]);
assertEquals("f1", features[0].getName());
assertEquals(1, features[0].getCapabilities().size());
assertEquals("cap", features[0].getCapabilities().get(0).getValue().trim());
assertEquals(1, features[0].getRequirements().size());
assertEquals("req", features[0].getRequirements().get(0).getValue().trim());
Resource res = FeatureResource.build(features[0], null, null);
assertEquals(1, res.getCapabilities("cap").size());
assertEquals(1, res.getRequirements("req").size());
}
use of org.osgi.resource.Resource in project karaf by apache.
the class FeaturesDependenciesTest method dumpWiring.
private void dumpWiring(SubsystemResolver resolver) {
System.out.println("Wiring");
Map<Resource, List<Wire>> wiring = resolver.getWiring();
List<Resource> resources = new ArrayList<>(wiring.keySet());
resources.sort(Comparator.comparing(this::getName));
for (Resource resource : resources) {
System.out.println(" " + getName(resource));
for (Wire wire : wiring.get(resource)) {
System.out.println(" " + wire);
}
}
}
use of org.osgi.resource.Resource in project karaf by apache.
the class FeaturesDependenciesTest method dumpBundles.
private void dumpBundles(SubsystemResolver resolver) {
System.out.println("Bundle mapping");
Map<String, Set<Resource>> bundles = resolver.getBundlesPerRegions();
for (Map.Entry<String, Set<Resource>> entry : bundles.entrySet()) {
System.out.println(" " + entry.getKey());
for (Resource b : entry.getValue()) {
System.out.println(" " + b);
}
}
}
use of org.osgi.resource.Resource in project karaf by apache.
the class RequirementSort method sort.
/**
* Sort {@link Resource} based on their {@link Requirement}s and {@link Capability}s.
*
* @param resources the resource to sort.
* @param <T> the resources type.
* @return sorted collection of resources.
*/
public static <T extends Resource> Collection<T> sort(Collection<T> resources) {
Set<String> namespaces = new HashSet<>();
for (Resource r : resources) {
for (Capability cap : r.getCapabilities(null)) {
namespaces.add(cap.getNamespace());
}
}
CapabilitySet capSet = new CapabilitySet(new ArrayList<>(namespaces));
for (Resource r : resources) {
for (Capability cap : r.getCapabilities(null)) {
capSet.addCapability(cap);
}
}
Set<T> sorted = new LinkedHashSet<>();
Set<T> visited = new LinkedHashSet<>();
for (T r : resources) {
visit(r, visited, sorted, capSet);
}
return sorted;
}
use of org.osgi.resource.Resource in project karaf by apache.
the class Builder method resolve.
private Map<String, Integer> resolve(DownloadManager manager, Resolver resolver, Collection<Features> repositories, Collection<String> features, Collection<String> bundles, Collection<String> overrides, Collection<String> optionals) throws Exception {
BundleRevision systemBundle = getSystemBundle();
AssemblyDeployCallback callback = new AssemblyDeployCallback(manager, this, systemBundle, repositories);
Deployer deployer = new Deployer(manager, resolver, callback, callback);
// Install framework
Deployer.DeploymentRequest request = createDeploymentRequest();
// Add overrides
request.overrides.addAll(overrides);
// Add optional resources
final List<Resource> resources = new ArrayList<>();
Downloader downloader = manager.createDownloader();
for (String optional : optionals) {
downloader.download(optional, provider -> {
Resource resource = ResourceBuilder.build(provider.getUrl(), getHeaders(provider));
synchronized (resources) {
resources.add(resource);
}
});
}
downloader.await();
request.globalRepository = new BaseRepository(resources);
// Install features
for (String feature : features) {
MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, feature);
}
for (String bundle : bundles) {
MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, "bundle:" + bundle);
}
Set<String> prereqs = new HashSet<>();
while (true) {
try {
deployer.deploy(callback.getDeploymentState(), request);
break;
} catch (Deployer.PartialDeploymentException e) {
if (!prereqs.containsAll(e.getMissing())) {
prereqs.addAll(e.getMissing());
} else {
throw new Exception("Deployment aborted due to loop in missing prerequisites: " + e.getMissing());
}
}
}
return callback.getStartupBundles();
}
Aggregations