Search in sources :

Example 51 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testSystemNLFragment.

public void testSystemNLFragment() throws BundleException {
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put("osgi.nl", "zh");
    Equinox equinox = new Equinox(configuration);
    equinox.start();
    equinox.getHeaders();
    BundleContext systemContext = equinox.getBundleContext();
    Bundle systemNLS = systemContext.installBundle(installer.getBundleLocation("test.system.nls"));
    equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(systemNLS));
    assertEquals("Wrong fragment state", Bundle.RESOLVED, systemNLS.getState());
    assertEquals("Wrong header value.", "TEST NAME", equinox.getHeaders().get(Constants.BUNDLE_NAME));
    equinox.stop();
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 52 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class SystemBundleTests method checkParentClassLoader.

private void checkParentClassLoader(Map<String, Object> configuration) {
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
        equinox.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start the framework", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
    Bundle test = null;
    try {
        // $NON-NLS-1$
        test = equinox.getBundleContext().installBundle(installer.getBundleLocation("substitutes.a"));
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to install bundle", e);
    }
    try {
        // $NON-NLS-1$
        Class activatorClazz = test.loadClass("substitutes.x.Ax");
        ClassLoader parentCL = activatorClazz.getClassLoader().getParent();
        String configParent = (String) configuration.get(Constants.FRAMEWORK_BUNDLE_PARENT);
        if (Constants.FRAMEWORK_BUNDLE_PARENT_APP.equals(configParent))
            // $NON-NLS-1$
            assertTrue("Wrong parent", parentCL == ClassLoader.getSystemClassLoader());
        else if (Constants.FRAMEWORK_BUNDLE_PARENT_EXT.equals(configParent))
            // $NON-NLS-1$
            assertTrue("Wrong parent", parentCL == ClassLoader.getSystemClassLoader().getParent());
        else if (Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK.equals(configParent))
            // $NON-NLS-1$
            assertTrue("Wrong parent", parentCL == equinox.getClass().getClassLoader());
    } catch (ClassNotFoundException e) {
        // $NON-NLS-1$
        fail("failed to load class", e);
    }
    try {
        equinox.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected erorr stopping framework", e);
    }
    FrameworkEvent stopEvent = null;
    try {
        stopEvent = equinox.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertNotNull("Stop event is null", stopEvent);
    // $NON-NLS-1$
    assertEquals("Wrong stopEvent", FrameworkEvent.STOPPED, stopEvent.getType());
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) URLClassLoader(java.net.URLClassLoader) WovenClass(org.osgi.framework.hooks.weaving.WovenClass) BundleException(org.osgi.framework.BundleException)

Example 53 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testBug352275.

public void testBug352275() {
    // simple test to create an embedded framework
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "");
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
        equinox.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start the framework", e);
    }
    try {
        equinox.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected erorr stopping framework", e);
    }
    try {
        equinox.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BundleException(org.osgi.framework.BundleException) File(java.io.File)

Example 54 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testNullConfigurationValue.

public void testNullConfigurationValue() throws BundleException {
    System.setProperty(nullTest, "system");
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put(nullTest, null);
    Equinox equinox = new Equinox(configuration);
    equinox.start();
    String nullValue = equinox.getBundleContext().getProperty(nullTest);
    assertNull(nullTest + " is not null: " + nullValue, nullValue);
    String systemNullValue = System.getProperty(nullTest);
    assertEquals("Wrong system null value.", "system", systemNullValue);
    equinox.stop();
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) File(java.io.File)

Example 55 with Equinox

use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testSystemBundle14.

public void testSystemBundle14() {
    // Test startlevel property
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle14");
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    // $NON-NLS-1$
    configuration.put(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, "10");
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
        equinox.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start the framework", e);
    }
    StartLevel st = (StartLevel) equinox.getBundleContext().getService(equinox.getBundleContext().getServiceReference(StartLevel.class.getName()));
    // $NON-NLS-1$
    assertNotNull("StartLevel service is null", st);
    // $NON-NLS-1$
    assertEquals("Unexpected start level", 10, st.getStartLevel());
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
    try {
        equinox.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected erorr stopping framework", e);
    }
    FrameworkEvent stopEvent = null;
    try {
        stopEvent = equinox.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertNotNull("Stop event is null", stopEvent);
    // $NON-NLS-1$
    assertEquals("Wrong stopEvent", FrameworkEvent.STOPPED, stopEvent.getType());
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FrameworkEvent(org.osgi.framework.FrameworkEvent) BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) FrameworkStartLevel(org.osgi.framework.startlevel.FrameworkStartLevel) StartLevel(org.osgi.service.startlevel.StartLevel) BundleException(org.osgi.framework.BundleException) File(java.io.File)

Aggregations

Equinox (org.eclipse.osgi.launch.Equinox)105 File (java.io.File)88 HashMap (java.util.HashMap)61 LinkedHashMap (java.util.LinkedHashMap)58 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)58 BundleException (org.osgi.framework.BundleException)52 BundleContext (org.osgi.framework.BundleContext)51 Bundle (org.osgi.framework.Bundle)43 IOException (java.io.IOException)18 FileNotFoundException (java.io.FileNotFoundException)11 URL (java.net.URL)10 Location (org.eclipse.osgi.service.datalocation.Location)10 Properties (java.util.Properties)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 FrameworkEvent (org.osgi.framework.FrameworkEvent)8 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)8 BundleWiring (org.osgi.framework.wiring.BundleWiring)8 ArrayList (java.util.ArrayList)7 ExecutionException (java.util.concurrent.ExecutionException)6 FileOutputStream (java.io.FileOutputStream)5