Search in sources :

Example 36 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testPersistence.

@Test
public void testPersistence() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install the system.bundle
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put("string", "sValue");
    attrs.put("string.list1", Arrays.asList("v1", "v2", "v3"));
    attrs.put("string.list2", Arrays.asList("v4", "v5", "v6"));
    attrs.put("version", Version.valueOf("1.1"));
    attrs.put("version.list", Arrays.asList(Version.valueOf("1.0"), Version.valueOf("2.0"), Version.valueOf("3.0")));
    attrs.put("long", Long.valueOf(12345));
    attrs.put("long.list", Arrays.asList(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3)));
    attrs.put("double", Double.valueOf(1.2345));
    attrs.put("double.list", Arrays.asList(Double.valueOf(1.1), Double.valueOf(1.2), Double.valueOf(1.3)));
    attrs.put("uri", "some.uri");
    attrs.put("set", Arrays.asList("s1", "s2", "s3"));
    // provider with all supported types
    Map<String, String> providerManifest = new HashMap<String, String>();
    providerManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    providerManifest.put(Constants.BUNDLE_SYMBOLICNAME, "provider");
    providerManifest.put(Constants.EXPORT_PACKAGE, "provider; version=1.1; attr1=attr1; attr2=attr2; dir1:=dir1; dir2:=dir2");
    providerManifest.put(Constants.PROVIDE_CAPABILITY, // 
    "provider.cap;" + // 
    " string=sValue;" + // 
    " string.list1:List=\"v1,v2,v3\";" + // 
    " string.list2:List<String>=\"v4,v5,v6\";" + // 
    " version:Version=1.1;" + // 
    " version.list:List<Version>=\"1.0,2.0,3.0\";" + // 
    " long:Long=12345;" + // 
    " long.list:List<Long>=\"1,2,3\";" + // 
    " double:Double=1.2345;" + // 
    " double.list:List<Double>=\"1.1,1.2,1.3\";" + // 
    " uri:uri=some.uri;" + " set:set=\"s1,s2,s3\"");
    Module providerModule = installDummyModule(providerManifest, "provider", container);
    Map<String, Object> providerAttrs = providerModule.getCurrentRevision().getCapabilities("provider.cap").get(0).getAttributes();
    assertEquals("Wrong provider attrs", attrs, providerAttrs);
    Map<String, String> requirerManifest = new HashMap<String, String>();
    requirerManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    requirerManifest.put(Constants.BUNDLE_SYMBOLICNAME, "requirer");
    requirerManifest.put(Constants.IMPORT_PACKAGE, "provider; version=1.1; attr1=attr1; attr2=attr2; dir1:=dir1; dir2:=dir2");
    requirerManifest.put(Constants.REQUIRE_CAPABILITY, // 
    "optional;" + // 
    " resolution:=optional; " + // 
    " string=sValue;" + // 
    " string.list1:List=\"v1,v2,v3\";" + // 
    " string.list2:List<String>=\"v4,v5,v6\";" + // 
    " version:Version=1.1;" + // 
    " version.list:List<Version>=\"1.0,2.0,3.0\";" + // 
    " long:Long=12345;" + // 
    " long.list:List<Long>=\"1,2,3\";" + // 
    " double:Double=1.2345;" + // 
    " double.list:List<Double>=\"1.1,1.2,1.3\";" + // 
    " uri:uri=some.uri;" + // 
    " set:set=\"s1,s2,s3\"," + // 
    "provider.cap; filter:=\"(string=sValue)\"," + // 
    "provider.cap; filter:=\"(string.list1=v2)\"," + // 
    "provider.cap; filter:=\"(string.list2=v5)\"," + // 
    "provider.cap; filter:=\"(string.list2=v5)\"," + // 
    "provider.cap; filter:=\"(&(version>=1.1)(version<=1.1.1))\"," + // 
    "provider.cap; filter:=\"(&(version.list=1)(version.list=2))\"," + // 
    "provider.cap; filter:=\"(long>=12344)\"," + // 
    "provider.cap; filter:=\"(long.list=2)\"," + // 
    "provider.cap; filter:=\"(double>=1.2)\"," + // 
    "provider.cap; filter:=\"(double.list=1.2)\"," + // 
    "provider.cap; filter:=\"(uri=some.uri)\"," + // 
    "provider.cap; filter:=\"(set=s2)\"" + "");
    Module requirerModule = installDummyModule(requirerManifest, "requirer", container);
    Map<String, Object> requirerAttrs = requirerModule.getCurrentRevision().getRequirements("optional").get(0).getAttributes();
    assertEquals("Wrong requirer attrs", attrs, requirerAttrs);
    ResolutionReport report = container.resolve(Collections.singleton(requirerModule), true);
    assertNull("Error resolving.", report.getResolutionException());
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(bytes);
    adaptor.getDatabase().store(data, true);
    // reload into a new container
    adaptor = createDummyAdaptor();
    container = adaptor.getContainer();
    adaptor.getDatabase().load(new DataInputStream(new ByteArrayInputStream(bytes.toByteArray())));
    providerModule = container.getModule("provider");
    providerAttrs = providerModule.getCurrentRevision().getCapabilities("provider.cap").get(0).getAttributes();
    assertEquals("Wrong provider attrs", attrs, providerAttrs);
    assertNotNull("No provider found.", providerModule);
    requirerModule = container.getModule("requirer");
    assertNotNull("No requirer found.", requirerModule);
    requirerAttrs = requirerModule.getCurrentRevision().getRequirements("optional").get(0).getAttributes();
    assertEquals("Wrong requirer attrs", attrs, requirerAttrs);
}
Also used : ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) DataInputStream(java.io.DataInputStream) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 37 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testMissingHost.

@Test
public void testMissingHost() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    Module f1v1 = installDummyModule("f1_v1.MF", "f1_v1", container);
    Module b3 = installDummyModule("b3_v1.MF", "b3_v1", container);
    ResolutionReport report = container.resolve(Arrays.asList(f1v1, b3), true);
    Assert.assertNotNull("Expected a resolution exception.", report.getResolutionException());
    Module h1v1 = installDummyModule("h1_v1.MF", "h1_v1", container);
    report = container.resolve(Arrays.asList(b3), true);
    Assert.assertNull("Expected no resolution exception.", report.getResolutionException());
    ModuleWiring wiring = b3.getCurrentRevision().getWiring();
    List<ModuleWire> packageWires = wiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Expected 1 import.", 1, packageWires.size());
    ModuleWire pkgWire = packageWires.get(0);
    Assert.assertEquals("Wrong host exporter.", pkgWire.getProviderWiring().getRevision(), h1v1.getCurrentRevision());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Example 38 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testModuleWiringToString.

@Test
public void testModuleWiringToString() throws BundleException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install a test module
    Map<String, String> testManifest = new HashMap<String, String>();
    testManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    testManifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.name");
    testManifest.put(Constants.BUNDLE_VERSION, "1.0");
    Module testModule = installDummyModule(testManifest, "host10", container);
    ResolutionReport report = container.resolve(Arrays.asList(testModule), true);
    Assert.assertNull("Failed to resolve test.", report.getResolutionException());
    ModuleRevision revision = testModule.getCurrentRevision();
    ModuleWiring wiring = revision.getWiring();
    Assert.assertEquals("Unexpected wiring.toString()", revision.toString(), wiring.toString());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) Test(org.junit.Test)

Example 39 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class SystemModule method init.

/**
 * Initializes the module container
 * @throws BundleException if an exeption occurred while initializing
 */
public final void init() throws BundleException {
    getRevisions().getContainer().checkAdminPermission(getBundle(), AdminPermission.EXECUTE);
    boolean lockedStarted = false;
    // Indicate we are in the middle of a start.
    // This must be incremented before we acquire the STARTED lock the first time.
    inStart.incrementAndGet();
    try {
        lockStateChange(ModuleEvent.STARTED);
        lockedStarted = true;
        getContainer().getAdaptor().initBegin();
        checkValid();
        if (ACTIVE_SET.contains(getState()))
            return;
        getRevisions().getContainer().open();
        if (getState().equals(State.INSTALLED)) {
            // must unlock to avoid out of order locks when multiple unresolved
            // bundles are started at the same time from different threads
            unlockStateChange(ModuleEvent.STARTED);
            lockedStarted = false;
            ResolutionReport report;
            try {
                report = getRevisions().getContainer().resolve(Arrays.asList((Module) this), true);
            } finally {
                lockStateChange(ModuleEvent.STARTED);
                lockedStarted = true;
            }
            // need to check valid again in case someone uninstalled the bundle
            checkValid();
            ResolutionException e = report.getResolutionException();
            if (e != null) {
                if (e.getCause() instanceof BundleException) {
                    throw (BundleException) e.getCause();
                }
            }
            if (ACTIVE_SET.contains(getState()))
                return;
            if (getState().equals(State.INSTALLED)) {
                String reportMessage = report.getResolutionReportMessage(getCurrentRevision());
                throw new BundleException(Msg.Module_ResolveError + reportMessage, BundleException.RESOLVE_ERROR);
            }
        }
        setState(State.STARTING);
        AtomicReference<ContainerEvent> existingForStop = forStop;
        if (existingForStop.get() != null) {
            // There was a previous launch, reset the reference forStop
            forStop = new AtomicReference<>();
        }
        publishEvent(ModuleEvent.STARTING);
        try {
            initWorker();
        } catch (Throwable t) {
            setState(State.STOPPING);
            publishEvent(ModuleEvent.STOPPING);
            setState(State.RESOLVED);
            publishEvent(ModuleEvent.STOPPED);
            getRevisions().getContainer().close();
            if (t instanceof BundleException) {
                throw (BundleException) t;
            }
            // $NON-NLS-1$
            throw new BundleException("Error initializing container.", BundleException.ACTIVATOR_ERROR, t);
        }
    } finally {
        getContainer().getAdaptor().initEnd();
        if (lockedStarted) {
            unlockStateChange(ModuleEvent.STARTED);
        }
        inStart.decrementAndGet();
    }
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) ContainerEvent(org.eclipse.osgi.container.ModuleContainerAdaptor.ContainerEvent) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport)

Example 40 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class EquinoxBundle method getModuleClassLoader.

private ModuleClassLoader getModuleClassLoader(boolean logResolveError) {
    ResolutionReport report = resolve();
    if (logResolveError && !Module.RESOLVED_SET.contains(module.getState())) {
        String reportMessage = report.getResolutionReportMessage(module.getCurrentRevision());
        equinoxContainer.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, this, new BundleException(reportMessage, BundleException.RESOLVE_ERROR));
    }
    return AccessController.doPrivileged(new PrivilegedAction<ModuleClassLoader>() {

        @Override
        public ModuleClassLoader run() {
            ModuleWiring wiring = getModule().getCurrentRevision().getWiring();
            if (wiring != null) {
                ModuleLoader moduleLoader = wiring.getModuleLoader();
                if (moduleLoader instanceof BundleLoader) {
                    return ((BundleLoader) moduleLoader).getModuleClassLoader();
                }
            }
            return null;
        }
    });
}
Also used : ModuleLoader(org.eclipse.osgi.container.ModuleLoader) ModuleClassLoader(org.eclipse.osgi.internal.loader.ModuleClassLoader) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) BundleException(org.osgi.framework.BundleException) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Aggregations

ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)42 Module (org.eclipse.osgi.container.Module)37 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)36 Test (org.junit.Test)33 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)23 HashMap (java.util.HashMap)22 ModuleWire (org.eclipse.osgi.container.ModuleWire)13 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)6 ArrayList (java.util.ArrayList)4 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)4 BundleException (org.osgi.framework.BundleException)3 HashSet (java.util.HashSet)2 ExecutorService (java.util.concurrent.ExecutorService)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)2 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)2 DummyContainerEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent)2 BundleCapability (org.osgi.framework.wiring.BundleCapability)2 ResolutionException (org.osgi.service.resolver.ResolutionException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1