Search in sources :

Example 16 with Analyzer

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

the class AnalyzerTest method testMultilevelInheritance.

public static void testMultilevelInheritance() throws Exception {
    try (Analyzer a = new Analyzer()) {
        a.setJar(new File("bin"));
        a.analyze();
        String result = a._classes("cmd", "named", "*T?", "extends", "test.T0", "concrete");
        System.err.println(result);
        assertTrue(result.contains("test.T2"));
        assertTrue(result.contains("test.T3"));
    }
}
Also used : Analyzer(aQute.bnd.osgi.Analyzer) File(java.io.File)

Example 17 with Analyzer

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

the class AnalyzerTest method testExportForJar.

/**
	 * There was an export generated for a jar file.
	 * 
	 * @throws Exception
	 */
public static void testExportForJar() throws Exception {
    try (Analyzer an = new Analyzer()) {
        Jar jar = new Jar("dot");
        jar.putResource("target/aopalliance.jar", new FileResource(IO.getFile("jar/asm.jar")));
        an.setJar(jar);
        an.setProperty("Export-Package", "target");
        Manifest manifest = an.calcManifest();
        assertTrue(an.check());
        String exports = manifest.getMainAttributes().getValue(Analyzer.EXPORT_PACKAGE);
        Parameters map = Analyzer.parseHeader(exports, null);
        assertEquals(1, map.size());
        assertEquals("target", map.keySet().iterator().next());
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) FileResource(aQute.bnd.osgi.FileResource) Jar(aQute.bnd.osgi.Jar) Analyzer(aQute.bnd.osgi.Analyzer) Manifest(java.util.jar.Manifest)

Example 18 with Analyzer

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

the class AnalyzerTest method testClassQuery.

public static void testClassQuery() throws Exception {
    try (Analyzer a = new Analyzer()) {
        a.setJar(IO.getFile("jar/osgi.jar"));
        a.analyze();
        String result = a._classes("cmd", "named", "org.osgi.service.http.*", "abstract");
        TreeSet<String> r = new TreeSet<String>(Processor.split(result));
        assertEquals(new TreeSet<String>(Arrays.asList("org.osgi.service.http.HttpContext", "org.osgi.service.http.HttpService")), r);
    }
}
Also used : TreeSet(java.util.TreeSet) Analyzer(aQute.bnd.osgi.Analyzer)

Example 19 with Analyzer

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

the class Target method testComponentReader.

public static void testComponentReader() throws Exception {
    Analyzer analyzer = new Analyzer();
    File f = IO.getFile("bin/test/AnnotationsTest$MyComponent.class");
    Clazz c = new Clazz(analyzer, "test.AnnotationsTest.MyComponent", new FileResource(f));
    @SuppressWarnings("restriction") Map<String, String> map = ComponentAnnotationReader.getDefinition(c);
    System.err.println(map);
    assertEquals("mycomp", map.get("name:"));
    assertEquals("true", map.get("servicefactory:"));
    assertEquals("activatex", map.get("activate:"));
    assertEquals("deactivatex", map.get("deactivate:"));
    assertEquals("modifiedx", map.get("modified:"));
    assertEquals("org.osgi.service.log.LogService(abc=3)~", map.get("log/setLog"));
    assertEquals("org.osgi.service.packageadmin.PackageAdmin", map.get("packageAdmin/setPackageAdmin"));
    assertEquals("aprop= a prop ,aprop2=    really dumb value   ! ", map.get("properties:"));
}
Also used : FileResource(aQute.bnd.osgi.FileResource) Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) File(java.io.File)

Example 20 with Analyzer

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

the class Target method testNestedAnnotations.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void testNestedAnnotations() throws Exception {
    try (Analyzer analyzer = new Analyzer()) {
        TypeRef typeref = analyzer.getTypeRefFromFQN(ActualAnnotation.class.getName());
        Map<String, Object> annMap = (Map) Collections.singletonMap("a", 5);
        Annotation annotation = new Annotation(typeref, annMap, ElementType.FIELD, RetentionPolicy.RUNTIME);
        Map<String, Object> properties = (Map) Collections.singletonMap("ann", annotation);
        ConfigurableInterface a = Configurable.createConfigurable(ConfigurableInterface.class, properties);
        assertNotNull(a);
        assertNotNull(a.ann());
        assertEquals(5, a.ann().a());
    }
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Analyzer(aQute.bnd.osgi.Analyzer) Map(java.util.Map) Annotation(aQute.bnd.osgi.Annotation)

Aggregations

Analyzer (aQute.bnd.osgi.Analyzer)55 File (java.io.File)21 Clazz (aQute.bnd.osgi.Clazz)14 Properties (java.util.Properties)14 Manifest (java.util.jar.Manifest)12 Jar (aQute.bnd.osgi.Jar)11 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)9 ClassDataCollector (aQute.bnd.osgi.ClassDataCollector)8 Parameters (aQute.bnd.header.Parameters)7 FileResource (aQute.bnd.osgi.FileResource)7 FileInputStream (java.io.FileInputStream)6 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)5 Description (aQute.lib.getopt.Description)5 Attrs (aQute.bnd.header.Attrs)4 Descriptors (aQute.bnd.osgi.Descriptors)4 Packages (aQute.bnd.osgi.Packages)4 Resource (aQute.bnd.osgi.Resource)4 Map (java.util.Map)4 PomFromManifest (aQute.bnd.maven.PomFromManifest)3 Domain (aQute.bnd.osgi.Domain)3