use of org.osgi.resource.Capability in project bndtools by bndtools.
the class BundleSorter method compare.
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
Resource r1 = (Resource) e1;
Resource r2 = (Resource) e2;
Capability id1 = ResourceUtils.getIdentityCapability(r1);
Capability id2 = ResourceUtils.getIdentityCapability(r2);
String name1 = ResourceUtils.getIdentity(id1);
if (name1 == null) {
name1 = "";
}
String name2 = ResourceUtils.getIdentity(id2);
if (name2 == null) {
name2 = "";
}
int ret = name1.compareTo(name2);
if (ret != 0) {
return ret;
}
Version ver1 = ResourceUtils.getVersion(id1);
if (ver1 == null) {
ver1 = Version.emptyVersion;
}
Version ver2 = ResourceUtils.getVersion(id2);
if (ver2 == null) {
ver2 = Version.emptyVersion;
}
// This comparison is the reverse of what you would expect
return ver2.compareTo(ver1);
}
use of org.osgi.resource.Capability in project bndtools by bndtools.
the class ResolutionChoiceSelectionDialog method updateSavePreferenceText.
private void updateSavePreferenceText() {
Resource resource = candidates.get(0).getResource();
Capability identity = ResourceUtils.getIdentityCapability(resource);
String name = ResourceUtils.getIdentity(identity);
StyledString label = new StyledString("Save top candidate (");
label.append(name, BoldStyler.INSTANCE_DEFAULT);
label.append(") as a ");
label.append("preferred resource.", ItalicStyler.INSTANCE_DEFAULT);
txtSavePreference.setText(label.getString());
txtSavePreference.setStyleRanges(label.getStyleRanges());
}
use of org.osgi.resource.Capability in project bnd by bndtools.
the class ResourceTest method getResources.
private Set<Resource> getResources(String locations) throws MalformedURLException, URISyntaxException {
FixedIndexedRepo repo = new FixedIndexedRepo();
repo.setLocations(locations);
Requirement wildcard = ResourceUtils.createWildcardRequirement();
Collection<Capability> caps = repo.findProviders(Collections.singleton(wildcard)).get(wildcard);
return ResourceUtils.getResources(caps);
}
use of org.osgi.resource.Capability in project bnd by bndtools.
the class P2Indexer method readRepository.
private Repository readRepository() throws Exception {
P2Impl p2 = new P2Impl(client, this.url, Processor.getExecutor());
List<Artifact> artifacts = p2.getArtifacts();
List<Promise<Resource>> fetched = new ArrayList<>(artifacts.size());
Set<URI> visitedURIs = new HashSet<>(artifacts.size());
Set<ArtifactID> visitedArtifacts = new HashSet<>(artifacts.size());
Map<ArtifactID, Resource> knownResources = new HashMap<>();
if (getBridge() != null) {
for (Capability capability : getBridge().getRepository().findProviders(singleton(MD5_REQUIREMENT)).get(MD5_REQUIREMENT)) {
Resource resource = capability.getResource();
IdentityCapability identity = ResourceUtils.getIdentityCapability(resource);
ArtifactID artifact = new ArtifactID(identity.osgi_identity(), identity.version(), (String) capability.getAttributes().get(MD5_ATTRIBUTE));
knownResources.put(artifact, resource);
}
}
for (final Artifact a : artifacts) {
if (!visitedURIs.add(a.uri))
continue;
if (a.md5 != null) {
ArtifactID id = new ArtifactID(a.id, toVersion(a.version), a.md5);
if (!visitedArtifacts.add(id))
continue;
if (knownResources.containsKey(id)) {
fetched.add(Promises.resolved(knownResources.get(id)));
continue;
}
}
Promise<Resource> promise = client.build().useCache(MAX_STALE).async(a.uri.toURL()).map(new Function<File, Resource>() {
@Override
public Resource apply(File file) {
try {
ResourceBuilder rb = new ResourceBuilder();
rb.addFile(file, a.uri);
if (a.md5 != null)
rb.addCapability(new CapabilityBuilder(P2_CAPABILITY_NAMESPACE).addAttribute(MD5_ATTRIBUTE, a.md5));
return rb.build();
} catch (Exception e) {
logger.debug("{}: Failed to create resource for %s from {}", name, a, file, e);
return RECOVERY;
}
}
}).recover(new Function<Promise<?>, Resource>() {
@Override
public Resource apply(Promise<?> failed) {
try {
logger.debug("{}: Failed to create resource for {}", name, a, failed.getFailure());
} catch (InterruptedException e) {
// impossible
}
return RECOVERY;
}
});
fetched.add(promise);
}
Promise<List<Resource>> all = Promises.all(fetched);
return all.map(new Function<List<Resource>, ResourcesRepository>() {
@Override
public ResourcesRepository apply(List<Resource> resources) {
ResourcesRepository rr = new ResourcesRepository();
for (Resource resource : resources) {
if (resource != RECOVERY) {
rr.add(resource);
}
}
return rr;
}
}).getValue();
}
use of org.osgi.resource.Capability in project bndtools by bndtools.
the class ResourceCapReqLoader method loadCapabilities.
@Override
public Map<String, List<Capability>> loadCapabilities() throws Exception {
Map<String, List<Capability>> result = new HashMap<String, List<Capability>>();
List<Capability> caps = resource.getCapabilities(null);
for (Capability cap : caps) {
String ns = cap.getNamespace();
List<Capability> listForNamespace = result.get(ns);
if (listForNamespace == null) {
listForNamespace = new LinkedList<Capability>();
result.put(ns, listForNamespace);
}
listForNamespace.add(cap);
}
return result;
}
Aggregations