Search in sources :

Example 66 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class ResolveTest method testSimpleResolve.

/**
	 * This is a basic test of resolving. This test is paired with
	 * {@link #testResolveWithDistro()}. If you change the resources, make sure
	 * this is done in the same way. The {@link #testResolveWithDistro()} has a
	 * negative check while this one checks positive.
	 */
public void testSimpleResolve() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel model = new BndEditModel();
    model.setRunFw("org.apache.felix.framework");
    List<Requirement> requires = new ArrayList<Requirement>();
    CapReqBuilder capReq = CapReqBuilder.createBundleRequirement("org.apache.felix.gogo.shell", "[0,1)");
    requires.add(capReq.buildSyntheticRequirement());
    model.setRunRequires(requires);
    BndrunResolveContext context = new BndrunResolveContext(model, registry, log);
    Resolver resolver = new BndResolver(new ResolverLogger(4));
    try {
        Map<Resource, List<Wire>> resolved = resolver.resolve(context);
        Set<Resource> resources = resolved.keySet();
        Resource resource = getResource(resources, "org.apache.felix.gogo.runtime", "0.10");
        assertNotNull(resource);
    } catch (ResolutionException e) {
        fail("Resolve failed");
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList) List(java.util.List) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 67 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bnd by bndtools.

the class ObrContentProvider method parseIndex.

public void parseIndex(InputStream stream, URI baseUri, IRepositoryIndexProcessor listener, LogService log) throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    inputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
    inputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
    inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
    StreamSource source = new StreamSource(stream, baseUri.toString());
    XMLStreamReader reader = inputFactory.createXMLStreamReader(source);
    ResourceBuilder resourceBuilder = null;
    CapReqBuilder capReqBuilder = null;
    while (reader.hasNext()) {
        int type = reader.next();
        String localName;
        switch(type) {
            case START_ELEMENT:
                localName = reader.getLocalName();
                if (TAG_REFERRAL.equals(localName)) {
                    Referral referral = new Referral(reader.getAttributeValue(null, ATTR_REFERRAL_URL), parseInt(reader.getAttributeValue(null, ATTR_REFERRAL_DEPTH)));
                    listener.processReferral(baseUri, referral, referral.getDepth(), 1);
                } else if (TAG_RESOURCE.equals(localName)) {
                    resourceBuilder = new ResourceBuilder();
                    String bsn = reader.getAttributeValue(null, ATTR_RESOURCE_SYMBOLIC_NAME);
                    String versionStr = reader.getAttributeValue(null, ATTR_RESOURCE_VERSION);
                    Version version = Version.parseVersion(versionStr);
                    String uri = reader.getAttributeValue(null, ATTR_RESOURCE_URI);
                    URI resolvedUri = resolveUri(uri, baseUri);
                    addBasicCapabilities(resourceBuilder, bsn, version, resolvedUri);
                } else if (TAG_CAPABILITY.equals(localName)) {
                    String obrName = reader.getAttributeValue(null, ATTR_NAME);
                    String namespace = mapObrNameToR5Namespace(obrName, false);
                    capReqBuilder = new CapReqBuilder(namespace);
                } else if (TAG_REQUIRE.equals(localName)) {
                    String obrName = reader.getAttributeValue(null, ATTR_NAME);
                    boolean extend = "true".equalsIgnoreCase(reader.getAttributeValue(null, ATTR_EXTEND));
                    String namespace = mapObrNameToR5Namespace(obrName, extend);
                    boolean optional = "true".equalsIgnoreCase(reader.getAttributeValue(null, ATTR_OPTIONAL));
                    capReqBuilder = new CapReqBuilder(namespace);
                    if (optional)
                        capReqBuilder.addDirective(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
                    String filter = translateObrFilter(namespace, reader.getAttributeValue(null, ATTR_FILTER), log);
                    capReqBuilder.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
                } else if (TAG_PROPERTY.equals(localName)) {
                    String name = reader.getAttributeValue(null, ATTR_PROPERTY_NAME);
                    String typeStr = reader.getAttributeValue(null, ATTR_PROPERTY_TYPE);
                    String valueStr = reader.getAttributeValue(null, ATTR_PROPERTY_VALUE);
                    if (capReqBuilder != null) {
                        name = mapObrPropertyToR5(capReqBuilder.getNamespace(), name);
                        if (PROPERTY_USES.equals(name))
                            capReqBuilder.addDirective(PROPERTY_USES, valueStr);
                        else {
                            Object value = convertProperty(valueStr, typeStr);
                            capReqBuilder.addAttribute(name, value);
                        }
                    }
                }
                break;
            case END_ELEMENT:
                localName = reader.getLocalName();
                if (TAG_RESOURCE.equals(localName)) {
                    if (resourceBuilder != null) {
                        Resource resource = resourceBuilder.build();
                        listener.processResource(resource);
                    }
                } else if (TAG_CAPABILITY.equals(localName)) {
                    if (resourceBuilder != null && capReqBuilder != null)
                        resourceBuilder.addCapability(capReqBuilder);
                    capReqBuilder = null;
                } else if (TAG_REQUIRE.equals(localName)) {
                    if (resourceBuilder != null && capReqBuilder != null)
                        resourceBuilder.addRequirement(capReqBuilder);
                    capReqBuilder = null;
                }
        }
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) XMLStreamReader(javax.xml.stream.XMLStreamReader) Referral(aQute.bnd.deployer.repository.api.Referral) Version(org.osgi.framework.Version) StreamSource(javax.xml.transform.stream.StreamSource) Resource(org.osgi.resource.Resource) URI(java.net.URI) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 68 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bndtools by bndtools.

the class ServiceSearchPanel method validate.

public void validate() {
    if (serviceClass == null || serviceClass.trim().isEmpty()) {
        setError(null);
        setRequirement(null);
    } else {
        String filter = String.format("(%s=%s)", ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, serviceClass);
        Requirement requirement = new CapReqBuilder(ServiceNamespace.SERVICE_NAMESPACE).addDirective(ServiceNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter).buildSyntheticRequirement();
        setError(null);
        setRequirement(requirement);
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement)

Example 69 with CapReqBuilder

use of aQute.bnd.osgi.resource.CapReqBuilder in project bndtools by bndtools.

the class PackageSearchPanel method validate.

private void validate() {
    try {
        String filter = null;
        if (packageName == null || packageName.trim().isEmpty()) {
            setError(null);
            setRequirement(null);
            return;
        }
        VersionRange versionRange = null;
        if (versionRangeStr != null && versionRangeStr.trim().length() > 0) {
            try {
                versionRange = new VersionRange(versionRangeStr);
            } catch (Exception e) {
                throw new IllegalArgumentException("Invalid version range: " + e.getMessage());
            }
        }
        filter = formatPackageRequirement(packageName, versionRange);
        if (filter != null)
            setRequirement(new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE).addDirective(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter).buildSyntheticRequirement());
        setError(null);
    } catch (Exception e) {
        setError(e.getMessage());
        setRequirement(null);
    }
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) VersionRange(aQute.bnd.version.VersionRange)

Aggregations

CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)69 Requirement (org.osgi.resource.Requirement)53 Capability (org.osgi.resource.Capability)35 BndEditModel (aQute.bnd.build.model.BndEditModel)32 MockRegistry (test.lib.MockRegistry)28 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)23 Resource (org.osgi.resource.Resource)18 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)10 Repository (org.osgi.service.repository.Repository)9 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)8 HashMap (java.util.HashMap)8 File (java.io.File)7 List (java.util.List)7 AndFilter (aQute.libg.filters.AndFilter)6 LiteralFilter (aQute.libg.filters.LiteralFilter)6 SimpleFilter (aQute.libg.filters.SimpleFilter)6 Parameters (aQute.bnd.header.Parameters)5 InfoRepository (aQute.bnd.service.repository.InfoRepository)5 Version (aQute.bnd.version.Version)5