Search in sources :

Example 96 with Equinox

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

the class MultiReleaseJarTests method doTestMultiReleaseBundleManifest.

private void doTestMultiReleaseBundleManifest(int rv) throws Exception {
    if (rv < 9) {
        System.setProperty("java.specification.version", "1." + rv);
    } else {
        System.setProperty("java.specification.version", Integer.toString(rv));
    }
    String expectedCap;
    String expectedPkg;
    if (rv < 9) {
        expectedCap = "capbase";
        expectedPkg = "pkgbase";
    } else {
        expectedCap = "cap" + rv;
        expectedPkg = "pkg" + 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();
        List<BundleWire> capWires = mrBundle.adapt(BundleWiring.class).getRequiredWires(expectedCap);
        assertEquals("Wrong number of capability wires.", 1, capWires.size());
        List<BundleRequirement> pkgReqs = mrBundle.adapt(BundleRevision.class).getDeclaredRequirements(PackageNamespace.PACKAGE_NAMESPACE);
        assertEquals("Wrong number of package requiremens.", 1, pkgReqs.size());
        String filter = pkgReqs.get(0).getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
        assertTrue("Wrong package filter: " + filter, filter.contains(expectedPkg));
    } finally {
        try {
            equinox.stop();
            equinox.waitForStop(10000);
        } catch (Exception e) {
        // ignore;
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleRevision(org.osgi.framework.wiring.BundleRevision) File(java.io.File) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BundleContext(org.osgi.framework.BundleContext)

Example 97 with Equinox

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

the class MultiReleaseJarTests method testMultiReleaseBundleManifestChangeRuntime.

public void testMultiReleaseBundleManifestChangeRuntime() throws Exception {
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, String> configMap = Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath() + " with space");
    Equinox equinox = new Equinox(configMap);
    String location;
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle mrBundle = systemContext.installBundle(mrJarBundle.toURI().toString());
        location = mrBundle.getLocation();
        mrBundle.start();
    } finally {
        equinox.stop();
        equinox.waitForStop(1000);
    }
    for (int rv = 8; rv <= 11; rv++) {
        doTestMultiReleaseBundleManifestChangeRuntime(rv, configMap, location);
    }
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle toUninstall = systemContext.getBundle(location);
        toUninstall.uninstall();
        Bundle mrBundle = systemContext.installBundle("reference:" + mrJarBundle.toURI().toString());
        location = mrBundle.getLocation();
        mrBundle.start();
    } finally {
        equinox.stop();
        equinox.waitForStop(1000);
    }
    for (int rv = 8; rv <= 11; rv++) {
        doTestMultiReleaseBundleManifestChangeRuntime(rv, configMap, location);
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 98 with Equinox

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

the class MultiReleaseJarTests method doTestMultiReleaseGetResource.

private void doTestMultiReleaseGetResource(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 resource.", "RESOURCE XX", readResource("multi/release/test/testResourceBase.txt", mrBundle));
        assertEquals("Wrong resource.", "RESOURCE XX", readResource("multi/release/test/testResource8.txt", mrBundle));
        assertEquals("Wrong resource.", RNF, readResource("multi/release/test/testResourceAdd8.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "RESOURCE 09" : "RESOURCE XX", readResource("multi/release/test/testResource9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "ADD 09" : RNF, readResource("multi/release/test/testResourceAdd9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "RESOURCE 10" : "RESOURCE XX", readResource("multi/release/test/testResource10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "ADD 10" : RNF, readResource("multi/release/test/testResourceAdd10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "RESOURCE 11" : "RESOURCE XX", readResource("multi/release/test/testResource11.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResource("multi/release/test/testResourceAdd11.txt", mrBundle));
        assertEquals("Wrong resource.", "RESOURCE XX", readResource("multi/release/test/sub/testResourceBase.txt", mrBundle));
        assertEquals("Wrong resource.", "RESOURCE XX", readResource("multi/release/test/sub/testResource8.txt", mrBundle));
        assertEquals("Wrong resource.", RNF, readResource("multi/release/test/testResourceAdd8.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "RESOURCE 09" : "RESOURCE XX", readResource("multi/release/test/sub/testResource9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "ADD 09" : RNF, readResource("multi/release/test/sub/testResourceAdd9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "RESOURCE 10" : "RESOURCE XX", readResource("multi/release/test/sub/testResource10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "ADD 10" : RNF, readResource("multi/release/test/sub/testResourceAdd10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "RESOURCE 11" : "RESOURCE XX", readResource("multi/release/test/sub/testResource11.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResource("multi/release/test/sub/testResourceAdd11.txt", mrBundle));
        assertEquals("Wrong resource.", "RESOURCE XX", readResource("multi/release/test/sub2/testResourceBase.txt", mrBundle));
        assertEquals("Wrong resource.", "RESOURCE XX", readResource("multi/release/test/sub2/testResource8.txt", mrBundle));
        assertEquals("Wrong resource.", RNF, readResource("multi/release/test/testResourceAdd8.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "RESOURCE 09" : "RESOURCE XX", readResource("multi/release/test/sub2/testResource9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 9) ? "ADD 09" : RNF, readResource("multi/release/test/sub2/testResourceAdd9.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "RESOURCE 10" : "RESOURCE XX", readResource("multi/release/test/sub2/testResource10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 10) ? "ADD 10" : RNF, readResource("multi/release/test/sub2/testResourceAdd10.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "RESOURCE 11" : "RESOURCE XX", readResource("multi/release/test/sub2/testResource11.txt", mrBundle));
        assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResource("multi/release/test/sub2/testResourceAdd11.txt", mrBundle));
    } 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)

Example 99 with Equinox

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

the class MultiReleaseJarTests method testMultiReleasePreventMetaInfResourceURLs.

public void testMultiReleasePreventMetaInfResourceURLs() throws Exception {
    System.setProperty("java.specification.version", "9");
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, String> configMap = Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configMap);
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle mrBundle = systemContext.installBundle("reference:" + mrJarBundle.toURI().toString());
        mrBundle.start();
        URL existingResource = mrBundle.getResource("multi/release/test/testResourceAdd9.txt");
        assertNotNull("Did not find Java 9 added resource.", existingResource);
        URL metaInfResource = new URL(existingResource, "/META-INF/addedFor9.txt");
        try {
            metaInfResource.openStream().close();
            fail("Expected error opening versioned META-INF resource.");
        } catch (IOException e) {
        // expected
        }
    } finally {
        equinox.stop();
        equinox.waitForStop(1000);
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) BundleContext(org.osgi.framework.BundleContext)

Example 100 with Equinox

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

the class MultiReleaseJarTests method doTestMultiReleaseBundleManifestChangeRuntime.

private void doTestMultiReleaseBundleManifestChangeRuntime(int rv, Map<String, String> configMap, String location) throws BundleException {
    if (rv < 9) {
        System.setProperty("java.specification.version", "1." + rv);
    } else {
        System.setProperty("java.specification.version", Integer.toString(rv));
    }
    String expectedCap;
    String expectedPkg;
    if (rv < 9) {
        expectedCap = "capbase";
        expectedPkg = "pkgbase";
    } else {
        expectedCap = "cap" + rv;
        expectedPkg = "pkg" + rv;
    }
    Equinox equinox = new Equinox(configMap);
    try {
        equinox.start();
        BundleContext systemContext = equinox.getBundleContext();
        Bundle mrBundle = systemContext.getBundle(location);
        assertNotNull("No mrBundle found: " + rv, mrBundle);
        assertEquals("Wrong state of mrBundle: " + rv, Bundle.ACTIVE, mrBundle.getState());
        List<BundleWire> capWires = mrBundle.adapt(BundleWiring.class).getRequiredWires(expectedCap);
        assertEquals("Wrong number of capability wires: " + rv, 1, capWires.size());
        List<BundleRequirement> pkgReqs = mrBundle.adapt(BundleRevision.class).getDeclaredRequirements(PackageNamespace.PACKAGE_NAMESPACE);
        assertEquals("Wrong number of package requiremens: " + rv, 1, pkgReqs.size());
        String filter = pkgReqs.get(0).getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
        assertTrue("Wrong package filter: " + rv + " " + filter, filter.contains(expectedPkg));
    } finally {
        try {
            equinox.stop();
            equinox.waitForStop(10000);
        } catch (Exception e) {
        // ignore;
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) 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