Search in sources :

Example 1 with CapReqBuilder

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

the class XMLResourceParser method parseCapabilityOrRequirement.

private void parseCapabilityOrRequirement(ResourceBuilder resourceBuilder) throws Exception {
    String name = reader.getLocalName();
    check(TAG_REQUIREMENT.equals(name) || TAG_CAPABILITY.equals(name), "Expected <%s> or <%s> tag, got <%s>", TAG_REQUIREMENT, TAG_CAPABILITY, name);
    String namespace = reader.getAttributeValue(null, ATTR_NAMESPACE);
    CapReqBuilder capReqBuilder = new CapReqBuilder(namespace);
    next();
    while (reader.isStartElement()) {
        parseAttributesOrDirectives(capReqBuilder);
    }
    if (TAG_REQUIREMENT.equals(name)) {
        resourceBuilder.addRequirement(capReqBuilder);
    } else {
        resourceBuilder.addCapability(capReqBuilder);
    }
    tagEnd(name);
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder)

Example 2 with CapReqBuilder

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

the class ObrContentProvider method addBasicCapabilities.

private static void addBasicCapabilities(ResourceBuilder builder, String bsn, Version version, URI resolvedUri) throws Exception {
    CapReqBuilder identity = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, bsn).addAttribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE).addAttribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
    CapReqBuilder content = new CapReqBuilder(ContentNamespace.CONTENT_NAMESPACE).addAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, resolvedUri);
    CapReqBuilder host = new CapReqBuilder(HostNamespace.HOST_NAMESPACE).addAttribute(HostNamespace.HOST_NAMESPACE, bsn).addAttribute(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE, version);
    builder.addCapability(identity).addCapability(content).addCapability(host);
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder)

Example 3 with CapReqBuilder

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

the class R5RepoContentProvider method parseIndex.

public void parseIndex(InputStream stream, URI baseUri, IRepositoryIndexProcessor listener, LogService log) throws Exception {
    XMLStreamReader reader = null;
    try {
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        inputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
        inputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
        inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
        reader = inputFactory.createXMLStreamReader(stream);
        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)) {
                        String url = reader.getAttributeValue(null, ATTR_REFERRAL_URL);
                        String depth = reader.getAttributeValue(null, ATTR_REFERRAL_DEPTH);
                        Referral referral = new Referral(url, parseInt(depth));
                        listener.processReferral(baseUri, referral, 0, 0);
                    } else if (TAG_RESOURCE.equals(localName)) {
                        resourceBuilder = new ResourceBuilder();
                    } else if (TAG_CAPABILITY.equals(localName) || TAG_REQUIREMENT.equals(localName)) {
                        String namespace = reader.getAttributeValue(null, ATTR_NAMESPACE);
                        capReqBuilder = new CapReqBuilder(namespace);
                    } else if (TAG_ATTRIBUTE.equals(localName)) {
                        String name = reader.getAttributeValue(null, ATTR_NAME);
                        String valueStr = reader.getAttributeValue(null, ATTR_VALUE);
                        String typeAttr = reader.getAttributeValue(null, ATTR_TYPE);
                        if (capReqBuilder != null) {
                            // base URI.
                            if (ContentNamespace.CONTENT_NAMESPACE.equals(capReqBuilder.getNamespace()) && ContentNamespace.CAPABILITY_URL_ATTRIBUTE.equals(name)) {
                                URI resolvedUri = resolveUri(valueStr, baseUri);
                                capReqBuilder.addAttribute(name, resolvedUri);
                            } else {
                                Object convertedAttr = convertAttribute(valueStr, typeAttr);
                                capReqBuilder.addAttribute(name, convertedAttr);
                            }
                        }
                    } else if (TAG_DIRECTIVE.equals(localName)) {
                        String name = reader.getAttributeValue(null, ATTR_NAME);
                        String valueStr = reader.getAttributeValue(null, ATTR_VALUE);
                        if (capReqBuilder != null)
                            capReqBuilder.addDirective(name, valueStr);
                    }
                    break;
                case END_ELEMENT:
                    localName = reader.getLocalName();
                    if (TAG_CAPABILITY.equals(localName)) {
                        if (resourceBuilder != null && capReqBuilder != null)
                            resourceBuilder.addCapability(capReqBuilder);
                        capReqBuilder = null;
                    } else if (TAG_REQUIREMENT.equals(localName)) {
                        if (resourceBuilder != null && capReqBuilder != null)
                            resourceBuilder.addRequirement(capReqBuilder);
                        capReqBuilder = null;
                    } else if (TAG_RESOURCE.equals(localName)) {
                        if (resourceBuilder != null) {
                            Resource resource = resourceBuilder.build();
                            listener.processResource(resource);
                            resourceBuilder = null;
                        }
                    }
                    break;
            }
        }
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception e) {
            }
        }
    }
}
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) Resource(org.osgi.resource.Resource) URI(java.net.URI) XMLInputFactory(javax.xml.stream.XMLInputFactory) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException)

Example 4 with CapReqBuilder

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

the class BndrunResolveContext method init.

/**
	 * Initializes the resolver. Here we will load all the information from the
	 * model.
	 */
@Override
public synchronized void init() {
    if (initialized)
        return;
    initialized = true;
    try {
        if (getLevel() <= 0) {
            Integer level = Converter.cnv(Integer.class, properties.getProperty("-resolvedebug", "0"));
            if (level != null)
                setLevel(level);
        }
        loadPreferences();
        Processor augments = loadRepositories();
        constructBlacklist(augments);
        Map<String, Set<String>> effectiveSet = loadEffectiveSet();
        if (effectiveSet != null)
            addEffectiveSet(effectiveSet);
        //
        // Create a resource from the -runrequire that contains
        // all the requirement
        //
        setInputResource(constructInputRequirements());
        //
        // We gradually build up the system resource that contains
        // the system packages, the EE, etc.
        //
        ResourceBuilder system = new ResourceBuilder();
        //
        // Let's identify the system resource to make it look less
        // ugly
        //
        //
        // If we have a distro, we do not load the environment
        // settings
        //
        String distro = properties.mergeProperties(Constants.DISTRO);
        if (distro != null && !distro.trim().isEmpty()) {
            loadPath(system, distro, Constants.DISTRO);
            loadProvidedCapabilities(system);
        } else {
            //
            // Load the EE's and packages that belong to it.
            //
            EE tmp = EE.parse(properties.getProperty(Constants.RUNEE));
            EE ee = (tmp != null) ? tmp : EE.JavaSE_1_6;
            system.addAllExecutionEnvironments(ee);
            //
            // We make the system packages as coming from the system
            // resource
            //
            Parameters systemPackages = new Parameters(properties.mergeProperties(Constants.RUNSYSTEMPACKAGES), project);
            system.addExportPackages(systemPackages);
            //
            // We make the system capabilities as coming from the system
            // resource
            //
            Parameters systemCapabilities = new Parameters(properties.mergeProperties(Constants.RUNSYSTEMCAPABILITIES), project);
            system.addProvideCapabilities(systemCapabilities);
            loadProvidedCapabilities(system);
            //
            // Load the frameworks capabilities
            //
            loadFramework(system);
            //
            // Analyze the path and add all exported packages and provided
            // capabilities
            // to the system resource
            //
            String runpath = properties.mergeProperties(Constants.RUNPATH);
            if (runpath != null && !runpath.trim().isEmpty())
                loadPath(system, runpath, Constants.RUNPATH);
        }
        //
        // We've not gathered all the capabilities of the system
        // so we can create the resource and set it as the system resource
        //
        //
        // TODO Add osgi.wiring.bundle + osgi.wiring.host
        // filed a bug about using the impl version for the system
        // capabilities
        //
        List<Capability> frameworkPackages = system.findCapabilities(PackageNamespace.PACKAGE_NAMESPACE, "(" + PackageNamespace.PACKAGE_NAMESPACE + "=org.osgi.framework)");
        if (!frameworkPackages.isEmpty()) {
            Capability c = frameworkPackages.get(0);
            Version version = (Version) c.getAttributes().get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            CapReqBuilder crb = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE);
            crb.addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, "system.bundle");
            crb.addAttribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
            system.addCapability(crb);
        }
        setSystemResource(system.build());
    } catch (Exception e) {
        log.log(LogService.LOG_ERROR, e.getMessage(), e);
        throw new RuntimeException(e);
    }
    super.init();
}
Also used : EE(aQute.bnd.build.model.EE) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Processor(aQute.bnd.osgi.Processor) Set(java.util.Set) HashSet(java.util.HashSet) Parameters(aQute.bnd.header.Parameters) Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version)

Example 5 with CapReqBuilder

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

the class BndrunResolveContext method constructInputRequirements.

Resource constructInputRequirements() throws Exception {
    ResourceBuilder resBuilder = new ResourceBuilder();
    CapReqBuilder identity = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, IDENTITY_INITIAL_RESOURCE);
    resBuilder.addCapability(identity);
    Parameters inputRequirements = new Parameters(properties.mergeProperties(Constants.RUNREQUIRES), project);
    if (inputRequirements != null && !inputRequirements.isEmpty()) {
        List<Requirement> requires = CapReqBuilder.getRequirementsFrom(inputRequirements);
        resBuilder.addRequirements(requires);
    }
    return resBuilder.build();
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters)

Aggregations

CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)72 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 HashMap (java.util.HashMap)9 Repository (org.osgi.service.repository.Repository)9 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)8 AndFilter (aQute.libg.filters.AndFilter)7 SimpleFilter (aQute.libg.filters.SimpleFilter)7 File (java.io.File)7 List (java.util.List)7 Attrs (aQute.bnd.header.Attrs)6 Filter (aQute.libg.filters.Filter)6 LiteralFilter (aQute.libg.filters.LiteralFilter)6 Parameters (aQute.bnd.header.Parameters)5