Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 164433 Details for
Bug 308650
[DI] Requestors pick up extra dependencies during updates
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch
patch DI 10.txt (text/plain), 20.59 KB, created by
Oleg Besedin
on 2010-04-09 16:56:24 EDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Oleg Besedin
Created:
2010-04-09 16:56:24 EDT
Size:
20.59 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.e4.core.contexts >Index: src/org/eclipse/e4/core/internal/contexts/ContextObjectSupplier.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/ContextObjectSupplier.java,v >retrieving revision 1.5 >diff -u -r1.5 ContextObjectSupplier.java >--- src/org/eclipse/e4/core/internal/contexts/ContextObjectSupplier.java 9 Apr 2010 14:18:15 -0000 1.5 >+++ src/org/eclipse/e4/core/internal/contexts/ContextObjectSupplier.java 9 Apr 2010 20:55:02 -0000 >@@ -10,6 +10,8 @@ > *******************************************************************************/ > package org.eclipse.e4.core.internal.contexts; > >+import java.lang.reflect.InvocationTargetException; >+ > import javax.inject.Named; > > import org.eclipse.e4.core.contexts.ContextChangeEvent; >@@ -19,6 +21,7 @@ > import org.eclipse.e4.core.di.IInjector; > import org.eclipse.e4.core.di.IObjectDescriptor; > import org.eclipse.e4.core.di.IRequestor; >+import org.eclipse.e4.core.di.InjectionException; > > public class ContextObjectSupplier extends AbstractObjectSupplier { > >@@ -36,7 +39,7 @@ > this.context = context; > } > >- public boolean notify(ContextChangeEvent event) { >+ public boolean notify(ContextChangeEvent event, final IContextRecorder recorder) { > if (event.getEventType() == ContextChangeEvent.INITIAL) { > // needs to be done inside runnable to establish dependencies > for (int i = 0; i < keys.length; i++) { >@@ -50,7 +53,7 @@ > } > return true; > } >- >+ > IInjector injector = requestor.getInjector(); > if (event.getEventType() == ContextChangeEvent.DISPOSE) { > IEclipseContext originatingContext = event.getContext(); >@@ -67,10 +70,35 @@ > return false; > } > } else { >- injector.update(new IRequestor[] { requestor }, requestor.getPrimarySupplier()); >+ boolean resolved = injector.resolveArguments(requestor, requestor.getPrimarySupplier()); >+ if (resolved) { >+ if (recorder != null) >+ recorder.stopAccessRecording(); >+ >+ try { >+ requestor.execute(); >+ } catch (InvocationTargetException e) { >+ logError("Injection failed for the object \"" >+ + requestor.getRequestingObject().toString() + "\". Unable to execute \"" >+ + requestor.toString() + "\""); >+ return false; >+ } catch (InstantiationException e) { >+ logError("Injection failed for the object \"" >+ + requestor.getRequestingObject().toString() + "\". Unable to execute \"" >+ + requestor.toString() + "\""); >+ return false; >+ } finally { >+ if (recorder != null) >+ recorder.startAcessRecording(); >+ } >+ } > } > return true; > } >+ >+ public boolean notify(ContextChangeEvent event) { >+ return notify(event, null); >+ } > > @Override > public int hashCode() { >@@ -103,15 +131,10 @@ > return true; > } > >- public Object getObject() { >- // XXX remove? >- // TODO Auto-generated method stub >- return null; >- } >- > public boolean batchProcess() { > return requestor.shouldGroupUpdates(); > } >+ > } > > final static private String ECLIPSE_CONTEXT_NAME = IEclipseContext.class.getName(); >@@ -186,5 +209,16 @@ > context.set(key, objectSupplier); > return objectSupplier; > } >+ // TBD implement logging >+ static protected void logError(String msg) { >+ logError(msg, new InjectionException()); >+ } >+ >+ static protected void logError(String msg, Throwable e) { >+ if (msg != null) >+ System.err.println(msg); >+ if (e != null) >+ e.printStackTrace(); >+ } > > } >Index: src/org/eclipse/e4/core/internal/contexts/EclipseContext.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/EclipseContext.java,v >retrieving revision 1.1 >diff -u -r1.1 EclipseContext.java >--- src/org/eclipse/e4/core/internal/contexts/EclipseContext.java 5 Apr 2010 19:53:04 -0000 1.1 >+++ src/org/eclipse/e4/core/internal/contexts/EclipseContext.java 9 Apr 2010 20:55:02 -0000 >@@ -85,7 +85,7 @@ > } > } > >- static class TrackableComputationExt extends Computation implements IRunAndTrack { >+ static class TrackableComputationExt extends Computation implements IRunAndTrack, IContextRecorder { > > private ContextChangeEvent cachedEvent; > >@@ -125,12 +125,6 @@ > this.runnable = runnable; > } > >- public Object getObject() { >- if (runnable instanceof IRunAndTrackObject) >- return ((IRunAndTrackObject) runnable).getObject(); >- return null; >- } >- > final protected void doHandleInvalid(ContextChangeEvent event, List<Scheduled> scheduledList) { > int eventType = event.getEventType(); > if (eventType == ContextChangeEvent.INITIAL || eventType == ContextChangeEvent.DISPOSE) { >@@ -153,7 +147,6 @@ > cachedEvent = event; > EclipseContext eventsContext = (EclipseContext) event.getContext(); > eventsContext.addWaiting(this); >- // eventsContext.getRoot().waiting.add(this); > return true; > } > } >@@ -162,11 +155,18 @@ > boolean result = true; > try { > if (cachedEvent != null) { >- result = runnable.notify(cachedEvent); >+ if (runnable instanceof IRunAndTrackObject) >+ result = ((IRunAndTrackObject)runnable).notify(event, this); >+ else >+ result = runnable.notify(cachedEvent); > cachedEvent = null; > } >- if (eventType != ContextChangeEvent.UPDATE) >- result = runnable.notify(event); >+ if (eventType != ContextChangeEvent.UPDATE) { >+ if (runnable instanceof IRunAndTrackObject) >+ result = ((IRunAndTrackObject)runnable).notify(event, this); >+ else >+ result = runnable.notify(event); >+ } > } finally { > currentComputation.set(oldComputation); > } >@@ -181,6 +181,14 @@ > public String toString() { > return "TrackableComputationExt(" + runnable + ')'; //$NON-NLS-1$ > } >+ >+ public void startAcessRecording() { >+ currentComputation.set(this); >+ } >+ >+ public void stopAccessRecording() { >+ currentComputation.set(null); >+ } > } > > static class Scheduled { >Index: src/org/eclipse/e4/core/internal/contexts/IContextRecorder.java >=================================================================== >RCS file: src/org/eclipse/e4/core/internal/contexts/IContextRecorder.java >diff -N src/org/eclipse/e4/core/internal/contexts/IContextRecorder.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/core/internal/contexts/IContextRecorder.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,20 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.e4.core.internal.contexts; >+ >+ >+public interface IContextRecorder { >+ >+ public void startAcessRecording(); >+ >+ public void stopAccessRecording(); >+} >Index: src/org/eclipse/e4/core/internal/contexts/IRunAndTrackObject.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.contexts/src/org/eclipse/e4/core/internal/contexts/IRunAndTrackObject.java,v >retrieving revision 1.1 >diff -u -r1.1 IRunAndTrackObject.java >--- src/org/eclipse/e4/core/internal/contexts/IRunAndTrackObject.java 5 Apr 2010 19:53:04 -0000 1.1 >+++ src/org/eclipse/e4/core/internal/contexts/IRunAndTrackObject.java 9 Apr 2010 20:55:03 -0000 >@@ -11,12 +11,13 @@ > > package org.eclipse.e4.core.internal.contexts; > >+import org.eclipse.e4.core.contexts.ContextChangeEvent; > import org.eclipse.e4.core.contexts.IRunAndTrack; > > public interface IRunAndTrackObject extends IRunAndTrack { > >- public Object getObject(); >- > public boolean batchProcess(); >+ >+ public boolean notify(ContextChangeEvent event, IContextRecorder recorder); > > } >#P org.eclipse.e4.core.di >Index: src/org/eclipse/e4/core/di/IInjector.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/di/IInjector.java,v >retrieving revision 1.1 >diff -u -r1.1 IInjector.java >--- src/org/eclipse/e4/core/di/IInjector.java 5 Apr 2010 19:51:26 -0000 1.1 >+++ src/org/eclipse/e4/core/di/IInjector.java 9 Apr 2010 20:55:04 -0000 >@@ -42,12 +42,11 @@ > > public boolean injectStatic(Class<?> clazz, AbstractObjectSupplier objectSupplier); > >- public boolean update(IRequestor[] requestors, AbstractObjectSupplier objectSupplier); >- > public boolean disposed(AbstractObjectSupplier objectSupplier); > > public IBinding addBinding(Class<?> clazz); > > public IBinding addBinding(IBinding binding); > >+ public boolean resolveArguments(IRequestor requestor, AbstractObjectSupplier objectSupplier); > } >Index: src/org/eclipse/e4/core/di/IRequestor.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/di/IRequestor.java,v >retrieving revision 1.2 >diff -u -r1.2 IRequestor.java >--- src/org/eclipse/e4/core/di/IRequestor.java 7 Apr 2010 19:54:52 -0000 1.2 >+++ src/org/eclipse/e4/core/di/IRequestor.java 9 Apr 2010 20:55:04 -0000 >@@ -10,6 +10,8 @@ > *******************************************************************************/ > package org.eclipse.e4.core.di; > >+import java.lang.reflect.InvocationTargetException; >+ > // TBD this is really a "feedback" object. > /** > * @noimplement This interface is not intended to be implemented by clients. >@@ -31,4 +33,5 @@ > > public boolean shouldGroupUpdates(); > >+ public abstract Object execute() throws InvocationTargetException, InstantiationException; > } >Index: src/org/eclipse/e4/core/internal/di/InjectorImpl.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/InjectorImpl.java,v >retrieving revision 1.2 >diff -u -r1.2 InjectorImpl.java >--- src/org/eclipse/e4/core/internal/di/InjectorImpl.java 7 Apr 2010 19:54:51 -0000 1.2 >+++ src/org/eclipse/e4/core/internal/di/InjectorImpl.java 9 Apr 2010 20:55:04 -0000 >@@ -347,29 +347,10 @@ > return true; > } > >- public boolean update(IRequestor[] requestors, AbstractObjectSupplier objectSupplier) { >- ArrayList<Requestor> list = new ArrayList<Requestor>(requestors.length); >- for (IRequestor requestor : requestors) { >- list.add((Requestor) requestor); >- } >+ public boolean resolveArguments(IRequestor requestor, AbstractObjectSupplier objectSupplier) { >+ ArrayList<Requestor> list = new ArrayList<Requestor>(1); >+ list.add((Requestor)requestor); > resolveRequestorArgs(list, objectSupplier, true); >- >- // Call requestors in order >- for (IRequestor requestor : requestors) { >- try { >- ((Requestor) requestor).execute(); >- } catch (InvocationTargetException e) { >- logError("Injection failed for the object \"" >- + requestor.getRequestingObject().toString() + "\". Unable to execute \"" >- + requestor.toString() + "\""); >- return false; >- } catch (InstantiationException e) { >- logError("Injection failed for the object \"" >- + requestor.getRequestingObject().toString() + "\". Unable to execute \"" >- + requestor.toString() + "\""); >- return false; >- } >- } > return true; > } > >Index: src/org/eclipse/e4/core/internal/di/Requestor.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/Requestor.java,v >retrieving revision 1.2 >diff -u -r1.2 Requestor.java >--- src/org/eclipse/e4/core/internal/di/Requestor.java 7 Apr 2010 19:54:51 -0000 1.2 >+++ src/org/eclipse/e4/core/internal/di/Requestor.java 9 Apr 2010 20:55:04 -0000 >@@ -11,7 +11,6 @@ > package org.eclipse.e4.core.internal.di; > > import java.lang.ref.WeakReference; >-import java.lang.reflect.InvocationTargetException; > > import org.eclipse.e4.core.di.AbstractObjectSupplier; > import org.eclipse.e4.core.di.IInjector; >@@ -39,8 +38,6 @@ > > public abstract IObjectDescriptor[] getDependentObjects(); > >- public abstract Object execute() throws InvocationTargetException, InstantiationException; >- > public Requestor(IInjector injector, AbstractObjectSupplier primarySupplier, Object requestingObject, boolean track, boolean groupUpdates, > boolean isOptional) { > this.injector = injector; >#P org.eclipse.e4.core.di.extensions >Index: src/org/eclipse/e4/core/di/internal/extensions/PreferencesObjectSupplier.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.core.di.extensions/src/org/eclipse/e4/core/di/internal/extensions/PreferencesObjectSupplier.java,v >retrieving revision 1.1 >diff -u -r1.1 PreferencesObjectSupplier.java >--- src/org/eclipse/e4/core/di/internal/extensions/PreferencesObjectSupplier.java 7 Apr 2010 19:47:40 -0000 1.1 >+++ src/org/eclipse/e4/core/di/internal/extensions/PreferencesObjectSupplier.java 9 Apr 2010 20:55:05 -0000 >@@ -10,6 +10,7 @@ > *******************************************************************************/ > package org.eclipse.e4.core.di.internal.extensions; > >+import java.lang.reflect.InvocationTargetException; > import java.util.ArrayList; > import java.util.HashMap; > import java.util.List; >@@ -23,6 +24,7 @@ > import org.eclipse.e4.core.di.IInjector; > import org.eclipse.e4.core.di.IObjectDescriptor; > import org.eclipse.e4.core.di.IRequestor; >+import org.eclipse.e4.core.di.InjectionException; > import org.eclipse.e4.core.di.extensions.Preferences; > import org.osgi.framework.FrameworkUtil; > >@@ -98,9 +100,25 @@ > node.addPreferenceChangeListener(new IPreferenceChangeListener() { > public void preferenceChange(PreferenceChangeEvent event) { > IInjector requestorInjector = requestor.getInjector(); >- if (requestorInjector != null) >- requestorInjector.update(new IRequestor[] { requestor }, requestor >+ if (requestorInjector != null) { >+ boolean resolved = requestorInjector.resolveArguments(requestor, requestor > .getPrimarySupplier()); >+ if (resolved) { >+ try { >+ requestor.execute(); >+ } catch (InvocationTargetException e) { >+ logError("Injection failed for the object \"" >+ + requestor.getRequestingObject().toString() >+ + "\". Unable to execute \"" + requestor.toString() + "\""); >+ return; >+ } catch (InstantiationException e) { >+ logError("Injection failed for the object \"" >+ + requestor.getRequestingObject().toString() >+ + "\". Unable to execute \"" + requestor.toString() + "\""); >+ return; >+ } >+ } >+ } > } > }); > synchronized (listenerCache) { >@@ -114,4 +132,16 @@ > } > } > >+ // TBD implement logging >+ static protected void logError(String msg) { >+ logError(msg, new InjectionException()); >+ } >+ >+ static protected void logError(String msg, Throwable e) { >+ if (msg != null) >+ System.err.println(msg); >+ if (e != null) >+ e.printStackTrace(); >+ } >+ > } >#P org.eclipse.e4.core.tests.services.annotations >Index: src/org/eclipse/e4/core/tests/services/internal/annotations/ExtraDependenciesTest.java >=================================================================== >RCS file: src/org/eclipse/e4/core/tests/services/internal/annotations/ExtraDependenciesTest.java >diff -N src/org/eclipse/e4/core/tests/services/internal/annotations/ExtraDependenciesTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/core/tests/services/internal/annotations/ExtraDependenciesTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,105 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.e4.core.tests.services.internal.annotations; >+ >+import java.lang.reflect.InvocationTargetException; >+ >+import javax.inject.Inject; >+import javax.inject.Named; >+ >+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.IDisposable; >+import org.eclipse.e4.core.di.annotations.PreDestroy; >+ >+public class ExtraDependenciesTest extends TestCase { >+ >+ static public class TestObject { >+ >+ public String string; >+ public Integer integer; >+ public String other; >+ >+ public boolean disposed = false; >+ >+ @Inject >+ public void injectedMethod(@Named("arg1") String strValue, @Named("arg2") Integer intValue, IEclipseContext context) { >+ string = strValue; >+ integer = intValue; >+ if (context == null) { >+ other = null; >+ return; >+ } >+ IEclipseContext otherContext = (IEclipseContext) context.get("otherContext"); >+ if (otherContext == null) >+ other = null; >+ else >+ other = (String) otherContext.get("arg3"); >+ } >+ >+ @PreDestroy >+ public void finita() { >+ disposed = true; >+ } >+ } >+ >+ public void testExtraDependencies() throws InvocationTargetException, InstantiationException { >+ IEclipseContext context = EclipseContextFactory.create(); >+ context.set("arg1", "abc"); >+ context.set("arg2", new Integer (123)); >+ >+ IEclipseContext otherContext = EclipseContextFactory.create(); >+ otherContext.set("arg3", "other"); >+ >+ context.set("otherContext", otherContext); >+ >+ TestObject object = (TestObject) ContextInjectionFactory.make(TestObject.class, context); >+ >+ // check that initial values are properly injected >+ assertEquals("abc", object.string); >+ assertEquals(new Integer(123), object.integer); >+ assertEquals("other", object.other); >+ >+ // modify argument value to cause update - bug 308650 >+ context.set("arg2", new Integer (789)); >+ >+ // change the "other" value; should not be propagated >+ otherContext.set("arg3", "wrong"); >+ assertEquals("other", object.other); >+ >+ // dispose the other context; should not cause disposal of the test object >+ ((IDisposable)otherContext).dispose(); >+ assertEquals("other", object.other); >+ assertFalse(object.disposed); >+ >+ // remove "other" context, should not be propagated >+ context.remove("otherContext"); >+ assertEquals("other", object.other); >+ >+ // check that changes in the method arguments are propagated >+ context.set("arg1", "xyz"); >+ context.set("arg2", new Integer (456)); >+ assertEquals("xyz", object.string); >+ assertEquals(new Integer(456), object.integer); >+ assertNull(object.other); >+ >+ // check that disposal of the injected context causes disposal of the injected object >+ ((IDisposable)context).dispose(); >+ assertTrue(object.disposed); >+ assertNull(object.string); >+ assertNull(object.integer); >+ assertNull(object.other); >+ } >+ >+} >Index: src/org/eclipse/e4/core/tests/services/internal/annotations/ServicesTestSuiteAnnotations.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/tests/org.eclipse.e4.core.tests.services.annotations/src/org/eclipse/e4/core/tests/services/internal/annotations/ServicesTestSuiteAnnotations.java,v >retrieving revision 1.7 >diff -u -r1.7 ServicesTestSuiteAnnotations.java >--- src/org/eclipse/e4/core/tests/services/internal/annotations/ServicesTestSuiteAnnotations.java 24 Mar 2010 19:09:32 -0000 1.7 >+++ src/org/eclipse/e4/core/tests/services/internal/annotations/ServicesTestSuiteAnnotations.java 9 Apr 2010 20:55:05 -0000 >@@ -29,5 +29,6 @@ > addTestSuite(InjectionOrderTest.class); > addTestSuite(GroupedUpdatesTest.class); > addTestSuite(Bug304585Test.class); >+ addTestSuite(ExtraDependenciesTest.class); > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 308650
:
164389
| 164433