use of aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability in project bnd by bndtools.
the class ResourceImpl method compareTo.
@Override
public int compareTo(Resource o) {
IdentityCapability me = ResourceUtils.getIdentityCapability(this);
IdentityCapability them = ResourceUtils.getIdentityCapability(o);
String myName = me.osgi_identity();
String theirName = them.osgi_identity();
if (myName == theirName)
return 0;
if (myName == null)
return -1;
if (theirName == null)
return 1;
int n = myName.compareTo(theirName);
if (n != 0)
return n;
Version myVersion = me.version();
Version theirVersion = them.version();
if (myVersion == theirVersion)
return 0;
if (myVersion == null)
return -1;
if (theirVersion == null)
return 1;
return myVersion.compareTo(theirVersion);
}
use of aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability in project bnd by bndtools.
the class BndrunResolveContextTest method testInputRequirementsAsMandatoryResource.
public static void testInputRequirementsAsMandatoryResource() {
MockRegistry registry = new MockRegistry();
registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
BndEditModel runModel = new BndEditModel();
runModel.setRunFw("org.apache.felix.framework");
Requirement req = new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.gogo.command)").buildSyntheticRequirement();
runModel.setRunRequires(Collections.singletonList(req));
BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
context.init();
assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(context.getFramework()));
Collection<Resource> mandRes = context.getMandatoryResources();
assertEquals(1, mandRes.size());
Resource resource = mandRes.iterator().next();
assertNotNull(resource);
IdentityCapability ic = ResourceUtils.getIdentityCapability(resource);
assertNotNull(ic);
assertEquals("<<INITIAL>>", ic.osgi_identity());
}
use of aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability in project bndtools by bndtools.
the class ReposTemplateLoader method findTemplates.
@Override
public Promise<List<Template>> findTemplates(String templateType, final Reporter reporter) {
String filterStr = String.format("(%s=%s)", NS_TEMPLATE, templateType);
final Requirement requirement = new CapReqBuilder(NS_TEMPLATE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filterStr).buildSyntheticRequirement();
// Try to get the repositories and BundleLocator from the workspace
List<Repository> workspaceRepos;
BundleLocator tmpLocator;
try {
if (workspace == null)
workspace = Central.getWorkspace();
workspaceRepos = workspace.getPlugins(Repository.class);
tmpLocator = new RepoPluginsBundleLocator(workspace.getRepositories());
} catch (Exception e) {
workspaceRepos = Collections.emptyList();
tmpLocator = new DirectDownloadBundleLocator();
}
final BundleLocator locator = tmpLocator;
// Setup the repos
List<Repository> repos = new ArrayList<>(workspaceRepos.size() + 1);
repos.addAll(workspaceRepos);
addPreferenceConfiguredRepos(repos, reporter);
// Generate a Promise<List<Template>> for each repository and add to an accumulator
Promise<List<Template>> accumulator = Promises.resolved((List<Template>) new LinkedList<Template>());
for (final Repository repo : repos) {
final Deferred<List<Template>> deferred = new Deferred<>();
final Promise<List<Template>> current = deferred.getPromise();
accumulator = accumulator.then(new Success<List<Template>, List<Template>>() {
@Override
public Promise<List<Template>> call(Promise<List<Template>> resolved) throws Exception {
final List<Template> prefix = resolved.getValue();
return current.map(new Function<List<Template>, List<Template>>() {
@Override
public List<Template> apply(List<Template> t) {
return CollectionUtils.append(prefix, t);
}
});
}
});
executor.submit(new Runnable() {
@Override
public void run() {
List<Template> templates = new LinkedList<>();
Map<Requirement, Collection<Capability>> providerMap = repo.findProviders(Collections.singleton(requirement));
if (providerMap != null) {
Collection<Capability> candidates = providerMap.get(requirement);
if (candidates != null) {
for (Capability cap : candidates) {
IdentityCapability idcap = ResourceUtils.getIdentityCapability(cap.getResource());
Object id = idcap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
Object ver = idcap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
try {
String engineName = (String) cap.getAttributes().get("engine");
if (engineName == null)
engineName = "stringtemplate";
TemplateEngine engine = engines.get(engineName);
if (engine != null)
templates.add(new CapabilityBasedTemplate(cap, locator, engine));
else
reporter.error("Error loading template from resource '%s' version %s: no Template Engine available matching '%s'", id, ver, engineName);
} catch (Exception e) {
reporter.error("Error loading template from resource '%s' version %s: %s", id, ver, e.getMessage());
}
}
}
}
deferred.resolve(templates);
}
});
}
return accumulator;
}
use of aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability in project bnd by bndtools.
the class ProjectResolver method getRunBundles.
/**
* Get the run bundles from the resolution. Resolve if this has not happened
* yet.
*/
public List<Container> getRunBundles() throws Exception {
Map<Resource, List<Wire>> resolution = this.resolution;
if (resolution == null) {
resolution = resolve();
}
List<Container> containers = new ArrayList<Container>();
for (Resource r : resolution.keySet()) {
IdentityCapability identity = ResourceUtils.getIdentityCapability(r);
if (identity == null) {
error("Identity for %s not found", r);
continue;
}
Container bundle = project.getBundle(identity.osgi_identity(), identity.version().toString(), Strategy.EXACT, null);
if (bundle == null) {
error("Bundle for %s-%s not found", identity.osgi_identity(), identity.version());
continue;
}
containers.add(bundle);
}
return containers;
}
use of aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability in project bnd by bndtools.
the class BridgeRepository method index.
private void index(Resource r) throws Exception {
IdentityCapability bc = ResourceUtils.getIdentityCapability(r);
String bsn = bc.osgi_identity();
Version version = bc.version();
Map<Version, ResourceInfo> map = index.get(bsn);
if (map == null) {
map = new HashMap<>();
index.put(bsn, map);
}
map.put(version, new ResourceInfo(r));
}
Aggregations