Search in sources :

Example 6 with ResourceBuilder

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

the class ProjectResolverTest method add.

private void add(ResourcesRepository fr, File file) throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    rb.addFile(file, file.toURI());
    Resource resource = rb.build();
    fr.add(resource);
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resource(org.osgi.resource.Resource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource)

Example 7 with ResourceBuilder

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

the class ValidatorTest method testValidatingResourcesWithDocumentaryAttributes.

public void testValidatingResourcesWithDocumentaryAttributes() throws Exception {
    try (ResolverValidator validator = new ResolverValidator()) {
        ResourceBuilder system = new ResourceBuilder();
        system.addEE(EE.JavaSE_1_8);
        system.addManifest(OSGI_CORE.R6_0_0.getManifest());
        validator.setSystem(system.build());
        validator.setTrace(true);
        ResourcesRepository repository = new ResourcesRepository();
        ResourceBuilder builder = new ResourceBuilder();
        File file = IO.getFile("testdata/osgi.cmpn-4.3.0.jar");
        builder.addFile(file, file.toURI());
        repository.add(builder.build());
        builder = new ResourceBuilder();
        file = IO.getFile("testdata/org.apache.felix.framework-4.0.0.jar");
        builder.addFile(file, file.toURI());
        repository.add(builder.build());
        List<Resource> resources = repository.getResources();
        validator.validateResources(repository, resources);
        assertTrue(validator.check());
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resource(org.osgi.resource.Resource) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 8 with ResourceBuilder

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

the class ValidatorTest method testDelibarateFail.

public void testDelibarateFail() throws Exception {
    try (ResolverValidator validator = new ResolverValidator()) {
        ResourceBuilder system = new ResourceBuilder();
        system.addEE(EE.JavaSE_1_8);
        system.addManifest(OSGI_CORE.R6_0_0.getManifest());
        validator.setSystem(system.build());
        validator.setTrace(true);
        validator.addRepository(IO.getFile("testdata/repo5-broken.index.xml").toURI());
        List<Resolution> resolutions = validator.validate();
        assertFalse(validator.check());
        assertEquals(1, resolutions.size());
        String message = resolutions.get(0).message;
        String expectedToContain = "missing requirement org.apache.felix.gogo.api";
        assertTrue(String.format("expected to contain <%s> but was <%s>", expectedToContain, message), message.contains(expectedToContain));
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resolution(biz.aQute.resolve.ResolverValidator.Resolution)

Example 9 with ResourceBuilder

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

the class XMLResourceParser method parseResource.

private void parseResource(List<Resource> resources) throws Exception {
    ResourceBuilder resourceBuilder = new ResourceBuilder();
    next();
    while (reader.isStartElement()) {
        parseCapabilityOrRequirement(resourceBuilder);
    }
    Resource resource = resourceBuilder.build();
    resources.add(resource);
    tagEnd(TAG_RESOURCE);
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resource(org.osgi.resource.Resource)

Example 10 with ResourceBuilder

use of aQute.bnd.osgi.resource.ResourceBuilder 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)

Aggregations

ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)41 Resource (org.osgi.resource.Resource)22 File (java.io.File)13 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)8 Capability (org.osgi.resource.Capability)8 Requirement (org.osgi.resource.Requirement)8 Parameters (aQute.bnd.header.Parameters)6 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)6 Version (org.osgi.framework.Version)6 Domain (aQute.bnd.osgi.Domain)5 Resolution (biz.aQute.resolve.ResolverValidator.Resolution)5 HashSet (java.util.HashSet)5 IOException (java.io.IOException)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Processor (aQute.bnd.osgi.Processor)3 HashMap (java.util.HashMap)3 List (java.util.List)3 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)2 Referral (aQute.bnd.deployer.repository.api.Referral)2