Search in sources :

Example 26 with Equinox

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

the class SystemBundleTests method testLazyTriggerOnLoadError.

public void testLazyTriggerOnLoadError() throws InterruptedException, BundleException {
    // create/start/stop/start/stop test
    // $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(EquinoxConfiguration.PROP_COMPATIBILITY_START_LAZY_ON_FAIL_CLASSLOAD, "true");
    Equinox equinox = new Equinox(configuration);
    equinox.start();
    BundleContext systemContext = equinox.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("System context is null", systemContext);
    // install a lazy activated bundle
    // $NON-NLS-1$
    Bundle b = systemContext.installBundle(installer.getBundleLocation("chain.test.d"));
    b.start(Bundle.START_ACTIVATION_POLICY);
    assertEquals("Wrong state of bundle.", Bundle.STARTING, b.getState());
    try {
        // trigger the start by loading non existing class
        b.loadClass("does.not.exist.Clazz");
        fail("Expected class load error");
    } catch (ClassNotFoundException e) {
    // expected
    }
    // should be active now
    assertEquals("Wrong state of bundle.", Bundle.ACTIVE, b.getState());
    // put the framework back to the RESOLVED state
    equinox.stop();
    equinox.waitForStop(10000);
    // revert back to default behavior
    configuration.remove(EquinoxConfiguration.PROP_COMPATIBILITY_START_LAZY_ON_FAIL_CLASSLOAD);
    equinox = new Equinox(configuration);
    equinox.start();
    b = equinox.getBundleContext().getBundle(b.getBundleId());
    assertEquals("Wrong state of bundle.", Bundle.STARTING, b.getState());
    try {
        // loading non-existing class should NOT trigger lazy activation now
        b.loadClass("does.not.exist.Clazz");
        fail("Expected class load error");
    } catch (ClassNotFoundException e) {
    // expected
    }
    // should still be in STARTING state.
    assertEquals("Wrong state of bundle.", Bundle.STARTING, b.getState());
    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) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 27 with Equinox

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

the class SystemBundleTests method testContextBootDelegation.

public void testContextBootDelegation() throws BundleException {
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    config.mkdirs();
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configuration);
    equinox.start();
    BundleContext systemContext = equinox.getBundleContext();
    try {
        Bundle b = systemContext.installBundle(installer.getBundleLocation("test.bug471551"));
        b.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected error", e);
    }
    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) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 28 with Equinox

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

the class SystemBundleTests method testBug258209_1.

public void testBug258209_1() throws BundleException {
    // create a framework to test thread context class loaders
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    ClassLoader current = Thread.currentThread().getContextClassLoader();
    Equinox equinox = new Equinox(configuration);
    equinox.init();
    Thread.currentThread().setContextClassLoader(current);
    BundleContext systemContext = equinox.getBundleContext();
    // $NON-NLS-1$
    Bundle testTCCL = systemContext.installBundle(installer.getBundleLocation("test.tccl"));
    equinox.adapt(FrameworkWiring.class).resolveBundles(Arrays.asList(testTCCL));
    try {
        testTCCL.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception starting bundle", e);
    }
    // $NON-NLS-1$
    assertEquals("Unexpected state", Bundle.RESOLVED, testTCCL.getState());
    // this will start the framework on the current thread; test that the correct tccl is used
    equinox.start();
    // $NON-NLS-1$
    assertEquals("Unexpected state", Bundle.ACTIVE, testTCCL.getState());
    // test that the correct tccl is used for framework update
    try {
        equinox.update();
        checkActive(testTCCL);
    } catch (Exception e) {
        // $NON-NLS-1$
        fail("Unexpected exception", e);
    }
    systemContext = equinox.getBundleContext();
    // $NON-NLS-1$
    assertEquals("Unexpected state", Bundle.ACTIVE, testTCCL.getState());
    // test that the correct tccl is used for refresh packages
    equinox.adapt(FrameworkWiring.class).refreshBundles(Arrays.asList(testTCCL));
    checkActive(testTCCL);
    // $NON-NLS-1$
    assertEquals("Unexpected state", Bundle.ACTIVE, testTCCL.getState());
    // use the tccl service to start the test bundle.
    ClassLoader serviceTCCL = null;
    try {
        // $NON-NLS-1$
        serviceTCCL = (ClassLoader) systemContext.getService(systemContext.getServiceReferences(ClassLoader.class.getName(), "(equinox.classloader.type=contextClassLoader)")[0]);
    } catch (InvalidSyntaxException e) {
        // $NON-NLS-1$
        fail("Unexpected", e);
    }
    current = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(serviceTCCL);
    try {
        testTCCL.stop();
        testTCCL.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unepected", e);
    } finally {
        Thread.currentThread().setContextClassLoader(current);
    }
    try {
        equinox.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected error stopping framework", e);
    }
    try {
        equinox.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) FileNotFoundException(java.io.FileNotFoundException) NoSuchElementException(java.util.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) Equinox(org.eclipse.osgi.launch.Equinox) URLClassLoader(java.net.URLClassLoader) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 29 with Equinox

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

the class SystemBundleTests method testSystemBundle02.

public void testSystemBundle02() {
    // create/start/stop/start/stop test
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle02");
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    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());
    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());
    try {
        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());
    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 30 with Equinox

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

the class SystemBundleTests method testWindowsAlias.

public void testWindowsAlias() {
    String origOS = System.getProperty("os.name");
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map configuration = new HashMap();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    System.setProperty("os.name", "Windows 5000");
    Equinox equinox = null;
    try {
        equinox = new Equinox(configuration);
        equinox.init();
        Assert.assertEquals("Wrong framework os name value", "win32", equinox.getBundleContext().getProperty(Constants.FRAMEWORK_OS_NAME));
    } catch (BundleException e) {
        fail("Failed init", e);
    } finally {
        System.setProperty("os.name", origOS);
        try {
            if (equinox != null) {
                equinox.stop();
                equinox.waitForStop(1000);
            }
        } catch (BundleException e) {
            fail("Failed to stop framework.", e);
        } catch (InterruptedException e) {
            fail("Failed to stop framework.", e);
        }
    }
}
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) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

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