Search in sources :

Example 91 with Equinox

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

the class DiscardBundleTests method doTest.

private void doTest(Map<String, ?> configuration, boolean discard, File bundleFile) throws Exception {
    Equinox equinox = new Equinox(configuration);
    initAndStart(equinox);
    try {
        String location = REFERENCE_PROTOCOL + bundleFile.toURI();
        equinox.getBundleContext().installBundle(location);
        try {
            equinox = restart(equinox, configuration);
            assertNotDiscarded(location, equinox);
            // Attempting to touch the file with equinox still running
            // will sometimes result in failure presumably due to a locked
            // file.
            stop(equinox);
            touchFile(bundleFile);
            equinox = restart(equinox, configuration);
            if (discard)
                assertDiscarded(location, equinox);
            else
                assertNotDiscarded(location, equinox);
        } finally {
            try {
                equinox.getBundleContext().getBundle(location).uninstall();
            } catch (Exception e) {
            // Ignore
            }
        }
    } finally {
        stopQuietly(equinox);
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox)

Example 92 with Equinox

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

the class DiscardBundleTests method restart.

private Equinox restart(Equinox equinox, Map<String, ?> configuration) throws BundleException, InterruptedException {
    stop(equinox);
    equinox = new Equinox(configuration);
    initAndStart(equinox);
    return equinox;
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox)

Example 93 with Equinox

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

the class DiscardBundleTests method doTestDiscardDeletedBundleFile.

private void doTestDiscardDeletedBundleFile(File bundleFile) throws Exception {
    Map<String, Object> configuration = createConfiguration();
    Equinox equinox = new Equinox(configuration);
    initAndStart(equinox);
    try {
        String location = REFERENCE_PROTOCOL + bundleFile.toURI();
        equinox.getBundleContext().installBundle(location);
        equinox = restart(equinox, configuration);
        assertNotDiscarded(location, equinox);
        // Attempting to delete the file with equinox still running
        // will sometimes result in failure presumably due to a locked
        // file.
        stop(equinox);
        rm(bundleFile);
        equinox = restart(equinox, configuration);
        assertDiscarded(location, equinox);
    } finally {
        stopQuietly(equinox);
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox)

Example 94 with Equinox

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

the class ImportJavaSEPackagesTests method doSystemPackages.

public void doSystemPackages(int rv, int expectedPackages) throws Exception {
    if (rv < 9) {
        System.setProperty("java.specification.version", "1." + rv);
    } else {
        System.setProperty("java.specification.version", Integer.toString(rv));
    }
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, String> headers = new HashMap<String, String>();
    headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    headers.put(Constants.BUNDLE_SYMBOLICNAME, getName());
    config.mkdirs();
    File bundle = SystemBundleTests.createBundle(config, getName(), headers);
    Equinox equinox = new Equinox(Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()));
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Dictionary<String, String> testHeaders = equinox.getHeaders();
        assertTrue(Constants.EXPORT_PACKAGE + " does not contain the java.* package", testHeaders.get(Constants.EXPORT_PACKAGE).contains(JAVA_LANG));
        assertTrue(Constants.EXPORT_PACKAGE + " does not contain the java.* package", testHeaders.get(Constants.EXPORT_PACKAGE).contains(JAVA_UTIL));
        List<BundleCapability> capabilities = equinox.adapt(BundleWiring.class).getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
        int count = 0;
        for (BundleCapability cap : capabilities) {
            if (cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE).toString().startsWith("java.")) {
                count++;
            }
        }
        assertEquals("Wrong number of java.* packages for version " + rv, expectedPackages, count);
        Bundle testBundle = systemContext.installBundle(bundle.toURI().toString());
        testBundle.start();
        String systemPackages = testBundle.getBundleContext().getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
        assertTrue("System packages should include java.* packages", systemPackages.contains(JAVA_LANG));
        assertTrue("System packages should include java.* packages", systemPackages.contains(JAVA_UTIL));
    } catch (BundleException e) {
        fail("Failed to test System packages");
    } finally {
        try {
            equinox.stop();
            equinox.waitForStop(10000);
        } catch (Exception e) {
        // do nothing
        }
    }
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleException(org.osgi.framework.BundleException) Equinox(org.eclipse.osgi.launch.Equinox) BundleException(org.osgi.framework.BundleException) BundleCapability(org.osgi.framework.wiring.BundleCapability) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 95 with Equinox

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

the class MultiReleaseJarTests method doTestMultiReleaseClassLoad.

private void doTestMultiReleaseClassLoad(int rv) throws Exception {
    if (rv < 9) {
        System.setProperty("java.specification.version", "1." + rv);
    } else {
        System.setProperty("java.specification.version", Integer.toString(rv));
    }
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Equinox equinox = new Equinox(Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()));
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle mrBundle = systemContext.installBundle(mrJarBundle.toURI().toString());
        mrBundle.start();
        assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.TestClassBase", mrBundle, false));
        assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.TestClass8", mrBundle, false));
        assertEquals("Wrong class.", CNFE, loadClass("multi.release.test.TestClassAdd8", mrBundle, true));
        assertEquals("Wrong class.", (rv >= 9) ? "BASE09" : "BASEXX", loadClass("multi.release.test.TestClass9", mrBundle, false));
        assertEquals("Wrong class.", (rv >= 9) ? "ADD09" : CNFE, loadClass("multi.release.test.TestClassAdd9", mrBundle, true));
        assertEquals("Wrong class.", (rv >= 10) ? "BASE10" : "BASEXX", loadClass("multi.release.test.TestClass10", mrBundle, false));
        assertEquals("Wrong class.", (rv >= 10) ? "ADD10" : CNFE, loadClass("multi.release.test.TestClassAdd10", mrBundle, true));
        assertEquals("Wrong class.", (rv >= 11) ? "BASE11" : "BASEXX", loadClass("multi.release.test.TestClass11", mrBundle, false));
        assertEquals("Wrong class.", (rv >= 11) ? "ADD11" : CNFE, loadClass("multi.release.test.TestClassAdd11", mrBundle, true));
        assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.sub.TestClassBase", mrBundle, false));
        assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.sub.TestClass8", mrBundle, false));
        assertEquals("Wrong class.", CNFE, loadClass("multi.release.test.TestClassAdd8", mrBundle, true));
        assertEquals("Wrong class.", (rv >= 9) ? "BASE09" : "BASEXX", loadClass("multi.release.test.sub.TestClass9", mrBundle, false));
        assertEquals("Wrong class.", (rv >= 9) ? "ADD09" : CNFE, loadClass("multi.release.test.sub.TestClassAdd9", mrBundle, true));
        assertEquals("Wrong class.", (rv >= 10) ? "BASE10" : "BASEXX", loadClass("multi.release.test.sub.TestClass10", mrBundle, false));
        assertEquals("Wrong class.", (rv >= 10) ? "ADD10" : CNFE, loadClass("multi.release.test.sub.TestClassAdd10", mrBundle, true));
        assertEquals("Wrong class.", (rv >= 11) ? "BASE11" : "BASEXX", loadClass("multi.release.test.sub.TestClass11", mrBundle, false));
        assertEquals("Wrong class.", (rv >= 11) ? "ADD11" : CNFE, loadClass("multi.release.test.sub.TestClassAdd11", mrBundle, true));
        assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.sub2.TestClassBase", mrBundle, false));
        assertEquals("Wrong class.", "BASEXX", loadClass("multi.release.test.sub2.TestClass8", mrBundle, false));
        assertEquals("Wrong class.", CNFE, loadClass("multi.release.test.TestClassAdd8", mrBundle, true));
        assertEquals("Wrong class.", (rv >= 9) ? "BASE09" : "BASEXX", loadClass("multi.release.test.sub2.TestClass9", mrBundle, false));
        assertEquals("Wrong class.", (rv >= 9) ? "ADD09" : CNFE, loadClass("multi.release.test.sub2.TestClassAdd9", mrBundle, true));
        assertEquals("Wrong class.", (rv >= 10) ? "BASE10" : "BASEXX", loadClass("multi.release.test.sub2.TestClass10", mrBundle, false));
        assertEquals("Wrong class.", (rv >= 10) ? "ADD10" : CNFE, loadClass("multi.release.test.sub2.TestClassAdd10", mrBundle, true));
        assertEquals("Wrong class.", (rv >= 11) ? "BASE11" : "BASEXX", loadClass("multi.release.test.sub2.TestClass11", mrBundle, false));
        assertEquals("Wrong class.", (rv >= 11) ? "ADD11" : CNFE, loadClass("multi.release.test.sub2.TestClassAdd11", mrBundle, true));
    } finally {
        try {
            equinox.stop();
            equinox.waitForStop(10000);
        } catch (Exception e) {
        // ignore;
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) File(java.io.File) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) 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