Search in sources :

Example 1 with Handler

use of org.eclipse.osgi.storage.url.reference.Handler in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testInitialBundleUpdate.

public void testInitialBundleUpdate() throws IOException {
    // test installing bundle with empty manifest
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    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 {
        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());
    File bundleFile = null;
    try {
        File baseDir = new File(config, "bundles");
        baseDir.mkdirs();
        bundleFile = createBundle(baseDir, getName(), true, true);
    } catch (IOException e) {
        fail("Unexpected error creating bundles.", e);
    }
    Bundle testBundle = null;
    try {
        String location = "reference:file:///" + bundleFile.getAbsolutePath();
        URL url = new URL(null, location, new Handler(systemContext.getProperty(EquinoxLocations.PROP_INSTALL_AREA)));
        // $NON-NLS-1$
        testBundle = systemContext.installBundle("initial@" + location, url.openStream());
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected install error", e);
    }
    try {
        testBundle.update();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected update error", 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 : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) Handler(org.eclipse.osgi.storage.url.reference.Handler) IOException(java.io.IOException) URL(java.net.URL) Equinox(org.eclipse.osgi.launch.Equinox) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Equinox (org.eclipse.osgi.launch.Equinox)1 Handler (org.eclipse.osgi.storage.url.reference.Handler)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1 BundleException (org.osgi.framework.BundleException)1