Search in sources :

Example 41 with Equinox

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

the class CascadeConfigTests method testCascadeConfigDataArea.

public void testCascadeConfigDataArea() throws Exception {
    // First create a framework with the 'parent' configuration
    File configParent = OSGiTestsActivator.getContext().getDataFile(getName() + "_parent");
    Map<String, Object> parentMap = new HashMap<String, Object>();
    parentMap.put(Constants.FRAMEWORK_STORAGE, configParent.getAbsolutePath());
    Equinox equinox = new Equinox(parentMap);
    equinox.init();
    BundleContext systemContext = equinox.getBundleContext();
    Bundle b = systemContext.installBundle(installer.getBundleLocation("substitutes.a"));
    equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singletonList(b));
    equinox.stop();
    equinox.waitForStop(10000);
    // Now create a child framework and make sure bundle is there
    File configChild = OSGiTestsActivator.getContext().getDataFile(getName() + "_child");
    Map<String, Object> childMap = new HashMap<String, Object>();
    childMap.put(Constants.FRAMEWORK_STORAGE, configChild.getAbsolutePath());
    childMap.put("osgi.sharedConfiguration.area", configParent.getCanonicalPath());
    equinox = new Equinox(childMap);
    equinox.init();
    systemContext = equinox.getBundleContext();
    b = systemContext.getBundle(installer.getBundleLocation("substitutes.a"));
    assertNotNull("Missing bundle.", b);
    equinox.start();
    b.start();
    BundleContext test1Context = b.getBundleContext();
    // get the data file and make sure it is part of the child config area
    File dataFile = test1Context.getDataFile("test1");
    assertTrue(dataFile.getAbsolutePath().startsWith(configChild.getAbsolutePath()));
    equinox.stop();
    equinox.waitForStop(10000);
    // get parent again
    equinox = new Equinox(parentMap);
    equinox.start();
    systemContext = equinox.getBundleContext();
    b = systemContext.getBundle(installer.getBundleLocation("substitutes.a"));
    assertNotNull("Missing bundle.", b);
    // Should not be active since we persistently started the bundle in child only.
    assertEquals("Bundle is not resolved.", Bundle.RESOLVED, b.getState());
    b.start();
    test1Context = b.getBundleContext();
    // get the data file and make sure it is part of the parent config area
    dataFile = test1Context.getDataFile("test1");
    assertTrue(dataFile.getAbsolutePath().startsWith(configParent.getAbsolutePath()));
    equinox.stop();
    equinox.waitForStop(10000);
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) File(java.io.File)

Example 42 with Equinox

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

the class CascadeConfigTests method testCascadeConfigBundleInstall.

public void testCascadeConfigBundleInstall() throws Exception {
    // First create a framework with the 'parent' configuration
    File configParent = OSGiTestsActivator.getContext().getDataFile(getName() + "_parent");
    Map<String, Object> parentMap = new HashMap<String, Object>();
    parentMap.put(Constants.FRAMEWORK_STORAGE, configParent.getAbsolutePath());
    Equinox equinox = new Equinox(parentMap);
    equinox.init();
    BundleContext systemContext = equinox.getBundleContext();
    systemContext.installBundle(installer.getBundleLocation("test"));
    equinox.stop();
    equinox.waitForStop(10000);
    // Now create a child framework and make sure test1 bundle is there
    File configChild = OSGiTestsActivator.getContext().getDataFile(getName() + "_child");
    Map<String, Object> childMap = new HashMap<String, Object>();
    childMap.put(Constants.FRAMEWORK_STORAGE, configChild.getAbsolutePath());
    childMap.put("osgi.sharedConfiguration.area", configParent.getCanonicalPath());
    equinox = new Equinox(childMap);
    equinox.init();
    systemContext = equinox.getBundleContext();
    Bundle test1 = systemContext.getBundle(installer.getBundleLocation("test"));
    assertNotNull("Missing bundle.", test1);
    systemContext.installBundle(installer.getBundleLocation("test2"));
    equinox.stop();
    equinox.waitForStop(10000);
    // reuse the same configuration and make sure both bundles are there
    equinox = new Equinox(childMap);
    equinox.init();
    systemContext = equinox.getBundleContext();
    test1 = systemContext.getBundle(installer.getBundleLocation("test"));
    assertNotNull("Missing bundle.", test1);
    Bundle test2 = systemContext.getBundle(installer.getBundleLocation("test2"));
    assertNotNull("Missing bundle.", test2);
    equinox.stop();
    equinox.waitForStop(10000);
    // restart using the parent and make sure only the test1 bundle is there
    equinox = new Equinox(parentMap);
    equinox.init();
    systemContext = equinox.getBundleContext();
    test1 = systemContext.getBundle(installer.getBundleLocation("test"));
    assertNotNull("Missing bundle.", test1);
    test2 = systemContext.getBundle(installer.getBundleLocation("test2"));
    assertNull("Unexpected bundle.", test2);
    equinox.stop();
    equinox.waitForStop(10000);
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) File(java.io.File)

Example 43 with Equinox

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

the class LogReaderServiceTest method testLogHistory2.

public void testLogHistory2() throws BundleException {
    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.start();
    try {
        LogService testLog = equinox.getBundleContext().getService(equinox.getBundleContext().getServiceReference(LogService.class));
        LogReaderService testReader = equinox.getBundleContext().getService(equinox.getBundleContext().getServiceReference(LogReaderService.class));
        assertEquals("Expecting no logs.", 0, countLogEntries(testReader.getLog(), 0));
        // log 9 things
        for (int i = 0; i < 9; i++) {
            testLog.log(LogService.LOG_WARNING, String.valueOf(i));
        }
        assertEquals("Wrong number of logs.", 0, countLogEntries(testReader.getLog(), 0));
    } finally {
        try {
            equinox.stop();
        } catch (BundleException e) {
        // ignore
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) File(java.io.File)

Example 44 with Equinox

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

the class SystemBundleTests method testSystemBundle09.

public void testSystemBundle09() {
    // test FrameworkUtil.createFilter
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle09");
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configuration);
    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 testFilterA = null;
    try {
        // $NON-NLS-1$
        testFilterA = equinox.getBundleContext().installBundle(installer.getBundleLocation("test.filter.a"));
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception installing", e);
    }
    try {
        testFilterA.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception starting test bundle", 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) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) File(java.io.File)

Example 45 with Equinox

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

the class SystemBundleTests method testOverrideEquinoxConfigAreaProp.

public void testOverrideEquinoxConfigAreaProp() {
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map configuration = new HashMap();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put(EquinoxLocations.PROP_CONFIG_AREA, config.getAbsolutePath() + "-override");
    configuration.put(EquinoxConfiguration.PROP_LOG_HISTORY_MAX, "10");
    Equinox equinox = null;
    try {
        equinox = new Equinox(configuration);
        equinox.init();
        BundleContext bc = equinox.getBundleContext();
        LogReaderService logReader = bc.getService(bc.getServiceReference(LogReaderService.class));
        Enumeration<LogEntry> logs = logReader.getLog();
        assertTrue("No logs found.", logs.hasMoreElements());
        LogEntry entry = logs.nextElement();
        assertEquals("Wrong log level.", LogLevel.WARN, entry.getLogLevel());
        assertTrue("Wrong message found: " + entry.getMessage(), entry.getMessage().contains(EquinoxLocations.PROP_CONFIG_AREA));
    } 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) LogReaderService(org.osgi.service.log.LogReaderService) ExtendedLogReaderService(org.eclipse.equinox.log.ExtendedLogReaderService) 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) LogEntry(org.osgi.service.log.LogEntry) 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