Search in sources :

Example 6 with BundleDescriptor

use of org.apache.felix.connect.launch.BundleDescriptor in project camel by apache.

the class CamelBlueprintHelper method createBundleContext.

public static BundleContext createBundleContext(String name, String bundleFilter, TinyBundle bundle, TinyBundle configAdminInitBundle, ClassLoader loader) throws Exception {
    // ensure felix-connect stores bundles in an unique target directory
    String uid = "" + System.currentTimeMillis();
    String tempDir = "target/bundles/" + uid;
    System.setProperty("org.osgi.framework.storage", tempDir);
    createDirectory(tempDir);
    // use another directory for the jar of the bundle as it cannot be in the same directory
    // as it has a file lock during running the tests which will cause the temp dir to not be
    // fully deleted between tests
    createDirectory("target/test-bundles");
    List<BundleDescriptor> bundles = new LinkedList<>();
    if (configAdminInitBundle != null) {
        String jarName = "configAdminInitBundle-" + uid + ".jar";
        bundles.add(getBundleDescriptor("target/test-bundles/" + jarName, configAdminInitBundle));
    }
    if (bundle != null) {
        String jarName = name.toLowerCase(Locale.ENGLISH) + "-" + uid + ".jar";
        bundles.add(getBundleDescriptor("target/test-bundles/" + jarName, bundle));
    }
    List<BundleDescriptor> bundleDescriptors = getBundleDescriptors(bundleFilter, loader);
    // let's put configadmin before blueprint.core
    int idx1 = -1;
    int idx2 = -1;
    for (int i = 0; i < bundleDescriptors.size(); i++) {
        BundleDescriptor bd = bundleDescriptors.get(i);
        if ("org.apache.felix.configadmin".equals(bd.getHeaders().get("Bundle-SymbolicName"))) {
            idx1 = i;
        }
        if ("org.apache.aries.blueprint.core".equals(bd.getHeaders().get("Bundle-SymbolicName"))) {
            idx2 = i;
        }
    }
    if (idx1 >= 0 && idx2 >= 0 && idx1 > idx2) {
        bundleDescriptors.add(idx2, bundleDescriptors.remove(idx1));
    }
    // get the bundles
    bundles.addAll(bundleDescriptors);
    if (LOG.isDebugEnabled()) {
        for (int i = 0; i < bundles.size(); i++) {
            BundleDescriptor desc = bundles.get(i);
            LOG.debug("Bundle #{} -> {}", i, desc);
        }
    }
    // setup felix-connect to use our bundles
    Map<String, Object> config = new HashMap<String, Object>();
    config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
    // create pojorsr osgi service registry
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
    return reg.getBundleContext();
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) HashMap(java.util.HashMap) PojoServiceRegistryFactoryImpl(org.apache.felix.connect.PojoServiceRegistryFactoryImpl) LinkedList(java.util.LinkedList)

Example 7 with BundleDescriptor

use of org.apache.felix.connect.launch.BundleDescriptor in project felix by apache.

the class PojoSR method createSystemBundle.

public static BundleDescriptor createSystemBundle() {
    final Map<String, String> headers = new HashMap<String, String>();
    headers.put(Constants.BUNDLE_SYMBOLICNAME, "org.apache.felix.connect");
    headers.put(Constants.BUNDLE_VERSION, "0.0.0");
    headers.put(Constants.BUNDLE_NAME, "System Bundle");
    headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    headers.put(Constants.BUNDLE_VENDOR, "Apache Software Foundation");
    Revision revision = new Revision() {

        final long lastModified = System.currentTimeMillis();

        @Override
        public long getLastModified() {
            return lastModified;
        }

        @Override
        public Enumeration<String> getEntries() {
            return Collections.enumeration(Collections.EMPTY_LIST);
        }

        @Override
        public URL getEntry(String entryName) {
            return getClass().getClassLoader().getResource(entryName);
        }
    };
    Map<Class, Object> services = new HashMap<Class, Object>();
    services.put(FrameworkStartLevel.class, new FrameworkStartLevelImpl());
    return new BundleDescriptor(PojoSR.class.getClassLoader(), "System Bundle", headers, revision, services);
}
Also used : BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) BundleRevision(org.osgi.framework.wiring.BundleRevision) HashMap(java.util.HashMap)

Example 8 with BundleDescriptor

use of org.apache.felix.connect.launch.BundleDescriptor in project karaf by apache.

the class EncryptablePropertyPlaceholderTest method setUp.

@Before
public void setUp() throws Exception {
    StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
    EnvironmentStringPBEConfig env = new EnvironmentStringPBEConfig();
    env.setAlgorithm("PBEWithMD5AndDES");
    env.setPassword("password");
    enc.setConfig(env);
    String val = enc.encrypt("bar");
    System.setProperty("foo", val);
    System.setProperty("org.bundles.framework.storage", "target/bundles/" + System.currentTimeMillis());
    System.setProperty("karaf.name", "root");
    List<BundleDescriptor> bundles = new ClasspathScanner().scanForBundles("(Bundle-SymbolicName=*)");
    bundles.add(getBundleDescriptor("target/jasypt.jar", bundle().add("OSGI-INF/blueprint/karaf-jaas-jasypt.xml", getClass().getResource("/OSGI-INF/blueprint/karaf-jaas-jasypt.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "jasypt").set("Bundle-Version", "0.0.0")));
    bundles.add(getBundleDescriptor("target/test.jar", bundle().add("OSGI-INF/blueprint/test.xml", getClass().getResource("test.xml")).set("Manifest-Version", "2").set("Bundle-ManifestVersion", "2").set("Bundle-SymbolicName", "test").set("Bundle-Version", "0.0.0")));
    Map config = new HashMap();
    config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, bundles);
    PojoServiceRegistry reg = new PojoServiceRegistryFactoryImpl().newPojoServiceRegistry(config);
    bundleContext = reg.getBundleContext();
}
Also used : PojoServiceRegistry(org.apache.felix.connect.launch.PojoServiceRegistry) StandardPBEStringEncryptor(org.jasypt.encryption.pbe.StandardPBEStringEncryptor) BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) HashMap(java.util.HashMap) PojoServiceRegistryFactoryImpl(org.apache.felix.connect.PojoServiceRegistryFactoryImpl) EnvironmentStringPBEConfig(org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig) HashMap(java.util.HashMap) Map(java.util.Map) ClasspathScanner(org.apache.felix.connect.launch.ClasspathScanner) Before(org.junit.Before)

Example 9 with BundleDescriptor

use of org.apache.felix.connect.launch.BundleDescriptor in project jackrabbit-oak by apache.

the class OakOSGiRepositoryFactory method startBundles.

private void startBundles(PojoServiceRegistry registry, String bundleFilter, Map config) {
    try {
        if (bundleFilter == null) {
            bundleFilter = REPOSITORY_BUNDLE_FILTER_DEFAULT;
        }
        List<BundleDescriptor> descriptors = new ClasspathScanner().scanForBundles(bundleFilter);
        descriptors = Lists.newArrayList(descriptors);
        if (PropertiesUtil.toBoolean(config.get(REPOSITORY_ENV_SPRING_BOOT), false)) {
            descriptors = SpringBootSupport.processDescriptors(descriptors);
        }
        descriptors = processDescriptors(descriptors);
        registry.startBundles(descriptors);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) TimeoutException(java.util.concurrent.TimeoutException) RepositoryException(javax.jcr.RepositoryException) BundleException(org.osgi.framework.BundleException) ExecutionException(java.util.concurrent.ExecutionException) ClasspathScanner(org.apache.felix.connect.launch.ClasspathScanner)

Example 10 with BundleDescriptor

use of org.apache.felix.connect.launch.BundleDescriptor in project felix by apache.

the class PojoSR method startBundles.

public void startBundles(Collection<BundleDescriptor> scan) throws Exception {
    for (BundleDescriptor desc : scan) {
        Revision revision = desc.getRevision();
        if (revision == null) {
            revision = buildRevision(desc);
        }
        Map<String, String> bundleHeaders = desc.getHeaders();
        Version osgiVersion;
        try {
            osgiVersion = Version.parseVersion(bundleHeaders.get(Constants.BUNDLE_VERSION));
        } catch (Exception ex) {
            ex.printStackTrace();
            osgiVersion = Version.emptyVersion;
        }
        String sym = bundleHeaders.get(Constants.BUNDLE_SYMBOLICNAME);
        if (sym != null) {
            int idx = sym.indexOf(';');
            if (idx > 0) {
                sym = sym.substring(0, idx);
            }
            sym = sym.trim();
        }
        Bundle bundle = new PojoSRBundle(m_registry, m_dispatcher, m_bundles, desc.getUrl(), m_bundles.size(), sym, osgiVersion, revision, desc.getClassLoader(), bundleHeaders, desc.getServices(), bundleConfig);
        m_bundles.put(bundle.getBundleId(), bundle);
    }
    for (Bundle bundle : m_bundles.values()) {
        try {
            bundle.start();
        } catch (Throwable e) {
            System.out.println("Unable to start bundle: " + bundle);
            e.printStackTrace();
        }
    }
}
Also used : BundleDescriptor(org.apache.felix.connect.launch.BundleDescriptor) BundleRevision(org.osgi.framework.wiring.BundleRevision) Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) RequiredBundle(org.osgi.service.packageadmin.RequiredBundle) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException)

Aggregations

BundleDescriptor (org.apache.felix.connect.launch.BundleDescriptor)10 HashMap (java.util.HashMap)5 Map (java.util.Map)3 JarInputStream (java.util.jar.JarInputStream)3 PojoServiceRegistryFactoryImpl (org.apache.felix.connect.PojoServiceRegistryFactoryImpl)3 ClasspathScanner (org.apache.felix.connect.launch.ClasspathScanner)3 PojoServiceRegistry (org.apache.felix.connect.launch.PojoServiceRegistry)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 StandardPBEStringEncryptor (org.jasypt.encryption.pbe.StandardPBEStringEncryptor)2 EnvironmentStringPBEConfig (org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig)2 Before (org.junit.Before)2 BundleException (org.osgi.framework.BundleException)2 BundleRevision (org.osgi.framework.wiring.BundleRevision)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 JarURLConnection (java.net.JarURLConnection)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1