Search in sources :

Example 66 with Equinox

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

the class SystemBundleTests method testUUID.

public void testUUID() {
    // $NON-NLS-1$
    File config1 = OSGiTestsActivator.getContext().getDataFile(getName() + "_1");
    Map configuration1 = new HashMap();
    configuration1.put(Constants.FRAMEWORK_STORAGE, config1.getAbsolutePath());
    Equinox equinox1 = new Equinox(configuration1);
    try {
        equinox1.init();
    } catch (BundleException e) {
        fail("Failed init", e);
    }
    String uuid1_1 = equinox1.getBundleContext().getProperty(Constants.FRAMEWORK_UUID);
    verifyUUID(uuid1_1);
    // $NON-NLS-1$
    File config2 = OSGiTestsActivator.getContext().getDataFile(getName() + "_2");
    Map configuration2 = new HashMap();
    configuration2.put(Constants.FRAMEWORK_STORAGE, config2.getAbsolutePath());
    Equinox equinox2 = new Equinox(configuration1);
    try {
        equinox2.init();
    } catch (BundleException e) {
        fail("Failed init", e);
    }
    String uuid2_1 = equinox2.getBundleContext().getProperty(Constants.FRAMEWORK_UUID);
    verifyUUID(uuid2_1);
    assertFalse("UUIDs are the same: " + uuid1_1, uuid1_1.equals(uuid2_1));
    try {
        equinox1.stop();
        equinox2.stop();
        equinox1.waitForStop(1000);
        equinox2.waitForStop(1000);
        equinox1.init();
        equinox2.init();
    } catch (BundleException e) {
        fail("Failed to re-init frameworks.", e);
    } catch (InterruptedException e) {
        fail("Failed to stop frameworks.", e);
    }
    String uuid1_2 = equinox1.getBundleContext().getProperty(Constants.FRAMEWORK_UUID);
    verifyUUID(uuid1_2);
    String uuid2_2 = equinox2.getBundleContext().getProperty(Constants.FRAMEWORK_UUID);
    verifyUUID(uuid2_2);
    assertFalse("UUIDs are the same: " + uuid1_1, uuid1_1.equals(uuid1_2));
    assertFalse("UUIDs are the same: " + uuid1_2, uuid1_2.equals(uuid2_2));
    assertFalse("UUIDs are the same: " + uuid2_1, uuid2_1.equals(uuid2_2));
    try {
        equinox1.stop();
        equinox2.stop();
        equinox1.waitForStop(1000);
        equinox2.waitForStop(1000);
    } catch (BundleException e) {
        fail("Failed to re-init frameworks.", e);
    } catch (InterruptedException e) {
        fail("Failed to stop frameworks.", 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 67 with Equinox

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

the class SystemBundleTests method testBug304213.

public void testBug304213() {
    // 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);
    }
    try {
        // $NON-NLS-1$
        systemContext.installBundle("reference:file:///" + bundleFile.getAbsolutePath());
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected install error", e);
    }
    // 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);
    }
    try {
        equinox.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start the framework", e);
    }
    // remove manifest for testing
    new File(bundleFile, "META-INF/MANIFEST.MF").delete();
    systemContext = equinox.getBundleContext();
    Bundle[] bundles = systemContext.getBundles();
    // get the headers from each bundle
    try {
        for (int i = 0; i < bundles.length; i++) {
            // $NON-NLS-1$
            bundles[i].getHeaders();
        }
    } catch (Throwable t) {
        // An exception used to get thrown here when we tried to close
        // the least used bundle file
        fail("Failed to get bundle entries", t);
    }
    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) IOException(java.io.IOException) Equinox(org.eclipse.osgi.launch.Equinox) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 68 with Equinox

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

the class SystemBundleTests method testExtraSystemBundleHeaders.

public void testExtraSystemBundleHeaders() throws BundleException, InterruptedException {
    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(Constants.FRAMEWORK_SYSTEMCAPABILITIES, "osgi.ee; osgi.ee=JavaSE; version:Version=1.7, something.system");
    configuration.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "something.system");
    configuration.put(Constants.FRAMEWORK_SYSTEMCAPABILITIES_EXTRA, "something.extra");
    configuration.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "something.extra");
    Equinox equinox = new Equinox(configuration);
    equinox.start();
    Dictionary<String, String> headers = equinox.getHeaders();
    String provideCapability = headers.get(Constants.PROVIDE_CAPABILITY);
    String exportPackage = headers.get(Constants.EXPORT_PACKAGE);
    assertTrue("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.system"));
    assertTrue("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.system"));
    assertTrue("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.extra"));
    assertTrue("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.extra"));
    equinox.stop();
    equinox.waitForStop(5000);
    configuration.put(EquinoxConfiguration.PROP_SYSTEM_PROVIDE_HEADER, EquinoxConfiguration.SYSTEM_PROVIDE_HEADER_ORIGINAL);
    equinox = new Equinox(configuration);
    equinox.start();
    headers = equinox.getHeaders();
    provideCapability = headers.get(Constants.PROVIDE_CAPABILITY);
    exportPackage = headers.get(Constants.EXPORT_PACKAGE);
    assertFalse("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.system"));
    assertFalse("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.system"));
    assertFalse("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.extra"));
    assertFalse("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.extra"));
    equinox.stop();
    equinox.waitForStop(5000);
    configuration.put(EquinoxConfiguration.PROP_SYSTEM_PROVIDE_HEADER, EquinoxConfiguration.SYSTEM_PROVIDE_HEADER_SYSTEM);
    equinox = new Equinox(configuration);
    equinox.start();
    headers = equinox.getHeaders();
    provideCapability = headers.get(Constants.PROVIDE_CAPABILITY);
    exportPackage = headers.get(Constants.EXPORT_PACKAGE);
    assertTrue("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.system"));
    assertTrue("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.system"));
    assertFalse("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.extra"));
    assertFalse("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.extra"));
    equinox.stop();
    equinox.waitForStop(5000);
    configuration.put(EquinoxConfiguration.PROP_SYSTEM_PROVIDE_HEADER, EquinoxConfiguration.SYSTEM_PROVIDE_HEADER_SYSTEM_EXTRA);
    equinox = new Equinox(configuration);
    equinox.start();
    headers = equinox.getHeaders();
    provideCapability = headers.get(Constants.PROVIDE_CAPABILITY);
    exportPackage = headers.get(Constants.EXPORT_PACKAGE);
    assertTrue("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.system"));
    assertTrue("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.system"));
    assertTrue("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.extra"));
    assertTrue("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.extra"));
    equinox.stop();
    equinox.waitForStop(5000);
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) File(java.io.File)

Example 69 with Equinox

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

the class SystemBundleTests method testSystemBundle13.

public void testSystemBundle13() {
    // create/install/start/stop clean test
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle13");
    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());
    // initialize the framework again to the same configuration
    configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    equinox = new Equinox(configuration);
    try {
        equinox.init();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    substitutesA = equinox.getBundleContext().getBundle(1);
    // make sure the bundle is there
    // $NON-NLS-1$
    assertNotNull("missing installed bundle", substitutesA);
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("Unexpected symbolic name", "substitutes.a", substitutesA.getSymbolicName());
    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());
    // initialize the framework again to the same configuration but use clean option
    configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    equinox = new Equinox(configuration);
    try {
        equinox.init();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception in init()", e);
    }
    substitutesA = equinox.getBundleContext().getBundle(1);
    // make sure the bundle is there
    // $NON-NLS-1$
    assertNull("Unexpected bundle is installed", substitutesA);
    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 70 with Equinox

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

the class SystemBundleTests method testLocalConfigReplaceSystemProperties.

public void testLocalConfigReplaceSystemProperties() 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.start();
    ServiceReference<EnvironmentInfo> envRef = equinox.getBundleContext().getServiceReference(EnvironmentInfo.class);
    EnvironmentInfo envInfo = equinox.getBundleContext().getService(envRef);
    // replace the system properties with a copy
    Properties copy = new Properties();
    copy.putAll(System.getProperties());
    System.setProperties(copy);
    // set a system prop for this test after replacement of the properties object
    String systemKey = getName() + ".system";
    System.setProperty(systemKey, getName());
    // make sure context properties reflect the new system test prop.
    // remember context properties are backed by system properties
    assertEquals("Wrong context value", getName(), equinox.getBundleContext().getProperty(systemKey));
    // also test EnvironmentInfo properties.
    // remember the getProperty method is backed by system properties
    assertEquals("Wrong context value", getName(), envInfo.getProperty(systemKey));
    // config options are not backed by system properties when framework is not using system properties for configuration
    assertNull("Wrong EquinoxConfiguration config value", ((EquinoxConfiguration) envInfo).getConfiguration(systemKey));
    // set environment info prop
    String envKey = getName() + ".env";
    envInfo.setProperty(envKey, getName());
    // make sure the system properties does NOT reflect the new test prop
    assertNull("Wrong system value", System.getProperty(envKey));
    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) Properties(java.util.Properties) File(java.io.File)

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