Search in sources :

Example 1 with PojoServiceRegistryFactoryImpl

use of de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl 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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FileSet(org.apache.tools.ant.types.FileSet) HashMap(java.util.HashMap) ServiceTracker(org.osgi.util.tracker.ServiceTracker) OutputStream(java.io.OutputStream) ResourceIndexer(org.osgi.service.indexer.ResourceIndexer) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ClasspathScanner(de.kalpatec.pojosr.framework.launch.ClasspathScanner) PojoServiceRegistryFactoryImpl(de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) Framework(org.osgi.framework.launch.Framework)

Example 2 with PojoServiceRegistryFactoryImpl

use of de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl 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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) ServiceTracker(org.osgi.util.tracker.ServiceTracker) OutputStream(java.io.OutputStream) ResourceIndexer(org.osgi.service.indexer.ResourceIndexer) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) CmdLineException(org.kohsuke.args4j.CmdLineException) ClasspathScanner(de.kalpatec.pojosr.framework.launch.ClasspathScanner) PojoServiceRegistryFactoryImpl(de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl) File(java.io.File) Framework(org.osgi.framework.launch.Framework)

Example 3 with PojoServiceRegistryFactoryImpl

use of de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl in project ddf by codice.

the class CatalogComponentTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    LOGGER.debug("INSIDE createCamelContext");
    CamelContext camelContext = super.createCamelContext();
    // Configure PojoSR to be our mock OSGi Registry
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(new HashMap());
    bundleContext = reg.getBundleContext();
    // Since the Camel BlueprintComponentResolver does not execute outside
    // of an OSGi container, we cannot
    // rely on the CatalogComponentResolver to be used for resolving the
    // CatalogComponent when Camel loads the route.
    // Therefore, we Mock what the CatalogComponent's blueprint.xml file
    // would have done by creating a
    // CatalogComponent explicitly and adding it to the CamelContext used
    // for this unit test.
    catalogComponent = new CatalogComponent();
    catalogComponent.setBundleContext(bundleContext);
    camelContext.addComponent(CatalogComponent.NAME, catalogComponent);
    return camelContext;
}
Also used : CamelContext(org.apache.camel.CamelContext) PojoServiceRegistry(de.kalpatec.pojosr.framework.launch.PojoServiceRegistry) HashMap(java.util.HashMap) PojoServiceRegistryFactoryImpl(de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl)

Example 4 with PojoServiceRegistryFactoryImpl

use of de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl in project aries by apache.

the class Helper method createBundleContext.

public static BundleContext createBundleContext(String bundleFilter, TinyBundle[] testBundles) throws Exception {
    deleteDirectory("target/bundles");
    createDirectory("target/bundles");
    // ensure pojosr stores bundles in an unique target directory
    System.setProperty("org.osgi.framework.storage", "target/bundles/" + System.currentTimeMillis());
    // get the bundles
    List<BundleDescriptor> bundles = getBundleDescriptors(bundleFilter);
    // with pojosr because it does not support bundle hooks, so events are lost.
    if (testBundles != null) {
        for (TinyBundle bundle : testBundles) {
            File tmp = File.createTempFile("test-", ".jar", new File("target/bundles/"));
            tmp.delete();
            bundles.add(0, getBundleDescriptor(tmp.getPath(), bundle));
        }
    }
    if (LOG.isDebugEnabled()) {
        for (int i = 0; i < bundles.size(); i++) {
            BundleDescriptor desc = bundles.get(i);
            LOG.debug("Bundle #{} -> {}", i, desc);
        }
    }
    // setup pojosr to use our bundles
    Map<String, List<BundleDescriptor>> config = new HashMap<String, List<BundleDescriptor>>();
    config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
    // create pojorsr osgi service registry
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
    return reg.getBundleContext();
}
Also used : TinyBundle(org.ops4j.pax.swissbox.tinybundles.core.TinyBundle) PojoServiceRegistry(de.kalpatec.pojosr.framework.launch.PojoServiceRegistry) BundleDescriptor(de.kalpatec.pojosr.framework.launch.BundleDescriptor) HashMap(java.util.HashMap) PojoServiceRegistryFactoryImpl(de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) File(java.io.File)

Example 5 with PojoServiceRegistryFactoryImpl

use of de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl in project ddf by codice.

the class CatalogComponentFrameworkTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    // Since the Camel BlueprintComponentResolver does not execute outside
    // of an OSGi container, we cannot
    // rely on the CatalogComponentResolver to be used for resolving the
    // CatalogComponent when Camel loads the route.
    // Therefore, we Mock what the CatalogComponent's blueprint.xml file
    // would have done by creating a
    // CatalogComponent explicitly and adding it to the CamelContext used
    // for this unit test.
    // Configure PojoSR to be our mock OSGi Registry
    final PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(new HashMap());
    final BundleContext bundleContext = reg.getBundleContext();
    final CamelContext camelContext = super.createCamelContext();
    final CatalogComponent catalogComponent = new CatalogComponent();
    catalogComponent.setBundleContext(bundleContext);
    catalogFramework = mock(CatalogFramework.class);
    catalogComponent.setCatalogFramework(catalogFramework);
    camelContext.addComponent(CatalogComponent.NAME, catalogComponent);
    return camelContext;
}
Also used : PojoServiceRegistry(de.kalpatec.pojosr.framework.launch.PojoServiceRegistry) CamelContext(org.apache.camel.CamelContext) HashMap(java.util.HashMap) PojoServiceRegistryFactoryImpl(de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl) CatalogFramework(ddf.catalog.CatalogFramework) BundleContext(org.osgi.framework.BundleContext)

Aggregations

PojoServiceRegistryFactoryImpl (de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl)5 HashMap (java.util.HashMap)5 PojoServiceRegistry (de.kalpatec.pojosr.framework.launch.PojoServiceRegistry)3 File (java.io.File)3 ClasspathScanner (de.kalpatec.pojosr.framework.launch.ClasspathScanner)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 LinkedHashSet (java.util.LinkedHashSet)2 CamelContext (org.apache.camel.CamelContext)2 Framework (org.osgi.framework.launch.Framework)2 ResourceIndexer (org.osgi.service.indexer.ResourceIndexer)2 ServiceTracker (org.osgi.util.tracker.ServiceTracker)2 CatalogFramework (ddf.catalog.CatalogFramework)1 BundleDescriptor (de.kalpatec.pojosr.framework.launch.BundleDescriptor)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BuildException (org.apache.tools.ant.BuildException)1 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)1 FileSet (org.apache.tools.ant.types.FileSet)1