Search in sources :

Example 61 with Equinox

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

the class SystemBundleTests method testLogOrderMultipleListeners.

public void testLogOrderMultipleListeners() throws InterruptedException {
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map configuration = new HashMap();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = null;
    try {
        equinox = new Equinox(configuration);
        equinox.start();
        doLoggingOnMultipleListeners(equinox);
        equinox.stop();
        equinox.waitForStop(1000);
        equinox.start();
        doLoggingOnMultipleListeners(equinox);
    } catch (BundleException e) {
        fail("Failed init", e);
    } finally {
        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)

Example 62 with Equinox

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

the class SystemBundleTests method testBug405919.

public void testBug405919() throws Exception {
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    config.mkdirs();
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put("osgi.framework", "boo");
    // Initialize and start a framework specifying an invalid osgi.framework configuration value.
    Equinox equinox = null;
    try {
        equinox = new Equinox(configuration);
        equinox.start();
    } catch (NullPointerException e) {
        fail("failed to accept an invalid value for osgi.framework", e);
    }
    try {
        // Make sure the framework can install and start a bundle.
        BundleContext systemContext = equinox.getBundleContext();
        try {
            Bundle tb1 = systemContext.installBundle(installer.getBundleLocation("test.bug375784"));
            tb1.start();
        } catch (BundleException e) {
            fail("failed to install and start test bundle", e);
        }
        // Check the capabilities and requirements of the system bundle.
        BundleRevision inner = systemContext.getBundle().adapt(BundleRevision.class);
        BundleRevision outer = getContext().getBundle(0).adapt(BundleRevision.class);
        // Capabilities.
        List<Capability> innerCaps = inner.getCapabilities(null);
        List<Capability> outerCaps = outer.getCapabilities(null);
        assertEquals("Number of capabilities differ", outerCaps.size(), innerCaps.size());
        for (int i = 0; i < innerCaps.size(); i++) {
            Capability innerCap = innerCaps.get(i);
            Capability outerCap = innerCaps.get(i);
            assertEquals("Capability namespaces differ: " + outerCap.getNamespace(), outerCap.getNamespace(), innerCap.getNamespace());
            String namespace = outerCap.getNamespace();
            if (NativeNamespace.NATIVE_NAMESPACE.equals(namespace) || "eclipse.platform".equals(namespace)) {
                // Ignore these because they are known to differ.
                continue;
            }
            assertEquals("Capability attributes differ: " + outerCap.getNamespace(), outerCap.getAttributes(), innerCap.getAttributes());
            assertEquals("Capability directives differ: " + outerCap.getNamespace(), outerCap.getDirectives(), innerCap.getDirectives());
        }
        // Requirements.
        List<Requirement> innerReqs = inner.getRequirements(null);
        List<Requirement> outerReqs = outer.getRequirements(null);
        assertEquals("Number of requirements differ", outerReqs.size(), innerReqs.size());
        for (int i = 0; i < innerReqs.size(); i++) {
            Requirement innerReq = innerReqs.get(i);
            Requirement outerReq = innerReqs.get(i);
            assertEquals("Requirement namespaces differ: " + outerReq.getNamespace(), outerReq.getNamespace(), innerReq.getNamespace());
            assertEquals("Requirement attributes differ: " + outerReq.getNamespace(), outerReq.getAttributes(), innerReq.getAttributes());
            assertEquals("Requirement directives differ: " + outerReq.getNamespace(), outerReq.getDirectives(), innerReq.getDirectives());
        }
    } finally {
        equinox.stop();
        equinox.waitForStop(5000);
    }
}
Also used : BundleCapability(org.osgi.framework.wiring.BundleCapability) Capability(org.osgi.resource.Capability) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Requirement(org.osgi.resource.Requirement) Equinox(org.eclipse.osgi.launch.Equinox) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 63 with Equinox

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

the class SystemBundleTests method testSystemBundle07.

public void testSystemBundle07() {
    // test init twice
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle07_01");
    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);
    }
    try {
        equinox.init();
    } catch (Exception e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", 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());
    BundleContext systemContext = equinox.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("SystemBundle context is null", systemContext);
    try {
        equinox.init();
    } catch (Exception e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    ServiceReference[] refs = null;
    try {
        // $NON-NLS-1$
        refs = systemContext.getServiceReferences(Location.class.getName(), "(type=osgi.configuration.area)");
    } catch (InvalidSyntaxException e) {
        // $NON-NLS-1$
        fail("Unexpected syntax error", e);
    }
    // $NON-NLS-1$
    assertNotNull("Configuration Location refs is null", refs);
    // $NON-NLS-1$
    assertEquals("config refs length is wrong", 1, refs.length);
    Location configLocation = (Location) systemContext.getService(refs[0]);
    URL configURL = configLocation.getURL();
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue("incorrect configuration location", configURL.toExternalForm().endsWith("testSystemBundle07_01/"));
    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) 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) URL(java.net.URL) ServiceReference(org.osgi.framework.ServiceReference) Equinox(org.eclipse.osgi.launch.Equinox) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Location(org.eclipse.osgi.service.datalocation.Location)

Example 64 with Equinox

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

the class SystemBundleTests method doTestBug351519Refresh.

private void doTestBug351519Refresh(Boolean refreshDuplicates) {
    // Create a framework with equinox.refresh.duplicate.bsn=false configuration
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    if (refreshDuplicates != null) {
        configuration.put("equinox.refresh.duplicate.bsn", refreshDuplicates.toString());
    } else {
        // we default to false now
        refreshDuplicates = Boolean.FALSE;
    }
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    BundleContext systemContext = equinox.getBundleContext();
    systemContext.registerService(ResolverHookFactory.class, new ResolverHookFactory() {

        public ResolverHook begin(Collection triggers) {
            return new ResolverHook() {

                public void filterResolvable(Collection candidates) {
                // nothing
                }

                public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
                    // resolve all singletons
                    collisionCandidates.clear();
                }

                public void filterMatches(BundleRequirement requirement, Collection candidates) {
                // nothing
                }

                public void end() {
                // nothing
                }
            };
        }
    }, null);
    BundleInstaller testBundleInstaller = null;
    BundleInstaller testBundleResolver = null;
    try {
        testBundleResolver = new BundleInstaller(OSGiTestsActivator.TEST_FILES_ROOT + "wiringTests/bundles", systemContext);
        testBundleInstaller = new BundleInstaller(OSGiTestsActivator.TEST_FILES_ROOT + "wiringTests/bundles", getContext());
    } catch (InvalidSyntaxException e) {
        fail("Failed to create installers.", e);
    }
    // $NON-NLS-1$
    assertNotNull("System context is null", systemContext);
    // try installing a bundle before starting
    Bundle tb1v1 = null, tb1v2 = null;
    try {
        // $NON-NLS-1$
        tb1v1 = systemContext.installBundle(testBundleInstaller.getBundleLocation("singleton.tb1v1"));
        // $NON-NLS-1$
        tb1v2 = systemContext.installBundle(testBundleInstaller.getBundleLocation("singleton.tb1v2"));
    } catch (BundleException e1) {
        // $NON-NLS-1$
        fail("failed to install a bundle", e1);
    }
    assertTrue("Could not resolve test bundles", testBundleResolver.resolveBundles(new Bundle[] { tb1v1, tb1v2 }));
    Bundle[] refreshed = testBundleResolver.refreshPackages(new Bundle[] { tb1v1 });
    if (refreshDuplicates) {
        List refreshedList = Arrays.asList(refreshed);
        assertEquals("Wrong number of refreshed bundles", 2, refreshed.length);
        assertTrue("Refreshed bundles does not include v1", refreshedList.contains(tb1v1));
        assertTrue("Refreshed bundles does not include v2", refreshedList.contains(tb1v2));
    } else {
        assertEquals("Wrong number of refreshed bundles", 1, refreshed.length);
        assertEquals("Refreshed bundles does not include v1", refreshed[0], tb1v1);
    }
    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 : ResolverHookFactory(org.osgi.framework.hooks.resolver.ResolverHookFactory) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) Bundle(org.osgi.framework.Bundle) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Equinox(org.eclipse.osgi.launch.Equinox) Collection(java.util.Collection) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BundleException(org.osgi.framework.BundleException) BundleCapability(org.osgi.framework.wiring.BundleCapability) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 65 with Equinox

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

the class SystemBundleTests method testBug412228.

public void testBug412228() 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());
    Equinox equinox = new Equinox(configuration);
    equinox.init();
    BundleContext systemContext = equinox.getBundleContext();
    Bundle b = systemContext.installBundle(installer.getBundleLocation("test.bug412228"));
    b.start();
    equinox.start();
    long startTime = System.currentTimeMillis();
    equinox.stop();
    try {
        equinox.waitForStop(500);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        fail("Unexpected interruption.", e);
    }
    long stopTime = System.currentTimeMillis() - startTime;
    if (stopTime > 2000) {
        fail("waitForStop time took too long: " + stopTime);
    }
}
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)

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