use of org.osgi.service.indexer.ResourceIndexer in project bndtools by bndtools.
the class ResourceIndexerTracker method index.
public void index(Set<File> files, OutputStream out, Map<String, String> config) throws Exception {
ResourceIndexer indexer = doGetIndexer();
indexer.index(files, out, config);
}
use of org.osgi.service.indexer.ResourceIndexer in project bndtools by bndtools.
the class ResourceIndexerTracker method indexFragment.
public void indexFragment(Set<File> files, Writer out, Map<String, String> config) throws Exception {
ResourceIndexer indexer = doGetIndexer();
indexer.indexFragment(files, out, config);
}
use of org.osgi.service.indexer.ResourceIndexer in project bnd by bndtools.
the class RepoIndexTask method execute.
@Override
public void execute() throws BuildException {
printCopyright(System.err);
if (repositoryFile == null)
throw new BuildException("Output file not specified");
try {
// Configure PojoSR
Map<String, Object> pojoSrConfig = new HashMap<String, Object>();
pojoSrConfig.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, new ClasspathScanner());
// Start PojoSR 'framework'
Framework framework = new PojoServiceRegistryFactoryImpl().newFramework(pojoSrConfig);
framework.init();
framework.start();
if (knownBundles) {
registerKnownBundles(framework.getBundleContext());
}
// Look for indexer and run index generation
ServiceTracker<ResourceIndexer, ResourceIndexer> tracker = new ServiceTracker<ResourceIndexer, ResourceIndexer>(framework.getBundleContext(), ResourceIndexer.class, null);
tracker.open();
ResourceIndexer index = tracker.waitForService(1000);
if (index == null)
throw new IllegalStateException("Timed out waiting for ResourceIndexer service.");
// Flatten the file sets into a single list
Set<File> fileList = new LinkedHashSet<File>();
for (FileSet fileSet : fileSets) {
DirectoryScanner ds = fileSet.getDirectoryScanner(getProject());
File basedir = ds.getBasedir();
String[] files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++) fileList.add(new File(basedir, files[i]));
}
// Run
try (OutputStream fos = Files.newOutputStream(repositoryFile.toPath())) {
index.index(fileList, fos, config);
}
} catch (Exception e) {
throw new BuildException(e);
}
}
use of org.osgi.service.indexer.ResourceIndexer in project bnd by bndtools.
the class Index method main.
/**
* Main entry point. See -help for options.
*
* @param args Program arguments
*/
public static void main(String[] args) {
try {
// Configure PojoSR
Map<String, Object> pojoSrConfig = new HashMap<String, Object>();
pojoSrConfig.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, new ClasspathScanner());
// Start PojoSR 'framework'
Framework framework = new PojoServiceRegistryFactoryImpl().newFramework(pojoSrConfig);
framework.init();
framework.start();
// Look for indexer and run index generation
ServiceTracker<ResourceIndexer, ResourceIndexer> tracker = new ServiceTracker<ResourceIndexer, ResourceIndexer>(framework.getBundleContext(), ResourceIndexer.class, null);
tracker.open();
ResourceIndexer index = tracker.waitForService(1000);
if (index == null)
throw new IllegalStateException("Timed out waiting for ResourceIndexer service.");
// Process arguments
Set<File> fileList = new LinkedHashSet<File>();
Map<String, String> config = new HashMap<String, String>();
File outputFile = processArgs(args, System.err, config, fileList, framework.getBundleContext());
if (outputFile == null) {
System.exit(1);
}
boolean verbose = Boolean.parseBoolean(config.get(ResourceIndexer.VERBOSE));
if (verbose) {
printCopyright(System.err);
}
try (@SuppressWarnings("null") OutputStream fos = Files.newOutputStream(outputFile.toPath())) {
index.index(fileList, fos, config);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
System.exit(1);
}
// We really need to ensure all non-daemon threads -- which may have
// been started by a bundle -- are terminated.
System.exit(0);
}
use of org.osgi.service.indexer.ResourceIndexer in project bnd by bndtools.
the class TestOSGiServices method testWhiteboardAnalyzer.
// Test whiteboard registration of Resource Analyzers.
public void testWhiteboardAnalyzer() throws Exception {
ServiceRegistration<ResourceAnalyzer> reg = context.registerService(ResourceAnalyzer.class, new WibbleAnalyzer(), null);
ServiceReference<ResourceIndexer> ref = context.getServiceReference(ResourceIndexer.class);
ResourceIndexer indexer = context.getService(ref);
StringWriter writer = new StringWriter();
Map<String, String> config = new HashMap<String, String>();
config.put(ResourceIndexer.ROOT_URL, tempDir.getAbsoluteFile().toURI().toString());
indexer.indexFragment(Collections.singleton(copyToTempFile(tempDir, "testdata/01-bsn+version.jar")), writer, config);
assertEquals(readStream(TestOSGiServices.class.getResourceAsStream("/testdata/fragment-wibble.txt")), writer.toString().trim());
context.ungetService(ref);
reg.unregister();
}
Aggregations