use of aQute.p2.provider.P2Impl 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();
}
Aggregations