Search in sources :

Example 56 with Resource

use of aQute.bnd.osgi.Resource in project bnd by bndtools.

the class DSAnnotationTest method checkDS13AnnoOverride.

private void checkDS13AnnoOverride(Jar jar, String name) throws Exception, XPathExpressionException {
    Resource r = jar.getResource("OSGI-INF/" + name + ".xml");
    System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    // Test the defaults
    xt.assertAttribute(name, "scr:component/implementation/@class");
    // Default must be the implementation class
    xt.assertAttribute(name, "scr:component/@name");
    xt.assertAttribute("", "scr:component/@configuration-policy");
    xt.assertAttribute("", "scr:component/@immediate");
    xt.assertAttribute("", "scr:component/@enabled");
    xt.assertAttribute("", "scr:component/@factory");
    xt.assertAttribute("", "scr:component/service/@scope");
    xt.assertAttribute("", "scr:component/@configuration-pid");
    xt.assertAttribute("activate", "scr:component/@activate");
    xt.assertAttribute("deactivate", "scr:component/@deactivate");
    xt.assertAttribute("modified", "scr:component/@modified");
    xt.assertAttribute("java.io.Serializable", "scr:component/service/provide[1]/@interface");
    xt.assertAttribute("java.lang.Runnable", "scr:component/service/provide[2]/@interface");
    xt.assertAttribute("4", "count(scr:component/property)");
    xt.assertAttribute("a", "scr:component/property[@name='a']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='a']/@type");
    xt.assertAttribute("b", "scr:component/property[@name='b']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='b']/@type");
    xt.assertAttribute("b", "scr:component/property[@name='one']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='one']/@type");
    xt.assertAttribute("c", "scr:component/property[@name='two']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='two']/@type");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Resource(aQute.bnd.osgi.Resource)

Example 57 with Resource

use of aQute.bnd.osgi.Resource in project bnd by bndtools.

the class DSAnnotationTest method testBridgeMethod.

/*
	 * See https://github.com/bndtools/bnd/issues/1546. If a component class has
	 * an annotated method for which the compiler generates a bridge method,
	 * javac will copy the annotations onto the bridge method. Bnd must ignore
	 * bridge methods.
	 */
public void testBridgeMethod() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*ActivatableComponent");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b, 0, 0);
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$ActivatableComponent.xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    xt.assertAttribute("activator", "scr:component/@activate");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 58 with Resource

use of aQute.bnd.osgi.Resource in project bnd by bndtools.

the class DSAnnotationTest method testFieldCardinality.

public void testFieldCardinality() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*FieldCardinality");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkRequires(a, "1.3.0", LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$FieldCardinality.xml");
    System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    // Test the defaults
    xt.assertAttribute("test.component.DSAnnotationTest$FieldCardinality", "scr:component/implementation/@class");
    xt.assertAttribute("log1", "scr:component/reference[1]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[1]/@interface");
    xt.assertAttribute("0..n", "scr:component/reference[1]/@cardinality");
    xt.assertNoAttribute("scr:component/reference[1]/@policy");
    xt.assertNoAttribute("scr:component/reference[1]/@field-option");
    xt.assertAttribute("log2", "scr:component/reference[2]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
    xt.assertAttribute("0..n", "scr:component/reference[2]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[2]/@policy");
    xt.assertNoAttribute("scr:component/reference[2]/@field-option");
    xt.assertAttribute("log3", "scr:component/reference[3]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[3]/@interface");
    xt.assertNoAttribute("scr:component/reference[3]/@cardinality");
    xt.assertNoAttribute("scr:component/reference[3]/@policy");
    xt.assertNoAttribute("scr:component/reference[3]/@field-option");
    xt.assertAttribute("log4", "scr:component/reference[4]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[4]/@interface");
    xt.assertNoAttribute("scr:component/reference[4]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[4]/@policy");
    xt.assertNoAttribute("scr:component/reference[4]/@field-option");
    xt.assertAttribute("log5", "scr:component/reference[5]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[5]/@interface");
    xt.assertAttribute("0..n", "scr:component/reference[5]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[5]/@policy");
    xt.assertAttribute("update", "scr:component/reference[5]/@field-option");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 59 with Resource

use of aQute.bnd.osgi.Resource in project bnd by bndtools.

the class DSAnnotationTest method testPrototypes.

public void testPrototypes() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*Prototypes");
    b.setProperty(Constants.DSANNOTATIONS_OPTIONS, "version;minimum=1.0.0");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkProvides(a);
    checkRequires(a, null, LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/prototypes.xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.2.0");
    xt.assertAttribute("LogService", "scr:component/reference[1]/@name");
    xt.assertAttribute("setLogService", "scr:component/reference[1]/@bind");
    xt.assertAttribute("unsetLogService", "scr:component/reference[1]/@unbind");
    xt.assertAttribute("updatedLogService", "scr:component/reference[1]/@updated");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 60 with Resource

use of aQute.bnd.osgi.Resource in project bnd by bndtools.

the class DSAnnotationTest method checkDS13AnnoConfigNames.

private void checkDS13AnnoConfigNames(Jar jar, String name) throws Exception, XPathExpressionException {
    Resource r = jar.getResource("OSGI-INF/" + name + ".xml");
    System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    // Test the defaults
    xt.assertAttribute(name, "scr:component/implementation/@class");
    // Default must be the implementation class
    xt.assertAttribute(name, "scr:component/@name");
    xt.assertAttribute("", "scr:component/@configuration-policy");
    xt.assertAttribute("", "scr:component/@immediate");
    xt.assertAttribute("", "scr:component/@enabled");
    xt.assertAttribute("", "scr:component/@factory");
    xt.assertAttribute("", "scr:component/service/@scope");
    xt.assertAttribute("", "scr:component/@configuration-pid");
    xt.assertAttribute("activate", "scr:component/@activate");
    xt.assertAttribute("deactivate", "scr:component/@deactivate");
    xt.assertAttribute("modified", "scr:component/@modified");
    xt.assertAttribute("java.io.Serializable", "scr:component/service/provide[1]/@interface");
    xt.assertAttribute("java.lang.Runnable", "scr:component/service/provide[2]/@interface");
    xt.assertAttribute("6", "count(scr:component/property)");
    xt.assertAttribute("foo", "scr:component/property[@name='myString1']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='myString1']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='myString2']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='myString2']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='my$String3']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='my$String3']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='my.String4']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='my.String4']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='my_String5']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='my_String5']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='my$_String6']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='my$_String6']/@type");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Resource(aQute.bnd.osgi.Resource)

Aggregations

Resource (aQute.bnd.osgi.Resource)147 Jar (aQute.bnd.osgi.Jar)87 Builder (aQute.bnd.osgi.Builder)83 File (java.io.File)76 XmlTester (aQute.bnd.test.XmlTester)48 JarResource (aQute.bnd.osgi.JarResource)20 Attributes (java.util.jar.Attributes)20 Map (java.util.Map)19 Manifest (java.util.jar.Manifest)19 FileResource (aQute.bnd.osgi.FileResource)17 LogService (org.osgi.service.log.LogService)15 HashMap (java.util.HashMap)14 Document (org.w3c.dom.Document)14 Properties (java.util.Properties)12 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)11 DocumentBuilder (javax.xml.parsers.DocumentBuilder)11 InputStream (java.io.InputStream)9 Attrs (aQute.bnd.header.Attrs)8 ArrayList (java.util.ArrayList)8 TreeMap (java.util.TreeMap)8