Search in sources :

Example 86 with Attributes

use of java.util.jar.Attributes in project bnd by bndtools.

the class DSAnnotationTest method testProperties.

public void testProperties() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*x");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    if (!b.check("Cannot convert data blabla to type Integer", "Cannot convert data 3.0 to type Integer"))
        fail();
    Attributes a = getAttr(jar);
    checkProvides(a);
    checkRequires(a, null);
    //
    // Test all the defaults
    //
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$PropertiesTestx.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.1.0");
    xt.assertAttribute("1", "scr:component/property[@name='b']/@value");
    xt.assertAttribute("", "scr:component/property[@name='a']/@value");
    xt.assertAttribute("Byte", "scr:component/property[@name='byte']/@type");
    xt.assertAttribute("Boolean", "scr:component/property[@name='boolean']/@type");
    xt.assertAttribute("Character", "scr:component/property[@name='char']/@type");
    xt.assertAttribute("Short", "scr:component/property[@name='short']/@type");
    xt.assertAttribute("Integer", "scr:component/property[@name='integer']/@type");
    xt.assertAttribute("Long", "scr:component/property[@name='long']/@type");
    xt.assertAttribute("Float", "scr:component/property[@name='float']/@type");
    xt.assertAttribute("Double", "scr:component/property[@name='double']/@type");
    xt.assertAttribute("Integer", "scr:component/property[@name='̓̈́͆ͅ']/@type");
}
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)

Example 87 with Attributes

use of java.util.jar.Attributes in project bnd by bndtools.

the class DSAnnotationTest method testBasicFelix12.

public void testBasicFelix12() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*_basicFelix12");
    b.setProperty("-ds-felix-extensions", "true");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkProvides(a, SERIALIZABLE_RUNNABLE);
    checkRequires(a, null, LogService.class.getName());
    // Test Felix12 activate gives Felix 1.2 namespace
    checkDSFelix12(jar, "test.component.DSAnnotationTest$activate_basicFelix12");
    // Test Felix12 deactivate gives Felix 1.2 namespace
    checkDSFelix12(jar, "test.component.DSAnnotationTest$deactivate_basicFelix12");
    // Test Felix12 modified gives Felix 1.2 namespace
    checkDSFelix12(jar, "test.component.DSAnnotationTest$modified_basicFelix12");
    // Test Felix12 bind gives Felix 1.2 namespace
    checkDSFelix12(jar, "test.component.DSAnnotationTest$bind_basicFelix12");
    // Test Felix12 bind gives Felix 1.2 namespace
    checkDSFelix12(jar, "test.component.DSAnnotationTest$unbind_basicFelix12");
    // Test Felix12 updated gives Felix 1.2 namespace
    checkDSFelix12(jar, "test.component.DSAnnotationTest$updated_basicFelix12");
}
Also used : Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 88 with Attributes

use of java.util.jar.Attributes in project bnd by bndtools.

the class DSAnnotationTest method testVolatileFieldDynamic.

public void testVolatileFieldDynamic() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*VolatileField");
    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$VolatileField.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$VolatileField", "scr:component/implementation/@class");
    xt.assertAttribute("log1", "scr:component/reference[1]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[1]/@interface");
    xt.assertAttribute("dynamic", "scr:component/reference[1]/@policy");
    xt.assertAttribute("log2", "scr:component/reference[2]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
    xt.assertNoAttribute("scr:component/reference[2]/@policy");
}
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 89 with Attributes

use of java.util.jar.Attributes in project bnd by bndtools.

the class DSAnnotationTest method testReferenceType.

public void testReferenceType() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*RefType");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b, 0, 0);
    Attributes a = getAttr(jar);
    checkRequires(a, null, Marker.class.getName(), GenericMarker.class.getName(), Object.class.getName());
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$RefType.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");
    Collection<String> indices = new TreeSet<String>();
    for (int i = 1; i < 16; i++) indices.add(Integer.toString(i));
    this.indices.addAll(indices);
    checkMarkerReference(xt, 1, Marker.class);
    checkMarkerReference(xt, 2, Marker.class);
    checkMarkerReference(xt, 3, Marker.class);
    checkMarkerReference(xt, 4, Marker.class);
    checkMarkerReference(xt, 5, GenericMarker.class);
    checkMarkerReference(xt, 6, GenericMarker.class);
    checkMarkerReference(xt, 7, GenericMarker.class);
    checkMarkerReference(xt, 8, GenericMarker.class);
    checkMarkerReference(xt, 9, GenericMarker.class);
    checkMarkerReference(xt, 10, GenericMarker.class);
    checkMarkerReference(xt, 11, GenericMarker.class);
    checkMarkerReference(xt, 12, GenericMarker.class);
    checkMarkerReference(xt, 13, GenericMarker.class);
    checkMarkerReference(xt, 14, Object.class);
    checkMarkerReference(xt, 15, Marker.class);
}
Also used : Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) XmlTester(aQute.bnd.test.XmlTester) TreeSet(java.util.TreeSet) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 90 with Attributes

use of java.util.jar.Attributes in project bnd by bndtools.

the class DSAnnotationTest method testNoHeaderDups.

public void testNoHeaderDups() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest$DS13_*");
    b.setProperty("Private-Package", "test.component");
    b.setProperty("Provide-Capability", "osgi.service;objectClass:List<String>=\"java.io.Serializable,java.lang.Runnable\"");
    b.setProperty("Require-Capability", "osgi.service;filter:=\"(objectClass=org.osgi.service.log.LogService)\";effective:=active");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkProvides(a, SERIALIZABLE_RUNNABLE);
    checkRequires(a, "1.3.0", LogService.class.getName());
}
Also used : Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Aggregations

Attributes (java.util.jar.Attributes)629 Manifest (java.util.jar.Manifest)356 IOException (java.io.IOException)152 File (java.io.File)143 JarFile (java.util.jar.JarFile)106 URL (java.net.URL)92 Map (java.util.Map)78 InputStream (java.io.InputStream)62 HashMap (java.util.HashMap)62 Jar (aQute.bnd.osgi.Jar)49 Builder (aQute.bnd.osgi.Builder)43 ArrayList (java.util.ArrayList)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)42 Test (org.junit.Test)41 ZipEntry (java.util.zip.ZipEntry)39 FileOutputStream (java.io.FileOutputStream)37 JarOutputStream (java.util.jar.JarOutputStream)36 ByteArrayInputStream (java.io.ByteArrayInputStream)33 FileInputStream (java.io.FileInputStream)33 JarEntry (java.util.jar.JarEntry)32