aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Alexander Kuppe2014-02-12 16:23:11 (EST)
committerGerrit Code Review @ Eclipse.org2014-02-13 10:51:30 (EST)
commit39d2772b91c00fe6c6d7dbccf135a2fd20bde60b (patch)
tree2bd9bb17ea7effe5275755ba5e0fe426ca08d446
parent9325979864ea67e22b04613ead3d5a8d6cc49da7 (diff)
downloadeclipse.platform.runtime-39d2772b91c00fe6c6d7dbccf135a2fd20bde60b.zip
eclipse.platform.runtime-39d2772b91c00fe6c6d7dbccf135a2fd20bde60b.tar.gz
eclipse.platform.runtime-39d2772b91c00fe6c6d7dbccf135a2fd20bde60b.tar.bz2
Bug 427731: Using @OSGiBundle in @Execute throwsrefs/changes/17/21917/2
IllegalArgumentException Bug-URL: https://bugs.eclipse.org/bugs/show_bug.cgi?id=427731 Change-Id: Iaf18b0ed6e54b52259a430b367aece5f765d3f53 Signed-off-by: Markus Alexander Kuppe <bugs.eclipse.org@lemmster.de>
-rw-r--r--bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/OSGiObjectSupplier.java5
-rw-r--r--tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiHandlerTest.java61
-rw-r--r--tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/tests/CoreTestSuite.java2
3 files changed, 67 insertions, 1 deletions
diff --git a/bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/OSGiObjectSupplier.java b/bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/OSGiObjectSupplier.java
index cde905c..b584622 100644
--- a/bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/OSGiObjectSupplier.java
+++ b/bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/OSGiObjectSupplier.java
@@ -42,11 +42,14 @@ public class OSGiObjectSupplier extends ExtendedObjectSupplier {
final Bundle bundle = FrameworkUtil.getBundle(requestingObjectClass);
// Cannot use BundleListener as a BL can only be registered with a BC (which might be null)
+ // Iff track is request and there is no listener yet, lets track the bundle
if (track) {
if (!requestor2listener.containsKey(requestor)) {
track(bundle, requestor);
}
- } else {
+ // Handlers only executed once and thus don't track the BC/Bundle.
+ // Still guard to now de-register a non-existing listener.
+ } else if (requestor2listener.containsKey(requestor)) {
untrack(requestor);
}
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiHandlerTest.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiHandlerTest.java
new file mode 100644
index 0000000..e0de6c4
--- /dev/null
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/InjectionOSGiHandlerTest.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Markus Alexander Kuppe and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Alexander Kuppe - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.core.internal.tests.di.extensions;
+
+import junit.framework.TestCase;
+
+import org.eclipse.e4.core.contexts.ContextInjectionFactory;
+import org.eclipse.e4.core.contexts.EclipseContextFactory;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.core.di.extensions.OSGiBundle;
+import org.eclipse.e4.core.internal.tests.CoreTestsActivator;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+
+public class InjectionOSGiHandlerTest extends TestCase {
+
+ public static class TestHandler {
+
+ private BundleContext ctx;
+
+ @Execute
+ public void execute(@OSGiBundle BundleContext ctx) {
+ this.ctx = ctx;
+ }
+
+ public BundleContext getCtx() {
+ return ctx;
+ }
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void testInjectBCinExecute() {
+
+ final BundleContext bundleContext = CoreTestsActivator
+ .getDefault().getBundleContext();
+ final IEclipseContext localContext = EclipseContextFactory
+ .getServiceContext(bundleContext);
+
+ TestHandler handler = new TestHandler();
+ ContextInjectionFactory.invoke(handler, Execute.class, localContext);
+
+ assertNotNull(handler.getCtx());
+ }
+
+}
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/tests/CoreTestSuite.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/tests/CoreTestSuite.java
index 8eb6be1..09db39b 100644
--- a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/tests/CoreTestSuite.java
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/tests/CoreTestSuite.java
@@ -51,6 +51,7 @@ import org.eclipse.e4.core.internal.tests.di.RecursiveObjectCreationTest;
import org.eclipse.e4.core.internal.tests.di.extensions.ExtendedSupplierInjectionTests;
import org.eclipse.e4.core.internal.tests.di.extensions.InjectionEventTest;
import org.eclipse.e4.core.internal.tests.di.extensions.InjectionMixedSuppliersTest;
+import org.eclipse.e4.core.internal.tests.di.extensions.InjectionOSGiHandlerTest;
import org.eclipse.e4.core.internal.tests.di.extensions.InjectionOSGiTest;
import org.eclipse.e4.core.internal.tests.di.extensions.InjectionPreferencesTest;
import org.eclipse.e4.core.internal.tests.nls.NLSTest;
@@ -66,6 +67,7 @@ public class CoreTestSuite extends TestSuite {
addTestSuite(InjectionMixedSuppliersTest.class);
addTestSuite(InjectionEventTest.class);
addTestSuite(InjectionOSGiTest.class);
+ addTestSuite(InjectionOSGiHandlerTest.class);
// DI
addTestSuite(InjectionOrderTest.class);