Search in sources :

Example 31 with ResourceBuilder

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

the class ValidatorTest method _testLarger.

public void _testLarger() 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/larger-repo.xml").toURI());
        validator.validate();
        assertTrue(validator.check());
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder)

Example 32 with ResourceBuilder

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

the class ValidatorTest method testSmallWithSpecificResources.

public void testSmallWithSpecificResources() 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/repo1.index.xml").toURI());
        List<Resource> resources = XMLResourceParser.getResources(IO.getFile("testdata/repo1.index.xml").toURI());
        validator.validate(resources);
        assertTrue(validator.check());
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resource(org.osgi.resource.Resource)

Example 33 with ResourceBuilder

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

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

the class DistroCommandTest method testMultipleCapabilitiesPerNamespace.

public void testMultipleCapabilitiesPerNamespace() throws Exception {
    bnd bnd = new bnd();
    CommandLine cmdline = new CommandLine(null);
    List<String> remoteArgs = new ArrayList<>();
    RemoteOptions remoteOptions = cmdline.getOptions(RemoteOptions.class, remoteArgs);
    File distro = new File("generated/tmp/test.distro.jar");
    List<String> distroArgs = new ArrayList<>();
    distroArgs.add("-o");
    distroArgs.add(distro.getPath());
    distroArgs.add("test.distro");
    distroArgs.add("1.0.0");
    DistroOptions distroOptions = cmdline.getOptions(DistroOptions.class, distroArgs);
    new RemoteCommand(bnd, remoteOptions)._distro(distroOptions);
    assertTrue(distro.exists());
    ResourceBuilder builder = new ResourceBuilder();
    Domain manifest = Domain.domain(new Jar(distro).getManifest());
    builder.addManifest(manifest);
    Resource resource = builder.build();
    List<Capability> capabilities = resource.getCapabilities(null);
    assertNotNull(capabilities);
    List<Capability> extenderCaps = resource.getCapabilities(ExtenderNamespace.EXTENDER_NAMESPACE);
    int jspTaglibCapabilityCount = 0;
    for (Capability capability : extenderCaps) {
        Map<String, Object> attributes = capability.getAttributes();
        if ("jsp.taglib".equals(attributes.get(ExtenderNamespace.EXTENDER_NAMESPACE))) {
            jspTaglibCapabilityCount++;
        }
    }
    assertEquals(2, jspTaglibCapabilityCount);
    List<Capability> eeCaps = resource.getCapabilities(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE);
    assertTrue(eeCaps.size() > 0);
    Capability javaSECap = null;
    for (Capability capability : eeCaps) {
        Map<String, Object> attributes = capability.getAttributes();
        if ("JavaSE".equals(attributes.get(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE))) {
            javaSECap = capability;
        }
    }
    assertNotNull(javaSECap);
    @SuppressWarnings("null") Map<String, Object> attributes = javaSECap.getAttributes();
    assertTrue(attributes.containsKey("version"));
    @SuppressWarnings("unchecked") List<Version> versions = (List<Version>) attributes.get("version");
    assertTrue(versions.size() > 1);
    assertTrue(versions.contains(new Version("1.7.0")));
    assertTrue(versions.contains(new Version("1.6.0")));
    assertTrue(versions.contains(new Version("1.5.0")));
    assertTrue(versions.contains(new Version("1.4.0")));
    assertTrue(versions.contains(new Version("1.3.0")));
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Capability(org.osgi.resource.Capability) RemoteOptions(aQute.bnd.main.RemoteCommand.RemoteOptions) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) CommandLine(aQute.lib.getopt.CommandLine) DistroOptions(aQute.bnd.main.RemoteCommand.DistroOptions) Version(org.osgi.framework.Version) Jar(aQute.bnd.osgi.Jar) ArrayList(java.util.ArrayList) List(java.util.List) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 35 with ResourceBuilder

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

the class NativeCodeHeaderTest method testNative.

public void testNative() throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    Requirement nativeCode = //
    rb.getNativeCode(//
    "f1;" + //
    "  osname=Windows95;" + //
    "  processor=x86;" + //
    "  selection-filter='(com.acme.windowing=win32)';" + //
    "  language=en;" + //
    "  osname=Windows98;" + //
    "  language=se, " + //
    "lib/solaris/libhttp.so;" + //
    "  osname=Solaris;" + //
    "  osname = SunOS ;" + //
    "  processor = sparc, " + //
    "lib/linux/libhttp.so ; " + //
    "  osname = Linux ; " + //
    "  processor = mips; " + //
    "  selection-filter = '(com.acme.windowing=gtk)'," + "*").synthetic();
    assertEquals(NativeNamespace.NATIVE_NAMESPACE, nativeCode.getNamespace());
    assertEquals("optional", nativeCode.getDirectives().get("resolution"));
    String filter = nativeCode.getDirectives().get("filter");
    assertEquals(null, Verifier.validateFilter(filter));
    FilterParser p = new FilterParser();
    Expression parse = p.parse(filter);
    assertEquals("(|(&(|(osgi.native.osname=Windows95)(osgi.native.osname=Windows98))(osgi.native.processor=x86)(|(osgi.native.language=en)(osgi.native.language=se))(com.acme.windowing=win32))(&(|(osgi.native.osname=Solaris)(osgi.native.osname=SunOS))(osgi.native.processor=sparc))(&(osgi.native.osname=Linux)(osgi.native.processor=mips)(com.acme.windowing=gtk)))", filter);
    System.out.println(nativeCode);
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Expression(aQute.bnd.osgi.resource.FilterParser.Expression) FilterParser(aQute.bnd.osgi.resource.FilterParser)

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