Search in sources :

Example 11 with ResourceIndexer

use of org.osgi.service.indexer.ResourceIndexer in project bnd by bndtools.

the class TestOSGiServices method testWhiteboardAnalyzerWithFilter.

// Test whiteboard registration of Resource Analyzers, with resource filter
// property.
public void testWhiteboardAnalyzerWithFilter() throws Exception {
    Dictionary<String, Object> analyzerProps = new Hashtable<String, Object>();
    analyzerProps.put(ResourceAnalyzer.FILTER, "(location=*sion.jar)");
    ServiceRegistration<ResourceAnalyzer> reg = context.registerService(ResourceAnalyzer.class, new WibbleAnalyzer(), analyzerProps);
    ServiceReference<ResourceIndexer> ref = context.getServiceReference(ResourceIndexer.class);
    ResourceIndexer indexer = context.getService(ref);
    StringWriter writer = new StringWriter();
    Set<File> files = new LinkedHashSet<File>();
    files.add(copyToTempFile(tempDir, "testdata/01-bsn+version.jar"));
    files.add(copyToTempFile(tempDir, "testdata/02-localization.jar"));
    Map<String, String> config = new HashMap<String, String>();
    config.put(ResourceIndexer.ROOT_URL, tempDir.getAbsoluteFile().toURI().toString());
    indexer.indexFragment(files, writer, config);
    assertEquals(readStream(TestOSGiServices.class.getResourceAsStream("/testdata/fragment-wibble-filtered.txt")), writer.toString().trim());
    context.ungetService(ref);
    reg.unregister();
}
Also used : WibbleAnalyzer(org.example.tests.utils.WibbleAnalyzer) ResourceAnalyzer(org.osgi.service.indexer.ResourceAnalyzer) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) Matchers.anyString(org.mockito.Matchers.anyString) ResourceIndexer(org.osgi.service.indexer.ResourceIndexer) StringWriter(java.io.StringWriter) Utils.copyToTempFile(org.example.tests.utils.Utils.copyToTempFile) File(java.io.File)

Aggregations

ResourceIndexer (org.osgi.service.indexer.ResourceIndexer)11 HashMap (java.util.HashMap)8 File (java.io.File)6 StringWriter (java.io.StringWriter)6 Utils.copyToTempFile (org.example.tests.utils.Utils.copyToTempFile)4 Matchers.anyString (org.mockito.Matchers.anyString)4 OutputStream (java.io.OutputStream)3 LinkedHashSet (java.util.LinkedHashSet)3 ResourceAnalyzer (org.osgi.service.indexer.ResourceAnalyzer)3 PojoServiceRegistryFactoryImpl (de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl)2 ClasspathScanner (de.kalpatec.pojosr.framework.launch.ClasspathScanner)2 IOException (java.io.IOException)2 WibbleAnalyzer (org.example.tests.utils.WibbleAnalyzer)2 ServiceReference (org.osgi.framework.ServiceReference)2 Framework (org.osgi.framework.launch.Framework)2 RepoIndex (org.osgi.service.indexer.impl.RepoIndex)2 LogService (org.osgi.service.log.LogService)2 ServiceTracker (org.osgi.util.tracker.ServiceTracker)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1