Search in sources :

Example 71 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class ResourceBuilder method getNativeCode.

/**
	 * Caclulate the requirement from a native code header
	 * 
	 * @param header the Bundle-NativeCode header or null
	 * @return a Requirement Builder set to the requirements according tot he
	 *         core spec
	 */
public RequirementBuilder getNativeCode(String header) throws Exception {
    if (header == null || header.isEmpty())
        return null;
    Parameters bundleNative = OSGiHeader.parseHeader(header, null, new Parameters(true));
    if (bundleNative.isEmpty())
        return null;
    boolean optional = false;
    List<String> options = new LinkedList<String>();
    RequirementBuilder rb = new RequirementBuilder(NativeNamespace.NATIVE_NAMESPACE);
    FilterBuilder sb = new FilterBuilder();
    sb.or();
    for (Entry<String, Attrs> entry : bundleNative.entrySet()) {
        String name = Processor.removeDuplicateMarker(entry.getKey());
        if ("*".equals(name)) {
            optional = true;
            continue;
        }
        sb.and();
        /*
			 * • osname - Name of the operating system. The value of this
			 * attribute must be the name of the operating system upon which the
			 * native libraries run. A number of canonical names are defined in
			 * Table 4.3.
			 */
        doOr(sb, "osname", NativeNamespace.CAPABILITY_OSNAME_ATTRIBUTE, entry.getValue());
        /*
			 * • processor - The processor architecture. The value of this
			 * attribute must be the name of the processor architecture upon
			 * which the native libraries run. A number of canonical names are
			 * defined in Table 4.2.
			 */
        doOr(sb, "processor", NativeNamespace.CAPABILITY_PROCESSOR_ATTRIBUTE, entry.getValue());
        /*
			 * • language - The ISO code for a language. The value of this
			 * attribute must be the name of the language for which the native
			 * libraries have been localized.
			 */
        doOr(sb, "language", NativeNamespace.CAPABILITY_LANGUAGE_ATTRIBUTE, entry.getValue());
        for (String key : entry.getValue().keySet()) {
            Object value = entry.getValue().getTyped(key);
            key = Processor.removeDuplicateMarker(key);
            switch(key) {
                case "osname":
                case "processor":
                case "language":
                    break;
                /*
					 * • osversion - The operating system version. The value of
					 * this attribute must be a version range as defined in
					 * Version Ranges on page 36.
					 */
                case "osversion":
                    sb.eq(NativeNamespace.CAPABILITY_OSVERSION_ATTRIBUTE, value);
                    break;
                /*
					 * • selection-filter - A selection filter. The value of
					 * this attribute must be a filter expression that in-
					 * dicates if the native code clause should be selected or
					 * not.
					 */
                case "selection-filter":
                    String filter = value.toString();
                    String validateFilter = Verifier.validateFilter(filter);
                    if (validateFilter != null) {
                        reporter.error("Invalid 'selection-filter' on Bundle-NativeCode %s", filter);
                    }
                    sb.literal(value.toString());
                    break;
                default:
                    reporter.warning("Unknown attribute on Bundle-NativeCode header %s=%s", key, value);
                    break;
            }
        }
        sb.endAnd();
    }
    sb.endOr();
    if (optional)
        rb.addDirective("resolution", "optional");
    rb.addFilter(sb.toString());
    return rb;
}
Also used : Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs) LinkedList(java.util.LinkedList)

Example 72 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class ResolveTest method testenRouteGuard.

/**
	 * The enRoute base guard resolved but is missing bundles, the runbundles do
	 * not run
	 */
public void testenRouteGuard() throws Exception {
    MockRegistry registry = new MockRegistry();
    Repository repo = createRepo(IO.getFile("testdata/enroute/index.xml"));
    registry.addPlugin(repo);
    List<Requirement> reqs = CapReqBuilder.getRequirementsFrom(new Parameters("osgi.wiring.package;filter:='(osgi.wiring.package=org.osgi.service.async)'"));
    Collection<Capability> pack = repo.findProviders(reqs).get(reqs.get(0));
    assertEquals(2, pack.size());
    ResourceBuilder b = new ResourceBuilder();
    File guard = IO.getFile("testdata/enroute/osgi.enroute.base.guard.jar");
    Domain manifest = Domain.domain(guard);
    b.addManifest(manifest);
    Repository resourceRepository = new ResourcesRepository(b.build());
    registry.addPlugin(resourceRepository);
    Processor model = new Processor();
    model.setRunfw("org.eclipse.osgi");
    model.setRunblacklist("osgi.identity;filter:='(osgi.identity=osgi.enroute.base.api)',osgi.identity;filter:='(osgi.identity=osgi.cmpn)',osgi.identity;filter:='(osgi.identity=osgi.core)");
    model.setRunRequires("osgi.identity;filter:='(osgi.identity=osgi.enroute.base.guard)'");
    model.setRunee("JavaSE-1.8");
    try {
        BndrunResolveContext context = new BndrunResolveContext(model, null, registry, log);
        Resolver resolver = new BndResolver(new ResolverLogger(4));
        Map<Resource, List<Wire>> resolved = resolver.resolve(context);
        Set<Resource> resources = resolved.keySet();
    } catch (ResolutionException e) {
        String msg = e.getMessage().replaceAll("\\[caused by:", "\n->");
        System.out.println(msg);
        fail(msg);
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters) Processor(aQute.bnd.osgi.Processor) Capability(org.osgi.resource.Capability) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) Resource(org.osgi.resource.Resource) ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) ArrayList(java.util.ArrayList) List(java.util.List) Domain(aQute.bnd.osgi.Domain) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 73 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class AttributesTest method testRemoveDirective.

/**
	 * Remove a version attribute A mandatory attribute adds the common and tst
	 * properties to the import. We remove them using remove:=*
	 * 
	 * @throws Exception
	 */
public static void testRemoveDirective() throws Exception {
    Jar javax = new Jar("test");
    Manifest m = new Manifest();
    m.getMainAttributes().putValue("Export-Package", "javax.microedition.io;a1=exp-1;a2=exp-2;a3=exp-3;x1=x1;x2=x2;x3=x3;mandatory:=\"a1,a2,a3,x1,x2,x3\"");
    javax.setManifest(m);
    Jar[] cp = { javax, new Jar(IO.getFile("jar/osgi.jar")) };
    Builder bmaker = new Builder();
    Properties p = new Properties();
    p.put("Import-Package", "javax.microedition.io;-remove-attribute:=a1|x?;a2=imp-2,*");
    p.put("Export-Package", "org.osgi.service.io");
    bmaker.setClasspath(cp);
    bmaker.setProperties(p);
    Jar jar = bmaker.build();
    assertTrue(bmaker.check());
    assertNotNull(bmaker.getImports());
    assertNotNull(bmaker.getImports().getByFQN("javax.microedition.io"));
    assertNotNull(bmaker.getImports().getByFQN("javax.microedition.io").get("a2"));
    jar.getManifest().write(System.err);
    Manifest manifest = jar.getManifest();
    Attributes main = manifest.getMainAttributes();
    String imprt = main.getValue("Import-Package");
    assertNotNull("Import package header", imprt);
    Parameters map = Processor.parseHeader(imprt, null);
    System.err.println("** " + map);
    Map<String, String> attrs = map.get("javax.microedition.io");
    assertNotNull(attrs);
    assertNull(attrs.get("a1"));
    assertNull(attrs.get("x1"));
    assertNull(attrs.get("x2"));
    assertNull(attrs.get("x3"));
    assertEquals("imp-2", attrs.get("a2"));
    assertEquals("exp-3", attrs.get("a3"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) Properties(java.util.Properties)

Example 74 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class BuilderTest method testClassQuery.

/**
	 * <pre>
	 *  [2013-12-11 15:55:14] BJ Hargrave: init: [echo] Enter project
	 * org.osgi.test.cases.prefs (${top}) [bndprepare] 2 WARNINGS [bndprepare]
	 * No translation found for macro:
	 * classes;extending;junit.framework.TestCase;concrete [bndprepare] No
	 * translation found for macro: classes,concrete [2013-12-11 15:55:31] BJ
	 * Hargrave: I am getting this on the latest bnd.master in the OSGi test
	 * projects
	 * </pre>
	 * 
	 * @throws Exception
	 */
public static void testClassQuery() throws Exception {
    Builder a = new Builder();
    try {
        a.addClasspath(new File("bin"));
        a.setExportPackage("test.component");
        a.setProperty("testcases", "${sort;${classes;extending;junit.framework.TestCase;concrete}}");
        a.setProperty("Test-Cases", "${testcases}");
        a.setProperty("-dsannotations", "!*");
        a.setProperty("-metatypeannotations", "!*");
        Jar jar = a.build();
        assertTrue(a.check());
        Manifest m = jar.getManifest();
        Parameters p = new Parameters(m.getMainAttributes().getValue("Test-Cases"));
        assertTrue(p.size() >= 4);
    } finally {
        a.close();
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 75 with Parameters

use of aQute.bnd.header.Parameters in project bnd by bndtools.

the class BuilderTest method testEEMacro.

/**
	 * #41 Test the EE macro
	 */
public static void testEEMacro() throws Exception {
    Builder b = new Builder();
    try {
        b.addClasspath(IO.getFile("jar/ifc112.jar"));
        b.setPrivatePackage("netscape.util.*");
        b.setBundleRequiredExecutionEnvironment("${ee}");
        Jar jar = b.build();
        assertTrue(b.check());
        Domain domain = Domain.domain(jar.getManifest());
        Parameters ee = domain.getBundleRequiredExecutionEnvironment();
        System.err.println(ee);
        assertTrue(ee.containsKey("JRE-1.1"));
    } finally {
        b.close();
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Aggregations

Parameters (aQute.bnd.header.Parameters)157 Attrs (aQute.bnd.header.Attrs)78 File (java.io.File)45 Jar (aQute.bnd.osgi.Jar)44 Manifest (java.util.jar.Manifest)39 Builder (aQute.bnd.osgi.Builder)35 Domain (aQute.bnd.osgi.Domain)24 ArrayList (java.util.ArrayList)20 Map (java.util.Map)16 Attributes (java.util.jar.Attributes)16 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Version (aQute.bnd.version.Version)11 Instructions (aQute.bnd.osgi.Instructions)9 HashSet (java.util.HashSet)9 Requirement (org.osgi.resource.Requirement)9 FileNotFoundException (java.io.FileNotFoundException)8 Properties (java.util.Properties)8 Matcher (java.util.regex.Matcher)8 Analyzer (aQute.bnd.osgi.Analyzer)7