Search in sources :

Example 56 with Equinox

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

the class SystemBundleTests method testSystemBundle04.

public void testSystemBundle04() {
    // create/start/stop/start/stop test
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle04");
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    // should be in the STARTING state
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
    BundleContext systemContext = equinox.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("System context is null", systemContext);
    // try installing a bundle before starting
    Bundle substitutesA = null;
    try {
        // $NON-NLS-1$
        substitutesA = systemContext.installBundle(installer.getBundleLocation("substitutes.a"));
    } catch (BundleException e1) {
        // $NON-NLS-1$
        fail("failed to install a bundle", e1);
    }
    try {
        substitutesA.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected bundle exception", e);
    }
    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());
    // $NON-NLS-1$
    assertEquals("Wrong state for installed bundle", Bundle.ACTIVE, substitutesA.getState());
    // put the framework back to the RESOLVED state
    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) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 57 with Equinox

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

the class SystemBundleTests method testSystemBundle05_2.

public void testSystemBundle05_2() {
    // create/install/start/stop/start/stop test
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle05_2");
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    // should be in the STARTING state
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
    BundleContext systemContext = equinox.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("System context is null", systemContext);
    // try installing a bundle before starting
    Bundle substitutesA = null;
    try {
        // $NON-NLS-1$
        substitutesA = systemContext.installBundle(installer.getBundleLocation("substitutes.a"));
    } catch (BundleException e1) {
        // $NON-NLS-1$
        fail("failed to install a bundle", e1);
    }
    // start framework first
    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());
    // $NON-NLS-1$
    assertEquals("Wrong state for installed bundle", Bundle.INSTALLED, substitutesA.getState());
    try {
        substitutesA.start();
    } catch (BundleException e1) {
        // $NON-NLS-1$
        fail("Failed to start a bundle", e1);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for active bundle", Bundle.ACTIVE, substitutesA.getState());
    // put the framework back to the RESOLVED state
    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());
    Bundle substitutesA2 = null;
    try {
        // $NON-NLS-1$
        substitutesA2 = equinox.getBundleContext().installBundle(installer.getBundleLocation("substitutes.a"));
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception installing", e);
    }
    // assert the same bundle ID
    // $NON-NLS-1$
    assertEquals("Bundle ids are not the same", substitutesA.getBundleId(), substitutesA2.getBundleId());
    // no need to start the bundle again it should have been persistently started
    // $NON-NLS-1$
    assertEquals("Wrong state for active bundle", Bundle.ACTIVE, substitutesA2.getState());
    // put the framework back to the RESOLVED state
    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) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 58 with Equinox

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

the class SystemBundleTests method testURLMultiplexing01.

public void testURLMultiplexing01() throws BundleException {
    // create multiple instances of Equinox to test
    File config1 = OSGiTestsActivator.getContext().getDataFile(getName() + "_1");
    Map<String, Object> configuration1 = new HashMap<String, Object>();
    configuration1.put(Constants.FRAMEWORK_STORAGE, config1.getAbsolutePath());
    Equinox equinox1 = new Equinox(configuration1);
    try {
        equinox1.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    // should be in the STARTING state
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox1.getState());
    // $NON-NLS-1$
    File config2 = OSGiTestsActivator.getContext().getDataFile(getName() + "_2");
    Map<String, Object> configuration2 = new HashMap<String, Object>();
    configuration2.put(Constants.FRAMEWORK_STORAGE, config2.getAbsolutePath());
    Equinox equinox2 = new Equinox(configuration2);
    try {
        equinox2.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    // should be in the STARTING state
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox2.getState());
    BundleContext systemContext1 = equinox1.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("System context is null", systemContext1);
    BundleContext systemContext2 = equinox2.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("System context is null", systemContext2);
    assertNotSame(systemContext1, systemContext2);
    // register a protocol hander in the "root" framework
    Dictionary props = new Hashtable();
    props.put(URLConstants.URL_HANDLER_PROTOCOL, getName().toLowerCase());
    ServiceRegistration handlerReg = OSGiTestsActivator.getContext().registerService(URLStreamHandlerService.class, new TestHandler(), props);
    try {
        URL baseTestUrl = new URL(getName().toLowerCase(), "", "/test/url");
        System.getProperties().put("test.url", baseTestUrl);
        System.setProperty("test.url.spec", baseTestUrl.toExternalForm());
    } catch (MalformedURLException e) {
        fail("Unexpected url exception.", e);
    }
    Bundle geturlBundle = systemContext1.installBundle(installer.getBundleLocation("geturl"));
    geturlBundle.start();
    PrivilegedAction geturlAction = systemContext1.getService(systemContext1.getServiceReference(PrivilegedAction.class));
    try {
        geturlAction.run();
    } catch (Exception e) {
        fail("Unexpected exception", e);
    }
    // put the framework 1 back to the RESOLVED state
    try {
        equinox1.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected error stopping framework", e);
    }
    try {
        equinox1.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox1.getState());
    // put the framework 2 back to the RESOLVED state
    try {
        equinox2.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected erorr stopping framework", e);
    }
    try {
        equinox2.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox2.getState());
    handlerReg.unregister();
    System.getProperties().remove("test.url");
}
Also used : Dictionary(java.util.Dictionary) MalformedURLException(java.net.MalformedURLException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) Bundle(org.osgi.framework.Bundle) URL(java.net.URL) 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) PrivilegedAction(java.security.PrivilegedAction) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 59 with Equinox

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

the class SystemBundleTests method testNullConfigurationValueSystemProperties.

public void testNullConfigurationValueSystemProperties() 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("osgi.framework.useSystemProperties", "true");
    configuration.put(nullTest, null);
    Equinox equinox = new Equinox(configuration);
    equinox.start();
    String nullValue = equinox.getBundleContext().getProperty(nullTest);
    assertNull(nullTest + " is not null: " + nullValue, nullValue);
    assertNull("Did not get null system value.", System.getProperties().get(nullTest));
    // also test EnvironmentInfo effects on system properties
    ServiceReference<EnvironmentInfo> envRef = equinox.getBundleContext().getServiceReference(EnvironmentInfo.class);
    EnvironmentInfo envInfo = equinox.getBundleContext().getService(envRef);
    envInfo.setProperty(getName(), getName());
    assertEquals("Got wrong value from system properties.", System.getProperty(getName()), getName());
    envInfo.setProperty(getName(), null);
    assertNull("Did not get null system value.", System.getProperties().get(getName()));
    equinox.stop();
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) EnvironmentInfo(org.eclipse.osgi.service.environment.EnvironmentInfo) File(java.io.File)

Example 60 with Equinox

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

the class SystemBundleTests method testSystemBundle06.

public void testSystemBundle06() {
    // create multiple instances test
    // $NON-NLS-1$
    File config1 = OSGiTestsActivator.getContext().getDataFile("testSystemBundle06_1");
    Map<String, Object> configuration1 = new HashMap<String, Object>();
    configuration1.put(Constants.FRAMEWORK_STORAGE, config1.getAbsolutePath());
    Equinox equinox1 = new Equinox(configuration1);
    try {
        equinox1.init();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    // should be in the STARTING state
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox1.getState());
    // $NON-NLS-1$
    File config2 = OSGiTestsActivator.getContext().getDataFile("testSystemBundle06_2");
    Map<String, Object> configuration2 = new HashMap<String, Object>();
    configuration2.put(Constants.FRAMEWORK_STORAGE, config2.getAbsolutePath());
    Equinox equinox2 = new Equinox(configuration2);
    try {
        equinox2.init();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    // should be in the STARTING state
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox2.getState());
    BundleContext systemContext1 = equinox1.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("System context is null", systemContext1);
    BundleContext systemContext2 = equinox2.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("System context is null", systemContext2);
    assertNotSame(systemContext1, systemContext2);
    // start framework 1 first
    try {
        equinox1.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start the framework", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox1.getState());
    // start framework 2 first
    try {
        equinox2.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start the framework", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox2.getState());
    // put the framework 1 back to the RESOLVED state
    try {
        equinox1.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected erorr stopping framework", e);
    }
    try {
        equinox1.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox1.getState());
    // put the framework 2 back to the RESOLVED state
    try {
        equinox2.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected erorr stopping framework", e);
    }
    try {
        equinox2.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox2.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) BundleContext(org.osgi.framework.BundleContext)

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