Search in sources :

Example 6 with IdentityCapability

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);
}
Also used : Version(aQute.bnd.version.Version) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)

Example 7 with IdentityCapability

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());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) MockRegistry(test.lib.MockRegistry) Resource(org.osgi.resource.Resource) BndEditModel(aQute.bnd.build.model.BndEditModel) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)

Example 8 with IdentityCapability

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;
}
Also used : Deferred(org.osgi.util.promise.Deferred) ArrayList(java.util.ArrayList) Success(org.osgi.util.promise.Success) Template(org.bndtools.templating.Template) TemplateEngine(org.bndtools.templating.TemplateEngine) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Requirement(org.osgi.resource.Requirement) Promise(org.osgi.util.promise.Promise) Repository(org.osgi.service.repository.Repository) Collection(java.util.Collection) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 9 with IdentityCapability

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;
}
Also used : Container(aQute.bnd.build.Container) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)

Example 10 with IdentityCapability

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));
}
Also used : Version(aQute.bnd.version.Version) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)

Aggregations

IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)11 Capability (org.osgi.resource.Capability)7 Requirement (org.osgi.resource.Requirement)7 Resource (org.osgi.resource.Resource)5 HashMap (java.util.HashMap)4 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)3 Version (aQute.bnd.version.Version)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Repository (org.osgi.service.repository.Repository)2 Promise (org.osgi.util.promise.Promise)2 Container (aQute.bnd.build.Container)1 BndEditModel (aQute.bnd.build.model.BndEditModel)1 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)1 CapabilityBuilder (aQute.bnd.osgi.resource.CapabilityBuilder)1 FilterParser (aQute.bnd.osgi.resource.FilterParser)1